From a71bb172b746bb0b24d81447fdcef2b8a314454a Mon Sep 17 00:00:00 2001 From: pcoleman Date: Mon, 19 Aug 2024 11:50:21 +0100 Subject: [PATCH 01/45] Add checks for correct DEM feature map for test --- src/python_testing/TC_DEMTestBase.py | 28 ++++++++++++++++++++++++++++ src/python_testing/TC_DEM_2_2.py | 2 ++ src/python_testing/TC_DEM_2_3.py | 5 ++++- src/python_testing/TC_DEM_2_4.py | 5 ++++- src/python_testing/TC_DEM_2_5.py | 6 +++++- src/python_testing/TC_DEM_2_6.py | 4 ++++ src/python_testing/TC_DEM_2_7.py | 4 ++++ src/python_testing/TC_DEM_2_8.py | 4 ++++ src/python_testing/TC_DEM_2_9.py | 4 +++- 9 files changed, 58 insertions(+), 4 deletions(-) diff --git a/src/python_testing/TC_DEMTestBase.py b/src/python_testing/TC_DEMTestBase.py index db53c36f8cd1c9..dedeac95b8f595 100644 --- a/src/python_testing/TC_DEMTestBase.py +++ b/src/python_testing/TC_DEMTestBase.py @@ -24,6 +24,14 @@ logger = logging.getLogger(__name__) +s_feature_strs = {Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerAdjustment: "kPowerAdjustment", + Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerForecastReporting: "kPowerForecastReporting", + Clusters.DeviceEnergyManagement.Bitmaps.Feature.kStateForecastReporting: "kStateForecastReporting", + Clusters.DeviceEnergyManagement.Bitmaps.Feature.kStartTimeAdjustment: "kStartTimeAdjustment", + Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPausable: "kPausable", + Clusters.DeviceEnergyManagement.Bitmaps.Feature.kForecastAdjustment: "kForecastAdjustment", + Clusters.DeviceEnergyManagement.Bitmaps.Feature.kConstraintBasedAdjustment: "kConstraintBasedAdjustment"} + class DEMTestBase: @@ -38,6 +46,26 @@ async def check_dem_attribute(self, attribute, expected_value, endpoint: int = N asserts.assert_equal(value, expected_value, f"Unexpected '{attribute}' value - expected {expected_value}, was {value}") + async def validate_feature_map(self, must_have_features, must_not_have_features): + feature_map = await self.read_dem_attribute_expect_success(attribute="FeatureMap") + for must_have_feature in must_have_features: + asserts.assert_true(feature_map & must_have_feature, + f"{s_feature_strs[must_have_feature]} must be set but is not. feature_map 0x{feature_map:x}") + + for must_not_have_feature in must_not_have_features: + asserts.assert_false(feature_map & must_not_have_feature, + f"{s_feature_strs[must_not_have_feature]} is not allowed to be set. feature_map 0x{feature_map:x}") + + async def validate_pfr_or_sfr_in_feature_map(self): + feature_map = await self.read_dem_attribute_expect_success(attribute="FeatureMap") + + illegal_combination = Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerForecastReporting | Clusters.DeviceEnergyManagement.Bitmaps.Feature.kStateForecastReporting + asserts.assert_not_equal(feature_map & illegal_combination, illegal_combination, + f"Cannot have kPowerForecastReporting and kStateForecastReporting both set. feature_map 0x{feature_map:x}") + + asserts.assert_not_equal(feature_map & illegal_combination, 0, + f"Must have one of kPowerForecastReporting and kStateForecastReporting set. feature_map 0x{feature_map:x}") + async def send_power_adjustment_command(self, power: int, duration: int, cause: Clusters.Objects.DeviceEnergyManagement.Enums.CauseEnum, endpoint: int = None, timedRequestTimeoutMs: int = 3000, diff --git a/src/python_testing/TC_DEM_2_2.py b/src/python_testing/TC_DEM_2_2.py index 0c32992d934174..710e8552fe6b8e 100644 --- a/src/python_testing/TC_DEM_2_2.py +++ b/src/python_testing/TC_DEM_2_2.py @@ -155,6 +155,8 @@ async def test_TC_DEM_2_2(self): self.step("1") # Commission DUT - already done + await self.validate_feature_map([Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerAdjustment], []) + # Subscribe to Events and when they are sent push them to a queue for checking later events_callback = EventChangeCallback(Clusters.DeviceEnergyManagement) await events_callback.start(self.default_controller, diff --git a/src/python_testing/TC_DEM_2_3.py b/src/python_testing/TC_DEM_2_3.py index 6bdd81c710a914..c44271bd3b5d41 100644 --- a/src/python_testing/TC_DEM_2_3.py +++ b/src/python_testing/TC_DEM_2_3.py @@ -22,7 +22,7 @@ # test-runner-run/run1/app: ${ENERGY_MANAGEMENT_APP} # test-runner-run/run1/factoryreset: True # test-runner-run/run1/quiet: True -# test-runner-run/run1/app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json --enable-key 000102030405060708090a0b0c0d0e0f --featureSet 0x7a +# test-runner-run/run1/app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json --enable-key 000102030405060708090a0b0c0d0e0f --featureSet 0xa # test-runner-run/run1/script-args: --storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --hex-arg enableKey:000102030405060708090a0b0c0d0e0f --endpoint 1 --trace-to json:${TRACE_TEST_JSON}.json --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto # === END CI TEST ARGUMENTS === @@ -138,6 +138,9 @@ async def test_TC_DEM_2_3(self): self.step("1") # Commission DUT - already done + await self.validate_feature_map([Clusters.DeviceEnergyManagement.Bitmaps.Feature.kStartTimeAdjustment], []) + await self.validate_pfr_or_sfr_in_feature_map() + # Subscribe to Events and when they are sent push them to a queue for checking later events_callback = EventChangeCallback(Clusters.DeviceEnergyManagement) await events_callback.start(self.default_controller, diff --git a/src/python_testing/TC_DEM_2_4.py b/src/python_testing/TC_DEM_2_4.py index 390889fc9f2d28..2528b646014d65 100644 --- a/src/python_testing/TC_DEM_2_4.py +++ b/src/python_testing/TC_DEM_2_4.py @@ -22,7 +22,7 @@ # test-runner-run/run1/app: ${ENERGY_MANAGEMENT_APP} # test-runner-run/run1/factoryreset: True # test-runner-run/run1/quiet: True -# test-runner-run/run1/app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json --enable-key 000102030405060708090a0b0c0d0e0f --featureSet 0x7a +# test-runner-run/run1/app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json --enable-key 000102030405060708090a0b0c0d0e0f --featureSet 0x12 # test-runner-run/run1/script-args: --storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --hex-arg enableKey:000102030405060708090a0b0c0d0e0f --endpoint 1 --trace-to json:${TRACE_TEST_JSON}.json --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto # === END CI TEST ARGUMENTS === @@ -159,6 +159,9 @@ async def test_TC_DEM_2_4(self): self.step("1") # Commission DUT - already done + await self.validate_feature_map([Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPausable], []) + await self.validate_pfr_or_sfr_in_feature_map() + # Subscribe to Events and when they are sent push them to a queue for checking later events_callback = EventChangeCallback(Clusters.DeviceEnergyManagement) await events_callback.start(self.default_controller, diff --git a/src/python_testing/TC_DEM_2_5.py b/src/python_testing/TC_DEM_2_5.py index 85d3cd779b22f4..d7ab0521e678ab 100644 --- a/src/python_testing/TC_DEM_2_5.py +++ b/src/python_testing/TC_DEM_2_5.py @@ -23,7 +23,7 @@ # test-runner-run/run1/app: ${ENERGY_MANAGEMENT_APP} # test-runner-run/run1/factoryreset: True # test-runner-run/run1/quiet: True -# test-runner-run/run1/app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json --enable-key 000102030405060708090a0b0c0d0e0f --featureSet 0x7a +# test-runner-run/run1/app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json --enable-key 000102030405060708090a0b0c0d0e0f --featureSet 0x22 # test-runner-run/run1/script-args: --storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --hex-arg enableKey:000102030405060708090a0b0c0d0e0f --endpoint 1 --trace-to json:${TRACE_TEST_JSON}.json --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto # === END CI TEST ARGUMENTS === @@ -144,6 +144,10 @@ async def test_TC_DEM_2_5(self): self.step("1") # Commission DUT - already done + await self.validate_feature_map([Clusters.DeviceEnergyManagement.Bitmaps.Feature.kForecastAdjustment, + Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerForecastReporting], + []) + # Subscribe to Events and when they are sent push them to a queue for checking later events_callback = EventChangeCallback(Clusters.DeviceEnergyManagement) await events_callback.start(self.default_controller, diff --git a/src/python_testing/TC_DEM_2_6.py b/src/python_testing/TC_DEM_2_6.py index 7390436effd937..2bc52e6b6f1cb9 100644 --- a/src/python_testing/TC_DEM_2_6.py +++ b/src/python_testing/TC_DEM_2_6.py @@ -140,6 +140,10 @@ async def test_TC_DEM_2_6(self): self.step("1") # Commission DUT - already done + await self.validate_feature_map([Clusters.DeviceEnergyManagement.Bitmaps.Feature.kForecastAdjustment, + Clusters.DeviceEnergyManagement.Bitmaps.Feature.kStateForecastReporting], + [Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerForecastReporting]) + # Subscribe to Events and when they are sent push them to a queue for checking later events_callback = EventChangeCallback(Clusters.DeviceEnergyManagement) await events_callback.start(self.default_controller, diff --git a/src/python_testing/TC_DEM_2_7.py b/src/python_testing/TC_DEM_2_7.py index fa7dba14a53315..16b974d3ff58f6 100644 --- a/src/python_testing/TC_DEM_2_7.py +++ b/src/python_testing/TC_DEM_2_7.py @@ -148,6 +148,10 @@ async def test_TC_DEM_2_7(self): self.step("1") # Commission DUT - already done + await self.validate_feature_map([Clusters.DeviceEnergyManagement.Bitmaps.Feature.kConstraintBasedAdjustment, + Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerForecastReporting], + [Clusters.DeviceEnergyManagement.Bitmaps.Feature.kStateForecastReporting]) + # Subscribe to Events and when they are sent push them to a queue for checking later events_callback = EventChangeCallback(Clusters.DeviceEnergyManagement) await events_callback.start(self.default_controller, diff --git a/src/python_testing/TC_DEM_2_8.py b/src/python_testing/TC_DEM_2_8.py index 773648c7e3ba8e..1c081be96e63f3 100644 --- a/src/python_testing/TC_DEM_2_8.py +++ b/src/python_testing/TC_DEM_2_8.py @@ -140,6 +140,10 @@ async def test_TC_DEM_2_8(self): self.step("1") # Commission DUT - already done + await self.validate_feature_map([Clusters.DeviceEnergyManagement.Bitmaps.Feature.kConstraintBasedAdjustment, + Clusters.DeviceEnergyManagement.Bitmaps.Feature.kStateForecastReporting], + [Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerForecastReporting]) + # Subscribe to Events and when they are sent push them to a queue for checking later events_callback = EventChangeCallback(Clusters.DeviceEnergyManagement) await events_callback.start(self.default_controller, diff --git a/src/python_testing/TC_DEM_2_9.py b/src/python_testing/TC_DEM_2_9.py index 8e60b69b481d93..5f033164cfad61 100644 --- a/src/python_testing/TC_DEM_2_9.py +++ b/src/python_testing/TC_DEM_2_9.py @@ -23,7 +23,7 @@ # test-runner-run/run1/app: ${ENERGY_MANAGEMENT_APP} # test-runner-run/run1/factoryreset: True # test-runner-run/run1/quiet: True -# test-runner-run/run1/app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json --enable-key 000102030405060708090a0b0c0d0e0f --featureSet 0x7e +# test-runner-run/run1/app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json --enable-key 000102030405060708090a0b0c0d0e0f --featureSet 0x7c # test-runner-run/run1/script-args: --storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --hex-arg enableKey:000102030405060708090a0b0c0d0e0f --endpoint 1 --trace-to json:${TRACE_TEST_JSON}.json --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto # === END CI TEST ARGUMENTS === @@ -81,6 +81,8 @@ async def test_TC_DEM_2_9(self): self.step("1") # Commission DUT - already done + await self.validate_pfr_or_sfr_in_feature_map() + # Subscribe to Events and when they are sent push them to a queue for checking later events_callback = EventChangeCallback(Clusters.DeviceEnergyManagement) await events_callback.start(self.default_controller, From d96208cb3a6683c8906897b9a9c24b19f4c86554 Mon Sep 17 00:00:00 2001 From: pcoleman Date: Mon, 19 Aug 2024 12:17:39 +0100 Subject: [PATCH 02/45] Add checks for a nominalPower having a value and get slotIndex check correct --- .../device-energy-management-server.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/app/clusters/device-energy-management-server/device-energy-management-server.cpp b/src/app/clusters/device-energy-management-server/device-energy-management-server.cpp index 438e2d7bd5f7d3..865fef443792f7 100644 --- a/src/app/clusters/device-energy-management-server/device-energy-management-server.cpp +++ b/src/app/clusters/device-energy-management-server/device-energy-management-server.cpp @@ -676,7 +676,7 @@ void Instance::HandleModifyForecastRequest(HandlerContext & ctx, const Commands: const Structs::SlotAdjustmentStruct::Type & slotAdjustment = iterator.GetValue(); // Check for an invalid slotIndex - if (slotAdjustment.slotIndex > forecast.Value().slots.size()) + if (slotAdjustment.slotIndex >= forecast.Value().slots.size()) { ChipLogError(Zcl, "DEM: Bad slot index %d", slotAdjustment.slotIndex); ctx.mCommandHandler.AddStatus(ctx.mRequestPath, Status::Failure); @@ -696,7 +696,8 @@ void Instance::HandleModifyForecastRequest(HandlerContext & ctx, const Commands: // NominalPower is only relevant if PFR is supported if (HasFeature(Feature::kPowerForecastReporting)) { - if (!slot.minPowerAdjustment.HasValue() || !slot.maxPowerAdjustment.HasValue() || + if (!slotAdjustment.nominalPower.HasValue() || + !slot.minPowerAdjustment.HasValue() || !slot.maxPowerAdjustment.HasValue() || slotAdjustment.nominalPower.Value() < slot.minPowerAdjustment.Value() || slotAdjustment.nominalPower.Value() > slot.maxPowerAdjustment.Value()) { From 2e1f99bc3076dfc0b6f610ca3e743b7979df9c8f Mon Sep 17 00:00:00 2001 From: pcoleman Date: Mon, 19 Aug 2024 12:23:38 +0100 Subject: [PATCH 03/45] Allow a little tolerance checking the duration returned in the event as CI tests can run slower --- src/python_testing/TC_DEM_2_2.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/python_testing/TC_DEM_2_2.py b/src/python_testing/TC_DEM_2_2.py index 710e8552fe6b8e..6bc2348fa8f738 100644 --- a/src/python_testing/TC_DEM_2_2.py +++ b/src/python_testing/TC_DEM_2_2.py @@ -345,8 +345,10 @@ async def test_TC_DEM_2_2(self): self.step("18") time.sleep(10) + # Allow a little tolerance checking the duration returned in the event as CI tests can run "slower" event_data = events_callback.wait_for_event_report(Clusters.DeviceEnergyManagement.Events.PowerAdjustEnd) - asserts.assert_equal(event_data.duration, 10) + asserts.assert_greater_equal(event_data.duration, 10) + asserts.assert_less_equal(event_data.duration, 12) asserts.assert_equal(event_data.cause, Clusters.DeviceEnergyManagement.Enums.CauseEnum.kNormalCompletion) asserts.assert_greater(event_data.energyUse, 0) From 8deab3d515b9ae58862cd3c4a6065f9a66bc657b Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Mon, 19 Aug 2024 11:24:10 +0000 Subject: [PATCH 04/45] Restyled by clang-format --- .../device-energy-management-server.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/app/clusters/device-energy-management-server/device-energy-management-server.cpp b/src/app/clusters/device-energy-management-server/device-energy-management-server.cpp index 865fef443792f7..0b7205dd83a33a 100644 --- a/src/app/clusters/device-energy-management-server/device-energy-management-server.cpp +++ b/src/app/clusters/device-energy-management-server/device-energy-management-server.cpp @@ -696,9 +696,8 @@ void Instance::HandleModifyForecastRequest(HandlerContext & ctx, const Commands: // NominalPower is only relevant if PFR is supported if (HasFeature(Feature::kPowerForecastReporting)) { - if (!slotAdjustment.nominalPower.HasValue() || - !slot.minPowerAdjustment.HasValue() || !slot.maxPowerAdjustment.HasValue() || - slotAdjustment.nominalPower.Value() < slot.minPowerAdjustment.Value() || + if (!slotAdjustment.nominalPower.HasValue() || !slot.minPowerAdjustment.HasValue() || + !slot.maxPowerAdjustment.HasValue() || slotAdjustment.nominalPower.Value() < slot.minPowerAdjustment.Value() || slotAdjustment.nominalPower.Value() > slot.maxPowerAdjustment.Value()) { ChipLogError(Zcl, "DEM: Bad nominalPower"); From 0c66ca83211b3244d280d6b7a587c564e39857fe Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Mon, 19 Aug 2024 11:24:12 +0000 Subject: [PATCH 05/45] Restyled by autopep8 --- src/python_testing/TC_DEMTestBase.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python_testing/TC_DEMTestBase.py b/src/python_testing/TC_DEMTestBase.py index dedeac95b8f595..befec0be815a97 100644 --- a/src/python_testing/TC_DEMTestBase.py +++ b/src/python_testing/TC_DEMTestBase.py @@ -54,7 +54,7 @@ async def validate_feature_map(self, must_have_features, must_not_have_features) for must_not_have_feature in must_not_have_features: asserts.assert_false(feature_map & must_not_have_feature, - f"{s_feature_strs[must_not_have_feature]} is not allowed to be set. feature_map 0x{feature_map:x}") + f"{s_feature_strs[must_not_have_feature]} is not allowed to be set. feature_map 0x{feature_map:x}") async def validate_pfr_or_sfr_in_feature_map(self): feature_map = await self.read_dem_attribute_expect_success(attribute="FeatureMap") From 4a6c8767e7be46d4452840e592fe2a9567be60d9 Mon Sep 17 00:00:00 2001 From: pcoleman Date: Tue, 20 Aug 2024 12:53:39 +0100 Subject: [PATCH 06/45] Add check DEM feature map step + add event registration step if necessary and renumber test cases --- src/python_testing/TC_DEM_2_2.py | 224 ++++++++++++------------- src/python_testing/TC_DEM_2_3.py | 208 ++++++++++++------------ src/python_testing/TC_DEM_2_4.py | 270 ++++++++++++++++--------------- src/python_testing/TC_DEM_2_5.py | 218 ++++++++++++------------- src/python_testing/TC_DEM_2_6.py | 204 ++++++++++++----------- src/python_testing/TC_DEM_2_7.py | 224 +++++++++++++------------ src/python_testing/TC_DEM_2_8.py | 204 ++++++++++++----------- src/python_testing/TC_DEM_2_9.py | 44 +++-- 8 files changed, 790 insertions(+), 806 deletions(-) diff --git a/src/python_testing/TC_DEM_2_2.py b/src/python_testing/TC_DEM_2_2.py index 6bc2348fa8f738..ac0f0d96bf54dc 100644 --- a/src/python_testing/TC_DEM_2_2.py +++ b/src/python_testing/TC_DEM_2_2.py @@ -61,86 +61,88 @@ def pics_TC_DEM_2_2(self): def steps_TC_DEM_2_2(self) -> list[TestStep]: """Execute the test steps.""" steps = [ - TestStep("1", "Commissioning, already done", - is_commissioning=True), - TestStep("2", "TH reads TestEventTriggersEnabled attribute from General Diagnostics Cluster.", - "Verify that TestEventTriggersEnabled attribute has a value of 1 (True)"), - TestStep("3", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Power Adjustment Test Event", - "Verify DUT responds with status SUCCESS(0x00)"), - TestStep("3a", "TH reads ESAState attribute.", - "Verify value is 0x01 (Online)"), - TestStep("3b", "TH reads PowerAdjustmentCapability attribute.", + TestStep("1", "Commission DUT to TH (can be skipped if done in a preceding test)"), + TestStep("2", "TH reads from the DUT the _Featuremap_ attribute", + "Verify that the DUT response contains the _Featuremap_ attribute. Verify PowerAdjustment is supported."), + TestStep("3", "Set up a subscription to all DeviceEnergyManagement cluster events"), + TestStep("4", "TH reads TestEventTriggersEnabled attribute from General Diagnostics Cluster", + "Value has to be 1 (True)"), + TestStep("5", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Power Adjustment Test Event", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("5a", "TH reads from the DUT the ESAState", + "Value has to be 0x01 (Online)"), + TestStep("5b", "TH reads from the DUT the PowerAdjustmentCapability", "Value has to include Cause=NoAdjustment. Note value for later. Determine the OverallMaxPower and OverallMaxDuration as the largest MaxPower and MaxDuration of the PowerAdjustStructs returned, and similarly the OverallMinPower and OverallMinDuration as the smallest of the MinPower and MinDuration values."), - TestStep("3c", "TH reads OptOutState attribute.", - "Verify value is 0x00 (NoOptOut)"), - TestStep("4", "TH sends PowerAdjustRequest with Power=PowerAdjustmentCapability[0].MaxPower, Duration=PowerAdjustmentCapability[0].MinDuration, Cause=LocalOptimization.", - "Verify DUT responds with status SUCCESS(0x00) and Event DEM.S.E00(PowerAdjustStart) sent"), - TestStep("4a", "TH reads ESAState attribute.", - "Verify value is 0x04 (PowerAdjustActive)"), - TestStep("4b", "TH reads PowerAdjustmentCapability attribute.", + TestStep("5c", "TH reads from the DUT the OptOutState", + "Value has to be 0x00 (NoOptOut)"), + TestStep("6", "TH sends command PowerAdjustRequest with Power=PowerAdjustmentCapability[0].MaxPower, Duration=PowerAdjustmentCapability[0].MinDuration, Cause=LocalOptimization", + "Verify DUT responds w/ status SUCCESS(0x00) and Event DEM.S.E00(PowerAdjustStart) sent"), + TestStep("6a", "TH reads from the DUT the ESAState", + "Value has to be 0x04 (PowerAdjustActive)"), + TestStep("6b", "TH reads from the DUT the PowerAdjustmentCapability", "Value has to include Cause=LocalOptimizationAdjustment."), - TestStep("5", "TH sends CancelPowerAdjustRequest.", - "Verify DUT responds with status SUCCESS(0x00) and Event DEM.S.E01(PowerAdjustEnd) sent with Cause=Cancelled"), - TestStep("5a", "TH reads PowerAdjustmentCapability attribute.", + TestStep("7", "TH sends command CancelPowerAdjustRequest", + "Verify DUT responds w/ status SUCCESS(0x00) and Event DEM.S.E01(PowerAdjustEnd) sent with Cause=Cancelled"), + TestStep("7a", "TH reads from the DUT the PowerAdjustmentCapability", "Value has to include Cause=NoAdjustment."), - TestStep("5b", "TH reads ESAState attribute.", - "Verify value is 0x01 (Online)"), - TestStep("6", "TH sends CancelPowerAdjustRequest.", - "Verify DUT responds with status INVALID_IN_STATE(0xcb)"), - TestStep("7", "TH sends PowerAdjustRequest with Power=OverallMaxPower+1 Duration=OverallMinDuration Cause=LocalOptimization.", - "Verify DUT responds with status CONSTRAINT_ERROR(0x87)"), - TestStep("8", "TH sends PowerAdjustRequest with Power=OverallMinPower Duration=OverallMaxDuration+1 Cause=LocalOptimization.", - "Verify DUT responds with status CONSTRAINT_ERROR(0x87)"), - TestStep("9", "TH sends PowerAdjustRequest with Power=OverallMinPower-1 Duration=OverallMaxDuration Cause=LocalOptimization.", - "Verify DUT responds with status CONSTRAINT_ERROR(0x87)"), - TestStep("10", "TH sends PowerAdjustRequest with Power=OverallMaxPower Duration=OverallMinDuration-1 Cause=LocalOptimization.", - "Verify DUT responds with status CONSTRAINT_ERROR(0x87)"), - TestStep("11", "TH sends PowerAdjustRequest with Power=PowerAdjustmentCapability[0].MaxPower, Duration=PowerAdjustmentCapability[0].MinDuration, Cause=LocalOptimization.", - "Verify DUT responds with status SUCCESS(0x00) and event DEM.S.E00(PowerAdjustStart) sent"), - TestStep("11a", "TH reads PowerAdjustmentCapability attribute.", + TestStep("7b", "TH reads from the DUT the ESAState", + "Value has to be 0x01 (Online)"), + TestStep("8", "TH sends command CancelPowerAdjustRequest", + "Verify DUT responds w/ status INVALID_IN_STATE(0xcb)"), + TestStep("9", "TH sends command PowerAdjustRequest with Power=OverallMaxPower+1 Duration=OverallMinDuration Cause=LocalOptimization", + "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"), + TestStep("10", "TH sends command PowerAdjustRequest with Power=OverallMinPower Duration=OverallMaxDuration+1 Cause=LocalOptimization", + "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"), + TestStep("11", "TH sends command PowerAdjustRequest with Power=OverallMinPower-1 Duration=OverallMaxDuration Cause=LocalOptimization", + "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"), + TestStep("12", "TH sends command PowerAdjustRequest with Power=OverallMaxPower Duration=OverallMinDuration-1 Cause=LocalOptimization", + "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"), + TestStep("13", "TH sends command PowerAdjustRequest with Power=PowerAdjustmentCapability[0].MaxPower, Duration=PowerAdjustmentCapability[0].MinDuration, Cause=LocalOptimization", + "Verify DUT responds w/ status SUCCESS(0x00) and event DEM.S.E00(PowerAdjustStart) sent"), + TestStep("13a", "TH reads from the DUT the PowerAdjustmentCapability", "Value has to include Cause=LocalOptimizationAdjustment."), - TestStep("12", "TH sends PowerAdjustRequest with Power=PowerAdjustmentCapability[0].MaxPower, Duration=PowerAdjustmentCapability[0].MinDuration, Cause=GridOptimization.", - "Verify DUT responds with status SUCCESS(0x00) and no event sent"), - TestStep("12a", "TH reads ESAState attribute.", - "Verify value is 0x04 (PowerAdjustActive)"), - TestStep("12b", "TH reads PowerAdjustmentCapability attribute.", + TestStep("14", "TH sends command PowerAdjustRequest with Power=PowerAdjustmentCapability[0].MaxPower, Duration=PowerAdjustmentCapability[0].MinDuration, Cause=GridOptimization", + "Verify DUT responds w/ status SUCCESS(0x00) and no event sent"), + TestStep("14a", "TH reads from the DUT the ESAState", + "Value has to be 0x04 (PowerAdjustActive)"), + TestStep("14b", "TH reads from the DUT the PowerAdjustmentCapability", "Value has to include Cause=GridOptimizationAdjustment."), - TestStep("13", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Local Optimization Test Event.", - "Verify DUT responds with status SUCCESS(0x00) and no event sent"), - TestStep("13a", "TH reads ESAState attribute.", - "Verify value is 0x04 (PowerAdjustActive)"), - TestStep("13b", "TH reads OptOutState attribute.", - "Verify value is 0x02 (LocalOptOut)"), - TestStep("14", "TH sends PowerAdjustRequest with Power=PowerAdjustmentCapability[0].MaxPower, Duration=PowerAdjustmentCapability[0].MinDuration, Cause=LocalOptimization.", - "Verify DUT responds with status CONSTRAINT_ERROR(0x87)"), - TestStep("15", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Grid Optimization Test Event.", - "Verify DUT responds with status SUCCESS(0x00) and event DEM.S.E01(PowerAdjustEnd) sent with Cause=UserOptOut, Duration= approx time from step 11 to step 15, EnergyUse= a valid value"), - TestStep("15a", "TH reads ESAState attribute.", - "Verify value is 0x01 (Online)"), - TestStep("15b", "TH reads OptOutState attribute.", - "Verify value is 0x03 (OptOut)"), - TestStep("15c", "TH reads PowerAdjustmentCapability attribute.", + TestStep("15", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Local Optimization Test Event", + "Verify DUT responds w/ status SUCCESS(0x00) and no event sent"), + TestStep("15a", "TH reads from the DUT the ESAState", + "Value has to be 0x04 (PowerAdjustActive)"), + TestStep("15b", "TH reads from the DUT the OptOutState", + "Value has to be 0x02 (LocalOptOut)"), + TestStep("16", "TH sends command PowerAdjustRequest with Power=PowerAdjustmentCapability[0].MaxPower, Duration=PowerAdjustmentCapability[0].MinDuration, Cause=LocalOptimization", + "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"), + TestStep("17", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Grid Optimization Test Event", + "Verify DUT responds w/ status SUCCESS(0x00) and event DEM.S.E01(PowerAdjustEnd) sent with Cause=UserOptOut, Duration= approx time from step 11 to step 15, EnergyUse= a valid value"), + TestStep("17a", "TH reads from the DUT the ESAState", + "Value has to be 0x01 (Online)"), + TestStep("17b", "TH reads from the DUT the OptOutState", + "Value has to be 0x03 (OptOut)"), + TestStep("17c", "TH reads from the DUT the PowerAdjustmentCapability", "Value has to include Cause=NoAdjustment."), - TestStep("16", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Test Event Clear", - "Verify DUT responds with status SUCCESS(0x00)"), - TestStep("16a", "TH reads ESAState attribute.", - "Verify value is 0x01 (Online)"), - TestStep("16b", "TH reads OptOutState attribute.", - "Verify value is 0x00 (NoOptOut)"), - TestStep("17", "TH sends PowerAdjustRequest with Power=PowerAdjustmentCapability[0].MaxPower, Duration=PowerAdjustmentCapability[0].MinDuration, Cause=LocalOptimization.", - "Verify DUT responds with status SUCCESS(0x00) and event DEM.S.E00(PowerAdjustStart) sent"), - TestStep("17a", "TH reads ESAState attribute.", - "Verify value is 0x04 (PowerAdjustActive)"), - TestStep("17b", "TH reads PowerAdjustmentCapability attribute.", + TestStep("18", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Test Event Clear", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("18a", "TH reads from the DUT the ESAState", + "Value has to be 0x01 (Online)"), + TestStep("18b", "TH reads from the DUT the OptOutState", + "Value has to be 0x00 (NoOptOut)"), + TestStep("19", "TH sends command PowerAdjustRequest with Power=PowerAdjustmentCapability[0].MaxPower, Duration=PowerAdjustmentCapability[0].MinDuration, Cause=LocalOptimization", + "Verify DUT responds w/ status SUCCESS(0x00) and event DEM.S.E00(PowerAdjustStart) sent"), + TestStep("19a", "TH reads from the DUT the ESAState", + "Value has to be 0x04 (PowerAdjustActive)"), + TestStep("19b", "TH reads from the DUT the PowerAdjustmentCapability", "Value has to include Cause=LocalOptimizationAdjustment."), - TestStep("18", "Wait 10 seconds.", + TestStep("20", "Wait 10 seconds", "Event DEM.S.E01(PowerAdjustEnd) sent with Cause=NormalCompletion, Duration=10s, EnergyUse= a valid value"), - TestStep("18a", "TH reads ESAState attribute.", - "Verify value is 0x01 (Online)"), - TestStep("18b", "TH reads PowerAdjustmentCapability attribute.", + TestStep("20a", "TH reads from the DUT the ESAState", + "Value has to be 0x01 (Online)"), + TestStep("20b", "TH reads from the DUT the PowerAdjustmentCapability", "Value has to include Cause=NoAdjustment."), - TestStep("19", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Power Adjustment Test Event Clear", - "Verify DUT responds with status SUCCESS(0x00)"), + TestStep("21", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Power Adjustment Test Event Clear", + "Verify DUT responds w/ status SUCCESS(0x00)"), ] return steps @@ -155,24 +157,26 @@ async def test_TC_DEM_2_2(self): self.step("1") # Commission DUT - already done + self.step("2") await self.validate_feature_map([Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerAdjustment], []) + self.step("3") # Subscribe to Events and when they are sent push them to a queue for checking later events_callback = EventChangeCallback(Clusters.DeviceEnergyManagement) await events_callback.start(self.default_controller, self.dut_node_id, self.matter_test_config.endpoint) - self.step("2") + self.step("4") await self.check_test_event_triggers_enabled() - self.step("3") + self.step("5") await self.send_test_event_trigger_power_adjustment() - self.step("3a") + self.step("5a") await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kOnline) - self.step("3b") + self.step("5b") powerAdjustCapabilityStruct = await self.read_dem_attribute_expect_success(attribute="PowerAdjustmentCapability") asserts.assert_greater_equal(len(powerAdjustCapabilityStruct.powerAdjustCapability), 1) logging.info(powerAdjustCapabilityStruct) @@ -194,66 +198,66 @@ async def test_TC_DEM_2_2(self): result = f"min_power {min_power} max_power {max_power} min_duration {min_duration} max_duration {max_duration}" logging.info(result) - self.step("3c") + self.step("5c") await self.check_dem_attribute("OptOutState", Clusters.DeviceEnergyManagement.Enums.OptOutStateEnum.kNoOptOut) - self.step("4") + self.step("6") await self.send_power_adjustment_command(power=powerAdjustCapabilityStruct.powerAdjustCapability[0].maxPower, duration=powerAdjustCapabilityStruct.powerAdjustCapability[0].minDuration, cause=Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization) event_data = events_callback.wait_for_event_report(Clusters.DeviceEnergyManagement.Events.PowerAdjustStart) - self.step("4a") + self.step("6a") await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kPowerAdjustActive) - self.step("4b") + self.step("6b") powerAdjustCapabilityStruct = await self.read_dem_attribute_expect_success(attribute="PowerAdjustmentCapability") asserts.assert_greater_equal(len(powerAdjustCapabilityStruct.powerAdjustCapability), 1) asserts.assert_equal(powerAdjustCapabilityStruct.cause, Clusters.DeviceEnergyManagement.Enums.PowerAdjustReasonEnum.kLocalOptimizationAdjustment) - self.step("5") + self.step("7") await self.send_cancel_power_adjustment_command() event_data = events_callback.wait_for_event_report(Clusters.DeviceEnergyManagement.Events.PowerAdjustEnd) asserts.assert_equal(event_data.cause, Clusters.DeviceEnergyManagement.Enums.CauseEnum.kCancelled) - self.step("5a") + self.step("7a") powerAdjustCapabilityStruct = await self.read_dem_attribute_expect_success(attribute="PowerAdjustmentCapability") asserts.assert_equal(powerAdjustCapabilityStruct.cause, Clusters.DeviceEnergyManagement.Enums.PowerAdjustReasonEnum.kNoAdjustment) - self.step("5b") + self.step("7b") await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kOnline) - self.step("6") + self.step("8") await self.send_cancel_power_adjustment_command(expected_status=Status.InvalidInState) - self.step("7") + self.step("9") await self.send_power_adjustment_command(power=max_power + 1, duration=min_duration, cause=Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization, expected_status=Status.ConstraintError) - self.step("8") + self.step("10") await self.send_power_adjustment_command(power=min_power, duration=max_duration + 1, cause=Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization, expected_status=Status.ConstraintError) - self.step("9") + self.step("11") await self.send_power_adjustment_command(power=min_power - 1, duration=max_duration, cause=Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization, expected_status=Status.ConstraintError) - self.step("10") + self.step("12") await self.send_power_adjustment_command(power=max_power, duration=min_duration - 1, cause=Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization, expected_status=Status.ConstraintError) - self.step("11") + self.step("13") start = datetime.datetime.now() await self.send_power_adjustment_command(power=powerAdjustCapabilityStruct.powerAdjustCapability[0].minPower, duration=min_duration, @@ -261,12 +265,12 @@ async def test_TC_DEM_2_2(self): event_data = events_callback.wait_for_event_report(Clusters.DeviceEnergyManagement.Events.PowerAdjustStart) - self.step("11a") + self.step("13a") powerAdjustCapabilityStruct = await self.read_dem_attribute_expect_success(attribute="PowerAdjustmentCapability") asserts.assert_equal(powerAdjustCapabilityStruct.cause, Clusters.DeviceEnergyManagement.Enums.PowerAdjustReasonEnum.kLocalOptimizationAdjustment) - self.step("12") + self.step("14") await self.send_power_adjustment_command(power=powerAdjustCapabilityStruct.powerAdjustCapability[0].maxPower, duration=powerAdjustCapabilityStruct.powerAdjustCapability[0].minDuration, cause=Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kGridOptimization) @@ -274,30 +278,30 @@ async def test_TC_DEM_2_2(self): # Wait 5 seconds for an event not to be reported events_callback.wait_for_event_expect_no_report(5) - self.step("12a") + self.step("14a") await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kPowerAdjustActive) - self.step("12b") + self.step("14b") powerAdjustCapabilityStruct = await self.read_dem_attribute_expect_success(attribute="PowerAdjustmentCapability") asserts.assert_equal(powerAdjustCapabilityStruct.cause, Clusters.DeviceEnergyManagement.Enums.PowerAdjustReasonEnum.kGridOptimizationAdjustment) - self.step("13") + self.step("15") await self.send_test_event_trigger_user_opt_out_local() - self.step("13a") + self.step("15a") await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kPowerAdjustActive) - self.step("13b") + self.step("15b") await self.check_dem_attribute("OptOutState", Clusters.DeviceEnergyManagement.Enums.OptOutStateEnum.kLocalOptOut) - self.step("14") + self.step("16") await self.send_power_adjustment_command(power=max_power, duration=powerAdjustCapabilityStruct.powerAdjustCapability[0].maxDuration, cause=Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization, expected_status=Status.ConstraintError) - self.step("15") + self.step("17") await self.send_test_event_trigger_user_opt_out_grid() event_data = events_callback.wait_for_event_report(Clusters.DeviceEnergyManagement.Events.PowerAdjustEnd) asserts.assert_equal(event_data.cause, Clusters.DeviceEnergyManagement.Enums.CauseEnum.kUserOptOut) @@ -307,42 +311,42 @@ async def test_TC_DEM_2_2(self): asserts.assert_less_equal(abs(elapsed.seconds - event_data.duration), 3) asserts.assert_greater_equal(event_data.energyUse, 0) - self.step("15a") + self.step("17a") await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kOnline) - self.step("15b") + self.step("17b") await self.check_dem_attribute("OptOutState", Clusters.DeviceEnergyManagement.Enums.OptOutStateEnum.kOptOut) - self.step("15c") + self.step("17c") powerAdjustCapabilityStruct = await self.read_dem_attribute_expect_success(attribute="PowerAdjustmentCapability") asserts.assert_equal(powerAdjustCapabilityStruct.cause, Clusters.DeviceEnergyManagement.Enums.PowerAdjustReasonEnum.kNoAdjustment) - self.step("16") + self.step("18") await self.send_test_event_trigger_user_opt_out_clear_all() - self.step("16a") + self.step("18a") await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kOnline) - self.step("16b") + self.step("18b") await self.check_dem_attribute("OptOutState", Clusters.DeviceEnergyManagement.Enums.OptOutStateEnum.kNoOptOut) - self.step("17") + self.step("19") await self.send_power_adjustment_command(power=powerAdjustCapabilityStruct.powerAdjustCapability[0].maxPower, duration=powerAdjustCapabilityStruct.powerAdjustCapability[0].minDuration, cause=Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization, expected_status=Status.Success) event_data = events_callback.wait_for_event_report(Clusters.DeviceEnergyManagement.Events.PowerAdjustStart) - self.step("17a") + self.step("19a") await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kPowerAdjustActive) - self.step("17b") + self.step("19b") powerAdjustCapabilityStruct = await self.read_dem_attribute_expect_success(attribute="PowerAdjustmentCapability") asserts.assert_equal(powerAdjustCapabilityStruct.cause, Clusters.DeviceEnergyManagement.Enums.PowerAdjustReasonEnum.kLocalOptimizationAdjustment) - self.step("18") + self.step("20") time.sleep(10) # Allow a little tolerance checking the duration returned in the event as CI tests can run "slower" @@ -352,15 +356,15 @@ async def test_TC_DEM_2_2(self): asserts.assert_equal(event_data.cause, Clusters.DeviceEnergyManagement.Enums.CauseEnum.kNormalCompletion) asserts.assert_greater(event_data.energyUse, 0) - self.step("18a") + self.step("20a") await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kOnline) - self.step("18b") + self.step("20b") powerAdjustCapabilityStruct = await self.read_dem_attribute_expect_success(attribute="PowerAdjustmentCapability") asserts.assert_equal(powerAdjustCapabilityStruct.cause, Clusters.DeviceEnergyManagement.Enums.PowerAdjustReasonEnum.kNoAdjustment) - self.step("19") + self.step("21") await self.send_test_event_trigger_power_adjustment_clear() diff --git a/src/python_testing/TC_DEM_2_3.py b/src/python_testing/TC_DEM_2_3.py index c44271bd3b5d41..5287546f79ace4 100644 --- a/src/python_testing/TC_DEM_2_3.py +++ b/src/python_testing/TC_DEM_2_3.py @@ -31,7 +31,7 @@ import chip.clusters as Clusters from chip.clusters.Types import NullValue from chip.interaction_model import Status -from matter_testing_support import EventChangeCallback, MatterBaseTest, TestStep, async_test_body, default_matter_test_main +from matter_testing_support import MatterBaseTest, TestStep, async_test_body, default_matter_test_main from mobly import asserts from TC_DEMTestBase import DEMTestBase @@ -54,78 +54,79 @@ def pics_TC_DEM_2_3(self): def steps_TC_DEM_2_3(self) -> list[TestStep]: steps = [ - TestStep("1", "Commissioning, already done", - is_commissioning=True), - TestStep("2", "TH reads TestEventTriggersEnabled attribute from General Diagnostics Cluster.", - "Verify that TestEventTriggersEnabled attribute has a value of 1 (True)"), - TestStep("3", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Start Time Adjustment Test Event", - "Verify DUT responds with status SUCCESS(0x00)"), - TestStep("3a", "TH reads ESAState attribute.", - "Verify value is 0x01 (Online)"), - TestStep("3b", "TH reads Forecast attribute.", + TestStep("1", "Commission DUT to TH (can be skipped if done in a preceding test)"), + TestStep("2", "TH reads from the DUT the _Featuremap_ attribute", + "Verify that the DUT response contains the _Featuremap_ attribute. Verify StartTimeAdjustment is supported."), + TestStep("3", "TH reads TestEventTriggersEnabled attribute from General Diagnostics Cluster", + "Value has to be 1 (True)"), + TestStep("4", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Start Time Adjustment Test Event", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("4a", "TH reads from the DUT the ESAState", + "Value has to be 0x01 (Online)"), + TestStep("4b", "TH reads from the DUT the Forecast", "Value has to include EarliestStartTime<=StartTime, LatestEndTime>=EndTime, and ForecastUpdateReason=Internal Optimization"), - TestStep("3c", "TH reads OptOutState attribute.", - "Verify value is 0x00 (NoOptOut)"), - TestStep("4", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Local Optimization Test Event", - "Verify DUT responds with status SUCCESS(0x00)"), - TestStep("4a", "TH reads ESAState attribute.", - "Verify value is 0x01 (Online)"), - TestStep("4b", "TH reads OptOutState attribute.", - "Verify value is 0x01 (LocalOptOut)"), - TestStep("5", "TH sends StartTimeAdjustRequest with RequestedStartTime=EarliestStartTime from Forecast, Cause=LocalOptimization.", - "Verify DUT responds with status CONSTRAINT_ERROR(0x87)"), - TestStep("5a", "TH reads ESAState attribute.", - "Verify value is 0x01 (Online)"), - TestStep("5b", "TH reads Forecast attribute.", + TestStep("4c", "TH reads from the DUT the OptOutState", + "Value has to be 0x00 (NoOptOut)"), + TestStep("5", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Local Optimization Test Event", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("5a", "TH reads from the DUT the ESAState", + "Value has to be 0x01 (Online)"), + TestStep("5b", "TH reads from the DUT the OptOutState", + "Value has to be 0x01 (LocalOptOut)"), + TestStep("6", "TH sends command StartTimeAdjustRequest with RequestedStartTime=EarliestStartTime from Forecast, Cause=LocalOptimization", + "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"), + TestStep("6a", "TH reads from the DUT the ESAState", + "Value has to be 0x01 (Online)"), + TestStep("6b", "TH reads from the DUT the Forecast", "Value has to be unchanged from step 3b"), - TestStep("6", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Test Event Clear", - "Verify DUT responds with status SUCCESS(0x00)"), - TestStep("6a", "TH reads ESAState attribute.", - "Verify value is 0x01 (Online)"), - TestStep("6b", "TH reads OptOutState attribute.", - "Verify value is 0x00 (NoOptOut)"), - TestStep("7", "TH sends StartTimeAdjustRequest with RequestedStartTime=EarliestStartTime from Forecast, Cause=LocalOptimization.", - "Verify DUT responds with status SUCCESS(0x00)"), - TestStep("7a", "TH reads ESAState attribute.", - "Verify value is 0x01 (Online)"), - TestStep("7b", "TH reads Forecast attribute.", + TestStep("7", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Test Event Clear", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("7a", "TH reads from the DUT the ESAState", + "Value has to be 0x01 (Online)"), + TestStep("7b", "TH reads from the DUT the OptOutState", + "Value has to be 0x00 (NoOptOut)"), + TestStep("8", "TH sends command StartTimeAdjustRequest with RequestedStartTime=EarliestStartTime from Forecast, Cause=LocalOptimization", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("8a", "TH reads from the DUT the ESAState", + "Value has to be 0x01 (Online)"), + TestStep("8b", "TH reads from the DUT the Forecast", "Value has to include EarliestStartTime=StartTime, LatestEndTime>=EndTime, and ForecastUpdateReason=Local Optimization"), - TestStep("8", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Local Optimization Test Event", - "Verify DUT responds with status SUCCESS(0x00)"), - TestStep("8a", "TH reads ESAState attribute.", - "Verify value is 0x01 (Online)"), - TestStep("8b", "TH reads OptOutState attribute.", - "Verify value is 0x01 (LocalOptOut)"), - TestStep("8c", "TH reads Forecast attribute.", + TestStep("9", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Local Optimization Test Event", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("9a", "TH reads from the DUT the ESAState", + "Value has to be 0x01 (Online)"), + TestStep("9b", "TH reads from the DUT the OptOutState", + "Value has to be 0x01 (LocalOptOut)"), + TestStep("9c", "TH reads from the DUT the Forecast", "Value has to include EarliestStartTime<=StartTime, LatestEndTime>=EndTime, and ForecastUpdateReason=Internal Optimization"), - TestStep("9", "TH sends StartTimeAdjustRequest with RequestedStartTime=StartTime+(LatestEndTime-EndTime) from Forecast, Cause=GridOptimization.", - "Verify DUT responds with status SUCCESS(0x00)"), - TestStep("9a", "TH reads ESAState attribute.", - "Verify value is 0x01 (Online)"), - TestStep("9b", "TH reads Forecast attribute.", + TestStep("10", "TH sends command StartTimeAdjustRequest with RequestedStartTime=StartTime+(LatestEndTime-EndTime) from Forecast, Cause=GridOptimization", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("10a", "TH reads from the DUT the ESAState", + "Value has to be 0x01 (Online)"), + TestStep("10b", "TH reads from the DUT the Forecast", "Value has to include EarliestStartTime<=StartTime, LatestEndTime=EndTime, and ForecastUpdateReason=Grid Optimization"), - TestStep("10", "TH sends CancelRequest.", - "Verify DUT responds with status SUCCESS(0x00)"), - TestStep("10a", "TH reads ESAState attribute.", - "Verify value is 0x01 (Online)"), - TestStep("10b", "TH reads Forecast attribute.", + TestStep("11", "TH sends command CancelRequest", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("11a", "TH reads from the DUT the ESAState", + "Value has to be 0x01 (Online)"), + TestStep("11b", "TH reads from the DUT the Forecast", "Value has to include EarliestStartTime<=StartTime, LatestEndTime>=EndTime, and ForecastUpdateReason=Internal Optimization"), - TestStep("11", "TH sends StartTimeAdjustRequest with RequestedStartTime=EarliestStartTime-1 from Forecast, Cause=LocalOptimization.", - "Verify DUT responds with status CONSTRAINT_ERROR(0x87)"), - TestStep("11a", "TH reads ESAState attribute.", - "Verify value is 0x01 (Online)"), - TestStep("11b", "TH reads Forecast attribute.", + TestStep("12", "TH sends command StartTimeAdjustRequest with RequestedStartTime=EarliestStartTime-1 from Forecast, Cause=LocalOptimization", + "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"), + TestStep("12a", "TH reads from the DUT the ESAState", + "Value has to be 0x01 (Online)"), + TestStep("12b", "TH reads from the DUT the Forecast", "Value has to include StartTime and EndTime unchanged from step 10b"), - TestStep("12", "TH sends StartTimeAdjustRequest with RequestedStartTime=StartTime+(LatestEndTime-EndTime)+1 from Forecast, Cause=LocalOptimization.", - "Verify DUT responds with status CONSTRAINT_ERROR(0x87)"), - TestStep("12a", "TH reads ESAState attribute.", - "Verify value is 0x01 (Online)"), - TestStep("12b", "TH reads Forecast attribute.", + TestStep("13", "TH sends command StartTimeAdjustRequest with RequestedStartTime=StartTime+(LatestEndTime-EndTime)+1 from Forecast, Cause=LocalOptimization", + "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"), + TestStep("13a", "TH reads from the DUT the ESAState", + "Value has to be 0x01 (Online)"), + TestStep("13b", "TH reads from the DUT the Forecast", "Value has to include StartTime and EndTime unchanged from step 10b"), - TestStep("13", "TH sends CancelRequest.", - "Verify DUT responds with status INVALID_IN_STATE(0xcb)"), - TestStep("14", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Start Time Adjustment Test Event Clear", - "Verify DUT responds with status SUCCESS(0x00)"), + TestStep("14", "TH sends command CancelRequest", + "Verify DUT responds w/ status INVALID_IN_STATE(0xcb)"), + TestStep("15", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Start Time Adjustment Test Event Clear", + "Verify DUT responds w/ status SUCCESS(0x00)"), ] return steps @@ -138,25 +139,20 @@ async def test_TC_DEM_2_3(self): self.step("1") # Commission DUT - already done + self.step("2") await self.validate_feature_map([Clusters.DeviceEnergyManagement.Bitmaps.Feature.kStartTimeAdjustment], []) await self.validate_pfr_or_sfr_in_feature_map() - # Subscribe to Events and when they are sent push them to a queue for checking later - events_callback = EventChangeCallback(Clusters.DeviceEnergyManagement) - await events_callback.start(self.default_controller, - self.dut_node_id, - self.matter_test_config.endpoint) - - self.step("2") + self.step("3") await self.check_test_event_triggers_enabled() - self.step("3") + self.step("4") await self.send_test_event_trigger_start_time_adjustment() - self.step("3a") + self.step("4a") await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kOnline) - self.step("3b") + self.step("4b") forecast = await self.read_dem_attribute_expect_success(attribute="Forecast") asserts.assert_not_equal(forecast, NullValue) @@ -169,48 +165,48 @@ async def test_TC_DEM_2_3(self): self.print_forecast(forecast) - self.step("3c") + self.step("4c") await self.check_dem_attribute("OptOutState", Clusters.DeviceEnergyManagement.Enums.OptOutStateEnum.kNoOptOut) - self.step("4") + self.step("5") await self.send_test_event_trigger_user_opt_out_local() - self.step("4a") + self.step("5a") await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kOnline) - self.step("4b") + self.step("5b") await self.check_dem_attribute("OptOutState", Clusters.DeviceEnergyManagement.Enums.OptOutStateEnum.kLocalOptOut) - self.step("5") + self.step("6") await self.send_start_time_adjust_request_command(requestedStartTime=forecast.earliestStartTime, cause=Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization, expected_status=Status.ConstraintError) - self.step("5a") + self.step("6a") await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kOnline) - self.step("5b") + self.step("6b") forecast2 = await self.read_dem_attribute_expect_success(attribute="Forecast") asserts.assert_equal(forecast, forecast2, f"Expected same forcast {forecast} to be == {forecast2}") - self.step("6") + self.step("7") await self.send_test_event_trigger_user_opt_out_clear_all() - self.step("6a") + self.step("7a") await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kOnline) - self.step("6b") + self.step("7b") await self.check_dem_attribute("OptOutState", Clusters.DeviceEnergyManagement.Enums.OptOutStateEnum.kNoOptOut) - self.step("7") + self.step("8") await self.send_start_time_adjust_request_command(requestedStartTime=forecast.earliestStartTime, cause=Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization) - self.step("7a") + self.step("8a") await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kOnline) - self.step("7b") + self.step("8b") forecast3 = await self.read_dem_attribute_expect_success(attribute="Forecast") asserts.assert_equal(forecast3.earliestStartTime, forecast3.startTime, f"Expected earliestStartTime {forecast3.earliestStartTime} to be == startTime {forecast3.startTime}") @@ -219,16 +215,16 @@ async def test_TC_DEM_2_3(self): asserts.assert_equal(forecast3.forecastUpdateReason, Clusters.DeviceEnergyManagement.Enums.ForecastUpdateReasonEnum.kLocalOptimization, f"Expected forecastUpdateReason {forecast3.forecastUpdateReason} to be == LocalOptimization {Clusters.DeviceEnergyManagement.Enums.ForecastUpdateReasonEnum.kLocalOptimization}") - self.step("8") + self.step("9") await self.send_test_event_trigger_user_opt_out_local() - self.step("8a") + self.step("9a") await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kOnline) - self.step("8b") + self.step("9b") await self.check_dem_attribute("OptOutState", Clusters.DeviceEnergyManagement.Enums.OptOutStateEnum.kLocalOptOut) - self.step("8c") + self.step("9c") forecast4 = await self.read_dem_attribute_expect_success(attribute="Forecast") asserts.assert_less_equal(forecast4.earliestStartTime, forecast4.startTime, f"Expected earliestStartTime {forecast4.earliestStartTime} to be <= startTime {forecast4.startTime}") @@ -237,14 +233,14 @@ async def test_TC_DEM_2_3(self): asserts.assert_equal(forecast4.forecastUpdateReason, Clusters.DeviceEnergyManagement.Enums.ForecastUpdateReasonEnum.kInternalOptimization, f"Expected forecastUpdateReason {forecast4.forecastUpdateReason} to be == InternalOptimization {Clusters.DeviceEnergyManagement.Enums.ForecastUpdateReasonEnum.kInternalOptimization}") - self.step("9") + self.step("10") await self.send_start_time_adjust_request_command(requestedStartTime=forecast4.startTime+forecast4.latestEndTime - forecast4.endTime, cause=Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kGridOptimization) - self.step("9a") + self.step("10a") await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kOnline) - self.step("9b") + self.step("10b") forecast5 = await self.read_dem_attribute_expect_success(attribute="Forecast") asserts.assert_less_equal(forecast5.earliestStartTime, forecast5.startTime, f"Expected earliestStartTime {forecast5.earliestStartTime} to be <= startTime {forecast5.startTime}") @@ -253,13 +249,13 @@ async def test_TC_DEM_2_3(self): asserts.assert_equal(forecast5.forecastUpdateReason, Clusters.DeviceEnergyManagement.Enums.ForecastUpdateReasonEnum.kGridOptimization, f"Expected forecastUpdateReason {forecast5.forecastUpdateReason} to be == GridOptimization {Clusters.DeviceEnergyManagement.Enums.ForecastUpdateReasonEnum.kGridOptimization}") - self.step("10") + self.step("11") await self.send_cancel_request_command() - self.step("10a") + self.step("11a") await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kOnline) - self.step("10b") + self.step("11b") forecast6 = await self.read_dem_attribute_expect_success(attribute="Forecast") asserts.assert_less_equal(forecast6.earliestStartTime, forecast6.startTime, f"Expected earliestStartTime {forecast6.earliestStartTime} to be <= startTime {forecast6.startTime}") @@ -268,38 +264,38 @@ async def test_TC_DEM_2_3(self): asserts.assert_equal(forecast6.forecastUpdateReason, Clusters.DeviceEnergyManagement.Enums.ForecastUpdateReasonEnum.kInternalOptimization, f"Expected forecastUpdateReason {forecast6.forecastUpdateReason} to be == InternalOptimization {Clusters.DeviceEnergyManagement.Enums.ForecastUpdateReasonEnum.kInternalOptimization}") - self.step("11") + self.step("12") await self.send_start_time_adjust_request_command(requestedStartTime=forecast6.earliestStartTime - 1, cause=Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization, expected_status=Status.ConstraintError) - self.step("11a") + self.step("12a") await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kOnline) - self.step("11b") + self.step("12b") forecast7 = await self.read_dem_attribute_expect_success(attribute="Forecast") asserts.assert_equal(forecast6.startTime, forecast7.startTime, f"Expected old startTime {forecast6.startTime} to be == startTime {forecast7.startTime}") asserts.assert_equal(forecast6.endTime, forecast7.endTime, f"Expected old endTime {forecast6.endTime} to be == endTime {forecast7.endTime}") - self.step("12") + self.step("13") await self.send_start_time_adjust_request_command(requestedStartTime=forecast7.startTime+(forecast7.latestEndTime-forecast7.endTime)+1, cause=Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization, expected_status=Status.ConstraintError) - self.step("12a") + self.step("13a") await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kOnline) - self.step("12b") + self.step("13b") forecast8 = await self.read_dem_attribute_expect_success(attribute="Forecast") asserts.assert_equal(forecast7.startTime, forecast8.startTime, f"Expected old startTime {forecast7.startTime} to be == startTime {forecast8.startTime}") asserts.assert_equal(forecast7.endTime, forecast8.endTime, f"Expected old endTime {forecast7.endTime} to be == endTime {forecast8.endTime}") - self.step("13") + self.step("14") await self.send_cancel_request_command(expected_status=Status.InvalidInState) - self.step("14") + self.step("15") await self.send_test_event_trigger_start_time_adjustment_clear() diff --git a/src/python_testing/TC_DEM_2_4.py b/src/python_testing/TC_DEM_2_4.py index 2528b646014d65..dc63e4b21a25a4 100644 --- a/src/python_testing/TC_DEM_2_4.py +++ b/src/python_testing/TC_DEM_2_4.py @@ -55,98 +55,100 @@ def pics_TC_DEM_2_4(self): def steps_TC_DEM_2_4(self) -> list[TestStep]: steps = [ - TestStep("1", "Commissioning, already done", - is_commissioning=True), - TestStep("2", "TH reads TestEventTriggersEnabled attribute from General Diagnostics Cluster.", - "Verify that TestEventTriggersEnabled attribute has a value of 1 (True)"), - TestStep("3", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Pausable Test Event", - "Verify DUT responds with status SUCCESS(0x00)"), - TestStep("3a", "TH reads ESAState.", - "Verify value is 0x01 (Online)"), - TestStep("3b", "TH reads Forecast.", - "Value has to include IsPausable=True, slot[0].SlotIsPausable=True, slot[0].MinPauseDuration>1, slot[0].MaxPauseDuration>1, slot[1].SlotIsPausable=False, ActiveSlotNumber=0, and ForecastUpdateReason=Internal Optimization"), - TestStep("3c", "TH reads OptOutState.", - "Verify value is 0x00 (NoOptOut)"), - TestStep("4", "TH sends PauseRequest with Duration=Forecast.slots[0].MinPauseDuration-1, Cause=LocalOptimization.", - "Verify DUT responds with status CONSTRAINT_ERROR(0x87)"), - TestStep("4a", "TH reads ESAState.", - "Verify value is 0x01 (Online)"), - TestStep("5", "TH sends PauseRequest with Duration=Forecast.slots[0].MaxPauseDuration+1, Cause=LocalOptimization.", - "Verify DUT responds with status CONSTRAINT_ERROR(0x87)"), - TestStep("5a", "TH reads ESAState.", - "Verify value is 0x01 (Online)"), - TestStep("6", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Grid Optimization Test Event", - "Verify DUT responds with status SUCCESS(0x00)"), - TestStep("6a", "TH reads ESAState.", - "Verify value is 0x01 (Online)"), - TestStep("6b", "TH reads OptOutState.", - "Verify value is 0x02 (GridOptOut)"), - TestStep("7", "TH sends PauseRequest with Duration=Forecast.slots[0].MinPauseDuration, Cause=GridOptimization.", - "Verify DUT responds with status CONSTRAINT_ERROR(0x87)"), - TestStep("7a", "TH reads ESAState.", - "Verify value is 0x01 (Online)"), - TestStep("8", "TH sends PauseRequest with Duration=Forecast.slots[0].MinPauseDuration, Cause=LocalOptimization.", - "Verify DUT responds with status SUCCESS(0x00) and event DEM.S.E02(Paused) sent"), - TestStep("8a", "TH reads ESAState.", - "Verify value is 0x05 (Paused)"), - TestStep("9", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Local Optimization Test Event.", - "Verify DUT responds with status SUCCESS(0x00) and event DEM.S.E03(Resumed) sent with Cause=3 (UserOptOut)"), - TestStep("9a", "TH reads ESAState.", - "Verify value is 0x01 (Online)"), - TestStep("9b", "TH reads OptOutState.", - "Verify value is 0x03 (OptOut)"), - TestStep("9c", "TH reads Forecast.", - "Value has to include ForecastUpdateReason=Internal Optimization"), - TestStep("10", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Test Event Clear", - "Verify DUT responds with status SUCCESS(0x00)"), - TestStep("10a", "TH reads ESAState.", - "Verify value is 0x01 (Online)"), - TestStep("10b", "TH reads OptOutState.", - "Verify value is 0x00 (NoOptOut)"), - TestStep("11", "TH sends PauseRequest with Duration=Forecast.slots[0].MinPauseDuration, Cause=LocalOptimization.", - "Verify DUT responds with status SUCCESS(0x00) and event DEM.S.E02(Paused) sent"), - TestStep("11a", "TH reads ESAState.", - "Verify value is 0x05 (Paused)"), - TestStep("11b", "TH reads Forecast.", + TestStep("1", "Commission DUT to TH (can be skipped if done in a preceding test)"), + TestStep("2", "TH reads from the DUT the _Featuremap_ attribute", + "Verify that the DUT response contains the _Featuremap_ attribute. Verify Pausable is supported."), + TestStep("3", "Set up a subscription to all DeviceEnergyManagement cluster events"), + TestStep("4", "TH reads TestEventTriggersEnabled attribute from General Diagnostics Cluster", + "Value has to be 1 (True)"), + TestStep("5", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Pausable Test Event", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("5a", "TH reads from the DUT the ESAState", + "Value has to be 0x01 (Online)"), + TestStep("5b", "TH reads from the DUT the Forecast", + "Value has to include IsPausable=True, slots[0].SlotIsPausable=True, slots[0].MinPauseDuration>1, slots[0].MaxPauseDuration>1, slots[1].SlotIsPausable=False, ActiveSlotNumber=0, and ForecastUpdateReason=Internal Optimization"), + TestStep("5c", "TH reads from the DUT the OptOutState", + "Value has to be 0x00 (NoOptOut)"), + TestStep("6", "TH sends command PauseRequest with Duration=Forecast.slots[0].MinPauseDuration-1, Cause=LocalOptimization", + "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"), + TestStep("6a", "TH reads from the DUT the ESAState", + "Value has to be 0x01 (Online)"), + TestStep("7", "TH sends command PauseRequest with Duration=Forecast.slots[0].MaxPauseDuration+1, Cause=LocalOptimization", + "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"), + TestStep("7a", "TH reads from the DUT the ESAState", + "Value has to be 0x01 (Online)"), + TestStep("8", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Grid Optimization Test Event", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("8a", "TH reads from the DUT the ESAState", + "Value has to be 0x01 (Online)"), + TestStep("8b", "TH reads from the DUT the OptOutState", + "Value has to be 0x02 (GridOptOut)"), + TestStep("9", "TH sends command PauseRequest with Duration=Forecast.slots[0].MinPauseDuration, Cause=GridOptimization", + "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"), + TestStep("9a", "TH reads from the DUT the ESAState", + "Value has to be 0x01 (Online)"), + TestStep("10", "TH sends command PauseRequest with Duration=Forecast.slots[0].MinPauseDuration, Cause=LocalOptimization", + "Verify DUT responds w/ status SUCCESS(0x00) and Event DEM.S.E02(Paused) sent"), + TestStep("10a", "TH reads from the DUT the ESAState", + "Value has to be 0x05 (Paused)"), + TestStep("11", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Local Optimization Test Event", + "Verify DUT responds w/ status SUCCESS(0x00) and Event DEM.S.E03(Resumed) sent with Cause=3 (UserOptOut)"), + TestStep("11a", "TH reads from the DUT the ESAState", + "Value has to be 0x01 (Online)"), + TestStep("11b", "TH reads from the DUT the OptOutState", + "Value has to be 0x03 (OptOut)"), + TestStep("11c", "TH reads from the DUT the Forecast", + "Value has to include ForecastUpdateReason=Internal Optimization"), + TestStep("12", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Test Event Clear", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("12a", "TH reads from the DUT the ESAState", + "Value has to be 0x01 (Online)"), + TestStep("12b", "TH reads from the DUT the OptOutState", + "Value has to be 0x00 (NoOptOut)"), + TestStep("13", "TH sends command PauseRequest with Duration=Forecast.slots[0].MinPauseDuration, Cause=LocalOptimization", + "Verify DUT responds w/ status SUCCESS(0x00) and Event DEM.S.E02(Paused) sent"), + TestStep("13a", "TH reads from the DUT the ESAState", + "Value has to be 0x05 (Paused)"), + TestStep("13b", "TH reads from the DUT the Forecast", "Value has to include ForecastUpdateReason=Local Optimization"), - TestStep("12", "TH sends ResumeRequest.", - "Verify DUT responds with status SUCCESS(0x00) and event DEM.S.E03(Resumed) sent with Cause=4 (Cancelled)"), - TestStep("12a", "TH reads ESAState.", - "Verify value is 0x01 (Online)"), - TestStep("12b", "TH reads Forecast.", - "Value has to include IsPausable=True, slots[0].SlotIsPausable=True, slots[0].MinPauseDuration>1, slots[0].MaxPauseDuration>1, slots[1].SlotIsPausable=False, ActiveSlotNumber=0, ForecastUpdateReason=Internal Optimization"), - TestStep("13", "TH sends PauseRequest with Duration=Forecast.slots[0].MinPauseDuration, Cause=LocalOptimization.", - "Verify DUT responds with status SUCCESS(0x00) and event DEM.S.E02(Paused) sent"), - TestStep("13a", "TH reads ESAState.", - "Verify value is 0x05 (Paused)"), - TestStep("13b", "TH reads Forecast.", + TestStep("14", "TH sends command ResumeRequest", + "Verify DUT responds w/ status SUCCESS(0x00) and Event DEM.S.E03(Resumed) sent with Cause=4 (Cancelled)"), + TestStep("14a", "TH reads from the DUT the ESAState", + "Value has to be 0x01 (Online)"), + TestStep("14b", "TH reads from the DUT the Forecast", + "Value has to include IsPausable=True, slots[0].SlotIsPausable=True, slots[0].MinPauseDuration>1, slots[0].MaxPauseDuration>1, slots[1].SlotIsPausable=False, ActiveSlotNumber=0, ForecastUpdateReason=InternalOptimization"), + TestStep("15", "TH sends command PauseRequest with Duration=Forecast.slots[0].MinPauseDuration, Cause=LocalOptimization", + "Verify DUT responds w/ status SUCCESS(0x00) and Event DEM.S.E02(Paused) sent"), + TestStep("15a", "TH reads from the DUT the ESAState", + "Value has to be 0x05 (Paused)"), + TestStep("15b", "TH reads from the DUT the Forecast", "Value has to include ForecastUpdateReason=Local Optimization"), - TestStep("14", "TH sends ResumeRequest.", - "Verify DUT responds with status SUCCESS(0x00) and event DEM.S.E03(Resumed) sent with Cause=4 (Cancelled)"), - TestStep("14a", "TH reads ESAState.", - "Verify value is 0x01 (Online)"), - TestStep("15", "TH sends PauseRequest with Duration=Forecast.slots[0].MinPauseDuration, Cause=LocalOptimization.", - "Verify DUT responds with status SUCCESS(0x00) and event DEM.S.E02(Paused) sent"), - TestStep("15a", "TH reads ESAState.", - "Verify value is 0x05 (Paused)"), - TestStep("16", "Wait for minPauseDuration.", + TestStep("16", "TH sends command ResumeRequest", + "Verify DUT responds w/ status SUCCESS(0x00) and Event DEM.S.E03(Resumed) sent with Cause=4 (Cancelled)"), + TestStep("16a", "TH reads from the DUT the ESAState", + "Value has to be 0x01 (Online)"), + TestStep("17", "TH sends command PauseRequest with Duration=Forecast.slots[0].MinPauseDuration, Cause=LocalOptimization", + "Verify DUT responds w/ status SUCCESS(0x00) and Event DEM.S.E02(Paused) sent"), + TestStep("17a", "TH reads from the DUT the ESAState", + "Value has to be 0x05 (Paused)"), + TestStep("18", "", "Event DEM.S.E03(Resumed) sent with Cause=0 (NormalCompletion)"), - TestStep("16a", "TH reads ESAState.", - "Verify value is 0x01 (Online)"), - TestStep("17", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Pausable Test Event Next Slot.", - "Verify DUT responds with status SUCCESS(0x00)"), - TestStep("17a", "TH reads ESAState.", - "Verify value is 0x01 (Online)"), - TestStep("17b", "TH reads Forecast.", + TestStep("18a", "TH reads from the DUT the ESAState", + "Value has to be 0x01 (Online)"), + TestStep("19", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Pausable Test Event Next Slot", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("19a", "TH reads from the DUT the ESAState", + "Value has to be 0x01 (Online)"), + TestStep("19b", "TH reads from the DUT the Forecast", "Value has to include ActiveSlotNumber=1"), - TestStep("18", "TH sends PauseRequest with Duration=Forecast.slots[0].MinPauseDuration, Cause=LocalOptimization.", - "Verify DUT responds with status FAILURE(0x01)"), - TestStep("18a", "TH reads ESAState.", - "Verify value is 0x01 (Online)"), - TestStep("19", "TH sends ResumeRequest.", - "Verify DUT responds with status INVALID_IN_STATE(0xcb)"), - TestStep("20", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Pausable Test Event Clear.", - "Verify DUT responds with status SUCCESS(0x00)"), + TestStep("20", "TH sends command PauseRequest with Duration=Forecast.slots[0].MinPauseDuration, Cause=LocalOptimization", + "Verify DUT responds w/ status FAILURE(0x01)"), + TestStep("20a", "TH reads from the DUT the ESAState", + "Value has to be 0x01 (Online)"), + TestStep("21", "TH sends command ResumeRequest", + "Verify DUT responds w/ status INVALID_IN_STATE(0xcb)"), + TestStep("22", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Pausable Test Event Clear", + "Verify DUT responds w/ status SUCCESS(0x00)"), ] return steps @@ -159,25 +161,27 @@ async def test_TC_DEM_2_4(self): self.step("1") # Commission DUT - already done + self.step("2") await self.validate_feature_map([Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPausable], []) await self.validate_pfr_or_sfr_in_feature_map() + self.step("3") # Subscribe to Events and when they are sent push them to a queue for checking later events_callback = EventChangeCallback(Clusters.DeviceEnergyManagement) await events_callback.start(self.default_controller, self.dut_node_id, self.matter_test_config.endpoint) - self.step("2") + self.step("4") await self.check_test_event_triggers_enabled() - self.step("3") + self.step("5") await self.send_test_event_trigger_pausable() - self.step("3a") + self.step("5a") await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kOnline) - self.step("3b") + self.step("5b") forecast = await self.read_dem_attribute_expect_success(attribute="Forecast") asserts.assert_not_equal(forecast, NullValue) @@ -196,100 +200,100 @@ async def test_TC_DEM_2_4(self): f"Expected forecast forecastUpdateReason {forecast.forecastUpdateReason} to be == Clusters.DeviceEnergyManagement.Enums.ForecastUpdateReasonEnum.kInternalOptimization") self.print_forecast(forecast) - self.step("3c") + self.step("5c") await self.check_dem_attribute("OptOutState", Clusters.DeviceEnergyManagement.Enums.OptOutStateEnum.kNoOptOut) - self.step("4") + self.step("6") await self.send_pause_request_command(forecast.slots[0].minPauseDuration - 1, Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization, expected_status=Status.ConstraintError) - self.step("4a") + self.step("6a") await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kOnline) - self.step("5") + self.step("7") await self.send_pause_request_command(forecast.slots[0].maxPauseDuration + 1, Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization, expected_status=Status.ConstraintError) - self.step("5a") + self.step("7a") await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kOnline) - self.step("6") + self.step("8") await self.send_test_event_trigger_user_opt_out_grid() - self.step("6a") + self.step("8a") await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kOnline) - self.step("6b") + self.step("8b") await self.check_dem_attribute("OptOutState", Clusters.DeviceEnergyManagement.Enums.OptOutStateEnum.kGridOptOut) - self.step("7") + self.step("9") await self.send_pause_request_command(forecast.slots[0].minPauseDuration, Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kGridOptimization, expected_status=Status.ConstraintError) - self.step("7a") + self.step("9a") await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kOnline) - self.step("8") + self.step("10") await self.send_pause_request_command(forecast.slots[0].minPauseDuration, Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization) event_data = events_callback.wait_for_event_report(Clusters.DeviceEnergyManagement.Events.Paused) - self.step("8a") + self.step("10a") await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kPaused) - self.step("9") + self.step("11") await self.send_test_event_trigger_user_opt_out_local() event_data = events_callback.wait_for_event_report(Clusters.DeviceEnergyManagement.Events.Resumed) asserts.assert_equal(event_data.cause, Clusters.DeviceEnergyManagement.Enums.CauseEnum.kUserOptOut) - self.step("9a") + self.step("11a") await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kOnline) - self.step("9b") + self.step("11b") await self.check_dem_attribute("OptOutState", Clusters.DeviceEnergyManagement.Enums.OptOutStateEnum.kOptOut) - self.step("9c") + self.step("11c") forecast = await self.read_dem_attribute_expect_success(attribute="Forecast") asserts.assert_not_equal(forecast, NullValue) asserts.assert_equal(forecast.forecastUpdateReason, Clusters.DeviceEnergyManagement.Enums.ForecastUpdateReasonEnum.kInternalOptimization) - self.step("10") + self.step("12") await self.send_test_event_trigger_user_opt_out_clear_all() - self.step("10a") + self.step("12a") await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kOnline) - self.step("10b") + self.step("12b") await self.check_dem_attribute("OptOutState", Clusters.DeviceEnergyManagement.Enums.OptOutStateEnum.kNoOptOut) - self.step("11") + self.step("13") await self.send_pause_request_command(forecast.slots[0].minPauseDuration, Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization) event_data = events_callback.wait_for_event_report(Clusters.DeviceEnergyManagement.Events.Paused) - self.step("11a") + self.step("13a") await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kPaused) - self.step("11b") + self.step("13b") forecast = await self.read_dem_attribute_expect_success(attribute="Forecast") asserts.assert_equal(forecast.forecastUpdateReason, Clusters.DeviceEnergyManagement.Enums.ForecastUpdateReasonEnum.kLocalOptimization) - self.step("12") + self.step("14") await self.send_resume_request_command() event_data = events_callback.wait_for_event_report(Clusters.DeviceEnergyManagement.Events.Resumed) asserts.assert_equal(event_data.cause, Clusters.DeviceEnergyManagement.Enums.CauseEnum.kCancelled) - self.step("12a") + self.step("14a") await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kOnline) - self.step("12b") + self.step("14b") forecast = await self.read_dem_attribute_expect_success(attribute="Forecast") asserts.assert_equal(forecast.isPausable, True) asserts.assert_greater(forecast.slots[0].minPauseDuration, 1) @@ -300,66 +304,66 @@ async def test_TC_DEM_2_4(self): asserts.assert_equal(forecast.forecastUpdateReason, Clusters.DeviceEnergyManagement.Enums.ForecastUpdateReasonEnum.kInternalOptimization) - self.step("13") + self.step("15") await self.send_pause_request_command(forecast.slots[0].minPauseDuration, Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization) event_data = events_callback.wait_for_event_report(Clusters.DeviceEnergyManagement.Events.Paused) - self.step("13a") + self.step("15a") await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kPaused) - self.step("13b") + self.step("15b") forecast = await self.read_dem_attribute_expect_success(attribute="Forecast") asserts.assert_equal(forecast.forecastUpdateReason, Clusters.DeviceEnergyManagement.Enums.ForecastUpdateReasonEnum.kLocalOptimization) - self.step("14") + self.step("16") await self.send_resume_request_command() event_data = events_callback.wait_for_event_report(Clusters.DeviceEnergyManagement.Events.Resumed) asserts.assert_equal(event_data.cause, Clusters.DeviceEnergyManagement.Enums.CauseEnum.kCancelled) - self.step("14a") + self.step("16a") await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kOnline) - self.step("15") + self.step("17") await self.send_pause_request_command(forecast.slots[0].minPauseDuration, Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization) event_data = events_callback.wait_for_event_report(Clusters.DeviceEnergyManagement.Events.Paused) - self.step("15a") + self.step("17a") await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kPaused) - self.step("16") + self.step("18") logging.info(f"Sleeping for forecast.slots[0].minPauseDuration {forecast.slots[0].minPauseDuration}s") time.sleep(forecast.slots[0].minPauseDuration) event_data = events_callback.wait_for_event_report(Clusters.DeviceEnergyManagement.Events.Resumed) asserts.assert_equal(event_data.cause, Clusters.DeviceEnergyManagement.Enums.CauseEnum.kNormalCompletion) - self.step("16a") + self.step("18a") await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kOnline) - self.step("17") + self.step("19") await self.send_test_event_trigger_pausable_next_slot() - self.step("17a") + self.step("19a") await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kOnline) - self.step("17b") + self.step("19b") forecast = await self.read_dem_attribute_expect_success(attribute="Forecast") asserts.assert_equal(forecast.activeSlotNumber, 1) - self.step("18") + self.step("20") await self.send_pause_request_command(forecast.slots[0].minPauseDuration, Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization, expected_status=Status.Failure) - self.step("18a") + self.step("20a") await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kOnline) - self.step("19") + self.step("21") await self.send_resume_request_command(expected_status=Status.InvalidInState) - self.step("20") + self.step("22") await self.send_test_event_trigger_user_opt_out_clear_all() diff --git a/src/python_testing/TC_DEM_2_5.py b/src/python_testing/TC_DEM_2_5.py index d7ab0521e678ab..f1cc81660e7ab5 100644 --- a/src/python_testing/TC_DEM_2_5.py +++ b/src/python_testing/TC_DEM_2_5.py @@ -34,7 +34,7 @@ import chip.clusters as Clusters from chip.interaction_model import Status -from matter_testing_support import EventChangeCallback, MatterBaseTest, TestStep, async_test_body, default_matter_test_main +from matter_testing_support import MatterBaseTest, TestStep, async_test_body, default_matter_test_main from mobly import asserts from TC_DEMTestBase import DEMTestBase @@ -59,80 +59,81 @@ def pics_TC_DEM_2_5(self): def steps_TC_DEM_2_5(self) -> list[TestStep]: """Execute the test steps.""" steps = [ - TestStep("1", "Commissioning, already done", - is_commissioning=True), - TestStep("2", "TH reads TestEventTriggersEnabled attribute from General Diagnostics Cluster.", - "Verify that TestEventTriggersEnabled attribute has a value of 1 (True)"), - TestStep("3", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Forecast Adjustment Test Event", - "Verify DUT responds with status SUCCESS(0x00)"), - TestStep("3a", "TH reads ESAState attribute.", - "Verify value is 0x01 (Online)"), - TestStep("3b", "TH reads Forecast attribute.", + TestStep("1", "Commission DUT to TH (can be skipped if done in a preceding test)"), + TestStep("2", "TH reads from the DUT the _Featuremap_ attribute", + "Verify that the DUT response contains the _Featuremap_ attribute. Verify ForecastAdjustment and PowerForecastReporting is supported. . Verify StateForecastReporting is not supported."), + TestStep("3", "TH reads TestEventTriggersEnabled attribute from General Diagnostics Cluster", + "Value has to be 1 (True)"), + TestStep("4", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Forecast Adjustment Test Event", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("4a", "TH reads from the DUT the ESAState", + "Value has to be 0x01 (Online)"), + TestStep("4b", "TH reads from the DUT the Forecast", "Value has to include slots[0].MinPowerAdjustment, slots[0].MaxPowerAdjustment, slots[0].MinDurationAdjustment, slots[0].MaxDurationAdjustment"), - TestStep("3c", "TH reads OptOutState attribute.", - "Verify value is 0x00 (NoOptOut)"), - TestStep("4", "TH sends ModifyForecastRequest with ForecastID=Forecast.ForecastID+1, SlotAdjustments[0].{SlotIndex=0, NominalPower=Forecast.Slots[0].MinPowerAdjustment, Duration=Forecast.Slots[0].MaxDurationAdjustment}, Cause=GridOptimization.", - "Verify DUT responds with status FAILURE(0x01)"), - TestStep("5", "TH sends ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=4, NominalPower=Forecast.Slots[0].MinPowerAdjustment, Duration=Forecast.Slots[0].MaxDurationAdjustment}, Cause=GridOptimization.", - "Verify DUT responds with status FAILURE(0x01)"), - TestStep("6", "TH sends ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, NominalPower=Forecast.Slots[0].MinPowerAdjustment-1, Duration=Forecast.Slots[0].MaxDurationAdjustment}, Cause=GridOptimization.", - "Verify DUT responds with status CONSTRAINT_ERROR(0x87)"), - TestStep("7", "TH sends ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, NominalPower=Forecast.Slots[0].MaxPowerAdjustment+1, Duration=Forecast.Slots[0].MinDurationAdjustment}, Cause=GridOptimization.", - "Verify DUT responds with status CONSTRAINT_ERROR(0x87)"), - TestStep("8", "TH sends ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, NominalPower=Forecast.Slots[0].MinPowerAdjustment, Duration=Forecast.Slots[0].MaxDurationAdjustment+1}, Cause=GridOptimization.", - "Verify DUT responds with status CONSTRAINT_ERROR(0x87)"), - TestStep("9", "TH sends ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, NominalPower=Forecast.Slots[0].MaxPowerAdjustment, Duration=Forecast.Slots[0].MinDurationAdjustment-1}, Cause=GridOptimization.", - "Verify DUT responds with status CONSTRAINT_ERROR(0x87)"), - TestStep("10", "TH sends ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, NominalPower=Forecast.Slots[0].MinPowerAdjustment, Duration=Forecast.Slots[0].MaxDurationAdjustment}, SlotAdjustments[1].{SlotIndex=4, NominalPower=Forecast.Slots[0].MinPowerAdjustment, Duration=Forecast.Slots[0].MaxDurationAdjustment}, Cause=GridOptimization.", - "Verify DUT responds with status FAILURE(0x01)"), - TestStep("11", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Local Optimization Test Event", - "Verify DUT responds with status SUCCESS(0x00)"), - TestStep("11a", "TH reads ESAState attribute.", - "Verify value is 0x01 (Online)"), - TestStep("11b", "TH reads OptOutState attribute.", - "Verify value is 0x02 (LocalOptOut)"), - TestStep("12", "TH sends ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, NominalPower=Forecast.Slots[0].MinPowerAdjustment, Duration=Forecast.Slots[0].MaxDurationAdjustment}, Cause=LocalOptimization.", - "Verify DUT responds with status CONSTRAINT_ERROR(0x87)"), - TestStep("13", "TH sends ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, NominalPower=Forecast.Slots[0].MinPowerAdjustment, Duration=Forecast.Slots[0].MaxDurationAdjustment}, Cause=GridOptimization.", - "Verify DUT responds with status SUCCESS(0x00)"), - TestStep("13a", "TH reads Forecast attribute.", + TestStep("4c", "TH reads from the DUT the OptOutState", + "Value has to be 0x00 (NoOptOut)"), + TestStep("5", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID+1, SlotAdjustments[0].{SlotIndex=0, NominalPower=Forecast.Slots[0].MinPowerAdjustment, Duration=Forecast.Slots[0].MaxDurationAdjustment}, Cause=GridOptimization", + "Verify DUT responds w/ status FAILURE(0x01)"), + TestStep("6", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=4, NominalPower=Forecast.Slots[0].MinPowerAdjustment, Duration=Forecast.Slots[0].MaxDurationAdjustment}, Cause=GridOptimization", + "Verify DUT responds w/ status FAILURE(0x01)"), + TestStep("7", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, NominalPower=Forecast.Slots[0].MinPowerAdjustment-1, Duration=Forecast.Slots[0].MaxDurationAdjustment}, Cause=GridOptimization", + "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"), + TestStep("8", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, NominalPower=Forecast.Slots[0].MaxPowerAdjustment+1, Duration=Forecast.Slots[0].MinDurationAdjustment}, Cause=GridOptimization", + "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"), + TestStep("9", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, NominalPower=Forecast.Slots[0].MinPowerAdjustment, Duration=Forecast.Slots[0].MaxDurationAdjustment+1}, Cause=GridOptimization", + "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"), + TestStep("10", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, NominalPower=Forecast.Slots[0].MaxPowerAdjustment, Duration=Forecast.Slots[0].MinDurationAdjustment-1}, Cause=GridOptimization", + "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"), + TestStep("11", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, NominalPower=Forecast.Slots[0].MinPowerAdjustment, Duration=Forecast.Slots[0].MaxDurationAdjustment}, SlotAdjustments[1].{SlotIndex=4, NominalPower=Forecast.Slots[0].MinPowerAdjustment, Duration=Forecast.Slots[0].MaxDurationAdjustment}, Cause=GridOptimization", + "Verify DUT responds w/ status FAILURE(0x01)"), + TestStep("12", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Local Optimization Test Event", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("12a", "TH reads from the DUT the ESAState", + "Value has to be 0x01 (Online)"), + TestStep("12b", "TH reads from the DUT the OptOutState", + "Value has to be 0x02 (LocalOptOut)"), + TestStep("13", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, NominalPower=Forecast.Slots[0].MinPowerAdjustment, Duration=Forecast.Slots[0].MaxDurationAdjustment}, Cause=LocalOptimization", + "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"), + TestStep("14", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, NominalPower=Forecast.Slots[0].MinPowerAdjustment, Duration=Forecast.Slots[0].MaxDurationAdjustment}, Cause=GridOptimization", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("14a", "TH reads from the DUT the Forecast", "Value has to include ForecastUpdateReason=GridOptimization"), - TestStep("14", "TH sends CancelRequest.", - "Verify DUT responds with status SUCCESS(0x00)"), - TestStep("14a", "TH reads Forecast attribute.", + TestStep("15", "TH sends command CancelRequest", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("15a", "TH reads from the DUT the Forecast", "Value has to include ForecastUpdateReason=InternalOptimization"), - TestStep("15", "TH sends ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, NominalPower=Forecast.Slots[0].MinPowerAdjustment, Duration=Forecast.Slots[0].MaxDurationAdjustment}, Cause=GridOptimization.", - "Verify DUT responds with status SUCCESS(0x00)"), - TestStep("15a", "TH reads Forecast attribute.", + TestStep("16", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, NominalPower=Forecast.Slots[0].MinPowerAdjustment, Duration=Forecast.Slots[0].MaxDurationAdjustment}, Cause=GridOptimization", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("16a", "TH reads from the DUT the Forecast", "Value has to include ForecastUpdateReason=GridOptimization"), - TestStep("16", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Grid Optimization Test Event", - "Verify DUT responds with status SUCCESS(0x00)"), - TestStep("16a", "TH reads OptOutState attribute.", - "Verify value is 0x03 (OptOut)"), - TestStep("16b", "TH reads Forecast attribute.", + TestStep("17", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Grid Optimization Test Event", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("17a", "TH reads from the DUT the OptOutState", + "Value has to be 0x03 (OptOut)"), + TestStep("17b", "TH reads from the DUT the Forecast", "Value has to include ForecastUpdateReason=Internal Optimization"), - TestStep("17", "TH sends ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, NominalPower=Forecast.Slots[0].MinPowerAdjustment, Duration=Forecast.Slots[0].MaxDurationAdjustment}, Cause=GridOptimization.", - "Verify DUT responds with status CONSTRAINT_ERROR(0x87)"), - TestStep("18", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Test Event Clear", - "Verify DUT responds with status SUCCESS(0x00)"), - TestStep("18a", "TH reads OptOutState attribute.", - "Verify value is 0x00 (NoOptOut)"), - TestStep("19", "TH sends ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, NominalPower=Forecast.Slots[0].MaxPowerAdjustment, Duration=Forecast.Slots[0].MinDurationAdjustment}, Cause=LocalOptimization.", - "Verify DUT responds with status SUCCESS(0x00)"), - TestStep("19a", "TH reads Forecast attribute.", + TestStep("18", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, NominalPower=Forecast.Slots[0].MinPowerAdjustment, Duration=Forecast.Slots[0].MaxDurationAdjustment}, Cause=GridOptimization", + "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"), + TestStep("19", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Test Event Clear", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("19a", "TH reads from the DUT the OptOutState", + "Value has to be 0x00 (NoOptOut)"), + TestStep("20", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, NominalPower=Forecast.Slots[0].MaxPowerAdjustment, Duration=Forecast.Slots[0].MinDurationAdjustment}, Cause=LocalOptimization", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("20a", "TH reads from the DUT the Forecast", "Value has to include ForecastUpdateReason=LocalOptimization"), - TestStep("20", "TH sends CancelRequest.", - "Verify DUT responds with status SUCCESS(0x00)"), - TestStep("20a", "TH reads Forecast attribute.", + TestStep("21", "TH sends command CancelRequest", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("21a", "TH reads from the DUT the Forecast", "Value has to include ForecastUpdateReason=InternalOptimization"), - TestStep("21", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Forecast Adjustment Test Event Next Slot", - "Verify DUT responds with status SUCCESS(0x00)"), - TestStep("22", "TH sends ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, NominalPower=Forecast.Slots[0].MaxPowerAdjustment, Duration=Forecast.Slots[0].MinDurationAdjustment}, Cause=LocalOptimization.", - "Verify DUT responds with status CONSTRAINT_ERROR(0x87)"), - TestStep("23", "TH sends CancelRequest.", - "Verify DUT responds with status INVALID_IN_STATE(0xcb)"), - TestStep("24", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Forecast Adjustment Test Event Clear", - "Verify DUT responds with status SUCCESS(0x00)"), + TestStep("22", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Forecast Adjustment Test Event Next Slot", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("23", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, NominalPower=Forecast.Slots[0].MaxPowerAdjustment, Duration=Forecast.Slots[0].MinDurationAdjustment}, Cause=LocalOptimization", + "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"), + TestStep("24", "TH sends command CancelRequest", + "Verify DUT responds w/ status INVALID_IN_STATE(0xcb)"), + TestStep("25", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Forecast Adjustment Test Event Clear", + "Verify DUT responds w/ status SUCCESS(0x00)"), ] return steps @@ -144,26 +145,21 @@ async def test_TC_DEM_2_5(self): self.step("1") # Commission DUT - already done + self.step("2") await self.validate_feature_map([Clusters.DeviceEnergyManagement.Bitmaps.Feature.kForecastAdjustment, Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerForecastReporting], - []) - - # Subscribe to Events and when they are sent push them to a queue for checking later - events_callback = EventChangeCallback(Clusters.DeviceEnergyManagement) - await events_callback.start(self.default_controller, - self.dut_node_id, - self.matter_test_config.endpoint) + [Clusters.DeviceEnergyManagement.Bitmaps.Feature.kStateForecastReporting]) - self.step("2") + self.step("3") await self.check_test_event_triggers_enabled() - self.step("3") + self.step("4") await self.send_test_event_trigger_forecast_adjustment() - self.step("3a") + self.step("4a") await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kOnline) - self.step("3b") + self.step("4b") forecast = await self.read_dem_attribute_expect_success(attribute="Forecast") asserts.assert_is_not_none(forecast.slots[0].minPowerAdjustment) @@ -171,138 +167,138 @@ async def test_TC_DEM_2_5(self): asserts.assert_is_not_none(forecast.slots[0].minDurationAdjustment) asserts.assert_is_not_none(forecast.slots[0].maxDurationAdjustment) - self.step("3c") + self.step("4c") await self.check_dem_attribute("OptOutState", Clusters.DeviceEnergyManagement.Enums.OptOutStateEnum.kNoOptOut) - self.step("4") + self.step("5") slotAdjustments = [Clusters.DeviceEnergyManagement.Structs.SlotAdjustmentStruct( slotIndex=0, nominalPower=forecast.slots[0].minPowerAdjustment, duration=forecast.slots[0].maxDurationAdjustment)] await self.send_modify_forecast_request_command(forecast.forecastID + 1, slotAdjustments, Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kGridOptimization, expected_status=Status.Failure) - self.step("5") + self.step("6") slotAdjustments = [Clusters.DeviceEnergyManagement.Structs.SlotAdjustmentStruct( slotIndex=4, nominalPower=forecast.slots[0].minPowerAdjustment, duration=forecast.slots[0].maxDurationAdjustment)] await self.send_modify_forecast_request_command(forecast.forecastID, slotAdjustments, Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kGridOptimization, expected_status=Status.Failure) - self.step("6") + self.step("7") slotAdjustments = [Clusters.DeviceEnergyManagement.Structs.SlotAdjustmentStruct( slotIndex=0, nominalPower=forecast.slots[0].minPowerAdjustment - 1, duration=forecast.slots[0].maxDurationAdjustment)] await self.send_modify_forecast_request_command(forecast.forecastID, slotAdjustments, Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kGridOptimization, expected_status=Status.ConstraintError) - self.step("7") + self.step("8") slotAdjustments = [Clusters.DeviceEnergyManagement.Structs.SlotAdjustmentStruct( slotIndex=0, nominalPower=forecast.slots[0].maxPowerAdjustment + 1, duration=forecast.slots[0].minDurationAdjustment)] await self.send_modify_forecast_request_command(forecast.forecastID, slotAdjustments, Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kGridOptimization, expected_status=Status.ConstraintError) - self.step("8") + self.step("9") slotAdjustments = [Clusters.DeviceEnergyManagement.Structs.SlotAdjustmentStruct( slotIndex=0, nominalPower=forecast.slots[0].minPowerAdjustment, duration=forecast.slots[0].maxDurationAdjustment + 1)] await self.send_modify_forecast_request_command(forecast.forecastID, slotAdjustments, Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kGridOptimization, expected_status=Status.ConstraintError) - self.step("9") + self.step("10") slotAdjustments = [Clusters.DeviceEnergyManagement.Structs.SlotAdjustmentStruct( slotIndex=0, nominalPower=forecast.slots[0].maxPowerAdjustment, duration=forecast.slots[0].minDurationAdjustment - 1)] await self.send_modify_forecast_request_command(forecast.forecastID, slotAdjustments, Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kGridOptimization, expected_status=Status.ConstraintError) - self.step("10") + self.step("11") slotAdjustments = [Clusters.DeviceEnergyManagement.Structs.SlotAdjustmentStruct(slotIndex=0, nominalPower=forecast.slots[0].minPowerAdjustment, duration=forecast.slots[0].maxDurationAdjustment), Clusters.DeviceEnergyManagement.Structs.SlotAdjustmentStruct(slotIndex=4, nominalPower=forecast.slots[0].minPowerAdjustment, duration=forecast.slots[0].maxDurationAdjustment)] await self.send_modify_forecast_request_command(forecast.forecastID, slotAdjustments, Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kGridOptimization, expected_status=Status.Failure) - self.step("11") + self.step("12") await self.send_test_event_trigger_user_opt_out_local() - self.step("11a") + self.step("12a") await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kOnline) - self.step("11b") + self.step("12b") await self.check_dem_attribute("OptOutState", Clusters.DeviceEnergyManagement.Enums.OptOutStateEnum.kLocalOptOut) - self.step("12") + self.step("13") slotAdjustments = [Clusters.DeviceEnergyManagement.Structs.SlotAdjustmentStruct( slotIndex=0, nominalPower=forecast.slots[0].minPowerAdjustment, duration=forecast.slots[0].maxDurationAdjustment)] await self.send_modify_forecast_request_command(forecast.forecastID, slotAdjustments, Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization, expected_status=Status.ConstraintError) - self.step("13") + self.step("14") slotAdjustments = [Clusters.DeviceEnergyManagement.Structs.SlotAdjustmentStruct( slotIndex=0, nominalPower=forecast.slots[0].minPowerAdjustment, duration=forecast.slots[0].maxDurationAdjustment)] await self.send_modify_forecast_request_command(forecast.forecastID, slotAdjustments, Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kGridOptimization, expected_status=Status.Success) - self.step("13a") + self.step("14a") forecast = await self.read_dem_attribute_expect_success(attribute="Forecast") asserts.assert_equal(forecast.forecastUpdateReason, Clusters.DeviceEnergyManagement.Enums.ForecastUpdateReasonEnum.kGridOptimization) - self.step("14") + self.step("15") await self.send_cancel_request_command() - self.step("14a") + self.step("15a") forecast = await self.read_dem_attribute_expect_success(attribute="Forecast") asserts.assert_equal(forecast.forecastUpdateReason, Clusters.DeviceEnergyManagement.Enums.ForecastUpdateReasonEnum.kInternalOptimization) - self.step("15") + self.step("16") slotAdjustments = [Clusters.DeviceEnergyManagement.Structs.SlotAdjustmentStruct( slotIndex=0, nominalPower=forecast.slots[0].minPowerAdjustment, duration=forecast.slots[0].maxDurationAdjustment)] await self.send_modify_forecast_request_command(forecast.forecastID, slotAdjustments, Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kGridOptimization, expected_status=Status.Success) - self.step("15a") + self.step("16a") forecast = await self.read_dem_attribute_expect_success(attribute="Forecast") asserts.assert_equal(forecast.forecastUpdateReason, Clusters.DeviceEnergyManagement.Enums.ForecastUpdateReasonEnum.kGridOptimization) - self.step("16") + self.step("17") await self.send_test_event_trigger_user_opt_out_grid() - self.step("16a") + self.step("17a") await self.check_dem_attribute("OptOutState", Clusters.DeviceEnergyManagement.Enums.OptOutStateEnum.kOptOut) - self.step("16b") + self.step("17b") forecast = await self.read_dem_attribute_expect_success(attribute="Forecast") asserts.assert_equal(forecast.forecastUpdateReason, Clusters.DeviceEnergyManagement.Enums.ForecastUpdateReasonEnum.kInternalOptimization) - self.step("17") + self.step("18") slotAdjustments = [Clusters.DeviceEnergyManagement.Structs.SlotAdjustmentStruct( slotIndex=0, nominalPower=forecast.slots[0].minPowerAdjustment, duration=forecast.slots[0].maxDurationAdjustment)] await self.send_modify_forecast_request_command(forecast.forecastID, slotAdjustments, Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kGridOptimization, expected_status=Status.ConstraintError) - self.step("18") + self.step("19") await self.send_test_event_trigger_user_opt_out_clear_all() - self.step("18a") + self.step("19a") await self.check_dem_attribute("OptOutState", Clusters.DeviceEnergyManagement.Enums.OptOutStateEnum.kNoOptOut) - self.step("19") + self.step("20") slotAdjustments = [Clusters.DeviceEnergyManagement.Structs.SlotAdjustmentStruct( slotIndex=0, nominalPower=forecast.slots[0].minPowerAdjustment, duration=forecast.slots[0].minDurationAdjustment)] await self.send_modify_forecast_request_command(forecast.forecastID, slotAdjustments, Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization, expected_status=Status.Success) - self.step("19a") + self.step("20a") forecast = await self.read_dem_attribute_expect_success(attribute="Forecast") asserts.assert_equal(forecast.forecastUpdateReason, Clusters.DeviceEnergyManagement.Enums.ForecastUpdateReasonEnum.kLocalOptimization) - self.step("20") + self.step("21") await self.send_cancel_request_command() - self.step("20a") + self.step("21a") forecast = await self.read_dem_attribute_expect_success(attribute="Forecast") asserts.assert_equal(forecast.forecastUpdateReason, Clusters.DeviceEnergyManagement.Enums.ForecastUpdateReasonEnum.kInternalOptimization) - self.step("21") + self.step("22") await self.send_test_event_trigger_forecast_adjustment_next_slot() - self.step("22") + self.step("23") slotAdjustments = [Clusters.DeviceEnergyManagement.Structs.SlotAdjustmentStruct( slotIndex=0, nominalPower=forecast.slots[0].minPowerAdjustment, duration=forecast.slots[0].minDurationAdjustment)] await self.send_modify_forecast_request_command(forecast.forecastID, slotAdjustments, Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization, expected_status=Status.ConstraintError) - self.step("23") + self.step("24") await self.send_cancel_request_command(expected_status=Status.InvalidInState) - self.step("24") + self.step("25") await self.send_test_event_trigger_forecast_adjustment_clear() diff --git a/src/python_testing/TC_DEM_2_6.py b/src/python_testing/TC_DEM_2_6.py index 2bc52e6b6f1cb9..dda744d699f70c 100644 --- a/src/python_testing/TC_DEM_2_6.py +++ b/src/python_testing/TC_DEM_2_6.py @@ -34,7 +34,7 @@ import chip.clusters as Clusters from chip.interaction_model import Status -from matter_testing_support import EventChangeCallback, MatterBaseTest, TestStep, async_test_body, default_matter_test_main +from matter_testing_support import MatterBaseTest, TestStep, async_test_body, default_matter_test_main from mobly import asserts from TC_DEMTestBase import DEMTestBase @@ -59,76 +59,77 @@ def pics_TC_DEM_2_6(self): def steps_TC_DEM_2_6(self) -> list[TestStep]: """Execute the test steps.""" steps = [ - TestStep("1", "Commissioning, already done", - is_commissioning=True), - TestStep("2", "TH reads TestEventTriggersEnabled attribute from General Diagnostics Cluster.", - "Verify that TestEventTriggersEnabled attribute has a value of 1 (True)"), - TestStep("3", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Forecast Adjustment Test Event", - "Verify DUT responds with status SUCCESS(0x00)"), - TestStep("3a", "TH reads ESAState attribute.", - "Verify value is 0x01 (Online)"), - TestStep("3b", "TH reads Forecast attribute.", + TestStep("1", "Commission DUT to TH (can be skipped if done in a preceding test)"), + TestStep("2", "TH reads from the DUT the _Featuremap_ attribute", + "Verify that the DUT response contains the _Featuremap_ attribute. Verify ForecastAdjustment and StateForecastReporting is supported. Verify PowerForecastReporting is not supported."), + TestStep("3", "TH reads TestEventTriggersEnabled attribute from General Diagnostics Cluster", + "Value has to be 1 (True)"), + TestStep("4", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Forecast Adjustment Test Event", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("4a", "TH reads from the DUT the ESAState", + "Value has to be 0x01 (Online)"), + TestStep("4b", "TH reads from the DUT the Forecast", "Value has to include slots[0].MinDurationAdjustment, slots[0].MaxDurationAdjustment"), - TestStep("3c", "TH reads OptOutState attribute.", - "Verify value is 0x00 (NoOptOut)"), - TestStep("4", "TH sends ModifyForecastRequest with ForecastID=Forecast.ForecastID+1, SlotAdjustments[0].{SlotIndex=0, Duration=Forecast.Slots[0].MaxDurationAdjustment}, Cause=GridOptimization.", - "Verify DUT responds with status FAILURE(0x01)"), - TestStep("5", "TH sends ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=4, Duration=Forecast.Slots[0].MaxDurationAdjustment}, Cause=GridOptimization.", - "Verify DUT responds with status FAILURE(0x01)"), - TestStep("6", "TH sends ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, Duration=Forecast.Slots[0].MaxDurationAdjustment+1}, Cause=GridOptimization.", - "Verify DUT responds with status CONSTRAINT_ERROR(0x87)"), - TestStep("7", "TH sends ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, Duration=Forecast.Slots[0].MinDurationAdjustment-1}, Cause=GridOptimization.", - "Verify DUT responds with status CONSTRAINT_ERROR(0x87)"), - TestStep("8", "TH sends ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, Duration=Forecast.Slots[0].MaxDurationAdjustment}, SlotAdjustments[1].{SlotIndex=4, Duration=Forecast.Slots[0].MaxDurationAdjustment}, Cause=GridOptimization.", - "Verify DUT responds with status FAILURE(0x01)"), - TestStep("9", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Local Optimization Test Event", - "Verify DUT responds with status SUCCESS(0x00)"), - TestStep("9a", "TH reads ESAState attribute.", - "Verify value is 0x01 (Online)"), - TestStep("9b", "TH reads OptOutState attribute.", - "Verify value is 0x02 (LocalOptOut)"), - TestStep("10", "TH sends ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, Duration=Forecast.Slots[0].MaxDurationAdjustment}, Cause=LocalOptimization.", - "Verify DUT responds with status CONSTRAINT_ERROR(0x87)"), - TestStep("11", "TH sends ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, Duration=Forecast.Slots[0].MaxDurationAdjustment}, Cause=GridOptimization.", - "Verify DUT responds with status SUCCESS(0x00)"), - TestStep("11a", "TH reads Forecast attribute.", + TestStep("4c", "TH reads from the DUT the OptOutState", + "Value has to be 0x00 (NoOptOut)"), + TestStep("5", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID+1, SlotAdjustments[0].{SlotIndex=0, Duration=Forecast.Slots[0].MaxDurationAdjustment}, Cause=GridOptimization", + "Verify DUT responds w/ status FAILURE(0x01)"), + TestStep("6", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=4, Duration=Forecast.Slots[0].MaxDurationAdjustment}, Cause=GridOptimization", + "Verify DUT responds w/ status FAILURE(0x01)"), + TestStep("7", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, Duration=Forecast.Slots[0].MaxDurationAdjustment+1}, Cause=GridOptimization", + "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"), + TestStep("8", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, Duration=Forecast.Slots[0].MinDurationAdjustment-1}, Cause=GridOptimization", + "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"), + TestStep("9", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, Duration=Forecast.Slots[0].MaxDurationAdjustment}, SlotAdjustments[1].{SlotIndex=4, Duration=Forecast.Slots[0].MaxDurationAdjustment}, Cause=GridOptimization", + "Verify DUT responds w/ status FAILURE(0x01)"), + TestStep("10", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Local Optimization Test Event", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("10a", "TH reads from the DUT the ESAState", + "Value has to be 0x01 (Online)"), + TestStep("10b", "TH reads from the DUT the OptOutState", + "Value has to be 0x02 (LocalOptOut)"), + TestStep("11", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, Duration=Forecast.Slots[0].MaxDurationAdjustment}, Cause=LocalOptimization", + "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"), + TestStep("12", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, Duration=Forecast.Slots[0].MaxDurationAdjustment}, Cause=GridOptimization", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("12a", "TH reads from the DUT the Forecast", "Value has to include ForecastUpdateReason=GridOptimization"), - TestStep("12", "TH sends CancelRequest.", - "Verify DUT responds with status SUCCESS(0x00)"), - TestStep("12a", "TH reads Forecast attribute.", + TestStep("13", "TH sends command CancelRequest", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("13a", "TH reads from the DUT the Forecast", "Value has to include ForecastUpdateReason=InternalOptimization"), - TestStep("13", "TH sends ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, Duration=Forecast.Slots[0].MaxDurationAdjustment}, Cause=GridOptimization.", - "Verify DUT responds with status SUCCESS(0x00)"), - TestStep("13a", "TH reads Forecast attribute.", + TestStep("14", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, Duration=Forecast.Slots[0].MaxDurationAdjustment}, Cause=GridOptimization", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("14a", "TH reads from the DUT the Forecast", "Value has to include ForecastUpdateReason=GridOptimization"), - TestStep("14", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Grid Optimization Test Event", - "Verify DUT responds with status SUCCESS(0x00)"), - TestStep("14a", "TH reads OptOutState attribute.", - "Verify value is 0x03 (OptOut)"), - TestStep("14b", "TH reads Forecast attribute.", + TestStep("15", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Grid Optimization Test Event", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("15a", "TH reads from the DUT the OptOutState", + "Value has to be 0x03 (OptOut)"), + TestStep("15b", "TH reads from the DUT the Forecast", "Value has to include ForecastUpdateReason=Internal Optimization"), - TestStep("15", "TH sends ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, Duration=Forecast.Slots[0].MaxDurationAdjustment}, Cause=GridOptimization.", - "Verify DUT responds with status CONSTRAINT_ERROR(0x87)"), - TestStep("16", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Test Event Clear", - "Verify DUT responds with status SUCCESS(0x00)"), - TestStep("16a", "TH reads OptOutState attribute.", - "Verify value is 0x00 (NoOptOut)"), - TestStep("17", "TH sends ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, Duration=Forecast.Slots[0].MinDurationAdjustment}, Cause=LocalOptimization.", - "Verify DUT responds with status SUCCESS(0x00)"), - TestStep("17a", "TH reads Forecast attribute.", + TestStep("16", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, Duration=Forecast.Slots[0].MaxDurationAdjustment}, Cause=GridOptimization", + "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"), + TestStep("17", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Test Event Clear", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("17a", "TH reads from the DUT the OptOutState", + "Value has to be 0x00 (NoOptOut)"), + TestStep("18", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, Duration=Forecast.Slots[0].MinDurationAdjustment}, Cause=LocalOptimization", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("18a", "TH reads from the DUT the Forecast", "Value has to include ForecastUpdateReason=LocalOptimization"), - TestStep("18", "TH sends CancelRequest.", - "Verify DUT responds with status SUCCESS(0x00)"), - TestStep("18a", "TH reads Forecast attribute.", + TestStep("19", "TH sends command CancelRequest", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("19a", "TH reads from the DUT the Forecast", "Value has to include ForecastUpdateReason=InternalOptimization"), - TestStep("19", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Forecast Adjustment Test Event Next Slot", - "Verify DUT responds with status SUCCESS(0x00)"), - TestStep("20", "TH sends ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, Duration=Forecast.Slots[0].MinDurationAdjustment}, Cause=LocalOptimization.", - "Verify DUT responds with status CONSTRAINT_ERROR(0x87)"), - TestStep("21", "TH sends CancelRequest.", - "Verify DUT responds with status INVALID_IN_STATE(0xcb)"), - TestStep("22", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Forecast Adjustment Test Event Clear", - "Verify DUT responds with status SUCCESS(0x00)"), + TestStep("20", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Forecast Adjustment Test Event Next Slot", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("21", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, Duration=Forecast.Slots[0].MinDurationAdjustment}, Cause=LocalOptimization", + "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"), + TestStep("22", "TH sends command CancelRequest", + "Verify DUT responds w/ status INVALID_IN_STATE(0xcb)"), + TestStep("23", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Forecast Adjustment Test Event Clear", + "Verify DUT responds w/ status SUCCESS(0x00)"), ] return steps @@ -140,153 +141,148 @@ async def test_TC_DEM_2_6(self): self.step("1") # Commission DUT - already done + self.step("2") await self.validate_feature_map([Clusters.DeviceEnergyManagement.Bitmaps.Feature.kForecastAdjustment, Clusters.DeviceEnergyManagement.Bitmaps.Feature.kStateForecastReporting], [Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerForecastReporting]) - # Subscribe to Events and when they are sent push them to a queue for checking later - events_callback = EventChangeCallback(Clusters.DeviceEnergyManagement) - await events_callback.start(self.default_controller, - self.dut_node_id, - self.matter_test_config.endpoint) - - self.step("2") + self.step("3") await self.check_test_event_triggers_enabled() - self.step("3") + self.step("4") await self.send_test_event_trigger_forecast_adjustment() - self.step("3a") + self.step("4a") await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kOnline) - self.step("3b") + self.step("4b") forecast = await self.read_dem_attribute_expect_success(attribute="Forecast") asserts.assert_is_not_none(forecast.slots[0].minDurationAdjustment) asserts.assert_is_not_none(forecast.slots[0].maxDurationAdjustment) - self.step("3c") + self.step("4c") await self.check_dem_attribute("OptOutState", Clusters.DeviceEnergyManagement.Enums.OptOutStateEnum.kNoOptOut) - self.step("4") + self.step("5") slotAdjustments = [Clusters.DeviceEnergyManagement.Structs.SlotAdjustmentStruct( slotIndex=0, duration=forecast.slots[0].maxDurationAdjustment)] await self.send_modify_forecast_request_command(forecast.forecastID + 1, slotAdjustments, Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kGridOptimization, expected_status=Status.Failure) - self.step("5") + self.step("6") slotAdjustments = [Clusters.DeviceEnergyManagement.Structs.SlotAdjustmentStruct( slotIndex=4, duration=forecast.slots[0].maxDurationAdjustment)] await self.send_modify_forecast_request_command(forecast.forecastID, slotAdjustments, Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kGridOptimization, expected_status=Status.Failure) - self.step("6") + self.step("7") slotAdjustments = [Clusters.DeviceEnergyManagement.Structs.SlotAdjustmentStruct( slotIndex=0, duration=forecast.slots[0].maxDurationAdjustment + 1)] await self.send_modify_forecast_request_command(forecast.forecastID, slotAdjustments, Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kGridOptimization, expected_status=Status.ConstraintError) - self.step("7") + self.step("8") slotAdjustments = [Clusters.DeviceEnergyManagement.Structs.SlotAdjustmentStruct( slotIndex=0, duration=forecast.slots[0].minDurationAdjustment - 1)] await self.send_modify_forecast_request_command(forecast.forecastID, slotAdjustments, Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kGridOptimization, expected_status=Status.ConstraintError) - self.step("8") + self.step("9") slotAdjustments = [Clusters.DeviceEnergyManagement.Structs.SlotAdjustmentStruct(slotIndex=0, duration=forecast.slots[0].maxDurationAdjustment), Clusters.DeviceEnergyManagement.Structs.SlotAdjustmentStruct(slotIndex=4, duration=forecast.slots[0].maxDurationAdjustment)] await self.send_modify_forecast_request_command(forecast.forecastID, slotAdjustments, Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kGridOptimization, expected_status=Status.Failure) - self.step("9") + self.step("10") await self.send_test_event_trigger_user_opt_out_local() - self.step("9a") + self.step("10a") await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kOnline) - self.step("9b") + self.step("10b") await self.check_dem_attribute("OptOutState", Clusters.DeviceEnergyManagement.Enums.OptOutStateEnum.kLocalOptOut) - self.step("10") + self.step("11") slotAdjustments = [Clusters.DeviceEnergyManagement.Structs.SlotAdjustmentStruct( slotIndex=0, duration=forecast.slots[0].maxDurationAdjustment)] await self.send_modify_forecast_request_command(forecast.forecastID, slotAdjustments, Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization, expected_status=Status.ConstraintError) - self.step("11") + self.step("12") slotAdjustments = [Clusters.DeviceEnergyManagement.Structs.SlotAdjustmentStruct( slotIndex=0, duration=forecast.slots[0].maxDurationAdjustment)] await self.send_modify_forecast_request_command(forecast.forecastID, slotAdjustments, Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kGridOptimization, expected_status=Status.Success) - self.step("11a") + self.step("12a") forecast = await self.read_dem_attribute_expect_success(attribute="Forecast") logging.info(forecast) asserts.assert_equal(forecast.forecastUpdateReason, Clusters.DeviceEnergyManagement.Enums.ForecastUpdateReasonEnum.kGridOptimization) - self.step("12") + self.step("13") await self.send_cancel_request_command() - self.step("12a") + self.step("13a") forecast = await self.read_dem_attribute_expect_success(attribute="Forecast") asserts.assert_equal(forecast.forecastUpdateReason, Clusters.DeviceEnergyManagement.Enums.ForecastUpdateReasonEnum.kInternalOptimization) - self.step("13") + self.step("14") slotAdjustments = [Clusters.DeviceEnergyManagement.Structs.SlotAdjustmentStruct( slotIndex=0, duration=forecast.slots[0].maxDurationAdjustment)] await self.send_modify_forecast_request_command(forecast.forecastID, slotAdjustments, Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kGridOptimization, expected_status=Status.Success) - self.step("13a") + self.step("14a") forecast = await self.read_dem_attribute_expect_success(attribute="Forecast") asserts.assert_equal(forecast.forecastUpdateReason, Clusters.DeviceEnergyManagement.Enums.ForecastUpdateReasonEnum.kGridOptimization) - self.step("14") + self.step("15") await self.send_test_event_trigger_user_opt_out_grid() - self.step("14a") + self.step("15a") await self.check_dem_attribute("OptOutState", Clusters.DeviceEnergyManagement.Enums.OptOutStateEnum.kOptOut) - self.step("14b") + self.step("15b") forecast = await self.read_dem_attribute_expect_success(attribute="Forecast") asserts.assert_equal(forecast.forecastUpdateReason, Clusters.DeviceEnergyManagement.Enums.ForecastUpdateReasonEnum.kInternalOptimization) - self.step("15") + self.step("16") slotAdjustments = [Clusters.DeviceEnergyManagement.Structs.SlotAdjustmentStruct( slotIndex=0, duration=forecast.slots[0].maxDurationAdjustment)] await self.send_modify_forecast_request_command(forecast.forecastID, slotAdjustments, Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kGridOptimization, expected_status=Status.ConstraintError) - self.step("16") + self.step("17") await self.send_test_event_trigger_user_opt_out_clear_all() - self.step("16a") + self.step("17a") await self.check_dem_attribute("OptOutState", Clusters.DeviceEnergyManagement.Enums.OptOutStateEnum.kNoOptOut) - self.step("17") + self.step("18") slotAdjustments = [Clusters.DeviceEnergyManagement.Structs.SlotAdjustmentStruct( slotIndex=0, duration=forecast.slots[0].minDurationAdjustment)] await self.send_modify_forecast_request_command(forecast.forecastID, slotAdjustments, Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization, expected_status=Status.Success) - self.step("17a") + self.step("18a") forecast = await self.read_dem_attribute_expect_success(attribute="Forecast") asserts.assert_equal(forecast.forecastUpdateReason, Clusters.DeviceEnergyManagement.Enums.ForecastUpdateReasonEnum.kLocalOptimization) - self.step("18") + self.step("19") await self.send_cancel_request_command() - self.step("18a") + self.step("19a") forecast = await self.read_dem_attribute_expect_success(attribute="Forecast") asserts.assert_equal(forecast.forecastUpdateReason, Clusters.DeviceEnergyManagement.Enums.ForecastUpdateReasonEnum.kInternalOptimization) - self.step("19") + self.step("20") await self.send_test_event_trigger_forecast_adjustment_next_slot() - self.step("20") + self.step("21") slotAdjustments = [Clusters.DeviceEnergyManagement.Structs.SlotAdjustmentStruct( slotIndex=0, duration=forecast.slots[0].minDurationAdjustment)] await self.send_modify_forecast_request_command(forecast.forecastID, slotAdjustments, Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization, expected_status=Status.ConstraintError) - self.step("21") + self.step("22") await self.send_cancel_request_command(expected_status=Status.InvalidInState) - self.step("22") + self.step("23") await self.send_test_event_trigger_forecast_adjustment_clear() diff --git a/src/python_testing/TC_DEM_2_7.py b/src/python_testing/TC_DEM_2_7.py index 16b974d3ff58f6..b749299c537557 100644 --- a/src/python_testing/TC_DEM_2_7.py +++ b/src/python_testing/TC_DEM_2_7.py @@ -34,7 +34,7 @@ import chip.clusters as Clusters from chip.interaction_model import Status -from matter_testing_support import EventChangeCallback, MatterBaseTest, TestStep, async_test_body, default_matter_test_main +from matter_testing_support import MatterBaseTest, TestStep, async_test_body, default_matter_test_main from mobly import asserts from TC_DEMTestBase import DEMTestBase @@ -59,84 +59,85 @@ def pics_TC_DEM_2_7(self): def steps_TC_DEM_2_7(self) -> list[TestStep]: """Execute the test steps.""" steps = [ - TestStep("1", "Commissioning, already done", - is_commissioning=True), - TestStep("2", "TH reads TestEventTriggersEnabled attribute from General Diagnostics Cluster.", - "Verify value is 1 (True)"), - TestStep("3", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Constraints-based Adjustment Test Event.", - "Verify DUT responds with status SUCCESS(0x00)"), - TestStep("3a", "TH reads ESAState attribute.", - "Verify value is 0x01 (Online)"), - TestStep("3b", "TH reads Forecast attribute.", + TestStep("1", "Commission DUT to TH (can be skipped if done in a preceding test)"), + TestStep("2", "TH reads from the DUT the _Featuremap_ attribute", + "Verify that the DUT response contains the _Featuremap_ attribute. Verify ConstraintBasedAdjustment and PowerForecastReporting is supported. Verify StateForecastReporting is not supported."), + TestStep("3", "TH reads TestEventTriggersEnabled attribute from General Diagnostics Cluster", + "Value has to be 1 (True)"), + TestStep("4", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Constraints-based Adjustment Test Event", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("4a", "TH reads from the DUT the ESAState", + "Value has to be 0x01 (Online)"), + TestStep("4b", "TH reads from the DUT the Forecast", "Value has to include valid slots[0].NominalPower, slots[0].MinPower, slots[0].MaxPower, slots[0].NominalEnergy"), - TestStep("3c", "TH reads OptOutState attribute.", - "Verify value is 0x00 (NoOptOut)"), - TestStep("4", "TH sends RequestConstraintBasedPowerForecast with constraints[0].{StartTime=now()-10, Duration=20, NominalPower=Forecast.Slots[0].NominalPower, MaximumEnergy=Forecast.Slots[0].NominalEnergy}, Cause=LocalOptimization.", - "Verify DUT responds with status CONSTRAINT_ERROR(0x87)"), - TestStep("5", "TH sends RequestConstraintBasedPowerForecast with constraints[0].{StartTime=now()+10, Duration=20, NominalPower=Forecast.Slots[0].NominalPower, MaximumEnergy=Forecast.Slots[0].NominalEnergy}, constraints[1].{StartTime=now()+20, Duration=20, NominalPower=Forecast.Slots[0].NominalPower, MaximumEnergy=Forecast.Slots[0].NominalEnergy}, constraints[2].{StartTime=now()+40, Duration=20, NominalPower=Forecast.Slots[0].NominalPower, MaximumEnergy=Forecast.Slots[0].NominalEnergy}, Cause=LocalOptimization.", - "Verify DUT responds with status CONSTRAINT_ERROR(0x87)"), - TestStep("6", "TH sends RequestConstraintBasedPowerForecast with constraints[0].{StartTime=now()+10, Duration=20, NominalPower=Forecast.Slots[0].NominalPower, MaximumEnergy=Forecast.Slots[0].NominalEnergy}, constraints[1].{StartTime=now()+30, Duration=20, NominalPower=Forecast.Slots[0].NominalPower, MaximumEnergy=Forecast.Slots[0].NominalEnergy}, constraints[2].{StartTime=now()+40, Duration=20, NominalPower=Forecast.Slots[0].NominalPower, MaximumEnergy=Forecast.Slots[0].NominalEnergy}, Cause=LocalOptimization.", - "Verify DUT responds with status CONSTRAINT_ERROR(0x87)"), - TestStep("7", "TH sends RequestConstraintBasedPowerForecast with constraints[0].{StartTime=now()+30, Duration=20, NominalPower=Forecast.Slots[0].NominalPower, MaximumEnergy=Forecast.Slots[0].NominalEnergy}, constraints[1].{StartTime=now()+10, Duration=20, NominalPower=Forecast.Slots[0].NominalPower, MaximumEnergy=Forecast.Slots[0].NominalEnergy}, constraints[2].{StartTime=now()+50, Duration=20, NominalPower=Forecast.Slots[0].NominalPower, MaximumEnergy=Forecast.Slots[0].NominalEnergy}, Cause=LocalOptimization.", - "Verify DUT responds with status CONSTRAINT_ERROR(0x87)"), - TestStep("8", "TH sends RequestConstraintBasedPowerForecast with constraints[0].{StartTime=now()+10, Duration=20, NominalPower=Forecast.Slots[0].NominalPower, MaximumEnergy=Forecast.Slots[0].NominalEnergy}, constraints[1].{StartTime=now()+50, Duration=20, NominalPower=Forecast.Slots[0].NominalPower, MaximumEnergy=Forecast.Slots[0].NominalEnergy}, constraints[2].{StartTime=now()+30, Duration=20, NominalPower=Forecast.Slots[0].NominalPower, MaximumEnergy=Forecast.Slots[0].NominalEnergy}, Cause=LocalOptimization.", - "Verify DUT responds with status CONSTRAINT_ERROR(0x87)"), - TestStep("9", "TH reads AbsMaxPower attribute attribute.", + TestStep("4c", "TH reads from the DUT the OptOutState", + "Value has to be 0x00 (NoOptOut)"), + TestStep("5", "TH sends command RequestConstraintBasedPowerForecast with constraints[0].{StartTime=now()-10, Duration=20, NominalPower=Forecast.Slots[0].NominalPower, MaximumEnergy=Forecast.Slots[0].NominalEnergy}, Cause=LocalOptimization", + "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"), + TestStep("6", "TH sends command RequestConstraintBasedPowerForecast with constraints[0].{StartTime=now()+10, Duration=20, NominalPower=Forecast.Slots[0].NominalPower, MaximumEnergy=Forecast.Slots[0].NominalEnergy}, constraints[1].{StartTime=now()+20, Duration=20, NominalPower=Forecast.Slots[0].NominalPower, MaximumEnergy=Forecast.Slots[0].NominalEnergy}, constraints[2].{StartTime=now()+40, Duration=20, NominalPower=Forecast.Slots[0].NominalPower, MaximumEnergy=Forecast.Slots[0].NominalEnergy}, Cause=LocalOptimization", + "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"), + TestStep("7", "TH sends command RequestConstraintBasedPowerForecast with constraints[0].{StartTime=now()+10, Duration=20, NominalPower=Forecast.Slots[0].NominalPower, MaximumEnergy=Forecast.Slots[0].NominalEnergy}, constraints[1].{StartTime=now()+30, Duration=20, NominalPower=Forecast.Slots[0].NominalPower, MaximumEnergy=Forecast.Slots[0].NominalEnergy}, constraints[2].{StartTime=now()+40, Duration=20, NominalPower=Forecast.Slots[0].NominalPower, MaximumEnergy=Forecast.Slots[0].NominalEnergy}, Cause=LocalOptimization", + "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"), + TestStep("8", "TH sends command RequestConstraintBasedPowerForecast with constraints[0].{StartTime=now()+30, Duration=20, NominalPower=Forecast.Slots[0].NominalPower, MaximumEnergy=Forecast.Slots[0].NominalEnergy}, constraints[1].{StartTime=now()+10, Duration=20, NominalPower=Forecast.Slots[0].NominalPower, MaximumEnergy=Forecast.Slots[0].NominalEnergy}, constraints[2].{StartTime=now()+50, Duration=20, NominalPower=Forecast.Slots[0].NominalPower, MaximumEnergy=Forecast.Slots[0].NominalEnergy}, Cause=LocalOptimization", + "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"), + TestStep("9", "TH sends command RequestConstraintBasedPowerForecast with constraints[0].{StartTime=now()+10, Duration=20, NominalPower=Forecast.Slots[0].NominalPower, MaximumEnergy=Forecast.Slots[0].NominalEnergy}, constraints[1].{StartTime=now()+50, Duration=20, NominalPower=Forecast.Slots[0].NominalPower, MaximumEnergy=Forecast.Slots[0].NominalEnergy}, constraints[2].{StartTime=now()+30, Duration=20, NominalPower=Forecast.Slots[0].NominalPower, MaximumEnergy=Forecast.Slots[0].NominalEnergy}, Cause=LocalOptimization", + "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"), + TestStep("10", "TH reads from the DUT the AbsMaxPower attribute.", "Save the value"), - TestStep("9a", "TH sends RequestConstraintBasedPowerForecast with constraints[0].{StartTime=Forecast.StartTime, Duration=Forecast.Slots[0].DefaultDuration, NominalPower=AbsMaxPower+1, MaximumEnergy=Forecast.Slots[0].NominalEnergy}, Cause=LocalOptimization.", - "Verify DUT responds with status CONSTRAINT_ERROR(0x87)"), - TestStep("10", "TH reads AbsMinPower attribute attribute.", + TestStep("10a", "TH sends command RequestConstraintBasedPowerForecast with constraints[0].{StartTime=Forecast.StartTime, Duration=Forecast.Slots[0].DefaultDuration, NominalPower=AbsMaxPower+1, MaximumEnergy=Forecast.Slots[0].NominalEnergy}, Cause=LocalOptimization", + "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"), + TestStep("11", "TH reads from the DUT the AbsMinPower attribute.", "Save the value"), - TestStep("10a", "TH sends RequestConstraintBasedPowerForecast with constraints[0].{StartTime=Forecast.StartTime, Duration=Forecast.Slots[0].DefaultDuration, NominalPower=AbsMinPower-1, MaximumEnergy=Forecast.Slots[0].NominalEnergy}, Cause=LocalOptimization.", - "Verify DUT responds with status CONSTRAINT_ERROR(0x87)"), - TestStep("11", "TH sends RequestConstraintBasedPowerForecast with constraints[0].{StartTime=Forecast.StartTime, Duration=Forecast.Slots[0].DefaultDuration, NominalPower=Forecast.Slots[0].NominalPower}, Cause=LocalOptimization.", - "Verify DUT responds with status InvalidCommand"), - TestStep("12", "TH sends RequestConstraintBasedPowerForecast with constraints[0].{StartTime=Forecast.StartTime, Duration=Forecast.Slots[0].DefaultDuration, MaximumEnergy=Forecast.Slots[0].NominalEnergy}, Cause=LocalOptimization.", - "Verify DUT responds with status InvalidCommand"), - TestStep("13", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Local Optimization Test Event.", - "Verify DUT responds with status SUCCESS(0x00)"), - TestStep("13a", "TH reads ESAState attribute.", - "Verify value is 0x01 (Online)"), - TestStep("13b", "TH reads OptOutState attribute.", - "Verify value is 0x02 (LocalOptOut)"), - TestStep("14", "TH sends RequestConstraintBasedPowerForecast with constraints[0].{StartTime=Forecast.StartTime, Duration=Forecast.Slots[0].DefaultDuration, NominalPower=Forecast.Slots[0].NominalPower, MaximumEnergy=Forecast.Slots[0].NominalEnergy}, Cause=LocalOptimization.", - "Verify DUT responds with status CONSTRAINT_ERROR(0x87)"), - TestStep("15", "TH sends RequestConstraintBasedPowerForecast with constraints[0].{StartTime=Forecast.StartTime, Duration=Forecast.Slots[0].DefaultDuration, NominalPower=Forecast.Slots[0].NominalPower, MaximumEnergy=Forecast.Slots[0].NominalEnergy}, Cause=GridOptimization.", - "Verify DUT responds with status SUCCESS(0x00)"), - TestStep("15a", "TH reads Forecast attribute.", + TestStep("11a", "TH sends command RequestConstraintBasedPowerForecast with constraints[0].{StartTime=Forecast.StartTime, Duration=Forecast.Slots[0].DefaultDuration, NominalPower=AbsMinPower-1, MaximumEnergy=Forecast.Slots[0].NominalEnergy}, Cause=LocalOptimization", + "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"), + TestStep("12", "TH sends command RequestConstraintBasedPowerForecast with constraints[0].{StartTime=Forecast.StartTime, Duration=Forecast.Slots[0].DefaultDuration, NominalPower=Forecast.Slots[0].NominalPower}, Cause=LocalOptimization", + "Verify DUT responds w/ status INVALID_COMMAND(0x85)"), + TestStep("13", "TH sends command RequestConstraintBasedPowerForecast with constraints[0].{StartTime=Forecast.StartTime, Duration=Forecast.Slots[0].DefaultDuration, MaximumEnergy=Forecast.Slots[0].NominalEnergy}, Cause=LocalOptimization", + "Verify DUT responds w/ status INVALID_COMMAND(0x85)"), + TestStep("14", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Local Optimization Test Event", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("14a", "TH reads from the DUT the ESAState", + "Value has to be 0x01 (Online)"), + TestStep("14b", "TH reads from the DUT the OptOutState", + "Value has to be 0x02 (LocalOptOut)"), + TestStep("15", "TH sends command RequestConstraintBasedPowerForecast with constraints[0].{StartTime=Forecast.StartTime, Duration=Forecast.Slots[0].DefaultDuration, NominalPower=Forecast.Slots[0].NominalPower, MaximumEnergy=Forecast.Slots[0].NominalEnergy}, Cause=LocalOptimization", + "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"), + TestStep("16", "TH sends command RequestConstraintBasedPowerForecast with constraints[0].{StartTime=Forecast.StartTime, Duration=Forecast.Slots[0].DefaultDuration, NominalPower=Forecast.Slots[0].NominalPower, MaximumEnergy=Forecast.Slots[0].NominalEnergy}, Cause=GridOptimization", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("16a", "TH reads from the DUT the Forecast", "Value has to include ForecastUpdateReason=GridOptimization"), - TestStep("16", "TH sends CancelRequest.", - "Verify DUT responds with status SUCCESS(0x00)"), - TestStep("16a", "TH reads Forecast attribute.", + TestStep("17", "TH sends command CancelRequest", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("17a", "TH reads from the DUT the Forecast", "Value has to include ForecastUpdateReason=InternalOptimization"), - TestStep("17", "TH sends RequestConstraintBasedPowerForecast with constraints[0].{StartTime=Forecast.StartTime, Duration=Forecast.Slots[0].DefaultDuration, NominalPower=Forecast.Slots[0].NominalPower, MaximumEnergy=Forecast.Slots[0].NominalEnergy}, Cause=GridOptimization.", - "Verify DUT responds with status SUCCESS(0x00)"), - TestStep("17a", "TH reads Forecast attribute.", + TestStep("18", "TH sends command RequestConstraintBasedPowerForecast with constraints[0].{StartTime=Forecast.StartTime, Duration=Forecast.Slots[0].DefaultDuration, NominalPower=Forecast.Slots[0].NominalPower, MaximumEnergy=Forecast.Slots[0].NominalEnergy}, Cause=GridOptimization", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("18a", "TH reads from the DUT the Forecast", "Value has to include ForecastUpdateReason=GridOptimization"), - TestStep("18", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Grid Optimization Test Event.", - "Verify DUT responds with status SUCCESS(0x00)"), - TestStep("18a", "TH reads OptOutState attribute.", - "Verify value is 0x03 (OptOut)"), - TestStep("18b", "TH reads Forecast attribute.", + TestStep("19", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Grid Optimization Test Event", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("19a", "TH reads from the DUT the OptOutState", + "Value has to be 0x03 (OptOut)"), + TestStep("19b", "TH reads from the DUT the Forecast", "Value has to include ForecastUpdateReason=InternalOptimization"), - TestStep("19", "TH sends RequestConstraintBasedPowerForecast with constraints[0].{StartTime=Forecast.StartTime, Duration=Forecast.Slots[0].DefaultDuration, NominalPower=Forecast.Slots[0].NominalPower, MaximumEnergy=Forecast.Slots[0].NominalEnergy}, Cause=GridOptimization.", - "Verify DUT responds with status CONSTRAINT_ERROR(0x87)"), - TestStep("20", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Test Event Clear.", - "Verify DUT responds with status SUCCESS(0x00)"), - TestStep("20a", "TH reads OptOutState attribute.", - "Verify value is 0x00 (NoOptOut)"), - TestStep("21", "TH sends RequestConstraintBasedPowerForecast with constraints[0].{StartTime=Forecast.StartTime, Duration=Forecast.Slots[0].DefaultDuration, NominalPower=Forecast.Slots[0].NominalPower, MaximumEnergy=Forecast.Slots[0].NominalEnergy}, Cause=LocalOptimization.", - "Verify DUT responds with status SUCCESS(0x00)"), - TestStep("21a", "TH reads Forecast attribute.", + TestStep("20", "TH sends command RequestConstraintBasedPowerForecast with constraints[0].{StartTime=Forecast.StartTime, Duration=Forecast.Slots[0].DefaultDuration, NominalPower=Forecast.Slots[0].NominalPower, MaximumEnergy=Forecast.Slots[0].NominalEnergy}, Cause=GridOptimization", + "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"), + TestStep("21", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Test Event Clear", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("21a", "TH reads from the DUT the OptOutState", + "Value has to be 0x00 (NoOptOut)"), + TestStep("22", "TH sends command RequestConstraintBasedPowerForecast with constraints[0].{StartTime=Forecast.StartTime, Duration=Forecast.Slots[0].DefaultDuration, NominalPower=Forecast.Slots[0].NominalPower, MaximumEnergy=Forecast.Slots[0].NominalEnergy}, Cause=LocalOptimization", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("22a", "TH reads from the DUT the Forecast", "Value has to include ForecastUpdateReason=LocalOptimization"), - TestStep("22", "TH sends CancelRequest.", - "Verify DUT responds with status SUCCESS(0x00)"), - TestStep("22a", "TH reads Forecast attribute.", + TestStep("23", "TH sends command CancelRequest", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("23a", "TH reads from the DUT the Forecast", "Value has to include ForecastUpdateReason=InternalOptimization"), - TestStep("23", "TH sends CancelRequest.", - "Verify DUT responds with status INVALID_IN_STATE(0xcb)"), - TestStep("24", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Constraints-based Adjustment Adjustment Test Event Clear.", - "Verify DUT responds with status SUCCESS(0x00)"), + TestStep("24", "TH sends command CancelRequest", + "Verify DUT responds w/ status INVALID_IN_STATE(0xcb)"), + TestStep("25", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Constraints-based Adjustment Adjustment Test Event Clear", + "Verify DUT responds w/ status SUCCESS(0x00)"), ] return steps @@ -148,26 +149,21 @@ async def test_TC_DEM_2_7(self): self.step("1") # Commission DUT - already done + self.step("2") await self.validate_feature_map([Clusters.DeviceEnergyManagement.Bitmaps.Feature.kConstraintBasedAdjustment, Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerForecastReporting], [Clusters.DeviceEnergyManagement.Bitmaps.Feature.kStateForecastReporting]) - # Subscribe to Events and when they are sent push them to a queue for checking later - events_callback = EventChangeCallback(Clusters.DeviceEnergyManagement) - await events_callback.start(self.default_controller, - self.dut_node_id, - self.matter_test_config.endpoint) - - self.step("2") + self.step("3") await self.check_test_event_triggers_enabled() - self.step("3") + self.step("4") await self.send_test_event_trigger_constraint_based_adjustment() - self.step("3a") + self.step("4a") await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kOnline) - self.step("3b") + self.step("4b") forecast = await self.read_dem_attribute_expect_success(attribute="Forecast") logging.info(forecast) asserts.assert_greater(forecast.slots[0].nominalPower, 0) @@ -175,10 +171,10 @@ async def test_TC_DEM_2_7(self): asserts.assert_greater(forecast.slots[0].maxPower, 0) asserts.assert_greater(forecast.slots[0].nominalEnergy, 0) - self.step("3c") + self.step("4c") await self.check_dem_attribute("OptOutState", Clusters.DeviceEnergyManagement.Enums.OptOutStateEnum.kNoOptOut) - self.step("4") + self.step("5") # Matter UTC is time since 00:00:00 1/1/2000 now = self.get_current_utc_time_in_seconds() @@ -186,7 +182,7 @@ async def test_TC_DEM_2_7(self): nominalPower=forecast.slots[0].nominalPower, maximumEnergy=forecast.slots[0].nominalEnergy)] await self.send_request_constraint_based_forecast(constraintList, cause=Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization, expected_status=Status.ConstraintError) - self.step("5") + self.step("6") now = self.get_current_utc_time_in_seconds() constraintList = [Clusters.DeviceEnergyManagement.Structs.ConstraintsStruct(startTime=now + 10, duration=20, @@ -197,7 +193,7 @@ async def test_TC_DEM_2_7(self): nominalPower=forecast.slots[0].nominalPower, maximumEnergy=forecast.slots[0].nominalEnergy)] await self.send_request_constraint_based_forecast(constraintList, cause=Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization, expected_status=Status.ConstraintError) - self.step("6") + self.step("7") now = self.get_current_utc_time_in_seconds() constraintList = [Clusters.DeviceEnergyManagement.Structs.ConstraintsStruct(startTime=now + 10, duration=20, @@ -208,7 +204,7 @@ async def test_TC_DEM_2_7(self): nominalPower=forecast.slots[0].nominalPower, maximumEnergy=forecast.slots[0].nominalEnergy)] await self.send_request_constraint_based_forecast(constraintList, cause=Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization, expected_status=Status.ConstraintError) - self.step("7") + self.step("8") now = self.get_current_utc_time_in_seconds() constraintList = [Clusters.DeviceEnergyManagement.Structs.ConstraintsStruct(startTime=now + 30, duration=20, @@ -219,7 +215,7 @@ async def test_TC_DEM_2_7(self): nominalPower=forecast.slots[0].nominalPower, maximumEnergy=forecast.slots[0].nominalEnergy)] await self.send_request_constraint_based_forecast(constraintList, cause=Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization, expected_status=Status.ConstraintError) - self.step("8") + self.step("9") now = self.get_current_utc_time_in_seconds() constraintList = [Clusters.DeviceEnergyManagement.Structs.ConstraintsStruct(startTime=now + 10, duration=20, @@ -230,118 +226,118 @@ async def test_TC_DEM_2_7(self): nominalPower=forecast.slots[0].nominalPower, maximumEnergy=forecast.slots[0].nominalEnergy)] await self.send_request_constraint_based_forecast(constraintList, cause=Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization, expected_status=Status.ConstraintError) - self.step("9") + self.step("10") absMaxPower = await self.read_dem_attribute_expect_success(attribute="AbsMaxPower") - self.step("9a") + self.step("10a") constraintList = [Clusters.DeviceEnergyManagement.Structs.ConstraintsStruct( startTime=forecast.startTime, duration=forecast.slots[0].defaultDuration, nominalPower=absMaxPower + 1, maximumEnergy=forecast.slots[0].nominalEnergy)] await self.send_request_constraint_based_forecast(constraintList, cause=Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization, expected_status=Status.ConstraintError) - self.step("10") + self.step("11") absMinPower = await self.read_dem_attribute_expect_success(attribute="AbsMinPower") - self.step("10a") + self.step("11a") constraintList = [Clusters.DeviceEnergyManagement.Structs.ConstraintsStruct( startTime=forecast.startTime, duration=forecast.slots[0].defaultDuration, nominalPower=absMinPower - 1, maximumEnergy=forecast.slots[0].nominalEnergy)] await self.send_request_constraint_based_forecast(constraintList, cause=Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization, expected_status=Status.ConstraintError) - self.step("11") + self.step("12") constraintList = [Clusters.DeviceEnergyManagement.Structs.ConstraintsStruct( startTime=forecast.startTime, duration=forecast.slots[0].defaultDuration, nominalPower=forecast.slots[0].nominalPower)] await self.send_request_constraint_based_forecast(constraintList, cause=Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization, expected_status=Status.InvalidCommand) - self.step("12") + self.step("13") constraintList = [Clusters.DeviceEnergyManagement.Structs.ConstraintsStruct( startTime=forecast.startTime, duration=forecast.slots[0].defaultDuration, maximumEnergy=forecast.slots[0].nominalEnergy)] await self.send_request_constraint_based_forecast(constraintList, cause=Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization, expected_status=Status.InvalidCommand) - self.step("13") + self.step("14") await self.send_test_event_trigger_user_opt_out_local() - self.step("13a") + self.step("14a") await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kOnline) - self.step("13b") + self.step("14b") await self.check_dem_attribute("OptOutState", Clusters.DeviceEnergyManagement.Enums.OptOutStateEnum.kLocalOptOut) - self.step("14") + self.step("15") constraintList = [Clusters.DeviceEnergyManagement.Structs.ConstraintsStruct( startTime=forecast.startTime, duration=forecast.slots[0].defaultDuration, nominalPower=forecast.slots[0].nominalPower, maximumEnergy=forecast.slots[0].nominalEnergy)] await self.send_request_constraint_based_forecast(constraintList, cause=Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization, expected_status=Status.ConstraintError) - self.step("15") + self.step("16") constraintList = [Clusters.DeviceEnergyManagement.Structs.ConstraintsStruct( startTime=forecast.startTime, duration=forecast.slots[0].defaultDuration, nominalPower=forecast.slots[0].nominalPower, maximumEnergy=forecast.slots[0].nominalEnergy)] await self.send_request_constraint_based_forecast(constraintList, cause=Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kGridOptimization, expected_status=Status.Success) - self.step("15a") + self.step("16a") forecast = await self.read_dem_attribute_expect_success(attribute="Forecast") asserts.assert_equal(forecast.forecastUpdateReason, Clusters.DeviceEnergyManagement.Enums.ForecastUpdateReasonEnum.kGridOptimization) - self.step("16") + self.step("17") await self.send_cancel_request_command() - self.step("16a") + self.step("17a") forecast = await self.read_dem_attribute_expect_success(attribute="Forecast") asserts.assert_equal(forecast.forecastUpdateReason, Clusters.DeviceEnergyManagement.Enums.ForecastUpdateReasonEnum.kInternalOptimization) - self.step("17") + self.step("18") constraintList = [Clusters.DeviceEnergyManagement.Structs.ConstraintsStruct( startTime=forecast.startTime, duration=forecast.slots[0].defaultDuration, nominalPower=forecast.slots[0].nominalPower, maximumEnergy=forecast.slots[0].nominalEnergy)] await self.send_request_constraint_based_forecast(constraintList, cause=Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kGridOptimization, expected_status=Status.Success) - self.step("17a") + self.step("18a") forecast = await self.read_dem_attribute_expect_success(attribute="Forecast") asserts.assert_equal(forecast.forecastUpdateReason, Clusters.DeviceEnergyManagement.Enums.ForecastUpdateReasonEnum.kGridOptimization) - self.step("18") + self.step("19") await self.send_test_event_trigger_user_opt_out_grid() - self.step("18a") + self.step("19a") await self.check_dem_attribute("OptOutState", Clusters.DeviceEnergyManagement.Enums.OptOutStateEnum.kOptOut) - self.step("18b") + self.step("19b") forecast = await self.read_dem_attribute_expect_success(attribute="Forecast") asserts.assert_equal(forecast.forecastUpdateReason, Clusters.DeviceEnergyManagement.Enums.ForecastUpdateReasonEnum.kInternalOptimization) - self.step("19") + self.step("20") constraintList = [Clusters.DeviceEnergyManagement.Structs.ConstraintsStruct( startTime=forecast.startTime, duration=forecast.slots[0].defaultDuration, nominalPower=forecast.slots[0].nominalPower, maximumEnergy=forecast.slots[0].nominalEnergy)] await self.send_request_constraint_based_forecast(constraintList, cause=Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kGridOptimization, expected_status=Status.ConstraintError) - self.step("20") + self.step("21") await self.send_test_event_trigger_user_opt_out_clear_all() - self.step("20a") + self.step("21a") await self.check_dem_attribute("OptOutState", Clusters.DeviceEnergyManagement.Enums.OptOutStateEnum.kNoOptOut) - self.step("21") + self.step("22") constraintList = [Clusters.DeviceEnergyManagement.Structs.ConstraintsStruct( startTime=forecast.startTime, duration=forecast.slots[0].defaultDuration, nominalPower=forecast.slots[0].nominalPower, maximumEnergy=forecast.slots[0].nominalEnergy)] await self.send_request_constraint_based_forecast(constraintList, cause=Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization, expected_status=Status.Success) - self.step("21a") + self.step("22a") forecast = await self.read_dem_attribute_expect_success(attribute="Forecast") asserts.assert_equal(forecast.forecastUpdateReason, Clusters.DeviceEnergyManagement.Enums.ForecastUpdateReasonEnum.kLocalOptimization) - self.step("22") + self.step("23") await self.send_cancel_request_command() - self.step("22a") + self.step("23a") forecast = await self.read_dem_attribute_expect_success(attribute="Forecast") asserts.assert_equal(forecast.forecastUpdateReason, Clusters.DeviceEnergyManagement.Enums.ForecastUpdateReasonEnum.kInternalOptimization) - self.step("23") + self.step("24") await self.send_cancel_request_command(expected_status=Status.InvalidInState) - self.step("24") + self.step("25") await self.send_test_event_trigger_constraint_based_adjustment_clear() diff --git a/src/python_testing/TC_DEM_2_8.py b/src/python_testing/TC_DEM_2_8.py index 1c081be96e63f3..ccb9554f50498b 100644 --- a/src/python_testing/TC_DEM_2_8.py +++ b/src/python_testing/TC_DEM_2_8.py @@ -34,7 +34,7 @@ import chip.clusters as Clusters from chip.interaction_model import Status -from matter_testing_support import EventChangeCallback, MatterBaseTest, TestStep, async_test_body, default_matter_test_main +from matter_testing_support import MatterBaseTest, TestStep, async_test_body, default_matter_test_main from mobly import asserts from TC_DEMTestBase import DEMTestBase @@ -59,76 +59,77 @@ def pics_TC_DEM_2_8(self): def steps_TC_DEM_2_8(self) -> list[TestStep]: """Execute the test steps.""" steps = [ - TestStep("1", "Commissioning, already done", - is_commissioning=True), - TestStep("2", "TH reads TestEventTriggersEnabled attribute from General Diagnostics Cluster.", - "Verify value is 1 (True)"), - TestStep("3", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Constraints-based Adjustment Test Event.", - "Verify DUT responds with status SUCCESS(0x00)"), - TestStep("3a", "TH reads ESAState attribute.", - "Verify value is 0x01 (Online)"), - TestStep("3b", "TH reads Forecast attribute.", + TestStep("1", "Commission DUT to TH (can be skipped if done in a preceding test)"), + TestStep("2", "TH reads from the DUT the _Featuremap_ attribute", + "Verify that the DUT response contains the _Featuremap_ attribute. Verify ConstraintBasedAdjustment and StateForecastReporting is supported. Verify PowerForecastReporting is not supported."), + TestStep("3", "TH reads TestEventTriggersEnabled attribute from General Diagnostics Cluster", + "Value has to be 1 (True)"), + TestStep("4", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Constraints-based Adjustment Test Event", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("4a", "TH reads from the DUT the ESAState", + "Value has to be 0x01 (Online)"), + TestStep("4b", "TH reads from the DUT the Forecast", "Value has to include valid slots[0].ManufacturerESAState"), - TestStep("3c", "TH reads OptOutState attribute.", - "Verify value is 0x00 (NoOptOut)"), - TestStep("4", "TH sends RequestConstraintBasedPowerForecast with constraints[0].{StartTime=now()-10, Duration=20, LoadControl=0}, Cause=LocalOptimization.", - "Verify DUT responds with status CONSTRAINT_ERROR(0x87)"), - TestStep("5", "TH sends RequestConstraintBasedPowerForecast with constraints[0].{StartTime=now()+10, Duration=20, LoadControl=0}, constraints[1].{StartTime=now()+20, Duration=20, LoadControl=0}, constraints[2].{StartTime=now()+50, Duration=20, LoadControl=0}, Cause=LocalOptimization.", - "Verify DUT responds with status CONSTRAINT_ERROR(0x87)"), - TestStep("6", "TH sends RequestConstraintBasedPowerForecast with constraints[0].{StartTime=now()+10, Duration=20, LoadControl=0}, constraints[1].{StartTime=now()+30, Duration=20, LoadControl=0}, constraints[2].{StartTime=now()+40, Duration=20, LoadControl=0}, Cause=LocalOptimization.", - "Verify DUT responds with status CONSTRAINT_ERROR(0x87)"), - TestStep("7", "TH sends RequestConstraintBasedPowerForecast with constraints[0].{StartTime=now()+30, Duration=20, LoadControl=0}, constraints[1].{StartTime=now()+10, Duration=20, LoadControl=0}, constraints[2].{StartTime=now()+50, Duration=20, LoadControl=0}, Cause=LocalOptimization.", - "Verify DUT responds with status CONSTRAINT_ERROR(0x87)"), - TestStep("8", "TH sends RequestConstraintBasedPowerForecast with constraints[0].{StartTime=now()+10, Duration=20, LoadControl=0}, constraints[1].{StartTime=now()+50, Duration=20, LoadControl=0}, constraints[2].{StartTime=now()+30, Duration=20, LoadControl=0}, Cause=LocalOptimization.", - "Verify DUT responds with status CONSTRAINT_ERROR(0x87)"), - TestStep("9", "TH sends RequestConstraintBasedPowerForecast with constraints[0].{StartTime=Forecast.StartTime, Duration=Forecast.Slots[0].DefaultDuration, LoadControl=101}, Cause=LocalOptimization.", - "Verify DUT responds with status CONSTRAINT_ERROR(0x87)"), - TestStep("10", "TH sends RequestConstraintBasedPowerForecast with constraints[0].{StartTime=Forecast.StartTime, Duration=Forecast.Slots[0].DefaultDuration, LoadControl=-101}, Cause=LocalOptimization.", - "Verify DUT responds with status CONSTRAINT_ERROR(0x87)"), - TestStep("11", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Local Optimization Test Event.", - "Verify DUT responds with status SUCCESS(0x00)"), - TestStep("11a", "TH reads ESAState attribute.", - "Verify value is 0x01 (Online)"), - TestStep("11b", "TH reads OptOutState attribute.", - "Verify value is 0x02 (LocalOptOut)"), - TestStep("12", "TH sends RequestConstraintBasedPowerForecast with constraints[0].{StartTime=Forecast.StartTime, Duration=Forecast.Slots[0].DefaultDuration, LoadControl=1}, Cause=LocalOptimization.", - "Verify DUT responds with status CONSTRAINT_ERROR(0x87)"), - TestStep("13", "TH sends RequestConstraintBasedPowerForecast with constraints[0].{StartTime=Forecast.StartTime, Duration=Forecast.Slots[0].DefaultDuration, LoadControl=1}, Cause=GridOptimization.", - "Verify DUT responds with status SUCCESS(0x00)"), - TestStep("13a", "TH reads Forecast attribute.", + TestStep("4c", "TH reads from the DUT the OptOutState", + "Value has to be 0x00 (NoOptOut)"), + TestStep("5", "TH sends command RequestConstraintBasedPowerForecast with constraints[0].{StartTime=now()-10, Duration=20, LoadControl=0}, Cause=LocalOptimization", + "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"), + TestStep("6", "TH sends command RequestConstraintBasedPowerForecast with constraints[0].{StartTime=now()+10, Duration=20, LoadControl=0}, constraints[1].{StartTime=now()+20, Duration=20, LoadControl=0}, constraints[2].{StartTime=now()+50, Duration=20, LoadControl=0}, Cause=LocalOptimization", + "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"), + TestStep("7", "TH sends command RequestConstraintBasedPowerForecast with constraints[0].{StartTime=now()+10, Duration=20, LoadControl=0}, constraints[1].{StartTime=now()+30, Duration=20, LoadControl=0}, constraints[2].{StartTime=now()+40, Duration=20, LoadControl=0}, Cause=LocalOptimization", + "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"), + TestStep("8", "TH sends command RequestConstraintBasedPowerForecast with constraints[0].{StartTime=now()+30, Duration=20, LoadControl=0}, constraints[1].{StartTime=now()+10, Duration=20, LoadControl=0}, constraints[2].{StartTime=now()+50, Duration=20, LoadControl=0}, Cause=LocalOptimization", + "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"), + TestStep("9", "TH sends command RequestConstraintBasedPowerForecast with constraints[0].{StartTime=now()+10, Duration=20, LoadControl=0}, constraints[1].{StartTime=now()+50, Duration=20, LoadControl=0}, constraints[2].{StartTime=now()+30, Duration=20, LoadControl=0}, Cause=LocalOptimization", + "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"), + TestStep("10", "TH sends command RequestConstraintBasedPowerForecast with constraints[0].{StartTime=Forecast.StartTime, Duration=Forecast.Slots[0].DefaultDuration, LoadControl=101}, Cause=LocalOptimization", + "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"), + TestStep("11", "TH sends command RequestConstraintBasedPowerForecast with constraints[0].{StartTime=Forecast.StartTime, Duration=Forecast.Slots[0].DefaultDuration, LoadControl=-101}, Cause=LocalOptimization", + "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"), + TestStep("12", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Local Optimization Test Event", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("12a", "TH reads from the DUT the ESAState", + "Value has to be 0x01 (Online)"), + TestStep("12b", "TH reads from the DUT the OptOutState", + "Value has to be 0x02 (LocalOptOut)"), + TestStep("13", "TH sends command RequestConstraintBasedPowerForecast with constraints[0].{StartTime=Forecast.StartTime, Duration=Forecast.Slots[0].DefaultDuration, LoadControl=1}, Cause=LocalOptimization", + "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"), + TestStep("14", "TH sends command RequestConstraintBasedPowerForecast with constraints[0].{StartTime=Forecast.StartTime, Duration=Forecast.Slots[0].DefaultDuration, LoadControl=1}, Cause=GridOptimization", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("14a", "TH reads from the DUT the Forecast", "Value has to include ForecastUpdateReason=GridOptimization"), - TestStep("14", "TH sends CancelRequest.", - "Verify DUT responds with status SUCCESS(0x00)"), - TestStep("14a", "TH reads Forecast attribute.", + TestStep("15", "TH sends command CancelRequest", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("15a", "TH reads from the DUT the Forecast", "Value has to include ForecastUpdateReason=InternalOptimization"), - TestStep("15", "TH sends RequestConstraintBasedPowerForecast with constraints[0].{StartTime=Forecast.StartTime, Duration=Forecast.Slots[0].DefaultDuration, LoadControl=1}, Cause=GridOptimization.", - "Verify DUT responds with status SUCCESS(0x00)"), - TestStep("15a", "TH reads Forecast attribute.", + TestStep("16", "TH sends command RequestConstraintBasedPowerForecast with constraints[0].{StartTime=Forecast.StartTime, Duration=Forecast.Slots[0].DefaultDuration, LoadControl=1}, Cause=GridOptimization", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("16a", "TH reads from the DUT the Forecast", "Value has to include ForecastUpdateReason=GridOptimization"), - TestStep("16", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Grid Optimization Test Event.", - "Verify DUT responds with status SUCCESS(0x00)"), - TestStep("16a", "TH reads OptOutState attribute.", - "Verify value is 0x03 (OptOut)"), - TestStep("16b", "TH reads Forecast attribute.", + TestStep("17", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Grid Optimization Test Event", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("17a", "TH reads from the DUT the OptOutState", + "Value has to be 0x03 (OptOut)"), + TestStep("17b", "TH reads from the DUT the Forecast", "Value has to include ForecastUpdateReason=InternalOptimization"), - TestStep("17", "TH sends RequestConstraintBasedPowerForecast with constraints[0].{StartTime=Forecast.StartTime, Duration=Forecast.Slots[0].DefaultDuration, LoadControl=1}, Cause=GridOptimization.", - "Verify DUT responds with status CONSTRAINT_ERROR(0x87)"), - TestStep("18", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Test Event Clear.", - "Verify DUT responds with status SUCCESS(0x00)"), - TestStep("18a", "TH reads OptOutState attribute.", - "Verify value is 0x00 (NoOptOut)"), - TestStep("19", "TH sends RequestConstraintBasedPowerForecast with constraints[0].{StartTime=Forecast.StartTime, Duration=Forecast.Slots[0].DefaultDuration, LoadControl=1}, Cause=LocalOptimization.", - "Verify DUT responds with status SUCCESS(0x00)"), - TestStep("19a", "TH reads Forecast attribute.", + TestStep("18", "TH sends command RequestConstraintBasedPowerForecast with constraints[0].{StartTime=Forecast.StartTime, Duration=Forecast.Slots[0].DefaultDuration, LoadControl=1}, Cause=GridOptimization", + "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"), + TestStep("19", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Test Event Clear", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("19a", "TH reads from the DUT the OptOutState", + "Value has to be 0x00 (NoOptOut)"), + TestStep("20", "TH sends command RequestConstraintBasedPowerForecast with constraints[0].{StartTime=Forecast.StartTime, Duration=Forecast.Slots[0].DefaultDuration, LoadControl=1}, Cause=LocalOptimization", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("20a", "TH reads from the DUT the Forecast", "Value has to include ForecastUpdateReason=LocalOptimization"), - TestStep("20", "TH sends CancelRequest.", - "Verify DUT responds with status SUCCESS(0x00)"), - TestStep("20a", "TH reads Forecast attribute.", + TestStep("21", "TH sends command CancelRequest", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("21a", "TH reads from the DUT the Forecast", "Value has to include ForecastUpdateReason=InternalOptimization"), - TestStep("21", "TH sends CancelRequest.", - "Verify DUT responds with status INVALID_IN_STATE(0xcb)"), - TestStep("22", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Constraints-based Adjustment Adjustment Test Event Clear.", - "Verify DUT responds with status SUCCESS(0x00)"), + TestStep("22", "TH sends command CancelRequest", + "Verify DUT responds w/ status INVALID_IN_STATE(0xcb)"), + TestStep("23", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Constraints-based Adjustment Adjustment Test Event Clear", + "Verify DUT responds w/ status SUCCESS(0x00)"), ] return steps @@ -140,33 +141,28 @@ async def test_TC_DEM_2_8(self): self.step("1") # Commission DUT - already done + self.step("2") await self.validate_feature_map([Clusters.DeviceEnergyManagement.Bitmaps.Feature.kConstraintBasedAdjustment, Clusters.DeviceEnergyManagement.Bitmaps.Feature.kStateForecastReporting], [Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerForecastReporting]) - # Subscribe to Events and when they are sent push them to a queue for checking later - events_callback = EventChangeCallback(Clusters.DeviceEnergyManagement) - await events_callback.start(self.default_controller, - self.dut_node_id, - self.matter_test_config.endpoint) - - self.step("2") + self.step("3") await self.check_test_event_triggers_enabled() - self.step("3") + self.step("4") await self.send_test_event_trigger_constraint_based_adjustment() - self.step("3a") + self.step("4a") await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kOnline) - self.step("3b") + self.step("4b") forecast = await self.read_dem_attribute_expect_success(attribute="Forecast") asserts.assert_is_not_none(forecast.slots[0].manufacturerESAState) - self.step("3c") + self.step("4c") await self.check_dem_attribute("OptOutState", Clusters.DeviceEnergyManagement.Enums.OptOutStateEnum.kNoOptOut) - self.step("4") + self.step("5") # Matter UTC is time since 00:00:00 1/1/2000 now = self.get_current_utc_time_in_seconds() @@ -174,7 +170,7 @@ async def test_TC_DEM_2_8(self): startTime=now - 10, duration=20, loadControl=0)] await self.send_request_constraint_based_forecast(constraintList, cause=Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization, expected_status=Status.ConstraintError) - self.step("5") + self.step("6") # Matter UTC is time since 00:00:00 1/1/2000 now = self.get_current_utc_time_in_seconds() @@ -183,7 +179,7 @@ async def test_TC_DEM_2_8(self): Clusters.DeviceEnergyManagement.Structs.ConstraintsStruct(startTime=now + 50, duration=20, loadControl=0)] await self.send_request_constraint_based_forecast(constraintList, cause=Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization, expected_status=Status.ConstraintError) - self.step("6") + self.step("7") # Matter UTC is time since 00:00:00 1/1/2000 now = self.get_current_utc_time_in_seconds() @@ -192,7 +188,7 @@ async def test_TC_DEM_2_8(self): Clusters.DeviceEnergyManagement.Structs.ConstraintsStruct(startTime=now + 40, duration=20, loadControl=0)] await self.send_request_constraint_based_forecast(constraintList, cause=Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization, expected_status=Status.ConstraintError) - self.step("7") + self.step("8") now = self.get_current_utc_time_in_seconds() constraintList = [Clusters.DeviceEnergyManagement.Structs.ConstraintsStruct(startTime=now + 30, duration=20, loadControl=0), @@ -200,7 +196,7 @@ async def test_TC_DEM_2_8(self): Clusters.DeviceEnergyManagement.Structs.ConstraintsStruct(startTime=now + 50, duration=20, loadControl=0)] await self.send_request_constraint_based_forecast(constraintList, cause=Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization, expected_status=Status.ConstraintError) - self.step("8") + self.step("9") now = self.get_current_utc_time_in_seconds() constraintList = [Clusters.DeviceEnergyManagement.Structs.ConstraintsStruct(startTime=now + 10, duration=20, loadControl=0), @@ -208,102 +204,102 @@ async def test_TC_DEM_2_8(self): Clusters.DeviceEnergyManagement.Structs.ConstraintsStruct(startTime=now + 30, duration=20, loadControl=0)] await self.send_request_constraint_based_forecast(constraintList, cause=Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization, expected_status=Status.ConstraintError) - self.step("9") + self.step("10") constraintList = [Clusters.DeviceEnergyManagement.Structs.ConstraintsStruct( startTime=forecast.startTime, duration=forecast.slots[0].defaultDuration, loadControl=101)] await self.send_request_constraint_based_forecast(constraintList, cause=Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization, expected_status=Status.ConstraintError) - self.step("10") + self.step("11") constraintList = [Clusters.DeviceEnergyManagement.Structs.ConstraintsStruct( startTime=forecast.startTime, duration=forecast.slots[0].defaultDuration, loadControl=-101)] await self.send_request_constraint_based_forecast(constraintList, cause=Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization, expected_status=Status.ConstraintError) - self.step("11") + self.step("12") await self.send_test_event_trigger_user_opt_out_local() - self.step("11a") + self.step("12a") await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kOnline) - self.step("11b") + self.step("12b") await self.check_dem_attribute("OptOutState", Clusters.DeviceEnergyManagement.Enums.OptOutStateEnum.kLocalOptOut) - self.step("12") + self.step("13") constraintList = [Clusters.DeviceEnergyManagement.Structs.ConstraintsStruct( startTime=forecast.startTime, duration=forecast.slots[0].defaultDuration, loadControl=1)] await self.send_request_constraint_based_forecast(constraintList, cause=Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization, expected_status=Status.ConstraintError) - self.step("13") + self.step("14") constraintList = [Clusters.DeviceEnergyManagement.Structs.ConstraintsStruct( startTime=forecast.startTime, duration=forecast.slots[0].defaultDuration, loadControl=1)] await self.send_request_constraint_based_forecast(constraintList, cause=Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kGridOptimization, expected_status=Status.Success) - self.step("13a") + self.step("14a") forecast = await self.read_dem_attribute_expect_success(attribute="Forecast") asserts.assert_equal(forecast.forecastUpdateReason, Clusters.DeviceEnergyManagement.Enums.ForecastUpdateReasonEnum.kGridOptimization) - self.step("14") + self.step("15") await self.send_cancel_request_command() - self.step("14a") + self.step("15a") forecast = await self.read_dem_attribute_expect_success(attribute="Forecast") asserts.assert_equal(forecast.forecastUpdateReason, Clusters.DeviceEnergyManagement.Enums.ForecastUpdateReasonEnum.kInternalOptimization) - self.step("15") + self.step("16") constraintList = [Clusters.DeviceEnergyManagement.Structs.ConstraintsStruct( startTime=forecast.startTime, duration=forecast.slots[0].defaultDuration, loadControl=1)] await self.send_request_constraint_based_forecast(constraintList, cause=Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kGridOptimization, expected_status=Status.Success) - self.step("15a") + self.step("16a") forecast = await self.read_dem_attribute_expect_success(attribute="Forecast") asserts.assert_equal(forecast.forecastUpdateReason, Clusters.DeviceEnergyManagement.Enums.ForecastUpdateReasonEnum.kGridOptimization) - self.step("16") + self.step("17") await self.send_test_event_trigger_user_opt_out_grid() - self.step("16a") + self.step("17a") await self.check_dem_attribute("OptOutState", Clusters.DeviceEnergyManagement.Enums.OptOutStateEnum.kOptOut) - self.step("16b") + self.step("17b") forecast = await self.read_dem_attribute_expect_success(attribute="Forecast") asserts.assert_equal(forecast.forecastUpdateReason, Clusters.DeviceEnergyManagement.Enums.ForecastUpdateReasonEnum.kInternalOptimization) - self.step("17") + self.step("18") constraintList = [Clusters.DeviceEnergyManagement.Structs.ConstraintsStruct( startTime=forecast.startTime, duration=forecast.slots[0].defaultDuration, loadControl=1)] await self.send_request_constraint_based_forecast(constraintList, cause=Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kGridOptimization, expected_status=Status.ConstraintError) - self.step("18") + self.step("19") await self.send_test_event_trigger_user_opt_out_clear_all() - self.step("18a") + self.step("19a") await self.check_dem_attribute("OptOutState", Clusters.DeviceEnergyManagement.Enums.OptOutStateEnum.kNoOptOut) - self.step("19") + self.step("20") constraintList = [Clusters.DeviceEnergyManagement.Structs.ConstraintsStruct( startTime=forecast.startTime, duration=forecast.slots[0].defaultDuration, loadControl=1)] await self.send_request_constraint_based_forecast(constraintList, cause=Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization, expected_status=Status.Success) - self.step("19a") + self.step("20a") forecast = await self.read_dem_attribute_expect_success(attribute="Forecast") asserts.assert_equal(forecast.forecastUpdateReason, Clusters.DeviceEnergyManagement.Enums.ForecastUpdateReasonEnum.kLocalOptimization) - self.step("20") + self.step("21") await self.send_cancel_request_command() - self.step("20a") + self.step("21a") forecast = await self.read_dem_attribute_expect_success(attribute="Forecast") asserts.assert_equal(forecast.forecastUpdateReason, Clusters.DeviceEnergyManagement.Enums.ForecastUpdateReasonEnum.kInternalOptimization) - self.step("21") + self.step("22") await self.send_cancel_request_command(expected_status=Status.InvalidInState) - self.step("22") + self.step("23") await self.send_test_event_trigger_constraint_based_adjustment_clear() diff --git a/src/python_testing/TC_DEM_2_9.py b/src/python_testing/TC_DEM_2_9.py index 5f033164cfad61..16e89f68cd9caa 100644 --- a/src/python_testing/TC_DEM_2_9.py +++ b/src/python_testing/TC_DEM_2_9.py @@ -33,7 +33,7 @@ import logging import chip.clusters as Clusters -from matter_testing_support import EventChangeCallback, MatterBaseTest, TestStep, async_test_body, default_matter_test_main +from matter_testing_support import MatterBaseTest, TestStep, async_test_body, default_matter_test_main from mobly import asserts from TC_DEMTestBase import DEMTestBase @@ -58,18 +58,19 @@ def pics_TC_DEM_2_9(self): def steps_TC_DEM_2_9(self) -> list[TestStep]: """Execute the test steps.""" steps = [ - TestStep("1", "Commissioning, already done", - is_commissioning=True), - TestStep("2", "TH reads TestEventTriggersEnabled attribute from General Diagnostics Cluster.", - "Verify that TestEventTriggersEnabled attribute has a value of 1 (True)"), - TestStep("3", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Forecast Test Event", - "Verify DUT responds with status SUCCESS(0x00)"), - TestStep("3a", "TH reads Forecast attribute.", + TestStep("1", "Commission DUT to TH (can be skipped if done in a preceding test)"), + TestStep("2", "TH reads from the DUT the _Featuremap_ attribute", + "Verify that the DUT response contains the _Featuremap_ attribute. Verify one of PowerForecastReporting or StateForecastReporting is supported but not both."), + TestStep("3", "TH reads TestEventTriggersEnabled attribute from General Diagnostics Cluster", + "Value has to be 1 (True)"), + TestStep("4", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Forecast Test Event", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("4a", "TH reads from the DUT the Forecast", "Value has to include a valid slots[0].ManufacturerESAState"), - TestStep("3b", "TH reads Forecast attribute.", + TestStep("4b", "TH reads from the DUT the Forecast", "Value has to include valid slots[0].NominalPower, slots[0].MinPower, slots[0].MaxPower, slots[0].NominalEnergy"), - TestStep("4", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Forecast Test Event Clear", - "Verify DUT responds with status SUCCESS(0x00)"), + TestStep("5", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Forecast Test Event Clear", + "Verify DUT responds w/ status SUCCESS(0x00)"), ] return steps @@ -81,29 +82,24 @@ async def test_TC_DEM_2_9(self): self.step("1") # Commission DUT - already done + self.step("2") await self.validate_pfr_or_sfr_in_feature_map() - # Subscribe to Events and when they are sent push them to a queue for checking later - events_callback = EventChangeCallback(Clusters.DeviceEnergyManagement) - await events_callback.start(self.default_controller, - self.dut_node_id, - self.matter_test_config.endpoint) - - self.step("2") + self.step("3") await self.check_test_event_triggers_enabled() - self.step("3") + self.step("4") await self.send_test_event_trigger_forecast() - self.step("3a") + self.step("4a") feature_map = await self.read_dem_attribute_expect_success(attribute="FeatureMap") if feature_map & Clusters.DeviceEnergyManagement.Bitmaps.Feature.kStateForecastReporting: forecast = await self.read_dem_attribute_expect_success(attribute="Forecast") asserts.assert_is_not_none(forecast.slots[0].manufacturerESAState) else: - logging.info('Device does not support StateForecastReporting. Skipping step 3a') + logging.info('Device does not support StateForecastReporting. Skipping step 4a') - self.step("3b") + self.step("4b") if feature_map & Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerForecastReporting: forecast = await self.read_dem_attribute_expect_success(attribute="Forecast") @@ -112,9 +108,9 @@ async def test_TC_DEM_2_9(self): asserts.assert_is_not_none(forecast.slots[0].maxPower) asserts.assert_is_not_none(forecast.slots[0].nominalEnergy) else: - logging.info('Device does not support StateForecastReporting. Skipping step 3b') + logging.info('Device does not support StateForecastReporting. Skipping step 4b') - self.step("4") + self.step("5") await self.send_test_event_trigger_forecast_clear() From 5bdddd1c16ad261598efee8a7300703145663b91 Mon Sep 17 00:00:00 2001 From: pcoleman Date: Tue, 20 Aug 2024 13:00:19 +0100 Subject: [PATCH 07/45] Fix issue #4415 Fails randomly on CI when checking pause duration --- src/python_testing/TC_DEM_2_2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python_testing/TC_DEM_2_2.py b/src/python_testing/TC_DEM_2_2.py index ac0f0d96bf54dc..f90f2f012e745a 100644 --- a/src/python_testing/TC_DEM_2_2.py +++ b/src/python_testing/TC_DEM_2_2.py @@ -136,7 +136,7 @@ def steps_TC_DEM_2_2(self) -> list[TestStep]: TestStep("19b", "TH reads from the DUT the PowerAdjustmentCapability", "Value has to include Cause=LocalOptimizationAdjustment."), TestStep("20", "Wait 10 seconds", - "Event DEM.S.E01(PowerAdjustEnd) sent with Cause=NormalCompletion, Duration=10s, EnergyUse= a valid value"), + "Event DEM.S.E01(PowerAdjustEnd) sent with Cause=NormalCompletion, Duration in the range 10-12s, EnergyUse= a valid value"), TestStep("20a", "TH reads from the DUT the ESAState", "Value has to be 0x01 (Online)"), TestStep("20b", "TH reads from the DUT the PowerAdjustmentCapability", From 20e44e911400b45cd4bd150de54d4b3dbdf77348 Mon Sep 17 00:00:00 2001 From: pcoleman Date: Tue, 20 Aug 2024 13:50:42 +0100 Subject: [PATCH 08/45] Test an illegal slot index == number of slots in a forecast --- src/python_testing/TC_DEM_2_5.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/python_testing/TC_DEM_2_5.py b/src/python_testing/TC_DEM_2_5.py index f1cc81660e7ab5..57ec98ab01e14f 100644 --- a/src/python_testing/TC_DEM_2_5.py +++ b/src/python_testing/TC_DEM_2_5.py @@ -74,7 +74,7 @@ def steps_TC_DEM_2_5(self) -> list[TestStep]: "Value has to be 0x00 (NoOptOut)"), TestStep("5", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID+1, SlotAdjustments[0].{SlotIndex=0, NominalPower=Forecast.Slots[0].MinPowerAdjustment, Duration=Forecast.Slots[0].MaxDurationAdjustment}, Cause=GridOptimization", "Verify DUT responds w/ status FAILURE(0x01)"), - TestStep("6", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=4, NominalPower=Forecast.Slots[0].MinPowerAdjustment, Duration=Forecast.Slots[0].MaxDurationAdjustment}, Cause=GridOptimization", + TestStep("6", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=len(Forecast.Slots), NominalPower=Forecast.Slots[0].MinPowerAdjustment, Duration=Forecast.Slots[0].MaxDurationAdjustment}, Cause=GridOptimization", "Verify DUT responds w/ status FAILURE(0x01)"), TestStep("7", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, NominalPower=Forecast.Slots[0].MinPowerAdjustment-1, Duration=Forecast.Slots[0].MaxDurationAdjustment}, Cause=GridOptimization", "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"), @@ -177,7 +177,7 @@ async def test_TC_DEM_2_5(self): self.step("6") slotAdjustments = [Clusters.DeviceEnergyManagement.Structs.SlotAdjustmentStruct( - slotIndex=4, nominalPower=forecast.slots[0].minPowerAdjustment, duration=forecast.slots[0].maxDurationAdjustment)] + slotIndex=len(forecast.slots), nominalPower=forecast.slots[0].minPowerAdjustment, duration=forecast.slots[0].maxDurationAdjustment)] await self.send_modify_forecast_request_command(forecast.forecastID, slotAdjustments, Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kGridOptimization, expected_status=Status.Failure) self.step("7") From 1f89e7ca140b1eecf5fe7b87825355b6ff53d86c Mon Sep 17 00:00:00 2001 From: pcoleman Date: Tue, 20 Aug 2024 14:04:37 +0100 Subject: [PATCH 09/45] Add a test in PFR when ModifyForecastRequest does not specify NominalPower --- src/python_testing/TC_DEM_2_5.py | 129 ++++++++++++++++--------------- 1 file changed, 68 insertions(+), 61 deletions(-) diff --git a/src/python_testing/TC_DEM_2_5.py b/src/python_testing/TC_DEM_2_5.py index 57ec98ab01e14f..f6ccd68f034590 100644 --- a/src/python_testing/TC_DEM_2_5.py +++ b/src/python_testing/TC_DEM_2_5.py @@ -72,67 +72,69 @@ def steps_TC_DEM_2_5(self) -> list[TestStep]: "Value has to include slots[0].MinPowerAdjustment, slots[0].MaxPowerAdjustment, slots[0].MinDurationAdjustment, slots[0].MaxDurationAdjustment"), TestStep("4c", "TH reads from the DUT the OptOutState", "Value has to be 0x00 (NoOptOut)"), - TestStep("5", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID+1, SlotAdjustments[0].{SlotIndex=0, NominalPower=Forecast.Slots[0].MinPowerAdjustment, Duration=Forecast.Slots[0].MaxDurationAdjustment}, Cause=GridOptimization", + TestStep("5", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, Duration=Forecast.Slots[0].MaxDurationAdjustment}, Cause=GridOptimization", + "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"), + TestStep("6", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID+1, SlotAdjustments[0].{SlotIndex=0, NominalPower=Forecast.Slots[0].MinPowerAdjustment, Duration=Forecast.Slots[0].MaxDurationAdjustment}, Cause=GridOptimization", "Verify DUT responds w/ status FAILURE(0x01)"), - TestStep("6", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=len(Forecast.Slots), NominalPower=Forecast.Slots[0].MinPowerAdjustment, Duration=Forecast.Slots[0].MaxDurationAdjustment}, Cause=GridOptimization", + TestStep("7", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=len(Forecast.Slots), NominalPower=Forecast.Slots[0].MinPowerAdjustment, Duration=Forecast.Slots[0].MaxDurationAdjustment}, Cause=GridOptimization", "Verify DUT responds w/ status FAILURE(0x01)"), - TestStep("7", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, NominalPower=Forecast.Slots[0].MinPowerAdjustment-1, Duration=Forecast.Slots[0].MaxDurationAdjustment}, Cause=GridOptimization", + TestStep("8", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, NominalPower=Forecast.Slots[0].MinPowerAdjustment-1, Duration=Forecast.Slots[0].MaxDurationAdjustment}, Cause=GridOptimization", "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"), - TestStep("8", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, NominalPower=Forecast.Slots[0].MaxPowerAdjustment+1, Duration=Forecast.Slots[0].MinDurationAdjustment}, Cause=GridOptimization", + TestStep("9", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, NominalPower=Forecast.Slots[0].MaxPowerAdjustment+1, Duration=Forecast.Slots[0].MinDurationAdjustment}, Cause=GridOptimization", "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"), - TestStep("9", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, NominalPower=Forecast.Slots[0].MinPowerAdjustment, Duration=Forecast.Slots[0].MaxDurationAdjustment+1}, Cause=GridOptimization", + TestStep("10", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, NominalPower=Forecast.Slots[0].MinPowerAdjustment, Duration=Forecast.Slots[0].MaxDurationAdjustment+1}, Cause=GridOptimization", "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"), - TestStep("10", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, NominalPower=Forecast.Slots[0].MaxPowerAdjustment, Duration=Forecast.Slots[0].MinDurationAdjustment-1}, Cause=GridOptimization", + TestStep("11", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, NominalPower=Forecast.Slots[0].MaxPowerAdjustment, Duration=Forecast.Slots[0].MinDurationAdjustment-1}, Cause=GridOptimization", "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"), - TestStep("11", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, NominalPower=Forecast.Slots[0].MinPowerAdjustment, Duration=Forecast.Slots[0].MaxDurationAdjustment}, SlotAdjustments[1].{SlotIndex=4, NominalPower=Forecast.Slots[0].MinPowerAdjustment, Duration=Forecast.Slots[0].MaxDurationAdjustment}, Cause=GridOptimization", + TestStep("12", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, NominalPower=Forecast.Slots[0].MinPowerAdjustment, Duration=Forecast.Slots[0].MaxDurationAdjustment}, SlotAdjustments[1].{SlotIndex=4, NominalPower=Forecast.Slots[0].MinPowerAdjustment, Duration=Forecast.Slots[0].MaxDurationAdjustment}, Cause=GridOptimization", "Verify DUT responds w/ status FAILURE(0x01)"), - TestStep("12", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Local Optimization Test Event", + TestStep("13", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Local Optimization Test Event", "Verify DUT responds w/ status SUCCESS(0x00)"), - TestStep("12a", "TH reads from the DUT the ESAState", + TestStep("13a", "TH reads from the DUT the ESAState", "Value has to be 0x01 (Online)"), - TestStep("12b", "TH reads from the DUT the OptOutState", + TestStep("13b", "TH reads from the DUT the OptOutState", "Value has to be 0x02 (LocalOptOut)"), - TestStep("13", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, NominalPower=Forecast.Slots[0].MinPowerAdjustment, Duration=Forecast.Slots[0].MaxDurationAdjustment}, Cause=LocalOptimization", + TestStep("14", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, NominalPower=Forecast.Slots[0].MinPowerAdjustment, Duration=Forecast.Slots[0].MaxDurationAdjustment}, Cause=LocalOptimization", "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"), - TestStep("14", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, NominalPower=Forecast.Slots[0].MinPowerAdjustment, Duration=Forecast.Slots[0].MaxDurationAdjustment}, Cause=GridOptimization", + TestStep("15", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, NominalPower=Forecast.Slots[0].MinPowerAdjustment, Duration=Forecast.Slots[0].MaxDurationAdjustment}, Cause=GridOptimization", "Verify DUT responds w/ status SUCCESS(0x00)"), - TestStep("14a", "TH reads from the DUT the Forecast", + TestStep("15a", "TH reads from the DUT the Forecast", "Value has to include ForecastUpdateReason=GridOptimization"), - TestStep("15", "TH sends command CancelRequest", + TestStep("16", "TH sends command CancelRequest", "Verify DUT responds w/ status SUCCESS(0x00)"), - TestStep("15a", "TH reads from the DUT the Forecast", + TestStep("16a", "TH reads from the DUT the Forecast", "Value has to include ForecastUpdateReason=InternalOptimization"), - TestStep("16", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, NominalPower=Forecast.Slots[0].MinPowerAdjustment, Duration=Forecast.Slots[0].MaxDurationAdjustment}, Cause=GridOptimization", + TestStep("17", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, NominalPower=Forecast.Slots[0].MinPowerAdjustment, Duration=Forecast.Slots[0].MaxDurationAdjustment}, Cause=GridOptimization", "Verify DUT responds w/ status SUCCESS(0x00)"), - TestStep("16a", "TH reads from the DUT the Forecast", + TestStep("17a", "TH reads from the DUT the Forecast", "Value has to include ForecastUpdateReason=GridOptimization"), - TestStep("17", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Grid Optimization Test Event", + TestStep("18", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Grid Optimization Test Event", "Verify DUT responds w/ status SUCCESS(0x00)"), - TestStep("17a", "TH reads from the DUT the OptOutState", + TestStep("18a", "TH reads from the DUT the OptOutState", "Value has to be 0x03 (OptOut)"), - TestStep("17b", "TH reads from the DUT the Forecast", + TestStep("18b", "TH reads from the DUT the Forecast", "Value has to include ForecastUpdateReason=Internal Optimization"), - TestStep("18", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, NominalPower=Forecast.Slots[0].MinPowerAdjustment, Duration=Forecast.Slots[0].MaxDurationAdjustment}, Cause=GridOptimization", + TestStep("19", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, NominalPower=Forecast.Slots[0].MinPowerAdjustment, Duration=Forecast.Slots[0].MaxDurationAdjustment}, Cause=GridOptimization", "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"), - TestStep("19", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Test Event Clear", + TestStep("20", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Test Event Clear", "Verify DUT responds w/ status SUCCESS(0x00)"), - TestStep("19a", "TH reads from the DUT the OptOutState", + TestStep("20a", "TH reads from the DUT the OptOutState", "Value has to be 0x00 (NoOptOut)"), - TestStep("20", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, NominalPower=Forecast.Slots[0].MaxPowerAdjustment, Duration=Forecast.Slots[0].MinDurationAdjustment}, Cause=LocalOptimization", + TestStep("21", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, NominalPower=Forecast.Slots[0].MaxPowerAdjustment, Duration=Forecast.Slots[0].MinDurationAdjustment}, Cause=LocalOptimization", "Verify DUT responds w/ status SUCCESS(0x00)"), - TestStep("20a", "TH reads from the DUT the Forecast", + TestStep("21a", "TH reads from the DUT the Forecast", "Value has to include ForecastUpdateReason=LocalOptimization"), - TestStep("21", "TH sends command CancelRequest", + TestStep("22", "TH sends command CancelRequest", "Verify DUT responds w/ status SUCCESS(0x00)"), - TestStep("21a", "TH reads from the DUT the Forecast", + TestStep("22a", "TH reads from the DUT the Forecast", "Value has to include ForecastUpdateReason=InternalOptimization"), - TestStep("22", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Forecast Adjustment Test Event Next Slot", + TestStep("23", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Forecast Adjustment Test Event Next Slot", "Verify DUT responds w/ status SUCCESS(0x00)"), - TestStep("23", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, NominalPower=Forecast.Slots[0].MaxPowerAdjustment, Duration=Forecast.Slots[0].MinDurationAdjustment}, Cause=LocalOptimization", + TestStep("24", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, NominalPower=Forecast.Slots[0].MaxPowerAdjustment, Duration=Forecast.Slots[0].MinDurationAdjustment}, Cause=LocalOptimization", "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"), - TestStep("24", "TH sends command CancelRequest", + TestStep("25", "TH sends command CancelRequest", "Verify DUT responds w/ status INVALID_IN_STATE(0xcb)"), - TestStep("25", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Forecast Adjustment Test Event Clear", + TestStep("26", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Forecast Adjustment Test Event Clear", "Verify DUT responds w/ status SUCCESS(0x00)"), ] @@ -171,134 +173,139 @@ async def test_TC_DEM_2_5(self): await self.check_dem_attribute("OptOutState", Clusters.DeviceEnergyManagement.Enums.OptOutStateEnum.kNoOptOut) self.step("5") + slotAdjustments = [Clusters.DeviceEnergyManagement.Structs.SlotAdjustmentStruct( + slotIndex=0, duration=forecast.slots[0].minDurationAdjustment)] + await self.send_modify_forecast_request_command(forecast.forecastID, slotAdjustments, Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kGridOptimization, expected_status=Status.ConstraintError) + + self.step("6") slotAdjustments = [Clusters.DeviceEnergyManagement.Structs.SlotAdjustmentStruct( slotIndex=0, nominalPower=forecast.slots[0].minPowerAdjustment, duration=forecast.slots[0].maxDurationAdjustment)] await self.send_modify_forecast_request_command(forecast.forecastID + 1, slotAdjustments, Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kGridOptimization, expected_status=Status.Failure) - self.step("6") + self.step("7") slotAdjustments = [Clusters.DeviceEnergyManagement.Structs.SlotAdjustmentStruct( slotIndex=len(forecast.slots), nominalPower=forecast.slots[0].minPowerAdjustment, duration=forecast.slots[0].maxDurationAdjustment)] await self.send_modify_forecast_request_command(forecast.forecastID, slotAdjustments, Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kGridOptimization, expected_status=Status.Failure) - self.step("7") + self.step("8") slotAdjustments = [Clusters.DeviceEnergyManagement.Structs.SlotAdjustmentStruct( slotIndex=0, nominalPower=forecast.slots[0].minPowerAdjustment - 1, duration=forecast.slots[0].maxDurationAdjustment)] await self.send_modify_forecast_request_command(forecast.forecastID, slotAdjustments, Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kGridOptimization, expected_status=Status.ConstraintError) - self.step("8") + self.step("9") slotAdjustments = [Clusters.DeviceEnergyManagement.Structs.SlotAdjustmentStruct( slotIndex=0, nominalPower=forecast.slots[0].maxPowerAdjustment + 1, duration=forecast.slots[0].minDurationAdjustment)] await self.send_modify_forecast_request_command(forecast.forecastID, slotAdjustments, Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kGridOptimization, expected_status=Status.ConstraintError) - self.step("9") + self.step("10") slotAdjustments = [Clusters.DeviceEnergyManagement.Structs.SlotAdjustmentStruct( slotIndex=0, nominalPower=forecast.slots[0].minPowerAdjustment, duration=forecast.slots[0].maxDurationAdjustment + 1)] await self.send_modify_forecast_request_command(forecast.forecastID, slotAdjustments, Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kGridOptimization, expected_status=Status.ConstraintError) - self.step("10") + self.step("11") slotAdjustments = [Clusters.DeviceEnergyManagement.Structs.SlotAdjustmentStruct( slotIndex=0, nominalPower=forecast.slots[0].maxPowerAdjustment, duration=forecast.slots[0].minDurationAdjustment - 1)] await self.send_modify_forecast_request_command(forecast.forecastID, slotAdjustments, Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kGridOptimization, expected_status=Status.ConstraintError) - self.step("11") + self.step("12") slotAdjustments = [Clusters.DeviceEnergyManagement.Structs.SlotAdjustmentStruct(slotIndex=0, nominalPower=forecast.slots[0].minPowerAdjustment, duration=forecast.slots[0].maxDurationAdjustment), Clusters.DeviceEnergyManagement.Structs.SlotAdjustmentStruct(slotIndex=4, nominalPower=forecast.slots[0].minPowerAdjustment, duration=forecast.slots[0].maxDurationAdjustment)] await self.send_modify_forecast_request_command(forecast.forecastID, slotAdjustments, Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kGridOptimization, expected_status=Status.Failure) - self.step("12") + self.step("13") await self.send_test_event_trigger_user_opt_out_local() - self.step("12a") + self.step("13a") await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kOnline) - self.step("12b") + self.step("13b") await self.check_dem_attribute("OptOutState", Clusters.DeviceEnergyManagement.Enums.OptOutStateEnum.kLocalOptOut) - self.step("13") + self.step("14") slotAdjustments = [Clusters.DeviceEnergyManagement.Structs.SlotAdjustmentStruct( slotIndex=0, nominalPower=forecast.slots[0].minPowerAdjustment, duration=forecast.slots[0].maxDurationAdjustment)] await self.send_modify_forecast_request_command(forecast.forecastID, slotAdjustments, Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization, expected_status=Status.ConstraintError) - self.step("14") + self.step("15") slotAdjustments = [Clusters.DeviceEnergyManagement.Structs.SlotAdjustmentStruct( slotIndex=0, nominalPower=forecast.slots[0].minPowerAdjustment, duration=forecast.slots[0].maxDurationAdjustment)] await self.send_modify_forecast_request_command(forecast.forecastID, slotAdjustments, Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kGridOptimization, expected_status=Status.Success) - self.step("14a") + self.step("15a") forecast = await self.read_dem_attribute_expect_success(attribute="Forecast") asserts.assert_equal(forecast.forecastUpdateReason, Clusters.DeviceEnergyManagement.Enums.ForecastUpdateReasonEnum.kGridOptimization) - self.step("15") + self.step("16") await self.send_cancel_request_command() - self.step("15a") + self.step("16a") forecast = await self.read_dem_attribute_expect_success(attribute="Forecast") asserts.assert_equal(forecast.forecastUpdateReason, Clusters.DeviceEnergyManagement.Enums.ForecastUpdateReasonEnum.kInternalOptimization) - self.step("16") + self.step("17") slotAdjustments = [Clusters.DeviceEnergyManagement.Structs.SlotAdjustmentStruct( slotIndex=0, nominalPower=forecast.slots[0].minPowerAdjustment, duration=forecast.slots[0].maxDurationAdjustment)] await self.send_modify_forecast_request_command(forecast.forecastID, slotAdjustments, Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kGridOptimization, expected_status=Status.Success) - self.step("16a") + self.step("17a") forecast = await self.read_dem_attribute_expect_success(attribute="Forecast") asserts.assert_equal(forecast.forecastUpdateReason, Clusters.DeviceEnergyManagement.Enums.ForecastUpdateReasonEnum.kGridOptimization) - self.step("17") + self.step("18") await self.send_test_event_trigger_user_opt_out_grid() - self.step("17a") + self.step("18a") await self.check_dem_attribute("OptOutState", Clusters.DeviceEnergyManagement.Enums.OptOutStateEnum.kOptOut) - self.step("17b") + self.step("18b") forecast = await self.read_dem_attribute_expect_success(attribute="Forecast") asserts.assert_equal(forecast.forecastUpdateReason, Clusters.DeviceEnergyManagement.Enums.ForecastUpdateReasonEnum.kInternalOptimization) - self.step("18") + self.step("19") slotAdjustments = [Clusters.DeviceEnergyManagement.Structs.SlotAdjustmentStruct( slotIndex=0, nominalPower=forecast.slots[0].minPowerAdjustment, duration=forecast.slots[0].maxDurationAdjustment)] await self.send_modify_forecast_request_command(forecast.forecastID, slotAdjustments, Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kGridOptimization, expected_status=Status.ConstraintError) - self.step("19") + self.step("20") await self.send_test_event_trigger_user_opt_out_clear_all() - self.step("19a") + self.step("20a") await self.check_dem_attribute("OptOutState", Clusters.DeviceEnergyManagement.Enums.OptOutStateEnum.kNoOptOut) - self.step("20") + self.step("21") slotAdjustments = [Clusters.DeviceEnergyManagement.Structs.SlotAdjustmentStruct( slotIndex=0, nominalPower=forecast.slots[0].minPowerAdjustment, duration=forecast.slots[0].minDurationAdjustment)] await self.send_modify_forecast_request_command(forecast.forecastID, slotAdjustments, Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization, expected_status=Status.Success) - self.step("20a") + self.step("21a") forecast = await self.read_dem_attribute_expect_success(attribute="Forecast") asserts.assert_equal(forecast.forecastUpdateReason, Clusters.DeviceEnergyManagement.Enums.ForecastUpdateReasonEnum.kLocalOptimization) - self.step("21") + self.step("22") await self.send_cancel_request_command() - self.step("21a") + self.step("22a") forecast = await self.read_dem_attribute_expect_success(attribute="Forecast") asserts.assert_equal(forecast.forecastUpdateReason, Clusters.DeviceEnergyManagement.Enums.ForecastUpdateReasonEnum.kInternalOptimization) - self.step("22") + self.step("23") await self.send_test_event_trigger_forecast_adjustment_next_slot() - self.step("23") + self.step("24") slotAdjustments = [Clusters.DeviceEnergyManagement.Structs.SlotAdjustmentStruct( slotIndex=0, nominalPower=forecast.slots[0].minPowerAdjustment, duration=forecast.slots[0].minDurationAdjustment)] await self.send_modify_forecast_request_command(forecast.forecastID, slotAdjustments, Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization, expected_status=Status.ConstraintError) - self.step("24") + self.step("25") await self.send_cancel_request_command(expected_status=Status.InvalidInState) - self.step("25") + self.step("26") await self.send_test_event_trigger_forecast_adjustment_clear() From 1e0db0945ab017c6e30807799f4a4d99e2931a1d Mon Sep 17 00:00:00 2001 From: pcoleman Date: Tue, 20 Aug 2024 16:22:21 +0100 Subject: [PATCH 10/45] Set ClusterRevision to 4 --- .../energy-management-common/energy-management-app.matter | 2 +- .../energy-management-common/energy-management-app.zap | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/energy-management-app/energy-management-common/energy-management-app.matter b/examples/energy-management-app/energy-management-common/energy-management-app.matter index e7fba7e08e028f..3ab9ea4cd88836 100644 --- a/examples/energy-management-app/energy-management-common/energy-management-app.matter +++ b/examples/energy-management-app/energy-management-common/energy-management-app.matter @@ -2575,7 +2575,7 @@ endpoint 1 { callback attribute eventList; callback attribute attributeList; callback attribute featureMap; - ram attribute clusterRevision default = 3; + ram attribute clusterRevision default = 4; handle command PowerAdjustRequest; handle command CancelPowerAdjustRequest; diff --git a/examples/energy-management-app/energy-management-common/energy-management-app.zap b/examples/energy-management-app/energy-management-common/energy-management-app.zap index 566588ab8e4d0d..caf6b584df5aef 100644 --- a/examples/energy-management-app/energy-management-common/energy-management-app.zap +++ b/examples/energy-management-app/energy-management-common/energy-management-app.zap @@ -3989,7 +3989,7 @@ "storageOption": "RAM", "singleton": 0, "bounded": 0, - "defaultValue": "3", + "defaultValue": "4", "reportable": 1, "minInterval": 1, "maxInterval": 65534, From 8f63c4943cefd6320d46788332dabe5787c0ace9 Mon Sep 17 00:00:00 2001 From: pcoleman Date: Tue, 20 Aug 2024 16:47:30 +0100 Subject: [PATCH 11/45] First versionof DEM 1-1 --- src/python_testing/TC_DEM_1_1.py | 216 +++++++++++++++++++++++++++++++ 1 file changed, 216 insertions(+) create mode 100644 src/python_testing/TC_DEM_1_1.py diff --git a/src/python_testing/TC_DEM_1_1.py b/src/python_testing/TC_DEM_1_1.py new file mode 100644 index 00000000000000..ba18b7eb34f454 --- /dev/null +++ b/src/python_testing/TC_DEM_1_1.py @@ -0,0 +1,216 @@ +# +# Copyright (c) 2024 Project CHIP Authors +# All rights reserved. +# +# 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. +# pylint: disable=invalid-name + +# See https://github.com/project-chip/connectedhomeip/blob/master/docs/testing/python.md#defining-the-ci-test-arguments +# for details about the block below. +# +# === BEGIN CI TEST ARGUMENTS === +# test-runner-runs: run1 +# test-runner-run/run1/app: ${ENERGY_MANAGEMENT_APP} +# test-runner-run/run1/factoryreset: True +# test-runner-run/run1/quiet: True +# test-runner-run/run1/app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json --enable-key 000102030405060708090a0b0c0d0e0f --featureSet 0x23 +# test-runner-run/run1/script-args: --storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --hex-arg enableKey:000102030405060708090a0b0c0d0e0f --endpoint 1 --trace-to json:${TRACE_TEST_JSON}.json --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto +# === END CI TEST ARGUMENTS === + +"""Define Matter test case TC_DEM_1_1.""" + + +import logging + +import chip.clusters as Clusters +from chip.interaction_model import Status +from matter_testing_support import MatterBaseTest, TestStep, async_test_body, default_matter_test_main +from mobly import asserts +from TC_DEMTestBase import DEMTestBase + +logger = logging.getLogger(__name__) + + +class TC_DEM_1_1(MatterBaseTest, DEMTestBase): + """Implementation of test case TC_DEM_1_1.""" + + def desc_TC_DEM_1_1(self) -> str: + """Return a description of this test.""" + return "4.1.3. [TC-DEM-2.5] Forecast Adjustment with Power Forecast Reporting feature functionality with DUT as Server" + + def pics_TC_DEM_1_1(self): + """Return the PICS definitions associated with this test.""" + pics = [ + # Depends on Feature 05 (ForecastAdjustment) & Feature 01 (PowerForecastReporting) + "DEM.S.F05", "DEM.S.F01" + ] + return pics + + def steps_TC_DEM_1_1(self) -> list[TestStep]: + """Execute the test steps.""" + steps = [ + TestStep("1", "Commission DUT to TH (can be skipped if done in a preceding test)."), + TestStep("2", "TH reads from the DUT the ClusterRevision attribute.", + "Verify that the DUT response contains the ClusterRevision attribute and has the value 3."), + TestStep("3", "TH reads from the DUT the FeatureMap attribute.", + "Verify that the DUT response contains the FeatureMap attribute and have the following bit set:\n- bit 0: SHALL be 1 if and only if DEM.S.F00(PowerAdjustment).\n- bit 1: SHALL be 1 if and only if DEM.S.F01(PowerForecastReporting).\n- bit 2: SHALL be 1 if and only if DEM.S.F02(StateForecastReporting).\n- bit 3: SHALL be 1 if and only if DEM.S.F03(StartTimeAdjustment).\n- bit 4: SHALL be 1 if and only if DEM.S.F04(Pausable).\nAll remaining bits SHALL be 0. Provisional features DEM.S.F05(ForecastAdjustment) and DEM.S.F06(ConstraintBasedAdjustment) must not be supported."), + TestStep("4", "TH reads from the DUT the AttributeList attribute.", + "Verify that the DUT response contains the AttributeList attribute and have the list of supported attributes:\nThe list SHALL include all the mandatory entries: +\n0x0000, 0x0001, 0x0002, 0x0003, 0x0004\n0xfff8, 0xfff9, 0xfffb, 0xfffc and 0xfffd.\nThe list includes entries based on feature support: +\n- 0x0005: SHALL be included if and only if DEM.S.F00(PowerAdjustment).\nDEM.S.F02(StateForecastReporting).\n- 0x0007: SHALL be included if and only if DEM.S.F00(PowerAdjustment)"), + TestStep("5", "TH reads from the DUT the EventList attribute.", + "Verify that the DUT response contains the EventList attribute and have the list of supported events:\nThe list includes entries based on feature support: +\n- 0x00, 0x01: SHALL be included if and only if DEM.S.F00(PowerAdjustment).\n- 0x02, 0x03: SHALL be included if and only if DEM.S.F04(Pausable)."), + TestStep("6", "TH reads from the DUT the AcceptedCommandList attribute.", + "Verify that the DUT response contains the AcceptedCommandList attribute and have the list of Accepted Command:\nThe list includes entries based on feature support: +\n- 0x00, 0x01: SHALL be included if and only if DEM.S.F00(PowerAdjustment).\n- 0x02: SHALL be included if and only if DEM.S.F03(StartTimeAdjustment).\n- 0x03, 0x04: SHALL be included if and only if DEM.S.F04(Pausable).\n- 0x05: SHALL be included if and only if DEM.S.F05(ForecastAdjustment).\n- 0x06: SHALL be included if and only if DEM.S.F06(ConstraintBasedAdjustment).\n- 0x07: SHALL be included if and only if DEM.S.F03(StartTimeAdjustment)"), + TestStep("7", "TH reads from the DUT the GeneratedCommandList attribute.", + "Verify that the DUT response contains the GeneratedCommandList attribute and have the list of Generated Command:\nThis cluster has no entries in the standard or scoped range. +"), + ] + + return steps + + @async_test_body + async def test_TC_DEM_1_1(self): + # pylint: disable=too-many-locals, too-many-statements + """Run the test steps.""" + self.step("1") + # Commission DUT - already done + + self.step("2") + await self.check_dem_attribute("ClusterRevision", 4) + + + self.step("3") + #await self.validate_feature_map([Clusters.DeviceEnergyManagement.Bitmaps.Feature.kForecastAdjustment, + # Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerForecastReporting], + # [Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerAdjustment, + # Clusters.DeviceEnergyManagement.Bitmaps.Feature.kStateForecastReporting, + # Clusters.DeviceEnergyManagement.Bitmaps.Feature.kStartTimeAdjustment, + # Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPausable, + # Clusters.DeviceEnergyManagement.Bitmaps.Feature.kConstraintBasedAdjustment]) + + self.step("4") + attribute_list = await self.read_dem_attribute_expect_success(attribute="AttributeList") + logging.info(attribute_list) + + mandatory_attributes = [Clusters.DeviceEnergyManagement.Attributes.ESAType.attribute_id, + Clusters.DeviceEnergyManagement.Attributes.ESACanGenerate.attribute_id, + Clusters.DeviceEnergyManagement.Attributes.ESAState.attribute_id, + Clusters.DeviceEnergyManagement.Attributes.AbsMinPower.attribute_id, + Clusters.DeviceEnergyManagement.Attributes.AbsMaxPower.attribute_id] + + for mandatory_attribute in mandatory_attributes: + asserts.assert_true(mandatory_attribute in attribute_list, + f"Expected to find mandatory attribute {mandatory_attribute} in attribute_list {attribute_list}") + + # Remove the enrty from the list + attribute_list.remove(mandatory_attribute) + + # Now check feature dependant attributes + feature_map = await self.read_dem_attribute_expect_success(attribute="FeatureMap") + + attribute_id = Clusters.DeviceEnergyManagement.Attributes.PowerAdjustmentCapability.attribute_id + required_features = Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerAdjustment + self.check_attribute_valid_and_remove_from_list(attribute_id, feature_map, attribute_list, required_features) + + attribute_id = Clusters.DeviceEnergyManagement.Attributes.Forecast.attribute_id + required_features = (Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerForecastReporting | + Clusters.DeviceEnergyManagement.Bitmaps.Feature.kStateForecastReporting) + self.check_attribute_valid_and_remove_from_list(attribute_id, feature_map, attribute_list, required_features) + + attribute_id = Clusters.DeviceEnergyManagement.Attributes.OptOutState.attribute_id + required_features = (Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerAdjustment | + Clusters.DeviceEnergyManagement.Bitmaps.Feature.kStartTimeAdjustment | + Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPausable | + Clusters.DeviceEnergyManagement.Bitmaps.Feature.kForecastAdjustment | + Clusters.DeviceEnergyManagement.Bitmaps.Feature.kConstraintBasedAdjustment) + + self.check_attribute_valid_and_remove_from_list(attribute_id, feature_map, attribute_list, required_features) + + global_attributes = [Clusters.DeviceEnergyManagement.Attributes.GeneratedCommandList.attribute_id, + Clusters.DeviceEnergyManagement.Attributes.AcceptedCommandList.attribute_id, + Clusters.DeviceEnergyManagement.Attributes.AttributeList.attribute_id, + Clusters.DeviceEnergyManagement.Attributes.FeatureMap.attribute_id, + Clusters.DeviceEnergyManagement.Attributes.ClusterRevision.attribute_id] + + for global_attribute in global_attributes: + logging.info(f"global_attribute {global_attribute} global_attributes {global_attributes}") + asserts.assert_true(global_attribute in attribute_list, + f"Expected to find global attribute {global_attribute} in attribute_list {attribute_list}") + + # Remove the enrty from the list + attribute_list.remove(global_attribute) + + # Check there are no unknown attributes left in the list + asserts.assert_equal(len(attribute_list), 0) + + self.step("5") + #event_list = await self.read_dem_attribute_expect_success(attribute="EventList") + #logging.info(f"event_list {event_list}") + + #n- 0x00, 0x01: SHALL be included if and only if DEM.S.F00(PowerAdjustment).\n- 0x02, 0x03: SHALL be included if and only if DEM.S.F04(Pausable)."), + self.step("6") + accepted_command_list = await self.read_dem_attribute_expect_success(attribute="AcceptedCommandList") + logging.info(f"accepted_command_list {accepted_command_list}") + + required_features = Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerAdjustment + expected_commands = [Clusters.DeviceEnergyManagement.Commands.PowerAdjustRequest.command_id, + Clusters.DeviceEnergyManagement.Commands.CancelPowerAdjustRequest.command_id] + self.check_expected_commands_in_list(expected_commands, feature_map, accepted_command_list, required_features) + + required_features = Clusters.DeviceEnergyManagement.Bitmaps.Feature.kStartTimeAdjustment + expected_commands = [Clusters.DeviceEnergyManagement.Commands.StartTimeAdjustRequest.command_id] + self.check_expected_commands_in_list(expected_commands, feature_map, accepted_command_list, required_features) + + required_features = Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPausable + expected_commands = [Clusters.DeviceEnergyManagement.Commands.PauseRequest.command_id, + Clusters.DeviceEnergyManagement.Commands.ResumeRequest.command_id] + self.check_expected_commands_in_list(expected_commands, feature_map, accepted_command_list, required_features) + + required_features = Clusters.DeviceEnergyManagement.Bitmaps.Feature.kForecastAdjustment + expected_commands = [Clusters.DeviceEnergyManagement.Commands.ModifyForecastRequest.command_id] + self.check_expected_commands_in_list(expected_commands, feature_map, accepted_command_list, required_features) + + required_features = Clusters.DeviceEnergyManagement.Bitmaps.Feature.kConstraintBasedAdjustment + expected_commands = [Clusters.DeviceEnergyManagement.Commands.RequestConstraintBasedForecast.command_id] + self.check_expected_commands_in_list(expected_commands, feature_map, accepted_command_list, required_features) + + required_features = (Clusters.DeviceEnergyManagement.Bitmaps.Feature.kStartTimeAdjustment | + Clusters.DeviceEnergyManagement.Bitmaps.Feature.kForecastAdjustment | + Clusters.DeviceEnergyManagement.Bitmaps.Feature.kConstraintBasedAdjustment) + expected_commands = [Clusters.DeviceEnergyManagement.Commands.CancelRequest.command_id] + self.check_expected_commands_in_list(expected_commands, feature_map, accepted_command_list, required_features) + + self.step("7") + generated_command_list = await self.read_dem_attribute_expect_success(attribute="GeneratedCommandList") + asserts.assert_equal(len(generated_command_list), 0) + + def check_attribute_valid_and_remove_from_list(self, attribute_id, feature_map, attribute_list, required_features): + if feature_map & required_features: + asserts.assert_true(attribute_id in attribute_list, + f"Expected to find attribute {attribute_id} in attribute_list {attribute_list} given feature_map 0x{feature_map:x}") + attribute_list.remove(attribute_id) + + else: + asserts.assert_false(attribute_id in attribute_list, + f"Did not expect to find attribute {attribute_id} in attribute_list {attribute_list} given feature_map 0x{feature_map:x}") + + def check_expected_commands_in_list(self, expected_commands, feature_map, accepted_command_list, required_features): + if (feature_map & required_features) != 0: + for command in expected_commands: + asserts.assert_true(command in accepted_command_list, + f"Expected command {command} to be in accepted_command_list {accepted_command_list} given required_features {required_features} in feature_map 0x{feature_map:x}") + + else: + for command in expected_commands: + asserts.assert_false(command in accepted_command_list, + f"Did not expect command {command} to be in accepted_command_list {accepted_command_list} given required_features {required_features} in feature_map 0x{feature_map:x}") +if __name__ == "__main__": + default_matter_test_main() From e854d86c3f39e12e49718d372bb670f430c653d7 Mon Sep 17 00:00:00 2001 From: pcoleman Date: Wed, 21 Aug 2024 22:22:03 +0100 Subject: [PATCH 12/45] Regenerate files --- .../cluster/clusters/AccessControlCluster.kt | 1599 +- .../cluster/clusters/AccountLoginCluster.kt | 752 +- .../cluster/clusters/ActionsCluster.kt | 1227 +- .../ActivatedCarbonFilterMonitoringCluster.kt | 1432 +- .../AdministratorCommissioningCluster.kt | 1063 +- .../cluster/clusters/AirQualityCluster.kt | 771 +- .../clusters/ApplicationBasicCluster.kt | 1494 +- .../clusters/ApplicationLauncherCluster.kt | 1152 +- .../cluster/clusters/AudioOutputCluster.kt | 910 +- .../clusters/BallastConfigurationCluster.kt | 2534 +-- .../cluster/clusters/BarrierControlCluster.kt | 1850 +- .../clusters/BasicInformationCluster.kt | 2781 +-- .../clusters/BinaryInputBasicCluster.kt | 1762 +- .../cluster/clusters/BindingCluster.kt | 845 +- .../cluster/clusters/BooleanStateCluster.kt | 776 +- .../BooleanStateConfigurationCluster.kt | 1613 +- .../BridgedDeviceBasicInformationCluster.kt | 2528 +-- ...nDioxideConcentrationMeasurementCluster.kt | 2082 +-- ...MonoxideConcentrationMeasurementCluster.kt | 2082 +-- .../cluster/clusters/ChannelCluster.kt | 1336 +- .../cluster/clusters/ColorControlCluster.kt | 7069 ++++---- .../clusters/CommissionerControlCluster.kt | 866 +- .../clusters/ContentAppObserverCluster.kt | 777 +- .../cluster/clusters/ContentControlCluster.kt | 1696 +- .../clusters/ContentLauncherCluster.kt | 1075 +- .../DemandResponseLoadControlCluster.kt | 1590 +- .../cluster/clusters/DescriptorCluster.kt | 1336 +- .../clusters/DeviceEnergyManagementCluster.kt | 1589 +- .../DeviceEnergyManagementModeCluster.kt | 1299 +- .../cluster/clusters/DiagnosticLogsCluster.kt | 762 +- .../clusters/DishwasherAlarmCluster.kt | 1060 +- .../cluster/clusters/DishwasherModeCluster.kt | 1297 +- .../cluster/clusters/DoorLockCluster.kt | 7068 ++++---- .../clusters/EcosystemInformationCluster.kt | 1094 +- .../ElectricalEnergyMeasurementCluster.kt | 1544 +- .../clusters/ElectricalMeasurementCluster.kt | 14219 ++++++++-------- .../ElectricalPowerMeasurementCluster.kt | 3262 ++-- .../cluster/clusters/EnergyEvseCluster.kt | 3575 ++-- .../cluster/clusters/EnergyEvseModeCluster.kt | 1297 +- .../clusters/EnergyPreferenceCluster.kt | 1405 +- .../EthernetNetworkDiagnosticsCluster.kt | 1792 +- .../cluster/clusters/FanControlCluster.kt | 2161 +-- .../cluster/clusters/FaultInjectionCluster.kt | 725 +- .../cluster/clusters/FixedLabelCluster.kt | 816 +- .../clusters/FlowMeasurementCluster.kt | 1191 +- ...aldehydeConcentrationMeasurementCluster.kt | 2082 +-- .../clusters/GeneralCommissioningCluster.kt | 1757 +- .../clusters/GeneralDiagnosticsCluster.kt | 1850 +- .../clusters/GroupKeyManagementCluster.kt | 1229 +- .../cluster/clusters/GroupsCluster.kt | 1012 +- .../clusters/HepaFilterMonitoringCluster.kt | 1432 +- .../cluster/clusters/IcdManagementCluster.kt | 1833 +- .../cluster/clusters/IdentifyCluster.kt | 895 +- .../clusters/IlluminanceMeasurementCluster.kt | 1336 +- .../cluster/clusters/KeypadInputCluster.kt | 719 +- .../clusters/LaundryDryerControlsCluster.kt | 970 +- .../clusters/LaundryWasherControlsCluster.kt | 1294 +- .../clusters/LaundryWasherModeCluster.kt | 1297 +- .../cluster/clusters/LevelControlCluster.kt | 2614 +-- .../LocalizationConfigurationCluster.kt | 924 +- .../cluster/clusters/LowPowerCluster.kt | 695 +- .../cluster/clusters/MediaInputCluster.kt | 918 +- .../cluster/clusters/MediaPlaybackCluster.kt | 2706 +-- .../cluster/clusters/MessagesCluster.kt | 987 +- .../clusters/MicrowaveOvenControlCluster.kt | 1698 +- .../clusters/MicrowaveOvenModeCluster.kt | 899 +- .../cluster/clusters/ModeSelectCluster.kt | 1456 +- .../clusters/NetworkCommissioningCluster.kt | 2648 +-- ...nDioxideConcentrationMeasurementCluster.kt | 2082 +-- .../clusters/OccupancySensingCluster.kt | 2407 +-- .../cluster/clusters/OnOffCluster.kt | 1370 +- .../OnOffSwitchConfigurationCluster.kt | 879 +- .../clusters/OperationalCredentialsCluster.kt | 1751 +- .../clusters/OperationalStateCluster.kt | 1518 +- .../OtaSoftwareUpdateProviderCluster.kt | 940 +- .../OtaSoftwareUpdateRequestorCluster.kt | 1157 +- .../OvenCavityOperationalStateCluster.kt | 1525 +- .../cluster/clusters/OvenModeCluster.kt | 1292 +- .../OzoneConcentrationMeasurementCluster.kt | 2079 +-- .../Pm10ConcentrationMeasurementCluster.kt | 2079 +-- .../Pm1ConcentrationMeasurementCluster.kt | 2079 +-- .../Pm25ConcentrationMeasurementCluster.kt | 2079 +-- .../cluster/clusters/PowerSourceCluster.kt | 4347 ++--- .../PowerSourceConfigurationCluster.kt | 818 +- .../cluster/clusters/PowerTopologyCluster.kt | 988 +- .../clusters/PressureMeasurementCluster.kt | 1847 +- .../clusters/ProxyConfigurationCluster.kt | 694 +- .../cluster/clusters/ProxyDiscoveryCluster.kt | 694 +- .../cluster/clusters/ProxyValidCluster.kt | 691 +- .../clusters/PulseWidthModulationCluster.kt | 694 +- .../PumpConfigurationAndControlCluster.kt | 3687 ++-- .../RadonConcentrationMeasurementCluster.kt | 2079 +-- .../clusters/RefrigeratorAlarmCluster.kt | 937 +- ...TemperatureControlledCabinetModeCluster.kt | 1306 +- .../RelativeHumidityMeasurementCluster.kt | 1191 +- .../cluster/clusters/RvcCleanModeCluster.kt | 954 +- .../clusters/RvcOperationalStateCluster.kt | 1497 +- .../cluster/clusters/RvcRunModeCluster.kt | 949 +- .../cluster/clusters/SampleMeiCluster.kt | 835 +- .../clusters/ScenesManagementCluster.kt | 1570 +- .../cluster/clusters/ServiceAreaCluster.kt | 1620 +- .../cluster/clusters/SmokeCoAlarmCluster.kt | 2007 +-- .../clusters/SoftwareDiagnosticsCluster.kt | 1177 +- .../cluster/clusters/SwitchCluster.kt | 962 +- .../clusters/TargetNavigatorCluster.kt | 987 +- .../clusters/TemperatureControlCluster.kt | 1402 +- .../clusters/TemperatureMeasurementCluster.kt | 1191 +- .../cluster/clusters/ThermostatCluster.kt | 8603 +++++----- ...mostatUserInterfaceConfigurationCluster.kt | 1046 +- .../ThreadBorderRouterManagementCluster.kt | 1357 +- .../ThreadNetworkDiagnosticsCluster.kt | 7669 +++++---- .../clusters/ThreadNetworkDirectoryCluster.kt | 1101 +- .../clusters/TimeFormatLocalizationCluster.kt | 1084 +- .../clusters/TimeSynchronizationCluster.kt | 2386 +-- .../cluster/clusters/TimerCluster.kt | 957 +- ...ompoundsConcentrationMeasurementCluster.kt | 2084 +-- .../clusters/UnitLocalizationCluster.kt | 827 +- .../cluster/clusters/UnitTestingCluster.kt | 13446 ++++++++------- .../cluster/clusters/UserLabelCluster.kt | 845 +- .../ValveConfigurationAndControlCluster.kt | 2173 +-- .../cluster/clusters/WakeOnLanCluster.kt | 913 +- .../clusters/WaterHeaterManagementCluster.kt | 1280 +- .../clusters/WaterHeaterModeCluster.kt | 1297 +- .../clusters/WiFiNetworkDiagnosticsCluster.kt | 2503 +-- .../clusters/WiFiNetworkManagementCluster.kt | 983 +- .../cluster/clusters/WindowCoveringCluster.kt | 3194 ++-- ...olClusterAccessControlEntryChangedEvent.kt | 61 +- ...usterAccessControlExtensionChangedEvent.kt | 62 +- ...usterAccessRestrictionEntryChangedEvent.kt | 13 +- ...usterFabricRestrictionReviewUpdateEvent.kt | 44 +- .../AccountLoginClusterLoggedOutEvent.kt | 20 +- .../ActionsClusterActionFailedEvent.kt | 8 +- .../ActionsClusterStateChangedEvent.kt | 8 +- .../BasicInformationClusterLeaveEvent.kt | 10 +- ...InformationClusterReachableChangedEvent.kt | 10 +- .../BasicInformationClusterStartUpEvent.kt | 10 +- .../BooleanStateClusterStateChangeEvent.kt | 10 +- ...igurationClusterAlarmsStateChangedEvent.kt | 21 +- ...ateConfigurationClusterSensorFaultEvent.kt | 13 +- ...sicInformationClusterActiveChangedEvent.kt | 16 +- ...InformationClusterReachableChangedEvent.kt | 13 +- ...viceBasicInformationClusterStartUpEvent.kt | 13 +- ...lClusterCommissioningRequestResultEvent.kt | 18 +- ...lusterLoadControlEventStatusChangeEvent.kt | 214 +- ...rgyManagementClusterPowerAdjustEndEvent.kt | 11 +- ...viceEnergyManagementClusterResumedEvent.kt | 10 +- .../DishwasherAlarmClusterNotifyEvent.kt | 8 +- .../DoorLockClusterDoorLockAlarmEvent.kt | 10 +- .../DoorLockClusterDoorStateChangeEvent.kt | 10 +- .../DoorLockClusterLockOperationErrorEvent.kt | 108 +- .../DoorLockClusterLockOperationEvent.kt | 107 +- .../DoorLockClusterLockUserChangeEvent.kt | 70 +- ...entClusterCumulativeEnergyMeasuredEvent.kt | 53 +- ...ementClusterPeriodicEnergyMeasuredEvent.kt | 53 +- ...mentClusterMeasurementPeriodRangesEvent.kt | 30 +- .../EnergyEvseClusterEVConnectedEvent.kt | 10 +- .../EnergyEvseClusterEVNotDetectedEvent.kt | 26 +- ...gyEvseClusterEnergyTransferStartedEvent.kt | 25 +- ...gyEvseClusterEnergyTransferStoppedEvent.kt | 26 +- .../EnergyEvseClusterFaultEvent.kt | 34 +- .../EnergyEvseClusterRFIDEvent.kt | 10 +- ...eneralDiagnosticsClusterBootReasonEvent.kt | 10 +- ...gnosticsClusterHardwareFaultChangeEvent.kt | 36 +- ...agnosticsClusterNetworkFaultChangeEvent.kt | 36 +- ...DiagnosticsClusterRadioFaultChangeEvent.kt | 33 +- .../MediaPlaybackClusterStateChangedEvent.kt | 36 +- .../MessagesClusterMessageCompleteEvent.kt | 81 +- .../MessagesClusterMessagePresentedEvent.kt | 10 +- .../MessagesClusterMessageQueuedEvent.kt | 10 +- ...nalStateClusterOperationCompletionEvent.kt | 70 +- ...tionalStateClusterOperationalErrorEvent.kt | 12 +- ...pdateRequestorClusterDownloadErrorEvent.kt | 44 +- ...ateRequestorClusterStateTransitionEvent.kt | 31 +- ...dateRequestorClusterVersionAppliedEvent.kt | 11 +- ...nalStateClusterOperationCompletionEvent.kt | 70 +- ...tionalStateClusterOperationalErrorEvent.kt | 18 +- ...rSourceClusterBatChargeFaultChangeEvent.kt | 33 +- .../PowerSourceClusterBatFaultChangeEvent.kt | 36 +- ...PowerSourceClusterWiredFaultChangeEvent.kt | 36 +- .../RefrigeratorAlarmClusterNotifyEvent.kt | 8 +- ...nalStateClusterOperationCompletionEvent.kt | 70 +- ...tionalStateClusterOperationalErrorEvent.kt | 15 +- .../SampleMeiClusterPingCountEventEvent.kt | 11 +- .../SmokeCoAlarmClusterCOAlarmEvent.kt | 10 +- ...eCoAlarmClusterInterconnectCOAlarmEvent.kt | 10 +- ...AlarmClusterInterconnectSmokeAlarmEvent.kt | 10 +- .../SmokeCoAlarmClusterLowBatteryEvent.kt | 10 +- .../SmokeCoAlarmClusterSmokeAlarmEvent.kt | 10 +- ...areDiagnosticsClusterSoftwareFaultEvent.kt | 29 +- .../SwitchClusterInitialPressEvent.kt | 10 +- .../SwitchClusterLongPressEvent.kt | 10 +- .../SwitchClusterLongReleaseEvent.kt | 10 +- .../SwitchClusterMultiPressCompleteEvent.kt | 11 +- .../SwitchClusterMultiPressOngoingEvent.kt | 11 +- .../SwitchClusterShortReleaseEvent.kt | 10 +- .../SwitchClusterSwitchLatchedEvent.kt | 10 +- ...argetNavigatorClusterTargetUpdatedEvent.kt | 25 +- ...DiagnosticsClusterConnectionStatusEvent.kt | 13 +- ...agnosticsClusterNetworkFaultChangeEvent.kt | 36 +- ...imeSynchronizationClusterDSTStatusEvent.kt | 10 +- ...nchronizationClusterTimeZoneStatusEvent.kt | 21 +- ...ClusterTestDifferentVendorMeiEventEvent.kt | 13 +- .../UnitTestingClusterTestEventEvent.kt | 44 +- ...estingClusterTestFabricScopedEventEvent.kt | 10 +- ...urationAndControlClusterValveFaultEvent.kt | 13 +- ...AndControlClusterValveStateChangedEvent.kt | 21 +- ...eaterManagementClusterBoostStartedEvent.kt | 13 +- ...agnosticsClusterAssociationFailureEvent.kt | 14 +- ...DiagnosticsClusterConnectionStatusEvent.kt | 13 +- ...orkDiagnosticsClusterDisconnectionEvent.kt | 13 +- ...sControlClusterAccessControlEntryStruct.kt | 79 +- ...trolClusterAccessControlExtensionStruct.kt | 11 +- ...ControlClusterAccessControlTargetStruct.kt | 45 +- ...trolClusterAccessRestrictionEntryStruct.kt | 32 +- ...ssControlClusterAccessRestrictionStruct.kt | 22 +- ...mmissioningAccessRestrictionEntryStruct.kt | 31 +- .../structs/ActionsClusterActionStruct.kt | 15 +- .../ActionsClusterEndpointListStruct.kt | 20 +- ...nitoringClusterReplacementProductStruct.kt | 22 +- ...pplicationBasicClusterApplicationStruct.kt | 6 +- ...ationLauncherClusterApplicationEPStruct.kt | 22 +- ...icationLauncherClusterApplicationStruct.kt | 6 +- .../AudioOutputClusterOutputInfoStruct.kt | 6 +- ...nformationClusterCapabilityMinimaStruct.kt | 17 +- ...formationClusterProductAppearanceStruct.kt | 22 +- .../structs/BindingClusterTargetStruct.kt | 49 +- ...formationClusterProductAppearanceStruct.kt | 24 +- .../ChannelClusterAdditionalInfoStruct.kt | 9 +- .../ChannelClusterChannelInfoStruct.kt | 70 +- .../ChannelClusterChannelPagingStruct.kt | 66 +- .../structs/ChannelClusterLineupInfoStruct.kt | 27 +- .../structs/ChannelClusterPageTokenStruct.kt | 38 +- .../ChannelClusterProgramCastStruct.kt | 9 +- .../ChannelClusterProgramCategoryStruct.kt | 19 +- .../structs/ChannelClusterProgramStruct.kt | 311 +- .../structs/ChannelClusterSeriesInfoStruct.kt | 9 +- .../ContentControlClusterRatingNameStruct.kt | 16 +- ...tentLauncherClusterAdditionalInfoStruct.kt | 9 +- ...auncherClusterBrandingInformationStruct.kt | 99 +- ...ntentLauncherClusterContentSearchStruct.kt | 18 +- .../ContentLauncherClusterDimensionStruct.kt | 6 +- .../ContentLauncherClusterParameterStruct.kt | 37 +- ...auncherClusterPlaybackPreferencesStruct.kt | 54 +- ...ntLauncherClusterStyleInformationStruct.kt | 40 +- ...entLauncherClusterTrackPreferenceStruct.kt | 43 +- ...dControlClusterAverageLoadControlStruct.kt | 13 +- ...oadControlClusterDutyCycleControlStruct.kt | 13 +- ...ontrolClusterHeatingSourceControlStruct.kt | 13 +- ...oadControlClusterLoadControlEventStruct.kt | 77 +- ...ClusterLoadControlEventTransitionStruct.kt | 100 +- ...dControlClusterLoadControlProgramStruct.kt | 58 +- ...ControlClusterPowerSavingsControlStruct.kt | 13 +- ...dControlClusterTemperatureControlStruct.kt | 125 +- .../DescriptorClusterDeviceTypeStruct.kt | 9 +- .../DescriptorClusterSemanticTagStruct.kt | 45 +- ...nergyManagementClusterConstraintsStruct.kt | 46 +- ...DeviceEnergyManagementClusterCostStruct.kt | 16 +- ...ceEnergyManagementClusterForecastStruct.kt | 82 +- ...ementClusterPowerAdjustCapabilityStruct.kt | 43 +- ...nergyManagementClusterPowerAdjustStruct.kt | 13 +- ...gyManagementClusterSlotAdjustmentStruct.kt | 21 +- ...DeviceEnergyManagementClusterSlotStruct.kt | 190 +- ...gyManagementModeClusterModeOptionStruct.kt | 25 +- ...nergyManagementModeClusterModeTagStruct.kt | 16 +- .../DishwasherModeClusterModeOptionStruct.kt | 20 +- .../DishwasherModeClusterModeTagStruct.kt | 19 +- .../DoorLockClusterCredentialStruct.kt | 9 +- ...ystemInformationClusterDeviceTypeStruct.kt | 9 +- ...InformationClusterEcosystemDeviceStruct.kt | 75 +- ...formationClusterEcosystemLocationStruct.kt | 27 +- ...ormationClusterLocationDescriptorStruct.kt | 43 +- ...ementClusterCumulativeEnergyResetStruct.kt | 125 +- ...asurementClusterEnergyMeasurementStruct.kt | 62 +- ...ntClusterMeasurementAccuracyRangeStruct.kt | 87 +- ...urementClusterMeasurementAccuracyStruct.kt | 38 +- ...urementClusterHarmonicMeasurementStruct.kt | 24 +- ...ntClusterMeasurementAccuracyRangeStruct.kt | 87 +- ...urementClusterMeasurementAccuracyStruct.kt | 38 +- ...easurementClusterMeasurementRangeStruct.kt | 112 +- ...EvseClusterChargingTargetScheduleStruct.kt | 23 +- .../EnergyEvseClusterChargingTargetStruct.kt | 36 +- .../EnergyEvseModeClusterModeOptionStruct.kt | 20 +- .../EnergyEvseModeClusterModeTagStruct.kt | 19 +- .../EnergyPreferenceClusterBalanceStruct.kt | 19 +- .../structs/FixedLabelClusterLabelStruct.kt | 9 +- ...missioningClusterBasicCommissioningInfo.kt | 22 +- ...neralDiagnosticsClusterNetworkInterface.kt | 82 +- ...pKeyManagementClusterGroupInfoMapStruct.kt | 30 +- ...upKeyManagementClusterGroupKeyMapStruct.kt | 6 +- ...upKeyManagementClusterGroupKeySetStruct.kt | 98 +- ...nitoringClusterReplacementProductStruct.kt | 22 +- ...mentClusterMonitoringRegistrationStruct.kt | 18 +- ...aundryWasherModeClusterModeOptionStruct.kt | 20 +- .../LaundryWasherModeClusterModeTagStruct.kt | 19 +- .../MediaInputClusterInputInfoStruct.kt | 6 +- ...iaPlaybackClusterPlaybackPositionStruct.kt | 22 +- ...diaPlaybackClusterTrackAttributesStruct.kt | 32 +- .../MediaPlaybackClusterTrackStruct.kt | 22 +- ...sagesClusterMessageResponseOptionStruct.kt | 27 +- .../structs/MessagesClusterMessageStruct.kt | 73 +- ...icrowaveOvenModeClusterModeOptionStruct.kt | 20 +- .../MicrowaveOvenModeClusterModeTagStruct.kt | 19 +- .../ModeSelectClusterModeOptionStruct.kt | 20 +- .../ModeSelectClusterSemanticTagStruct.kt | 9 +- ...rkCommissioningClusterNetworkInfoStruct.kt | 66 +- ...gClusterThreadInterfaceScanResultStruct.kt | 22 +- ...ingClusterWiFiInterfaceScanResultStruct.kt | 20 +- ...pancySensingClusterHoldTimeLimitsStruct.kt | 6 +- ...redentialsClusterFabricDescriptorStruct.kt | 20 +- .../OperationalCredentialsClusterNOCStruct.kt | 19 +- ...OperationalStateClusterErrorStateStruct.kt | 33 +- ...ionalStateClusterOperationalStateStruct.kt | 21 +- ...eUpdateRequestorClusterProviderLocation.kt | 17 +- ...OperationalStateClusterErrorStateStruct.kt | 38 +- ...ionalStateClusterOperationalStateStruct.kt | 26 +- .../OvenModeClusterModeOptionStruct.kt | 20 +- .../structs/OvenModeClusterModeTagStruct.kt | 19 +- ...erSourceClusterBatChargeFaultChangeType.kt | 35 +- .../PowerSourceClusterBatFaultChangeType.kt | 38 +- .../PowerSourceClusterWiredFaultChangeType.kt | 38 +- ...olledCabinetModeClusterModeOptionStruct.kt | 36 +- ...ntrolledCabinetModeClusterModeTagStruct.kt | 21 +- .../RvcCleanModeClusterModeOptionStruct.kt | 20 +- .../RvcCleanModeClusterModeTagStruct.kt | 19 +- ...OperationalStateClusterErrorStateStruct.kt | 33 +- ...ionalStateClusterOperationalStateStruct.kt | 26 +- .../RvcRunModeClusterModeOptionStruct.kt | 20 +- .../structs/RvcRunModeClusterModeTagStruct.kt | 19 +- ...nagementClusterAttributeValuePairStruct.kt | 110 +- ...cenesManagementClusterExtensionFieldSet.kt | 20 +- .../ScenesManagementClusterSceneInfoStruct.kt | 15 +- .../ServiceAreaClusterAreaInfoStruct.kt | 38 +- .../structs/ServiceAreaClusterAreaStruct.kt | 22 +- .../ServiceAreaClusterLandmarkInfoStruct.kt | 22 +- ...viceAreaClusterLocationDescriptorStruct.kt | 32 +- .../structs/ServiceAreaClusterMapStruct.kt | 9 +- .../ServiceAreaClusterProgressStruct.kt | 59 +- ...reDiagnosticsClusterThreadMetricsStruct.kt | 57 +- .../TargetNavigatorClusterTargetInfoStruct.kt | 9 +- ...ostatClusterAtomicAttributeStatusStruct.kt | 9 +- .../structs/ThermostatClusterPresetStruct.kt | 89 +- .../ThermostatClusterPresetTypeStruct.kt | 6 +- .../ThermostatClusterScheduleStruct.kt | 76 +- ...ermostatClusterScheduleTransitionStruct.kt | 58 +- .../ThermostatClusterScheduleTypeStruct.kt | 12 +- ...atClusterWeeklyScheduleTransitionStruct.kt | 43 +- ...rkDiagnosticsClusterNeighborTableStruct.kt | 54 +- ...ticsClusterOperationalDatasetComponents.kt | 41 +- ...tworkDiagnosticsClusterRouteTableStruct.kt | 24 +- ...NetworkDiagnosticsClusterSecurityPolicy.kt | 9 +- ...workDirectoryClusterThreadNetworkStruct.kt | 18 +- ...meSynchronizationClusterDSTOffsetStruct.kt | 19 +- ...sterFabricScopedTrustedTimeSourceStruct.kt | 11 +- ...imeSynchronizationClusterTimeZoneStruct.kt | 16 +- ...onizationClusterTrustedTimeSourceStruct.kt | 11 +- ...nitTestingClusterDoubleNestedStructList.kt | 22 +- .../structs/UnitTestingClusterNestedStruct.kt | 18 +- .../UnitTestingClusterNestedStructList.kt | 65 +- ...stingClusterNullablesAndOptionalsStruct.kt | 297 +- .../structs/UnitTestingClusterSimpleStruct.kt | 16 +- .../UnitTestingClusterTestFabricScoped.kt | 102 +- .../UnitTestingClusterTestGlobalStruct.kt | 45 +- .../UnitTestingClusterTestListStructOctet.kt | 9 +- .../structs/UserLabelClusterLabelStruct.kt | 9 +- ...gementClusterWaterHeaterBoostInfoStruct.kt | 74 +- .../WaterHeaterModeClusterModeOptionStruct.kt | 20 +- .../WaterHeaterModeClusterModeTagStruct.kt | 19 +- 367 files changed, 128546 insertions(+), 116172 deletions(-) diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/AccessControlCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/AccessControlCluster.kt index 099162a899b419..a3ee5ef67646cf 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/AccessControlCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/AccessControlCluster.kt @@ -17,126 +17,155 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.UIntSubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState +import matter.controller.UByteSubscriptionState import matter.controller.UShortSubscriptionState +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.cluster.structs.* +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class AccessControlCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class AclAttribute(val value: List) +class AccessControlCluster(private val controller: MatterController, private val endpointId: UShort) {class AclAttribute( + val value: List + ) sealed class AclAttributeSubscriptionState { - data class Success(val value: List) : - AclAttributeSubscriptionState() - + data class Success( + val value: List + ) : AclAttributeSubscriptionState() + data class Error(val exception: Exception) : AclAttributeSubscriptionState() - object SubscriptionEstablished : AclAttributeSubscriptionState() - } - - class ExtensionAttribute(val value: List?) + object SubscriptionEstablished : AclAttributeSubscriptionState() + } +class ExtensionAttribute( + val value: List? + ) sealed class ExtensionAttributeSubscriptionState { - data class Success(val value: List?) : - ExtensionAttributeSubscriptionState() - + data class Success( + val value: List? + ) : ExtensionAttributeSubscriptionState() + data class Error(val exception: Exception) : ExtensionAttributeSubscriptionState() - object SubscriptionEstablished : ExtensionAttributeSubscriptionState() - } - - class CommissioningARLAttribute( + object SubscriptionEstablished : ExtensionAttributeSubscriptionState() + } +class CommissioningARLAttribute( val value: List? ) sealed class CommissioningARLAttributeSubscriptionState { data class Success( - val value: List? + val value: List? ) : CommissioningARLAttributeSubscriptionState() - + data class Error(val exception: Exception) : CommissioningARLAttributeSubscriptionState() - object SubscriptionEstablished : CommissioningARLAttributeSubscriptionState() - } - - class ArlAttribute(val value: List?) + object SubscriptionEstablished : CommissioningARLAttributeSubscriptionState() + } +class ArlAttribute( + val value: List? + ) sealed class ArlAttributeSubscriptionState { - data class Success(val value: List?) : - ArlAttributeSubscriptionState() - + data class Success( + val value: List? + ) : ArlAttributeSubscriptionState() + data class Error(val exception: Exception) : ArlAttributeSubscriptionState() - object SubscriptionEstablished : ArlAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : ArlAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun reviewFabricRestrictions( - arl: List, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun reviewFabricRestrictions(arl: List + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() @@ -144,85 +173,92 @@ class AccessControlCluster( val TAG_ARL_REQ: Int = 0 tlvWriter.startArray(ContextSpecificTag(TAG_ARL_REQ)) - for (item in arl.iterator()) { - item.toTlv(AnonymousTag, tlvWriter) - } - tlvWriter.endArray() + for (item in arl.iterator()) { + item.toTlv(AnonymousTag, tlvWriter) + } + tlvWriter.endArray() tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - - suspend fun readAclAttribute(): AclAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readAclAttribute(): AclAttribute {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}") - } + 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) { "Acl attribute not found in response" } + } + + requireNotNull(attributeData) { + "Acl 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(AccessControlClusterAccessControlEntryStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(AccessControlClusterAccessControlEntryStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + return AclAttribute(decodedValue) } suspend fun writeAclAttribute( value: List, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startArray(AnonymousTag) - for (item in value.iterator()) { - item.toTlv(AnonymousTag, tlvWriter) - } - tlvWriter.endArray() + for (item in value.iterator()) { + item.toTlv(AnonymousTag, tlvWriter) + } + tlvWriter.endArray() val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -243,56 +279,53 @@ class AccessControlCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeAclAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - AclAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(AclAttributeSubscriptionState.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) { "Acl attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Acl 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(AccessControlClusterAccessControlEntryStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(AccessControlClusterAccessControlEntryStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(AclAttributeSubscriptionState.Success(decodedValue)) } @@ -300,75 +333,82 @@ class AccessControlCluster( emit(AclAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readExtensionAttribute(): ExtensionAttribute { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readExtensionAttribute(): ExtensionAttribute {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}") - } + 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) { "Extension attribute not found in response" } + } + + requireNotNull(attributeData) { + "Extension attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(AccessControlClusterAccessControlExtensionStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(AccessControlClusterAccessControlExtensionStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + } else { + null + } + return ExtensionAttribute(decodedValue) } suspend fun writeExtensionAttribute( value: List, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 1u val tlvWriter = TlvWriter() tlvWriter.startArray(AnonymousTag) - for (item in value.iterator()) { - item.toTlv(AnonymousTag, tlvWriter) - } - tlvWriter.endArray() + for (item in value.iterator()) { + item.toTlv(AnonymousTag, tlvWriter) + } + tlvWriter.endArray() val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -389,145 +429,141 @@ class AccessControlCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeExtensionAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ExtensionAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ExtensionAttributeSubscriptionState.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) { "Extension attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Extension attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add( - AccessControlClusterAccessControlExtensionStruct.fromTlv( - AnonymousTag, - tlvReader, - ) - ) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { emit(ExtensionAttributeSubscriptionState.Success(it)) } + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(AccessControlClusterAccessControlExtensionStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { + emit(ExtensionAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ExtensionAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readSubjectsPerAccessControlEntryAttribute(): 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)) - +suspend fun readSubjectsPerAccessControlEntryAttribute(): 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}") - } + 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) { - "Subjectsperaccesscontrolentry attribute not found in response" + } + + requireNotNull(attributeData) { + "Subjectsperaccesscontrolentry 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 subscribeSubjectsPerAccessControlEntryAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Subjectsperaccesscontrolentry attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Subjectsperaccesscontrolentry attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -540,77 +576,80 @@ class AccessControlCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readTargetsPerAccessControlEntryAttribute(): UShort { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readTargetsPerAccessControlEntryAttribute(): UShort {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}") - } + 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) { "Targetsperaccesscontrolentry attribute not found in response" } + } + + requireNotNull(attributeData) { + "Targetsperaccesscontrolentry 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 subscribeTargetsPerAccessControlEntryAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Targetsperaccesscontrolentry attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Targetsperaccesscontrolentry attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -623,79 +662,80 @@ class AccessControlCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readAccessControlEntriesPerFabricAttribute(): UShort { - val ATTRIBUTE_ID: UInt = 4u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readAccessControlEntriesPerFabricAttribute(): UShort {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}") - } + 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) { - "Accesscontrolentriesperfabric attribute not found in response" + } + + requireNotNull(attributeData) { + "Accesscontrolentriesperfabric 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 subscribeAccessControlEntriesPerFabricAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Accesscontrolentriesperfabric attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Accesscontrolentriesperfabric attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -708,319 +748,315 @@ class AccessControlCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readCommissioningARLAttribute(): CommissioningARLAttribute { - val ATTRIBUTE_ID: UInt = 5u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readCommissioningARLAttribute(): CommissioningARLAttribute {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}") - } + 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) { "Commissioningarl attribute not found in response" } + } + + requireNotNull(attributeData) { + "Commissioningarl attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add( - AccessControlClusterCommissioningAccessRestrictionEntryStruct.fromTlv( - AnonymousTag, - tlvReader, - ) - ) - } - tlvReader.exitContainer() - } - } else { - null + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(AccessControlClusterCommissioningAccessRestrictionEntryStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + } else { + null + } + return CommissioningARLAttribute(decodedValue) } suspend fun subscribeCommissioningARLAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - CommissioningARLAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(CommissioningARLAttributeSubscriptionState.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) { - "Commissioningarl attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Commissioningarl attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add( - AccessControlClusterCommissioningAccessRestrictionEntryStruct.fromTlv( - AnonymousTag, - tlvReader, - ) - ) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { emit(CommissioningARLAttributeSubscriptionState.Success(it)) } + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(AccessControlClusterCommissioningAccessRestrictionEntryStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { + emit(CommissioningARLAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(CommissioningARLAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readArlAttribute(): ArlAttribute { - val ATTRIBUTE_ID: UInt = 6u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readArlAttribute(): ArlAttribute {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}") - } + 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) { "Arl attribute not found in response" } + } + + requireNotNull(attributeData) { + "Arl attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(AccessControlClusterAccessRestrictionEntryStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(AccessControlClusterAccessRestrictionEntryStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + } else { + null + } + return ArlAttribute(decodedValue) } suspend fun subscribeArlAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ArlAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ArlAttributeSubscriptionState.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) { "Arl attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Arl attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add( - AccessControlClusterAccessRestrictionEntryStruct.fromTlv( - AnonymousTag, - tlvReader, - ) - ) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { emit(ArlAttributeSubscriptionState.Success(it)) } + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(AccessControlClusterAccessRestrictionEntryStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { + emit(ArlAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ArlAttributeSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1028,96 +1064,97 @@ class AccessControlCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1125,94 +1162,97 @@ class AccessControlCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1220,94 +1260,97 @@ class AccessControlCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1315,76 +1358,81 @@ class AccessControlCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1396,77 +1444,80 @@ class AccessControlCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1479,7 +1530,7 @@ class AccessControlCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/AccountLoginCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/AccountLoginCluster.kt index 3357ffff9b5b1a..d8f104bfd40c06 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/AccountLoginCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/AccountLoginCluster.kt @@ -17,92 +17,121 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.UIntSubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState +import matter.controller.UByteSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class AccountLoginCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class GetSetupPINResponse(val setupPIN: String) - - class GeneratedCommandListAttribute(val value: List) +class AccountLoginCluster(private val controller: MatterController, private val endpointId: UShort) { + class GetSetupPINResponse( + val setupPIN: String + ) +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun getSetupPIN( - tempAccountIdentifier: String, - timedInvokeTimeout: Duration, - ): GetSetupPINResponse { + suspend fun getSetupPIN(tempAccountIdentifier: String + ,timedInvokeTimeout: Duration): GetSetupPINResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_TEMP_ACCOUNT_IDENTIFIER_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_TEMP_ACCOUNT_IDENTIFIER_REQ), tempAccountIdentifier) + tlvWriter.put(ContextSpecificTag(TAG_TEMP_ACCOUNT_IDENTIFIER_REQ), tempAccountIdentifier) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -112,32 +141,38 @@ class AccountLoginCluster( tlvReader.enterStructure(AnonymousTag) val TAG_SETUP_PIN: Int = 0 var setupPIN_decoded: String? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_SETUP_PIN)) { - setupPIN_decoded = tlvReader.getString(tag) - } else { + + if (tag == ContextSpecificTag(TAG_SETUP_PIN)) {setupPIN_decoded = tlvReader.getString(tag)} + + + else { tlvReader.skipElement() } } + + if (setupPIN_decoded == null) { - throw IllegalStateException("setupPIN not found in TLV") + throw IllegalStateException("setupPIN not found in TLV") } + tlvReader.exitContainer() - return GetSetupPINResponse(setupPIN_decoded) + return GetSetupPINResponse( + setupPIN_decoded + ) } - suspend fun login( - tempAccountIdentifier: String, - setupPIN: String, - node: ULong?, - timedInvokeTimeout: Duration, - ) { + suspend fun login(tempAccountIdentifier: String + ,setupPIN: String + ,node: ULong? + ,timedInvokeTimeout: Duration) { val commandId: UInt = 2u val tlvWriter = TlvWriter() @@ -150,128 +185,134 @@ class AccountLoginCluster( tlvWriter.put(ContextSpecificTag(TAG_SETUP_PIN_REQ), setupPIN) val TAG_NODE_REQ: Int = 2 - node?.let { tlvWriter.put(ContextSpecificTag(TAG_NODE_REQ), node) } + node?.let { + tlvWriter.put(ContextSpecificTag(TAG_NODE_REQ), node) + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun logout(node: ULong?, timedInvokeTimeout: Duration) { + suspend fun logout(node: ULong? + ,timedInvokeTimeout: Duration) { val commandId: UInt = 3u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_NODE_REQ: Int = 0 - node?.let { tlvWriter.put(ContextSpecificTag(TAG_NODE_REQ), node) } + node?.let { + tlvWriter.put(ContextSpecificTag(TAG_NODE_REQ), node) + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - - 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -279,96 +320,97 @@ class AccountLoginCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -376,94 +418,97 @@ class AccountLoginCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -471,94 +516,97 @@ class AccountLoginCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -566,76 +614,81 @@ class AccountLoginCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -647,77 +700,80 @@ class AccountLoginCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -730,7 +786,7 @@ class AccountLoginCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/ActionsCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/ActionsCluster.kt index 79245c8dc8657b..f3f845d1368c16 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/ActionsCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/ActionsCluster.kt @@ -17,97 +17,130 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest -import matter.controller.StringSubscriptionState +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.UIntSubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState +import matter.controller.UByteSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class ActionsCluster(private val controller: MatterController, private val endpointId: UShort) { - class ActionListAttribute(val value: List) +class ActionsCluster(private val controller: MatterController, private val endpointId: UShort) {class ActionListAttribute( + val value: List + ) sealed class ActionListAttributeSubscriptionState { - data class Success(val value: List) : - ActionListAttributeSubscriptionState() - + data class Success( + val value: List + ) : ActionListAttributeSubscriptionState() + data class Error(val exception: Exception) : ActionListAttributeSubscriptionState() - object SubscriptionEstablished : ActionListAttributeSubscriptionState() - } - - class EndpointListsAttribute(val value: List) + object SubscriptionEstablished : ActionListAttributeSubscriptionState() + } +class EndpointListsAttribute( + val value: List + ) sealed class EndpointListsAttributeSubscriptionState { - data class Success(val value: List) : - EndpointListsAttributeSubscriptionState() - + data class Success( + val value: List + ) : EndpointListsAttributeSubscriptionState() + data class Error(val exception: Exception) : EndpointListsAttributeSubscriptionState() - object SubscriptionEstablished : EndpointListsAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : EndpointListsAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun instantAction( - actionID: UShort, - invokeID: UInt?, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun instantAction(actionID: UShort + ,invokeID: UInt? + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() @@ -117,26 +150,26 @@ class ActionsCluster(private val controller: MatterController, private val endpo tlvWriter.put(ContextSpecificTag(TAG_ACTION_ID_REQ), actionID) val TAG_INVOKE_ID_REQ: Int = 1 - invokeID?.let { tlvWriter.put(ContextSpecificTag(TAG_INVOKE_ID_REQ), invokeID) } + invokeID?.let { + tlvWriter.put(ContextSpecificTag(TAG_INVOKE_ID_REQ), invokeID) + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun instantActionWithTransition( - actionID: UShort, - invokeID: UInt?, - transitionTime: UShort, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun instantActionWithTransition(actionID: UShort + ,invokeID: UInt? + ,transitionTime: UShort + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 1u val tlvWriter = TlvWriter() @@ -146,24 +179,28 @@ class ActionsCluster(private val controller: MatterController, private val endpo tlvWriter.put(ContextSpecificTag(TAG_ACTION_ID_REQ), actionID) val TAG_INVOKE_ID_REQ: Int = 1 - invokeID?.let { tlvWriter.put(ContextSpecificTag(TAG_INVOKE_ID_REQ), invokeID) } + invokeID?.let { + tlvWriter.put(ContextSpecificTag(TAG_INVOKE_ID_REQ), invokeID) + } val TAG_TRANSITION_TIME_REQ: Int = 2 - tlvWriter.put(ContextSpecificTag(TAG_TRANSITION_TIME_REQ), transitionTime) + 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, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun startAction(actionID: UShort, invokeID: UInt?, timedInvokeTimeout: Duration? = null) { + suspend fun startAction(actionID: UShort + ,invokeID: UInt? + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 2u val tlvWriter = TlvWriter() @@ -173,26 +210,26 @@ class ActionsCluster(private val controller: MatterController, private val endpo tlvWriter.put(ContextSpecificTag(TAG_ACTION_ID_REQ), actionID) val TAG_INVOKE_ID_REQ: Int = 1 - invokeID?.let { tlvWriter.put(ContextSpecificTag(TAG_INVOKE_ID_REQ), invokeID) } + invokeID?.let { + tlvWriter.put(ContextSpecificTag(TAG_INVOKE_ID_REQ), invokeID) + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun startActionWithDuration( - actionID: UShort, - invokeID: UInt?, - duration: UInt, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun startActionWithDuration(actionID: UShort + ,invokeID: UInt? + ,duration: UInt + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 3u val tlvWriter = TlvWriter() @@ -202,24 +239,28 @@ class ActionsCluster(private val controller: MatterController, private val endpo tlvWriter.put(ContextSpecificTag(TAG_ACTION_ID_REQ), actionID) val TAG_INVOKE_ID_REQ: Int = 1 - invokeID?.let { tlvWriter.put(ContextSpecificTag(TAG_INVOKE_ID_REQ), invokeID) } + invokeID?.let { + tlvWriter.put(ContextSpecificTag(TAG_INVOKE_ID_REQ), invokeID) + } val TAG_DURATION_REQ: Int = 2 - tlvWriter.put(ContextSpecificTag(TAG_DURATION_REQ), duration) + tlvWriter.put(ContextSpecificTag(TAG_DURATION_REQ), duration) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun stopAction(actionID: UShort, invokeID: UInt?, timedInvokeTimeout: Duration? = null) { + suspend fun stopAction(actionID: UShort + ,invokeID: UInt? + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 4u val tlvWriter = TlvWriter() @@ -229,21 +270,25 @@ class ActionsCluster(private val controller: MatterController, private val endpo tlvWriter.put(ContextSpecificTag(TAG_ACTION_ID_REQ), actionID) val TAG_INVOKE_ID_REQ: Int = 1 - invokeID?.let { tlvWriter.put(ContextSpecificTag(TAG_INVOKE_ID_REQ), invokeID) } + invokeID?.let { + tlvWriter.put(ContextSpecificTag(TAG_INVOKE_ID_REQ), invokeID) + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun pauseAction(actionID: UShort, invokeID: UInt?, timedInvokeTimeout: Duration? = null) { + suspend fun pauseAction(actionID: UShort + ,invokeID: UInt? + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 5u val tlvWriter = TlvWriter() @@ -253,26 +298,26 @@ class ActionsCluster(private val controller: MatterController, private val endpo tlvWriter.put(ContextSpecificTag(TAG_ACTION_ID_REQ), actionID) val TAG_INVOKE_ID_REQ: Int = 1 - invokeID?.let { tlvWriter.put(ContextSpecificTag(TAG_INVOKE_ID_REQ), invokeID) } + invokeID?.let { + tlvWriter.put(ContextSpecificTag(TAG_INVOKE_ID_REQ), invokeID) + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun pauseActionWithDuration( - actionID: UShort, - invokeID: UInt?, - duration: UInt, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun pauseActionWithDuration(actionID: UShort + ,invokeID: UInt? + ,duration: UInt + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 6u val tlvWriter = TlvWriter() @@ -282,28 +327,28 @@ class ActionsCluster(private val controller: MatterController, private val endpo tlvWriter.put(ContextSpecificTag(TAG_ACTION_ID_REQ), actionID) val TAG_INVOKE_ID_REQ: Int = 1 - invokeID?.let { tlvWriter.put(ContextSpecificTag(TAG_INVOKE_ID_REQ), invokeID) } + invokeID?.let { + tlvWriter.put(ContextSpecificTag(TAG_INVOKE_ID_REQ), invokeID) + } val TAG_DURATION_REQ: Int = 2 - tlvWriter.put(ContextSpecificTag(TAG_DURATION_REQ), duration) + tlvWriter.put(ContextSpecificTag(TAG_DURATION_REQ), duration) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun resumeAction( - actionID: UShort, - invokeID: UInt?, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun resumeAction(actionID: UShort + ,invokeID: UInt? + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 7u val tlvWriter = TlvWriter() @@ -313,25 +358,25 @@ class ActionsCluster(private val controller: MatterController, private val endpo tlvWriter.put(ContextSpecificTag(TAG_ACTION_ID_REQ), actionID) val TAG_INVOKE_ID_REQ: Int = 1 - invokeID?.let { tlvWriter.put(ContextSpecificTag(TAG_INVOKE_ID_REQ), invokeID) } + invokeID?.let { + tlvWriter.put(ContextSpecificTag(TAG_INVOKE_ID_REQ), invokeID) + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun enableAction( - actionID: UShort, - invokeID: UInt?, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun enableAction(actionID: UShort + ,invokeID: UInt? + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 8u val tlvWriter = TlvWriter() @@ -341,26 +386,26 @@ class ActionsCluster(private val controller: MatterController, private val endpo tlvWriter.put(ContextSpecificTag(TAG_ACTION_ID_REQ), actionID) val TAG_INVOKE_ID_REQ: Int = 1 - invokeID?.let { tlvWriter.put(ContextSpecificTag(TAG_INVOKE_ID_REQ), invokeID) } + invokeID?.let { + tlvWriter.put(ContextSpecificTag(TAG_INVOKE_ID_REQ), invokeID) + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun enableActionWithDuration( - actionID: UShort, - invokeID: UInt?, - duration: UInt, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun enableActionWithDuration(actionID: UShort + ,invokeID: UInt? + ,duration: UInt + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 9u val tlvWriter = TlvWriter() @@ -370,28 +415,28 @@ class ActionsCluster(private val controller: MatterController, private val endpo tlvWriter.put(ContextSpecificTag(TAG_ACTION_ID_REQ), actionID) val TAG_INVOKE_ID_REQ: Int = 1 - invokeID?.let { tlvWriter.put(ContextSpecificTag(TAG_INVOKE_ID_REQ), invokeID) } + invokeID?.let { + tlvWriter.put(ContextSpecificTag(TAG_INVOKE_ID_REQ), invokeID) + } val TAG_DURATION_REQ: Int = 2 - tlvWriter.put(ContextSpecificTag(TAG_DURATION_REQ), duration) + tlvWriter.put(ContextSpecificTag(TAG_DURATION_REQ), duration) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun disableAction( - actionID: UShort, - invokeID: UInt?, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun disableAction(actionID: UShort + ,invokeID: UInt? + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 10u val tlvWriter = TlvWriter() @@ -401,26 +446,26 @@ class ActionsCluster(private val controller: MatterController, private val endpo tlvWriter.put(ContextSpecificTag(TAG_ACTION_ID_REQ), actionID) val TAG_INVOKE_ID_REQ: Int = 1 - invokeID?.let { tlvWriter.put(ContextSpecificTag(TAG_INVOKE_ID_REQ), invokeID) } + invokeID?.let { + tlvWriter.put(ContextSpecificTag(TAG_INVOKE_ID_REQ), invokeID) + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun disableActionWithDuration( - actionID: UShort, - invokeID: UInt?, - duration: UInt, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun disableActionWithDuration(actionID: UShort + ,invokeID: UInt? + ,duration: UInt + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 11u val tlvWriter = TlvWriter() @@ -430,108 +475,113 @@ class ActionsCluster(private val controller: MatterController, private val endpo tlvWriter.put(ContextSpecificTag(TAG_ACTION_ID_REQ), actionID) val TAG_INVOKE_ID_REQ: Int = 1 - invokeID?.let { tlvWriter.put(ContextSpecificTag(TAG_INVOKE_ID_REQ), invokeID) } + invokeID?.let { + tlvWriter.put(ContextSpecificTag(TAG_INVOKE_ID_REQ), invokeID) + } val TAG_DURATION_REQ: Int = 2 - tlvWriter.put(ContextSpecificTag(TAG_DURATION_REQ), duration) + tlvWriter.put(ContextSpecificTag(TAG_DURATION_REQ), duration) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - - suspend fun readActionListAttribute(): ActionListAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readActionListAttribute(): ActionListAttribute {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}") - } + 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) { "Actionlist attribute not found in response" } + } + + requireNotNull(attributeData) { + "Actionlist 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(ActionsClusterActionStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(ActionsClusterActionStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + return ActionListAttribute(decodedValue) } suspend fun subscribeActionListAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ActionListAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ActionListAttributeSubscriptionState.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) { "Actionlist attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Actionlist 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(ActionsClusterActionStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(ActionsClusterActionStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(ActionListAttributeSubscriptionState.Success(decodedValue)) } @@ -539,94 +589,97 @@ class ActionsCluster(private val controller: MatterController, private val endpo emit(ActionListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readEndpointListsAttribute(): EndpointListsAttribute { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readEndpointListsAttribute(): EndpointListsAttribute {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}") - } + 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) { "Endpointlists attribute not found in response" } + } + + requireNotNull(attributeData) { + "Endpointlists 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(ActionsClusterEndpointListStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(ActionsClusterEndpointListStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + return EndpointListsAttribute(decodedValue) } suspend fun subscribeEndpointListsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - EndpointListsAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(EndpointListsAttributeSubscriptionState.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) { "Endpointlists attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Endpointlists 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(ActionsClusterEndpointListStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(ActionsClusterEndpointListStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(EndpointListsAttributeSubscriptionState.Success(decodedValue)) } @@ -634,187 +687,194 @@ class ActionsCluster(private val controller: MatterController, private val endpo emit(EndpointListsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readSetupURLAttribute(): String? { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readSetupURLAttribute(): String? {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}") - } + 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) { "Setupurl attribute not found in response" } + } + + requireNotNull(attributeData) { + "Setupurl attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeSetupURLAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StringSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StringSubscriptionState.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) { "Setupurl attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Setupurl attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(StringSubscriptionState.Success(it)) } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(StringSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -822,96 +882,97 @@ class ActionsCluster(private val controller: MatterController, private val endpo 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -919,94 +980,97 @@ class ActionsCluster(private val controller: MatterController, private val endpo 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1014,94 +1078,97 @@ class ActionsCluster(private val controller: MatterController, private val endpo 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1109,76 +1176,81 @@ class ActionsCluster(private val controller: MatterController, private val endpo 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1190,77 +1262,80 @@ class ActionsCluster(private val controller: MatterController, private val endpo 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1273,7 +1348,7 @@ class ActionsCluster(private val controller: MatterController, private val endpo emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/ActivatedCarbonFilterMonitoringCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/ActivatedCarbonFilterMonitoringCluster.kt index 07a7a1191d5881..73fbba68b06ac4 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/ActivatedCarbonFilterMonitoringCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/ActivatedCarbonFilterMonitoringCluster.kt @@ -17,370 +17,410 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration 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.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.cluster.structs.* +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class ActivatedCarbonFilterMonitoringCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class LastChangedTimeAttribute(val value: UInt?) +class ActivatedCarbonFilterMonitoringCluster(private val controller: MatterController, private val endpointId: UShort) {class LastChangedTimeAttribute( + val value: UInt? + ) sealed class LastChangedTimeAttributeSubscriptionState { - data class Success(val value: UInt?) : LastChangedTimeAttributeSubscriptionState() - + data class Success( + val value: UInt? + ) : LastChangedTimeAttributeSubscriptionState() + data class Error(val exception: Exception) : LastChangedTimeAttributeSubscriptionState() - object SubscriptionEstablished : LastChangedTimeAttributeSubscriptionState() - } - - class ReplacementProductListAttribute( + object SubscriptionEstablished : LastChangedTimeAttributeSubscriptionState() + } +class ReplacementProductListAttribute( val value: List? ) sealed class ReplacementProductListAttributeSubscriptionState { data class Success( - val value: List? + val value: List? ) : ReplacementProductListAttributeSubscriptionState() - + data class Error(val exception: Exception) : ReplacementProductListAttributeSubscriptionState() - object SubscriptionEstablished : ReplacementProductListAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : ReplacementProductListAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } suspend fun resetCondition(timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - - suspend fun readConditionAttribute(): 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)) - +suspend fun readConditionAttribute(): 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}") - } + 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) { "Condition attribute not found in response" } + } + + requireNotNull(attributeData) { + "Condition 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeConditionAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Condition attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Condition 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)) } + 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 readDegradationDirectionAttribute(): 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)) - +suspend fun readDegradationDirectionAttribute(): 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}") - } + 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) { "Degradationdirection attribute not found in response" } + } + + requireNotNull(attributeData) { + "Degradationdirection 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeDegradationDirectionAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Degradationdirection attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Degradationdirection 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)) } + 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 readChangeIndicationAttribute(): UByte { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readChangeIndicationAttribute(): UByte {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}") - } + 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) { "Changeindication attribute not found in response" } + } + + requireNotNull(attributeData) { + "Changeindication 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 subscribeChangeIndicationAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Changeindication attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Changeindication attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -393,160 +433,174 @@ class ActivatedCarbonFilterMonitoringCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readInPlaceIndicatorAttribute(): 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)) - +suspend fun readInPlaceIndicatorAttribute(): 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}") - } + 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) { "Inplaceindicator attribute not found in response" } + } + + requireNotNull(attributeData) { + "Inplaceindicator 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 - } + val decodedValue: Boolean? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeInPlaceIndicatorAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Inplaceindicator attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Inplaceindicator 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)) } + 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 readLastChangedTimeAttribute(): LastChangedTimeAttribute { - val ATTRIBUTE_ID: UInt = 4u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readLastChangedTimeAttribute(): LastChangedTimeAttribute {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}") - } + 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) { "Lastchangedtime attribute not found in response" } + } + + requireNotNull(attributeData) { + "Lastchangedtime attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return LastChangedTimeAttribute(decodedValue) } - suspend fun writeLastChangedTimeAttribute(value: UInt, timedWriteTimeout: Duration? = null) { + suspend fun writeLastChangedTimeAttribute( + value: UInt, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 4u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -567,273 +621,266 @@ class ActivatedCarbonFilterMonitoringCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeLastChangedTimeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - LastChangedTimeAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(LastChangedTimeAttributeSubscriptionState.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) { - "Lastchangedtime attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Lastchangedtime attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(LastChangedTimeAttributeSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(LastChangedTimeAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(LastChangedTimeAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readReplacementProductListAttribute(): ReplacementProductListAttribute { - val ATTRIBUTE_ID: UInt = 5u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readReplacementProductListAttribute(): ReplacementProductListAttribute {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}") - } + 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) { "Replacementproductlist attribute not found in response" } + } + + requireNotNull(attributeData) { + "Replacementproductlist attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add( - ActivatedCarbonFilterMonitoringClusterReplacementProductStruct.fromTlv( - AnonymousTag, - tlvReader, - ) - ) - } - tlvReader.exitContainer() - } - } else { - null + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(ActivatedCarbonFilterMonitoringClusterReplacementProductStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + } else { + null + } + return ReplacementProductListAttribute(decodedValue) } suspend fun subscribeReplacementProductListAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ReplacementProductListAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ReplacementProductListAttributeSubscriptionState.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) { - "Replacementproductlist attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Replacementproductlist attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add( - ActivatedCarbonFilterMonitoringClusterReplacementProductStruct.fromTlv( - AnonymousTag, - tlvReader, - ) - ) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { emit(ReplacementProductListAttributeSubscriptionState.Success(it)) } + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(ActivatedCarbonFilterMonitoringClusterReplacementProductStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { + emit(ReplacementProductListAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ReplacementProductListAttributeSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -841,96 +888,97 @@ class ActivatedCarbonFilterMonitoringCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -938,94 +986,97 @@ class ActivatedCarbonFilterMonitoringCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1033,94 +1084,97 @@ class ActivatedCarbonFilterMonitoringCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1128,76 +1182,81 @@ class ActivatedCarbonFilterMonitoringCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1209,77 +1268,80 @@ class ActivatedCarbonFilterMonitoringCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1292,7 +1354,7 @@ class ActivatedCarbonFilterMonitoringCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/AdministratorCommissioningCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/AdministratorCommissioningCluster.kt index 5ac1e18a200d19..50dc00e41902ff 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/AdministratorCommissioningCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/AdministratorCommissioningCluster.kt @@ -17,101 +17,133 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class AdministratorCommissioningCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class AdminFabricIndexAttribute(val value: UByte?) +class AdministratorCommissioningCluster(private val controller: MatterController, private val endpointId: UShort) {class AdminFabricIndexAttribute( + val value: UByte? + ) sealed class AdminFabricIndexAttributeSubscriptionState { - data class Success(val value: UByte?) : AdminFabricIndexAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : AdminFabricIndexAttributeSubscriptionState() + data class Error(val exception: Exception) : AdminFabricIndexAttributeSubscriptionState() - object SubscriptionEstablished : AdminFabricIndexAttributeSubscriptionState() - } - - class AdminVendorIdAttribute(val value: UShort?) + object SubscriptionEstablished : AdminFabricIndexAttributeSubscriptionState() + } +class AdminVendorIdAttribute( + val value: UShort? + ) sealed class AdminVendorIdAttributeSubscriptionState { - data class Success(val value: UShort?) : AdminVendorIdAttributeSubscriptionState() - + data class Success( + val value: UShort? + ) : AdminVendorIdAttributeSubscriptionState() + data class Error(val exception: Exception) : AdminVendorIdAttributeSubscriptionState() - object SubscriptionEstablished : AdminVendorIdAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : AdminVendorIdAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun openCommissioningWindow( - commissioningTimeout: UShort, - PAKEPasscodeVerifier: ByteArray, - discriminator: UShort, - iterations: UInt, - salt: ByteArray, - timedInvokeTimeout: Duration, - ) { + suspend fun openCommissioningWindow(commissioningTimeout: UShort + ,PAKEPasscodeVerifier: ByteArray + ,discriminator: UShort + ,iterations: UInt + ,salt: ByteArray + ,timedInvokeTimeout: Duration) { val commandId: UInt = 0u val tlvWriter = TlvWriter() @@ -130,38 +162,36 @@ class AdministratorCommissioningCluster( tlvWriter.put(ContextSpecificTag(TAG_ITERATIONS_REQ), iterations) val TAG_SALT_REQ: Int = 4 - tlvWriter.put(ContextSpecificTag(TAG_SALT_REQ), salt) + tlvWriter.put(ContextSpecificTag(TAG_SALT_REQ), salt) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun openBasicCommissioningWindow( - commissioningTimeout: UShort, - timedInvokeTimeout: Duration, - ) { + suspend fun openBasicCommissioningWindow(commissioningTimeout: UShort + ,timedInvokeTimeout: Duration) { val commandId: UInt = 1u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_COMMISSIONING_TIMEOUT_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_COMMISSIONING_TIMEOUT_REQ), commissioningTimeout) + tlvWriter.put(ContextSpecificTag(TAG_COMMISSIONING_TIMEOUT_REQ), commissioningTimeout) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -172,87 +202,92 @@ class AdministratorCommissioningCluster( val commandId: UInt = 2u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - - suspend fun readWindowStatusAttribute(): 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)) - +suspend fun readWindowStatusAttribute(): 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}") - } + 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) { "Windowstatus attribute not found in response" } + } + + requireNotNull(attributeData) { + "Windowstatus 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 subscribeWindowStatusAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Windowstatus attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Windowstatus attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -264,284 +299,295 @@ class AdministratorCommissioningCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readAdminFabricIndexAttribute(): AdminFabricIndexAttribute { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readAdminFabricIndexAttribute(): AdminFabricIndexAttribute {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}") - } + 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) { "Adminfabricindex attribute not found in response" } + } + + requireNotNull(attributeData) { + "Adminfabricindex attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return AdminFabricIndexAttribute(decodedValue) } suspend fun subscribeAdminFabricIndexAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - AdminFabricIndexAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(AdminFabricIndexAttributeSubscriptionState.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) { - "Adminfabricindex attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Adminfabricindex 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.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(AdminFabricIndexAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(AdminFabricIndexAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(AdminFabricIndexAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readAdminVendorIdAttribute(): AdminVendorIdAttribute { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readAdminVendorIdAttribute(): AdminVendorIdAttribute {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}") - } + 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) { "Adminvendorid attribute not found in response" } + } + + requireNotNull(attributeData) { + "Adminvendorid attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = - if (!tlvReader.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return AdminVendorIdAttribute(decodedValue) } suspend fun subscribeAdminVendorIdAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - AdminVendorIdAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(AdminVendorIdAttributeSubscriptionState.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) { "Adminvendorid attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Adminvendorid 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.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(AdminVendorIdAttributeSubscriptionState.Success(it)) } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(AdminVendorIdAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(AdminVendorIdAttributeSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -549,96 +595,97 @@ class AdministratorCommissioningCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -646,94 +693,97 @@ class AdministratorCommissioningCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -741,94 +791,97 @@ class AdministratorCommissioningCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -836,76 +889,81 @@ class AdministratorCommissioningCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -917,77 +975,80 @@ class AdministratorCommissioningCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1000,7 +1061,7 @@ class AdministratorCommissioningCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/AirQualityCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/AirQualityCluster.kt index 3b8b97c9484f10..7622ac8f893d32 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/AirQualityCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/AirQualityCluster.kt @@ -17,132 +17,173 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath +import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader +import matter.tlv.TlvWriter -class AirQualityCluster(private val controller: MatterController, private val endpointId: UShort) { - class GeneratedCommandListAttribute(val value: List) +class AirQualityCluster(private val controller: MatterController, private val endpointId: UShort) {class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } - - suspend fun readAirQualityAttribute(): 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)) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } +suspend fun readAirQualityAttribute(): 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}") - } + 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) { "Airquality attribute not found in response" } + } + + requireNotNull(attributeData) { + "Airquality 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 subscribeAirQualityAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Airquality attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Airquality attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -154,96 +195,97 @@ class AirQualityCluster(private val controller: MatterController, private val en emit(UByteSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -251,96 +293,97 @@ class AirQualityCluster(private val controller: MatterController, private val en 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -348,94 +391,97 @@ class AirQualityCluster(private val controller: MatterController, private val en 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -443,94 +489,97 @@ class AirQualityCluster(private val controller: MatterController, private val en 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -538,76 +587,81 @@ class AirQualityCluster(private val controller: MatterController, private val en 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -619,77 +673,80 @@ class AirQualityCluster(private val controller: MatterController, private val en 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -702,7 +759,7 @@ class AirQualityCluster(private val controller: MatterController, private val en emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/ApplicationBasicCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/ApplicationBasicCluster.kt index 02e84a912d3fd0..880e6385833234 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/ApplicationBasicCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/ApplicationBasicCluster.kt @@ -17,340 +17,392 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest -import matter.controller.StringSubscriptionState +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath +import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader +import matter.tlv.TlvWriter -class ApplicationBasicCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class ApplicationAttribute(val value: ApplicationBasicClusterApplicationStruct) +class ApplicationBasicCluster(private val controller: MatterController, private val endpointId: UShort) {class ApplicationAttribute( + val value: ApplicationBasicClusterApplicationStruct + ) sealed class ApplicationAttributeSubscriptionState { - data class Success(val value: ApplicationBasicClusterApplicationStruct) : - ApplicationAttributeSubscriptionState() - + data class Success( + val value: ApplicationBasicClusterApplicationStruct + ) : ApplicationAttributeSubscriptionState() + data class Error(val exception: Exception) : ApplicationAttributeSubscriptionState() - object SubscriptionEstablished : ApplicationAttributeSubscriptionState() - } - - class AllowedVendorListAttribute(val value: List) + object SubscriptionEstablished : ApplicationAttributeSubscriptionState() + } +class AllowedVendorListAttribute( + val value: List + ) sealed class AllowedVendorListAttributeSubscriptionState { - data class Success(val value: List) : AllowedVendorListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AllowedVendorListAttributeSubscriptionState() + data class Error(val exception: Exception) : AllowedVendorListAttributeSubscriptionState() - object SubscriptionEstablished : AllowedVendorListAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : AllowedVendorListAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } - - suspend fun readVendorNameAttribute(): String? { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } +suspend fun readVendorNameAttribute(): String? {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}") - } + 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) { "Vendorname attribute not found in response" } + } + + requireNotNull(attributeData) { + "Vendorname attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeVendorNameAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StringSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StringSubscriptionState.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) { "Vendorname attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Vendorname attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(StringSubscriptionState.Success(it)) } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(StringSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readVendorIDAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readVendorIDAttribute(): UShort? {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}") - } + 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) { "Vendorid attribute not found in response" } + } + + requireNotNull(attributeData) { + "Vendorid 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeVendorIDAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Vendorid attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Vendorid 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)) } + 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 readApplicationNameAttribute(): String { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readApplicationNameAttribute(): String {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}") - } + 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) { "Applicationname attribute not found in response" } + } + + requireNotNull(attributeData) { + "Applicationname attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: String = tlvReader.getString(AnonymousTag) + return decodedValue } suspend fun subscribeApplicationNameAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StringSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StringSubscriptionState.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) { - "Applicationname attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Applicationname attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -363,173 +415,182 @@ class ApplicationBasicCluster( emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readProductIDAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readProductIDAttribute(): UShort? {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}") - } + 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) { "Productid attribute not found in response" } + } + + requireNotNull(attributeData) { + "Productid 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeProductIDAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Productid attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Productid 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)) } + 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 readApplicationAttribute(): ApplicationAttribute { - val ATTRIBUTE_ID: UInt = 4u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readApplicationAttribute(): ApplicationAttribute {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}") - } + 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) { "Application attribute not found in response" } + } + + requireNotNull(attributeData) { + "Application attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ApplicationBasicClusterApplicationStruct = - ApplicationBasicClusterApplicationStruct.fromTlv(AnonymousTag, tlvReader) + val decodedValue: ApplicationBasicClusterApplicationStruct = ApplicationBasicClusterApplicationStruct.fromTlv(AnonymousTag, tlvReader) + return ApplicationAttribute(decodedValue) } suspend fun subscribeApplicationAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ApplicationAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ApplicationAttributeSubscriptionState.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) { "Application attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Application attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ApplicationBasicClusterApplicationStruct = - ApplicationBasicClusterApplicationStruct.fromTlv(AnonymousTag, tlvReader) + val decodedValue: ApplicationBasicClusterApplicationStruct = ApplicationBasicClusterApplicationStruct.fromTlv(AnonymousTag, tlvReader) emit(ApplicationAttributeSubscriptionState.Success(decodedValue)) } @@ -537,76 +598,81 @@ class ApplicationBasicCluster( emit(ApplicationAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readStatusAttribute(): UByte { - val ATTRIBUTE_ID: UInt = 5u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readStatusAttribute(): UByte {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}") - } + 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) { "Status attribute not found in response" } + } + + requireNotNull(attributeData) { + "Status 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 subscribeStatusAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Status attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Status attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -618,77 +684,80 @@ class ApplicationBasicCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readApplicationVersionAttribute(): String { - val ATTRIBUTE_ID: UInt = 6u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readApplicationVersionAttribute(): String {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}") - } + 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) { "Applicationversion attribute not found in response" } + } + + requireNotNull(attributeData) { + "Applicationversion attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: String = tlvReader.getString(AnonymousTag) + return decodedValue } suspend fun subscribeApplicationVersionAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StringSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StringSubscriptionState.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) { - "Applicationversion attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Applicationversion attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -701,96 +770,97 @@ class ApplicationBasicCluster( emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readAllowedVendorListAttribute(): AllowedVendorListAttribute { - val ATTRIBUTE_ID: UInt = 7u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readAllowedVendorListAttribute(): AllowedVendorListAttribute {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}") - } + 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) { "Allowedvendorlist attribute not found in response" } + } + + requireNotNull(attributeData) { + "Allowedvendorlist 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.getUShort(AnonymousTag)) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUShort(AnonymousTag)) } + tlvReader.exitContainer() + } + return AllowedVendorListAttribute(decodedValue) } suspend fun subscribeAllowedVendorListAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - AllowedVendorListAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(AllowedVendorListAttributeSubscriptionState.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) { - "Allowedvendorlist attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Allowedvendorlist 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.getUShort(AnonymousTag)) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUShort(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AllowedVendorListAttributeSubscriptionState.Success(decodedValue)) } @@ -798,96 +868,97 @@ class ApplicationBasicCluster( emit(AllowedVendorListAttributeSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -895,96 +966,97 @@ class ApplicationBasicCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -992,94 +1064,97 @@ class ApplicationBasicCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1087,94 +1162,97 @@ class ApplicationBasicCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1182,76 +1260,81 @@ class ApplicationBasicCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1263,77 +1346,80 @@ class ApplicationBasicCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1346,7 +1432,7 @@ class ApplicationBasicCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/ApplicationLauncherCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/ApplicationLauncherCluster.kt index 2f6d4b74bdbb85..5045bf8de2e5ee 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/ApplicationLauncherCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/ApplicationLauncherCluster.kt @@ -17,117 +17,156 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.UIntSubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState +import matter.controller.UByteSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class ApplicationLauncherCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class LauncherResponse(val status: UByte, val data: ByteArray?) - - class CatalogListAttribute(val value: List?) +class ApplicationLauncherCluster(private val controller: MatterController, private val endpointId: UShort) { + class LauncherResponse( + val status: UByte, + val data: ByteArray? + ) +class CatalogListAttribute( + val value: List? + ) sealed class CatalogListAttributeSubscriptionState { - data class Success(val value: List?) : CatalogListAttributeSubscriptionState() - + data class Success( + val value: List? + ) : CatalogListAttributeSubscriptionState() + data class Error(val exception: Exception) : CatalogListAttributeSubscriptionState() - object SubscriptionEstablished : CatalogListAttributeSubscriptionState() - } - - class CurrentAppAttribute(val value: ApplicationLauncherClusterApplicationEPStruct?) + object SubscriptionEstablished : CatalogListAttributeSubscriptionState() + } +class CurrentAppAttribute( + val value: ApplicationLauncherClusterApplicationEPStruct? + ) sealed class CurrentAppAttributeSubscriptionState { - data class Success(val value: ApplicationLauncherClusterApplicationEPStruct?) : - CurrentAppAttributeSubscriptionState() - + data class Success( + val value: ApplicationLauncherClusterApplicationEPStruct? + ) : CurrentAppAttributeSubscriptionState() + data class Error(val exception: Exception) : CurrentAppAttributeSubscriptionState() - object SubscriptionEstablished : CurrentAppAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : CurrentAppAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun launchApp( - application: ApplicationLauncherClusterApplicationStruct?, - data: ByteArray?, - timedInvokeTimeout: Duration? = null, - ): LauncherResponse { + suspend fun launchApp(application: ApplicationLauncherClusterApplicationStruct? + ,data: ByteArray? + ,timedInvokeTimeout: Duration? = null): LauncherResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_APPLICATION_REQ: Int = 0 - application?.let { application.toTlv(ContextSpecificTag(TAG_APPLICATION_REQ), tlvWriter) } + application?.let { + application.toTlv(ContextSpecificTag(TAG_APPLICATION_REQ), tlvWriter) + } val TAG_DATA_REQ: Int = 1 - data?.let { tlvWriter.put(ContextSpecificTag(TAG_DATA_REQ), data) } + data?.let { + tlvWriter.put(ContextSpecificTag(TAG_DATA_REQ), data) + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -137,61 +176,70 @@ class ApplicationLauncherCluster( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_DATA: Int = 1 var data_decoded: ByteArray? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_STATUS)) { - status_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_DATA)) { - data_decoded = + + if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_DATA)) {data_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getByteArray(tag) - } else { - null - } - } - } else { + tlvReader.getByteArray(tag) + } else { + null + } + }} + + + else { tlvReader.skipElement() } } + + if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } + + + tlvReader.exitContainer() - return LauncherResponse(status_decoded, data_decoded) + return LauncherResponse( + status_decoded, + data_decoded + ) } - suspend fun stopApp( - application: ApplicationLauncherClusterApplicationStruct?, - timedInvokeTimeout: Duration? = null, - ): LauncherResponse { + suspend fun stopApp(application: ApplicationLauncherClusterApplicationStruct? + ,timedInvokeTimeout: Duration? = null): LauncherResponse { val commandId: UInt = 1u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_APPLICATION_REQ: Int = 0 - application?.let { application.toTlv(ContextSpecificTag(TAG_APPLICATION_REQ), tlvWriter) } + application?.let { + application.toTlv(ContextSpecificTag(TAG_APPLICATION_REQ), tlvWriter) + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -201,61 +249,70 @@ class ApplicationLauncherCluster( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_DATA: Int = 1 var data_decoded: ByteArray? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_STATUS)) { - status_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_DATA)) { - data_decoded = + + if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_DATA)) {data_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getByteArray(tag) - } else { - null - } - } - } else { + tlvReader.getByteArray(tag) + } else { + null + } + }} + + + else { tlvReader.skipElement() } } + + if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } + + + tlvReader.exitContainer() - return LauncherResponse(status_decoded, data_decoded) + return LauncherResponse( + status_decoded, + data_decoded + ) } - suspend fun hideApp( - application: ApplicationLauncherClusterApplicationStruct?, - timedInvokeTimeout: Duration? = null, - ): LauncherResponse { + suspend fun hideApp(application: ApplicationLauncherClusterApplicationStruct? + ,timedInvokeTimeout: Duration? = null): LauncherResponse { val commandId: UInt = 2u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_APPLICATION_REQ: Int = 0 - application?.let { application.toTlv(ContextSpecificTag(TAG_APPLICATION_REQ), tlvWriter) } + application?.let { + application.toTlv(ContextSpecificTag(TAG_APPLICATION_REQ), tlvWriter) + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -265,334 +322,356 @@ class ApplicationLauncherCluster( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_DATA: Int = 1 var data_decoded: ByteArray? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_STATUS)) { - status_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_DATA)) { - data_decoded = + + if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_DATA)) {data_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getByteArray(tag) - } else { - null - } - } - } else { + tlvReader.getByteArray(tag) + } else { + null + } + }} + + + else { tlvReader.skipElement() } } + + if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } + + + tlvReader.exitContainer() - return LauncherResponse(status_decoded, data_decoded) + return LauncherResponse( + status_decoded, + data_decoded + ) } - - suspend fun readCatalogListAttribute(): CatalogListAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readCatalogListAttribute(): CatalogListAttribute {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}") - } + 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) { "Cataloglist attribute not found in response" } + } + + requireNotNull(attributeData) { + "Cataloglist attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getUShort(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUShort(AnonymousTag)) } + tlvReader.exitContainer() + } + } else { + null + } + return CatalogListAttribute(decodedValue) } suspend fun subscribeCatalogListAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - CatalogListAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(CatalogListAttributeSubscriptionState.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) { "Cataloglist attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Cataloglist attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getUShort(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { emit(CatalogListAttributeSubscriptionState.Success(it)) } + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUShort(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { + emit(CatalogListAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(CatalogListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readCurrentAppAttribute(): CurrentAppAttribute { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readCurrentAppAttribute(): CurrentAppAttribute {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}") - } + 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) { "Currentapp attribute not found in response" } + } + + requireNotNull(attributeData) { + "Currentapp attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ApplicationLauncherClusterApplicationEPStruct? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - ApplicationLauncherClusterApplicationEPStruct.fromTlv(AnonymousTag, tlvReader) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ApplicationLauncherClusterApplicationEPStruct? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + ApplicationLauncherClusterApplicationEPStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return CurrentAppAttribute(decodedValue) } suspend fun subscribeCurrentAppAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - CurrentAppAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(CurrentAppAttributeSubscriptionState.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) { "Currentapp attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Currentapp attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ApplicationLauncherClusterApplicationEPStruct? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - ApplicationLauncherClusterApplicationEPStruct.fromTlv(AnonymousTag, tlvReader) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(CurrentAppAttributeSubscriptionState.Success(it)) } + val decodedValue: ApplicationLauncherClusterApplicationEPStruct? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + ApplicationLauncherClusterApplicationEPStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(CurrentAppAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(CurrentAppAttributeSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -600,96 +679,97 @@ class ApplicationLauncherCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -697,94 +777,97 @@ class ApplicationLauncherCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -792,94 +875,97 @@ class ApplicationLauncherCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -887,76 +973,81 @@ class ApplicationLauncherCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -968,77 +1059,80 @@ class ApplicationLauncherCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1051,7 +1145,7 @@ class ApplicationLauncherCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/AudioOutputCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/AudioOutputCluster.kt index 6238d2b18bf749..c038970d786898 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/AudioOutputCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/AudioOutputCluster.kt @@ -17,103 +17,139 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class AudioOutputCluster(private val controller: MatterController, private val endpointId: UShort) { - class OutputListAttribute(val value: List) +class AudioOutputCluster(private val controller: MatterController, private val endpointId: UShort) {class OutputListAttribute( + val value: List + ) sealed class OutputListAttributeSubscriptionState { - data class Success(val value: List) : - OutputListAttributeSubscriptionState() - + data class Success( + val value: List + ) : OutputListAttributeSubscriptionState() + data class Error(val exception: Exception) : OutputListAttributeSubscriptionState() - object SubscriptionEstablished : OutputListAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : OutputListAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun selectOutput(index: UByte, timedInvokeTimeout: Duration? = null) { + suspend fun selectOutput(index: UByte + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_INDEX_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_INDEX_REQ), index) + tlvWriter.put(ContextSpecificTag(TAG_INDEX_REQ), index) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun renameOutput(index: UByte, name: String, timedInvokeTimeout: Duration? = null) { + suspend fun renameOutput(index: UByte + ,name: String + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 1u val tlvWriter = TlvWriter() @@ -123,105 +159,108 @@ class AudioOutputCluster(private val controller: MatterController, private val e tlvWriter.put(ContextSpecificTag(TAG_INDEX_REQ), index) val TAG_NAME_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_NAME_REQ), name) + tlvWriter.put(ContextSpecificTag(TAG_NAME_REQ), name) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - - suspend fun readOutputListAttribute(): OutputListAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readOutputListAttribute(): OutputListAttribute {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}") - } + 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) { "Outputlist attribute not found in response" } + } + + requireNotNull(attributeData) { + "Outputlist 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(AudioOutputClusterOutputInfoStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(AudioOutputClusterOutputInfoStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + return OutputListAttribute(decodedValue) } suspend fun subscribeOutputListAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - OutputListAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(OutputListAttributeSubscriptionState.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) { "Outputlist attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Outputlist 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(AudioOutputClusterOutputInfoStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(AudioOutputClusterOutputInfoStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(OutputListAttributeSubscriptionState.Success(decodedValue)) } @@ -229,76 +268,81 @@ class AudioOutputCluster(private val controller: MatterController, private val e emit(OutputListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readCurrentOutputAttribute(): 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)) - +suspend fun readCurrentOutputAttribute(): 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}") - } + 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) { "Currentoutput attribute not found in response" } + } + + requireNotNull(attributeData) { + "Currentoutput 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 subscribeCurrentOutputAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Currentoutput attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Currentoutput attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -310,96 +354,97 @@ class AudioOutputCluster(private val controller: MatterController, private val e emit(UByteSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -407,96 +452,97 @@ class AudioOutputCluster(private val controller: MatterController, private val e 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -504,94 +550,97 @@ class AudioOutputCluster(private val controller: MatterController, private val e 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -599,94 +648,97 @@ class AudioOutputCluster(private val controller: MatterController, private val e 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -694,76 +746,81 @@ class AudioOutputCluster(private val controller: MatterController, private val e 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -775,77 +832,80 @@ class AudioOutputCluster(private val controller: MatterController, private val e 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -858,7 +918,7 @@ class AudioOutputCluster(private val controller: MatterController, private val e emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/BallastConfigurationCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/BallastConfigurationCluster.kt index d013a6e1203d0f..e733a38744d421 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/BallastConfigurationCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/BallastConfigurationCluster.kt @@ -17,192 +17,237 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest -import matter.controller.StringSubscriptionState +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.cluster.structs.* +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath +import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class BallastConfigurationCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class IntrinsicBallastFactorAttribute(val value: UByte?) +class BallastConfigurationCluster(private val controller: MatterController, private val endpointId: UShort) {class IntrinsicBallastFactorAttribute( + val value: UByte? + ) sealed class IntrinsicBallastFactorAttributeSubscriptionState { - data class Success(val value: UByte?) : IntrinsicBallastFactorAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : IntrinsicBallastFactorAttributeSubscriptionState() + data class Error(val exception: Exception) : IntrinsicBallastFactorAttributeSubscriptionState() - object SubscriptionEstablished : IntrinsicBallastFactorAttributeSubscriptionState() - } - - class BallastFactorAdjustmentAttribute(val value: UByte?) + object SubscriptionEstablished : IntrinsicBallastFactorAttributeSubscriptionState() + } +class BallastFactorAdjustmentAttribute( + val value: UByte? + ) sealed class BallastFactorAdjustmentAttributeSubscriptionState { - data class Success(val value: UByte?) : BallastFactorAdjustmentAttributeSubscriptionState() - - data class Error(val exception: Exception) : - BallastFactorAdjustmentAttributeSubscriptionState() - - object SubscriptionEstablished : BallastFactorAdjustmentAttributeSubscriptionState() - } - - class LampRatedHoursAttribute(val value: UInt?) + data class Success( + val value: UByte? + ) : BallastFactorAdjustmentAttributeSubscriptionState() + + data class Error(val exception: Exception) : BallastFactorAdjustmentAttributeSubscriptionState() + + object SubscriptionEstablished : BallastFactorAdjustmentAttributeSubscriptionState() + } +class LampRatedHoursAttribute( + val value: UInt? + ) sealed class LampRatedHoursAttributeSubscriptionState { - data class Success(val value: UInt?) : LampRatedHoursAttributeSubscriptionState() - + data class Success( + val value: UInt? + ) : LampRatedHoursAttributeSubscriptionState() + data class Error(val exception: Exception) : LampRatedHoursAttributeSubscriptionState() - object SubscriptionEstablished : LampRatedHoursAttributeSubscriptionState() - } - - class LampBurnHoursAttribute(val value: UInt?) + object SubscriptionEstablished : LampRatedHoursAttributeSubscriptionState() + } +class LampBurnHoursAttribute( + val value: UInt? + ) sealed class LampBurnHoursAttributeSubscriptionState { - data class Success(val value: UInt?) : LampBurnHoursAttributeSubscriptionState() - + data class Success( + val value: UInt? + ) : LampBurnHoursAttributeSubscriptionState() + data class Error(val exception: Exception) : LampBurnHoursAttributeSubscriptionState() - object SubscriptionEstablished : LampBurnHoursAttributeSubscriptionState() - } - - class LampBurnHoursTripPointAttribute(val value: UInt?) + object SubscriptionEstablished : LampBurnHoursAttributeSubscriptionState() + } +class LampBurnHoursTripPointAttribute( + val value: UInt? + ) sealed class LampBurnHoursTripPointAttributeSubscriptionState { - data class Success(val value: UInt?) : LampBurnHoursTripPointAttributeSubscriptionState() - + data class Success( + val value: UInt? + ) : LampBurnHoursTripPointAttributeSubscriptionState() + data class Error(val exception: Exception) : LampBurnHoursTripPointAttributeSubscriptionState() - object SubscriptionEstablished : LampBurnHoursTripPointAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : LampBurnHoursTripPointAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } - - suspend fun readPhysicalMinLevelAttribute(): 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)) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } +suspend fun readPhysicalMinLevelAttribute(): 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}") - } + 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) { "Physicalminlevel attribute not found in response" } + } + + requireNotNull(attributeData) { + "Physicalminlevel 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 subscribePhysicalMinLevelAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Physicalminlevel attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Physicalminlevel attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -215,77 +260,80 @@ class BallastConfigurationCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readPhysicalMaxLevelAttribute(): 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)) - +suspend fun readPhysicalMaxLevelAttribute(): 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}") - } + 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) { "Physicalmaxlevel attribute not found in response" } + } + + requireNotNull(attributeData) { + "Physicalmaxlevel 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 subscribePhysicalMaxLevelAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Physicalmaxlevel attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Physicalmaxlevel attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -298,148 +346,165 @@ class BallastConfigurationCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readBallastStatusAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readBallastStatusAttribute(): UByte? {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}") - } + 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) { "Ballaststatus attribute not found in response" } + } + + requireNotNull(attributeData) { + "Ballaststatus 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeBallastStatusAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Ballaststatus attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Ballaststatus 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readMinLevelAttribute(): UByte { - val ATTRIBUTE_ID: UInt = 16u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMinLevelAttribute(): UByte {val ATTRIBUTE_ID: UInt = 16u + + 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}") - } + 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) { "Minlevel attribute not found in response" } + } + + requireNotNull(attributeData) { + "Minlevel 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 writeMinLevelAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeMinLevelAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -460,45 +525,43 @@ class BallastConfigurationCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeMinLevelAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Minlevel attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Minlevel attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -510,57 +573,68 @@ class BallastConfigurationCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readMaxLevelAttribute(): UByte { - val ATTRIBUTE_ID: UInt = 17u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMaxLevelAttribute(): UByte {val ATTRIBUTE_ID: UInt = 17u + + 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}") - } + 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) { "Maxlevel attribute not found in response" } + } + + requireNotNull(attributeData) { + "Maxlevel 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 writeMaxLevelAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeMaxLevelAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 17u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -581,45 +655,43 @@ class BallastConfigurationCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeMaxLevelAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 17u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Maxlevel attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Maxlevel attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -631,70 +703,77 @@ class BallastConfigurationCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readIntrinsicBallastFactorAttribute(): IntrinsicBallastFactorAttribute { - val ATTRIBUTE_ID: UInt = 20u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readIntrinsicBallastFactorAttribute(): IntrinsicBallastFactorAttribute {val ATTRIBUTE_ID: UInt = 20u + + 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}") - } + 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) { "Intrinsicballastfactor attribute not found in response" } + } + + requireNotNull(attributeData) { + "Intrinsicballastfactor attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return IntrinsicBallastFactorAttribute(decodedValue) } suspend fun writeIntrinsicBallastFactorAttribute( value: UByte, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 20u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -715,132 +794,137 @@ class BallastConfigurationCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeIntrinsicBallastFactorAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 20u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - IntrinsicBallastFactorAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(IntrinsicBallastFactorAttributeSubscriptionState.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) { - "Intrinsicballastfactor attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Intrinsicballastfactor 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(IntrinsicBallastFactorAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(IntrinsicBallastFactorAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(IntrinsicBallastFactorAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readBallastFactorAdjustmentAttribute(): BallastFactorAdjustmentAttribute { - val ATTRIBUTE_ID: UInt = 21u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readBallastFactorAdjustmentAttribute(): BallastFactorAdjustmentAttribute {val ATTRIBUTE_ID: UInt = 21u + + 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}") - } + 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) { "Ballastfactoradjustment attribute not found in response" } + } + + requireNotNull(attributeData) { + "Ballastfactoradjustment attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return BallastFactorAdjustmentAttribute(decodedValue) } suspend fun writeBallastFactorAdjustmentAttribute( value: UByte, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 21u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -861,138 +945,141 @@ class BallastConfigurationCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeBallastFactorAdjustmentAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 21u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - BallastFactorAdjustmentAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(BallastFactorAdjustmentAttributeSubscriptionState.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) { - "Ballastfactoradjustment attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Ballastfactoradjustment 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(BallastFactorAdjustmentAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(BallastFactorAdjustmentAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(BallastFactorAdjustmentAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readLampQuantityAttribute(): UByte { - val ATTRIBUTE_ID: UInt = 32u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readLampQuantityAttribute(): UByte {val ATTRIBUTE_ID: UInt = 32u + + 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}") - } + 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) { "Lampquantity attribute not found in response" } + } + + requireNotNull(attributeData) { + "Lampquantity 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 subscribeLampQuantityAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 32u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Lampquantity attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Lampquantity attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -1004,62 +1091,72 @@ class BallastConfigurationCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readLampTypeAttribute(): String? { - val ATTRIBUTE_ID: UInt = 48u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readLampTypeAttribute(): String? {val ATTRIBUTE_ID: UInt = 48u + + 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}") - } + 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) { "Lamptype attribute not found in response" } + } + + requireNotNull(attributeData) { + "Lamptype attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + return decodedValue } - suspend fun writeLampTypeAttribute(value: String, timedWriteTimeout: Duration? = null) { + suspend fun writeLampTypeAttribute( + value: String, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 48u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -1080,117 +1177,127 @@ class BallastConfigurationCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeLampTypeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 48u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StringSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StringSubscriptionState.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) { "Lamptype attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Lamptype attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(StringSubscriptionState.Success(it)) } + decodedValue?.let { + emit(StringSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readLampManufacturerAttribute(): String? { - val ATTRIBUTE_ID: UInt = 49u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readLampManufacturerAttribute(): String? {val ATTRIBUTE_ID: UInt = 49u + + 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}") - } + 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) { "Lampmanufacturer attribute not found in response" } + } + + requireNotNull(attributeData) { + "Lampmanufacturer attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + return decodedValue } - suspend fun writeLampManufacturerAttribute(value: String, timedWriteTimeout: Duration? = null) { + suspend fun writeLampManufacturerAttribute( + value: String, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 49u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -1211,124 +1318,132 @@ class BallastConfigurationCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeLampManufacturerAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 49u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StringSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StringSubscriptionState.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) { - "Lampmanufacturer attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Lampmanufacturer attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(StringSubscriptionState.Success(it)) } + decodedValue?.let { + emit(StringSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readLampRatedHoursAttribute(): LampRatedHoursAttribute { - val ATTRIBUTE_ID: UInt = 50u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readLampRatedHoursAttribute(): LampRatedHoursAttribute {val ATTRIBUTE_ID: UInt = 50u + + 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}") - } + 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) { "Lampratedhours attribute not found in response" } + } + + requireNotNull(attributeData) { + "Lampratedhours attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return LampRatedHoursAttribute(decodedValue) } - suspend fun writeLampRatedHoursAttribute(value: UInt, timedWriteTimeout: Duration? = null) { + suspend fun writeLampRatedHoursAttribute( + value: UInt, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 50u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -1349,129 +1464,137 @@ class BallastConfigurationCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeLampRatedHoursAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 50u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - LampRatedHoursAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(LampRatedHoursAttributeSubscriptionState.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) { - "Lampratedhours attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Lampratedhours attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(LampRatedHoursAttributeSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(LampRatedHoursAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(LampRatedHoursAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readLampBurnHoursAttribute(): LampBurnHoursAttribute { - val ATTRIBUTE_ID: UInt = 51u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readLampBurnHoursAttribute(): LampBurnHoursAttribute {val ATTRIBUTE_ID: UInt = 51u + + 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}") - } + 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) { "Lampburnhours attribute not found in response" } + } + + requireNotNull(attributeData) { + "Lampburnhours attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return LampBurnHoursAttribute(decodedValue) } - suspend fun writeLampBurnHoursAttribute(value: UInt, timedWriteTimeout: Duration? = null) { + suspend fun writeLampBurnHoursAttribute( + value: UInt, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 51u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -1492,122 +1615,132 @@ class BallastConfigurationCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeLampBurnHoursAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 51u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - LampBurnHoursAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(LampBurnHoursAttributeSubscriptionState.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) { "Lampburnhours attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Lampburnhours attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(LampBurnHoursAttributeSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(LampBurnHoursAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(LampBurnHoursAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readLampAlarmModeAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 52u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readLampAlarmModeAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 52u + + 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}") - } + 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) { "Lampalarmmode attribute not found in response" } + } + + requireNotNull(attributeData) { + "Lampalarmmode 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } - suspend fun writeLampAlarmModeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeLampAlarmModeAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 52u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -1628,125 +1761,132 @@ class BallastConfigurationCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeLampAlarmModeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 52u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Lampalarmmode attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Lampalarmmode 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readLampBurnHoursTripPointAttribute(): LampBurnHoursTripPointAttribute { - val ATTRIBUTE_ID: UInt = 53u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readLampBurnHoursTripPointAttribute(): LampBurnHoursTripPointAttribute {val ATTRIBUTE_ID: UInt = 53u + + 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}") - } + 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) { "Lampburnhourstrippoint attribute not found in response" } + } + + requireNotNull(attributeData) { + "Lampburnhourstrippoint attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return LampBurnHoursTripPointAttribute(decodedValue) } suspend fun writeLampBurnHoursTripPointAttribute( value: UInt, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 53u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -1767,158 +1907,157 @@ class BallastConfigurationCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeLampBurnHoursTripPointAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 53u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - LampBurnHoursTripPointAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(LampBurnHoursTripPointAttributeSubscriptionState.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) { - "Lampburnhourstrippoint attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Lampburnhourstrippoint attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(LampBurnHoursTripPointAttributeSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(LampBurnHoursTripPointAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(LampBurnHoursTripPointAttributeSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1926,96 +2065,97 @@ class BallastConfigurationCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -2023,94 +2163,97 @@ class BallastConfigurationCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -2118,94 +2261,97 @@ class BallastConfigurationCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -2213,76 +2359,81 @@ class BallastConfigurationCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -2294,77 +2445,80 @@ class BallastConfigurationCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -2377,7 +2531,7 @@ class BallastConfigurationCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/BarrierControlCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/BarrierControlCluster.kt index 1c424199292f41..01b8f509d4f7af 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/BarrierControlCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/BarrierControlCluster.kt @@ -17,91 +17,117 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.cluster.structs.* +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class BarrierControlCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class GeneratedCommandListAttribute(val value: List) +class BarrierControlCluster(private val controller: MatterController, private val endpointId: UShort) {class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun barrierControlGoToPercent(percentOpen: UByte, timedInvokeTimeout: Duration? = null) { + suspend fun barrierControlGoToPercent(percentOpen: UByte + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_PERCENT_OPEN_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_PERCENT_OPEN_REQ), percentOpen) + tlvWriter.put(ContextSpecificTag(TAG_PERCENT_OPEN_REQ), percentOpen) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -112,88 +138,91 @@ class BarrierControlCluster( val commandId: UInt = 1u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - - suspend fun readBarrierMovingStateAttribute(): 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)) - +suspend fun readBarrierMovingStateAttribute(): 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}") - } + 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) { "Barriermovingstate attribute not found in response" } + } + + requireNotNull(attributeData) { + "Barriermovingstate 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 subscribeBarrierMovingStateAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Barriermovingstate attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Barriermovingstate attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -206,77 +235,80 @@ class BarrierControlCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readBarrierSafetyStatusAttribute(): 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)) - +suspend fun readBarrierSafetyStatusAttribute(): 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}") - } + 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) { "Barriersafetystatus attribute not found in response" } + } + + requireNotNull(attributeData) { + "Barriersafetystatus 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 subscribeBarrierSafetyStatusAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Barriersafetystatus attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Barriersafetystatus attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -289,77 +321,80 @@ class BarrierControlCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readBarrierCapabilitiesAttribute(): UByte { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readBarrierCapabilitiesAttribute(): UByte {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}") - } + 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) { "Barriercapabilities attribute not found in response" } + } + + requireNotNull(attributeData) { + "Barriercapabilities 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 subscribeBarrierCapabilitiesAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Barriercapabilities attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Barriercapabilities attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -372,62 +407,72 @@ class BarrierControlCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readBarrierOpenEventsAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 4u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readBarrierOpenEventsAttribute(): UShort? {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}") - } + 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) { "Barrieropenevents attribute not found in response" } + } + + requireNotNull(attributeData) { + "Barrieropenevents 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } - suspend fun writeBarrierOpenEventsAttribute(value: UShort, timedWriteTimeout: Duration? = null) { + suspend fun writeBarrierOpenEventsAttribute( + value: UShort, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 4u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -448,119 +493,127 @@ class BarrierControlCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeBarrierOpenEventsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Barrieropenevents attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Barrieropenevents 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)) } + 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 readBarrierCloseEventsAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 5u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readBarrierCloseEventsAttribute(): UShort? {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}") - } + 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) { "Barriercloseevents attribute not found in response" } + } + + requireNotNull(attributeData) { + "Barriercloseevents 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } - suspend fun writeBarrierCloseEventsAttribute(value: UShort, timedWriteTimeout: Duration? = null) { + suspend fun writeBarrierCloseEventsAttribute( + value: UShort, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 5u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -581,122 +634,127 @@ class BarrierControlCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeBarrierCloseEventsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Barriercloseevents attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Barriercloseevents 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)) } + 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 readBarrierCommandOpenEventsAttribute(): 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)) - +suspend fun readBarrierCommandOpenEventsAttribute(): 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}") - } + 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) { "Barriercommandopenevents attribute not found in response" } + } + + requireNotNull(attributeData) { + "Barriercommandopenevents 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun writeBarrierCommandOpenEventsAttribute( value: UShort, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 6u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -717,122 +775,127 @@ class BarrierControlCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeBarrierCommandOpenEventsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Barriercommandopenevents attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Barriercommandopenevents 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)) } + 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 readBarrierCommandCloseEventsAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 7u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readBarrierCommandCloseEventsAttribute(): UShort? {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}") - } + 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) { "Barriercommandcloseevents attribute not found in response" } + } + + requireNotNull(attributeData) { + "Barriercommandcloseevents 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun writeBarrierCommandCloseEventsAttribute( value: UShort, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 7u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -853,119 +916,127 @@ class BarrierControlCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeBarrierCommandCloseEventsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Barriercommandcloseevents attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Barriercommandcloseevents 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)) } + 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 readBarrierOpenPeriodAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 8u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readBarrierOpenPeriodAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 8u + + 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}") - } + 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) { "Barrieropenperiod attribute not found in response" } + } + + requireNotNull(attributeData) { + "Barrieropenperiod 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } - suspend fun writeBarrierOpenPeriodAttribute(value: UShort, timedWriteTimeout: Duration? = null) { + suspend fun writeBarrierOpenPeriodAttribute( + value: UShort, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 8u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -986,119 +1057,127 @@ class BarrierControlCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeBarrierOpenPeriodAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Barrieropenperiod attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Barrieropenperiod 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)) } + 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 readBarrierClosePeriodAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 9u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readBarrierClosePeriodAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 9u + + 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}") - } + 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) { "Barriercloseperiod attribute not found in response" } + } + + requireNotNull(attributeData) { + "Barriercloseperiod 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } - suspend fun writeBarrierClosePeriodAttribute(value: UShort, timedWriteTimeout: Duration? = null) { + suspend fun writeBarrierClosePeriodAttribute( + value: UShort, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 9u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -1119,134 +1198,135 @@ class BarrierControlCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeBarrierClosePeriodAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Barriercloseperiod attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Barriercloseperiod 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)) } + 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 readBarrierPositionAttribute(): UByte { - val ATTRIBUTE_ID: UInt = 10u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readBarrierPositionAttribute(): UByte {val ATTRIBUTE_ID: UInt = 10u + + 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}") - } + 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) { "Barrierposition attribute not found in response" } + } + + requireNotNull(attributeData) { + "Barrierposition 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 subscribeBarrierPositionAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Barrierposition attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Barrierposition attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -1259,96 +1339,97 @@ class BarrierControlCluster( emit(UByteSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1356,96 +1437,97 @@ class BarrierControlCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1453,94 +1535,97 @@ class BarrierControlCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1548,94 +1633,97 @@ class BarrierControlCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1643,76 +1731,81 @@ class BarrierControlCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1724,77 +1817,80 @@ class BarrierControlCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1807,7 +1903,7 @@ class BarrierControlCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/BasicInformationCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/BasicInformationCluster.kt index e60bab759236b3..27183e2fe9b379 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/BasicInformationCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/BasicInformationCluster.kt @@ -17,184 +17,216 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration 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.StringSubscriptionState +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.UIntSubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState +import matter.controller.UByteSubscriptionState import matter.controller.UShortSubscriptionState +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.cluster.structs.* +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class BasicInformationCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class CapabilityMinimaAttribute(val value: BasicInformationClusterCapabilityMinimaStruct) +class BasicInformationCluster(private val controller: MatterController, private val endpointId: UShort) {class CapabilityMinimaAttribute( + val value: BasicInformationClusterCapabilityMinimaStruct + ) sealed class CapabilityMinimaAttributeSubscriptionState { - data class Success(val value: BasicInformationClusterCapabilityMinimaStruct) : - CapabilityMinimaAttributeSubscriptionState() - + data class Success( + val value: BasicInformationClusterCapabilityMinimaStruct + ) : CapabilityMinimaAttributeSubscriptionState() + data class Error(val exception: Exception) : CapabilityMinimaAttributeSubscriptionState() - object SubscriptionEstablished : CapabilityMinimaAttributeSubscriptionState() - } - - class ProductAppearanceAttribute(val value: BasicInformationClusterProductAppearanceStruct?) + object SubscriptionEstablished : CapabilityMinimaAttributeSubscriptionState() + } +class ProductAppearanceAttribute( + val value: BasicInformationClusterProductAppearanceStruct? + ) sealed class ProductAppearanceAttributeSubscriptionState { - data class Success(val value: BasicInformationClusterProductAppearanceStruct?) : - ProductAppearanceAttributeSubscriptionState() - + data class Success( + val value: BasicInformationClusterProductAppearanceStruct? + ) : ProductAppearanceAttributeSubscriptionState() + data class Error(val exception: Exception) : ProductAppearanceAttributeSubscriptionState() - object SubscriptionEstablished : ProductAppearanceAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : ProductAppearanceAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } suspend fun mfgSpecificPing(timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } +suspend fun readDataModelRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 0u - suspend fun readDataModelRevisionAttribute(): UShort { - 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 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}") - } + 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) { "Datamodelrevision attribute not found in response" } + } + + requireNotNull(attributeData) { + "Datamodelrevision 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 subscribeDataModelRevisionAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Datamodelrevision attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Datamodelrevision attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -207,76 +239,81 @@ class BasicInformationCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readVendorNameAttribute(): String {val ATTRIBUTE_ID: UInt = 1u - suspend fun readVendorNameAttribute(): String { - 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 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}") - } + 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) { "Vendorname attribute not found in response" } + } + + requireNotNull(attributeData) { + "Vendorname attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: String = tlvReader.getString(AnonymousTag) + return decodedValue } suspend fun subscribeVendorNameAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StringSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StringSubscriptionState.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) { "Vendorname attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Vendorname attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -288,76 +325,81 @@ class BasicInformationCluster( emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readVendorIDAttribute(): UShort {val ATTRIBUTE_ID: UInt = 2u - suspend fun readVendorIDAttribute(): 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 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}") - } + 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) { "Vendorid attribute not found in response" } + } + + requireNotNull(attributeData) { + "Vendorid 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 subscribeVendorIDAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Vendorid attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Vendorid attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -369,76 +411,81 @@ class BasicInformationCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readProductNameAttribute(): String {val ATTRIBUTE_ID: UInt = 3u - suspend fun readProductNameAttribute(): String { - 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 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}") - } + 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) { "Productname attribute not found in response" } + } + + requireNotNull(attributeData) { + "Productname attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: String = tlvReader.getString(AnonymousTag) + return decodedValue } suspend fun subscribeProductNameAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StringSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StringSubscriptionState.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) { "Productname attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Productname attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -450,76 +497,81 @@ class BasicInformationCluster( emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readProductIDAttribute(): UShort {val ATTRIBUTE_ID: UInt = 4u - suspend fun readProductIDAttribute(): UShort { - 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 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}") - } + 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) { "Productid attribute not found in response" } + } + + requireNotNull(attributeData) { + "Productid 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 subscribeProductIDAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Productid attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Productid attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -531,57 +583,68 @@ class BasicInformationCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNodeLabelAttribute(): String {val ATTRIBUTE_ID: UInt = 5u - suspend fun readNodeLabelAttribute(): String { - 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 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}") - } + 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) { "Nodelabel attribute not found in response" } + } + + requireNotNull(attributeData) { + "Nodelabel attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: String = tlvReader.getString(AnonymousTag) + return decodedValue } - suspend fun writeNodeLabelAttribute(value: String, timedWriteTimeout: Duration? = null) { + suspend fun writeNodeLabelAttribute( + value: String, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 5u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -602,45 +665,43 @@ class BasicInformationCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNodeLabelAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StringSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StringSubscriptionState.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) { "Nodelabel attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Nodelabel attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -652,57 +713,68 @@ class BasicInformationCluster( emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readLocationAttribute(): String {val ATTRIBUTE_ID: UInt = 6u - suspend fun readLocationAttribute(): String { - 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 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}") - } + 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) { "Location attribute not found in response" } + } + + requireNotNull(attributeData) { + "Location attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: String = tlvReader.getString(AnonymousTag) + return decodedValue } - suspend fun writeLocationAttribute(value: String, timedWriteTimeout: Duration? = null) { + suspend fun writeLocationAttribute( + value: String, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 6u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -723,45 +795,43 @@ class BasicInformationCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeLocationAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StringSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StringSubscriptionState.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) { "Location attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Location attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -773,77 +843,80 @@ class BasicInformationCluster( emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readHardwareVersionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 7u - suspend fun readHardwareVersionAttribute(): UShort { - 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 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}") - } + 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) { "Hardwareversion attribute not found in response" } + } + + requireNotNull(attributeData) { + "Hardwareversion 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 subscribeHardwareVersionAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Hardwareversion attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Hardwareversion attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -856,77 +929,80 @@ class BasicInformationCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readHardwareVersionStringAttribute(): String {val ATTRIBUTE_ID: UInt = 8u - suspend fun readHardwareVersionStringAttribute(): String { - val ATTRIBUTE_ID: UInt = 8u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Hardwareversionstring attribute not found in response" } + } + + requireNotNull(attributeData) { + "Hardwareversionstring attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: String = tlvReader.getString(AnonymousTag) + return decodedValue } suspend fun subscribeHardwareVersionStringAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StringSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StringSubscriptionState.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) { - "Hardwareversionstring attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Hardwareversionstring attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -939,77 +1015,80 @@ class BasicInformationCluster( emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readSoftwareVersionAttribute(): UInt {val ATTRIBUTE_ID: UInt = 9u - suspend fun readSoftwareVersionAttribute(): UInt { - val ATTRIBUTE_ID: UInt = 9u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Softwareversion attribute not found in response" } + } + + requireNotNull(attributeData) { + "Softwareversion 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 subscribeSoftwareVersionAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Softwareversion attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Softwareversion attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -1022,77 +1101,80 @@ class BasicInformationCluster( emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readSoftwareVersionStringAttribute(): String {val ATTRIBUTE_ID: UInt = 10u - suspend fun readSoftwareVersionStringAttribute(): String { - val ATTRIBUTE_ID: UInt = 10u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Softwareversionstring attribute not found in response" } + } + + requireNotNull(attributeData) { + "Softwareversionstring attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: String = tlvReader.getString(AnonymousTag) + return decodedValue } suspend fun subscribeSoftwareVersionStringAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StringSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StringSubscriptionState.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) { - "Softwareversionstring attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Softwareversionstring attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -1105,522 +1187,557 @@ class BasicInformationCluster( emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readManufacturingDateAttribute(): String? {val ATTRIBUTE_ID: UInt = 11u - suspend fun readManufacturingDateAttribute(): String? { - val ATTRIBUTE_ID: UInt = 11u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Manufacturingdate attribute not found in response" } + } + + requireNotNull(attributeData) { + "Manufacturingdate attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeManufacturingDateAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 11u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StringSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StringSubscriptionState.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) { - "Manufacturingdate attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Manufacturingdate attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(StringSubscriptionState.Success(it)) } + decodedValue?.let { + emit(StringSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readPartNumberAttribute(): String? {val ATTRIBUTE_ID: UInt = 12u - suspend fun readPartNumberAttribute(): String? { - val ATTRIBUTE_ID: UInt = 12u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Partnumber attribute not found in response" } + } + + requireNotNull(attributeData) { + "Partnumber attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribePartNumberAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 12u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StringSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StringSubscriptionState.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) { "Partnumber attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Partnumber attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(StringSubscriptionState.Success(it)) } + decodedValue?.let { + emit(StringSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readProductURLAttribute(): String? {val ATTRIBUTE_ID: UInt = 13u - suspend fun readProductURLAttribute(): String? { - val ATTRIBUTE_ID: UInt = 13u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Producturl attribute not found in response" } + } + + requireNotNull(attributeData) { + "Producturl attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeProductURLAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 13u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StringSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StringSubscriptionState.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) { "Producturl attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Producturl attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(StringSubscriptionState.Success(it)) } + decodedValue?.let { + emit(StringSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readProductLabelAttribute(): String? {val ATTRIBUTE_ID: UInt = 14u - suspend fun readProductLabelAttribute(): String? { - val ATTRIBUTE_ID: UInt = 14u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Productlabel attribute not found in response" } + } + + requireNotNull(attributeData) { + "Productlabel attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeProductLabelAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 14u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StringSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StringSubscriptionState.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) { "Productlabel attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Productlabel attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(StringSubscriptionState.Success(it)) } + decodedValue?.let { + emit(StringSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readSerialNumberAttribute(): String? {val ATTRIBUTE_ID: UInt = 15u - suspend fun readSerialNumberAttribute(): String? { - val ATTRIBUTE_ID: UInt = 15u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Serialnumber attribute not found in response" } + } + + requireNotNull(attributeData) { + "Serialnumber attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeSerialNumberAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 15u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StringSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StringSubscriptionState.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) { "Serialnumber attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Serialnumber attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(StringSubscriptionState.Success(it)) } + decodedValue?.let { + emit(StringSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readLocalConfigDisabledAttribute(): Boolean? {val ATTRIBUTE_ID: UInt = 16u - suspend fun readLocalConfigDisabledAttribute(): Boolean? { - val ATTRIBUTE_ID: UInt = 16u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Localconfigdisabled attribute not found in response" } + } + + requireNotNull(attributeData) { + "Localconfigdisabled 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 - } + val decodedValue: Boolean? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun writeLocalConfigDisabledAttribute( value: Boolean, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -1641,224 +1758,233 @@ class BasicInformationCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeLocalConfigDisabledAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Localconfigdisabled attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Localconfigdisabled 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 - } + val decodedValue: Boolean? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(BooleanSubscriptionState.Success(it)) } + decodedValue?.let { + emit(BooleanSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readReachableAttribute(): Boolean? {val ATTRIBUTE_ID: UInt = 17u - suspend fun readReachableAttribute(): Boolean? { - val ATTRIBUTE_ID: UInt = 17u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Reachable attribute not found in response" } + } + + requireNotNull(attributeData) { + "Reachable 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 - } + val decodedValue: Boolean? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeReachableAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 17u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Reachable attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Reachable 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 - } + val decodedValue: Boolean? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(BooleanSubscriptionState.Success(it)) } + decodedValue?.let { + emit(BooleanSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readUniqueIDAttribute(): String {val ATTRIBUTE_ID: UInt = 18u - suspend fun readUniqueIDAttribute(): String { - val ATTRIBUTE_ID: UInt = 18u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Uniqueid attribute not found in response" } + } + + requireNotNull(attributeData) { + "Uniqueid attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: String = tlvReader.getString(AnonymousTag) + return decodedValue } suspend fun subscribeUniqueIDAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 18u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StringSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StringSubscriptionState.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) { "Uniqueid attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Uniqueid attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -1870,84 +1996,85 @@ class BasicInformationCluster( emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readCapabilityMinimaAttribute(): CapabilityMinimaAttribute {val ATTRIBUTE_ID: UInt = 19u - suspend fun readCapabilityMinimaAttribute(): CapabilityMinimaAttribute { - val ATTRIBUTE_ID: UInt = 19u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Capabilityminima attribute not found in response" } + } + + requireNotNull(attributeData) { + "Capabilityminima attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: BasicInformationClusterCapabilityMinimaStruct = - BasicInformationClusterCapabilityMinimaStruct.fromTlv(AnonymousTag, tlvReader) + val decodedValue: BasicInformationClusterCapabilityMinimaStruct = BasicInformationClusterCapabilityMinimaStruct.fromTlv(AnonymousTag, tlvReader) + return CapabilityMinimaAttribute(decodedValue) } suspend fun subscribeCapabilityMinimaAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 19u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - CapabilityMinimaAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(CapabilityMinimaAttributeSubscriptionState.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) { - "Capabilityminima attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Capabilityminima attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: BasicInformationClusterCapabilityMinimaStruct = - BasicInformationClusterCapabilityMinimaStruct.fromTlv(AnonymousTag, tlvReader) + val decodedValue: BasicInformationClusterCapabilityMinimaStruct = BasicInformationClusterCapabilityMinimaStruct.fromTlv(AnonymousTag, tlvReader) emit(CapabilityMinimaAttributeSubscriptionState.Success(decodedValue)) } @@ -1955,170 +2082,177 @@ class BasicInformationCluster( emit(CapabilityMinimaAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readProductAppearanceAttribute(): ProductAppearanceAttribute {val ATTRIBUTE_ID: UInt = 20u - suspend fun readProductAppearanceAttribute(): ProductAppearanceAttribute { - val ATTRIBUTE_ID: UInt = 20u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Productappearance attribute not found in response" } + } + + requireNotNull(attributeData) { + "Productappearance attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: BasicInformationClusterProductAppearanceStruct? = - if (tlvReader.isNextTag(AnonymousTag)) { - BasicInformationClusterProductAppearanceStruct.fromTlv(AnonymousTag, tlvReader) - } else { - null - } + val decodedValue: BasicInformationClusterProductAppearanceStruct? = if (tlvReader.isNextTag(AnonymousTag)) { + BasicInformationClusterProductAppearanceStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } + return ProductAppearanceAttribute(decodedValue) } suspend fun subscribeProductAppearanceAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 20u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ProductAppearanceAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ProductAppearanceAttributeSubscriptionState.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) { - "Productappearance attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Productappearance attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: BasicInformationClusterProductAppearanceStruct? = - if (tlvReader.isNextTag(AnonymousTag)) { - BasicInformationClusterProductAppearanceStruct.fromTlv(AnonymousTag, tlvReader) - } else { - null - } + val decodedValue: BasicInformationClusterProductAppearanceStruct? = if (tlvReader.isNextTag(AnonymousTag)) { + BasicInformationClusterProductAppearanceStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } - decodedValue?.let { emit(ProductAppearanceAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ProductAppearanceAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ProductAppearanceAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readSpecificationVersionAttribute(): UInt {val ATTRIBUTE_ID: UInt = 21u - suspend fun readSpecificationVersionAttribute(): UInt { - val ATTRIBUTE_ID: UInt = 21u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Specificationversion attribute not found in response" } + } + + requireNotNull(attributeData) { + "Specificationversion 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 subscribeSpecificationVersionAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 21u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Specificationversion attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Specificationversion attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -2131,77 +2265,80 @@ class BasicInformationCluster( emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readMaxPathsPerInvokeAttribute(): UShort {val ATTRIBUTE_ID: UInt = 22u - suspend fun readMaxPathsPerInvokeAttribute(): UShort { - val ATTRIBUTE_ID: UInt = 22u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Maxpathsperinvoke attribute not found in response" } + } + + requireNotNull(attributeData) { + "Maxpathsperinvoke 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 subscribeMaxPathsPerInvokeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 22u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Maxpathsperinvoke attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Maxpathsperinvoke attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -2214,96 +2351,97 @@ class BasicInformationCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65528u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -2311,96 +2449,97 @@ class BasicInformationCluster( emit(GeneratedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65529u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -2408,94 +2547,97 @@ class BasicInformationCluster( emit(AcceptedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt = 65530u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -2503,94 +2645,97 @@ class BasicInformationCluster( emit(EventListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ID: UInt = 65531u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -2598,76 +2743,81 @@ class BasicInformationCluster( emit(AttributeListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u - 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 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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -2679,77 +2829,80 @@ class BasicInformationCluster( emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 65533u - 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 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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -2762,7 +2915,7 @@ class BasicInformationCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/BinaryInputBasicCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/BinaryInputBasicCluster.kt index a3aeb110b47fbc..6573eb5ba275c1 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/BinaryInputBasicCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/BinaryInputBasicCluster.kt @@ -17,127 +17,164 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.BooleanSubscriptionState import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest -import matter.controller.StringSubscriptionState +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.cluster.structs.* +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath +import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class BinaryInputBasicCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class GeneratedCommandListAttribute(val value: List) +class BinaryInputBasicCluster(private val controller: MatterController, private val endpointId: UShort) {class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } - - suspend fun readActiveTextAttribute(): String? { - val ATTRIBUTE_ID: UInt = 4u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } +suspend fun readActiveTextAttribute(): String? {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}") - } + 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) { "Activetext attribute not found in response" } + } + + requireNotNull(attributeData) { + "Activetext attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + return decodedValue } - suspend fun writeActiveTextAttribute(value: String, timedWriteTimeout: Duration? = null) { + suspend fun writeActiveTextAttribute( + value: String, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 4u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -158,117 +195,127 @@ class BinaryInputBasicCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeActiveTextAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StringSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StringSubscriptionState.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) { "Activetext attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Activetext attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(StringSubscriptionState.Success(it)) } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(StringSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readDescriptionAttribute(): String? { - val ATTRIBUTE_ID: UInt = 28u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readDescriptionAttribute(): String? {val ATTRIBUTE_ID: UInt = 28u + + 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}") - } + 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) { "Description attribute not found in response" } + } + + requireNotNull(attributeData) { + "Description attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + return decodedValue } - suspend fun writeDescriptionAttribute(value: String, timedWriteTimeout: Duration? = null) { + suspend fun writeDescriptionAttribute( + value: String, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 28u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -289,117 +336,127 @@ class BinaryInputBasicCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeDescriptionAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 28u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StringSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StringSubscriptionState.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) { "Description attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Description attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(StringSubscriptionState.Success(it)) } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(StringSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readInactiveTextAttribute(): String? { - val ATTRIBUTE_ID: UInt = 46u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readInactiveTextAttribute(): String? {val ATTRIBUTE_ID: UInt = 46u + + 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}") - } + 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) { "Inactivetext attribute not found in response" } + } + + requireNotNull(attributeData) { + "Inactivetext attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + return decodedValue } - suspend fun writeInactiveTextAttribute(value: String, timedWriteTimeout: Duration? = null) { + suspend fun writeInactiveTextAttribute( + value: String, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 46u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -420,112 +477,123 @@ class BinaryInputBasicCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeInactiveTextAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 46u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StringSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StringSubscriptionState.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) { "Inactivetext attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Inactivetext attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(StringSubscriptionState.Success(it)) } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(StringSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readOutOfServiceAttribute(): Boolean { - val ATTRIBUTE_ID: UInt = 81u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readOutOfServiceAttribute(): Boolean {val ATTRIBUTE_ID: UInt = 81u + + 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}") - } + 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) { "Outofservice attribute not found in response" } + } + + requireNotNull(attributeData) { + "Outofservice attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Boolean = tlvReader.getBoolean(AnonymousTag) + return decodedValue } - suspend fun writeOutOfServiceAttribute(value: Boolean, timedWriteTimeout: Duration? = null) { + suspend fun writeOutOfServiceAttribute( + value: Boolean, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 81u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -546,45 +614,43 @@ class BinaryInputBasicCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeOutOfServiceAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 81u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Outofservice attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Outofservice attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -596,148 +662,165 @@ class BinaryInputBasicCluster( emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readPolarityAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 84u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readPolarityAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 84u + + 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}") - } + 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) { "Polarity attribute not found in response" } + } + + requireNotNull(attributeData) { + "Polarity 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribePolarityAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 84u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Polarity attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Polarity 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)) } + 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 readPresentValueAttribute(): Boolean { - val ATTRIBUTE_ID: UInt = 85u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readPresentValueAttribute(): Boolean {val ATTRIBUTE_ID: UInt = 85u + + 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}") - } + 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) { "Presentvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Presentvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Boolean = tlvReader.getBoolean(AnonymousTag) + return decodedValue } - suspend fun writePresentValueAttribute(value: Boolean, timedWriteTimeout: Duration? = null) { + suspend fun writePresentValueAttribute( + value: Boolean, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 85u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -758,45 +841,43 @@ class BinaryInputBasicCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribePresentValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 85u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Presentvalue attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Presentvalue attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -808,62 +889,72 @@ class BinaryInputBasicCluster( emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readReliabilityAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 103u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readReliabilityAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 103u + + 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}") - } + 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) { "Reliability attribute not found in response" } + } + + requireNotNull(attributeData) { + "Reliability 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } - suspend fun writeReliabilityAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeReliabilityAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 103u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -884,131 +975,136 @@ class BinaryInputBasicCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeReliabilityAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 103u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Reliability attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Reliability 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)) } + 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 readStatusFlagsAttribute(): UByte { - val ATTRIBUTE_ID: UInt = 111u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readStatusFlagsAttribute(): UByte {val ATTRIBUTE_ID: UInt = 111u + + 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}") - } + 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) { "Statusflags attribute not found in response" } + } + + requireNotNull(attributeData) { + "Statusflags 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 subscribeStatusFlagsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 111u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Statusflags attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Statusflags attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -1020,189 +1116,194 @@ class BinaryInputBasicCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readApplicationTypeAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 256u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readApplicationTypeAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 256u + + 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}") - } + 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) { "Applicationtype attribute not found in response" } + } + + requireNotNull(attributeData) { + "Applicationtype attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeApplicationTypeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 256u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Applicationtype attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Applicationtype attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1210,96 +1311,97 @@ class BinaryInputBasicCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1307,94 +1409,97 @@ class BinaryInputBasicCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1402,94 +1507,97 @@ class BinaryInputBasicCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1497,76 +1605,81 @@ class BinaryInputBasicCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1578,77 +1691,80 @@ class BinaryInputBasicCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1661,7 +1777,7 @@ class BinaryInputBasicCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/BindingCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/BindingCluster.kt index d1309a2bd28ca4..a29864051af0d1 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/BindingCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/BindingCluster.kt @@ -17,141 +17,183 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.UIntSubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState +import matter.controller.UByteSubscriptionState import matter.controller.UShortSubscriptionState +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.cluster.structs.* +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath +import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class BindingCluster(private val controller: MatterController, private val endpointId: UShort) { - class BindingAttribute(val value: List) +class BindingCluster(private val controller: MatterController, private val endpointId: UShort) {class BindingAttribute( + val value: List + ) sealed class BindingAttributeSubscriptionState { - data class Success(val value: List) : - BindingAttributeSubscriptionState() - + data class Success( + val value: List + ) : BindingAttributeSubscriptionState() + data class Error(val exception: Exception) : BindingAttributeSubscriptionState() - object SubscriptionEstablished : BindingAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : BindingAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } - - suspend fun readBindingAttribute(): BindingAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } +suspend fun readBindingAttribute(): BindingAttribute {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}") - } + 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) { "Binding attribute not found in response" } + } + + requireNotNull(attributeData) { + "Binding 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(BindingClusterTargetStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(BindingClusterTargetStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + return BindingAttribute(decodedValue) } suspend fun writeBindingAttribute( value: List, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startArray(AnonymousTag) - for (item in value.iterator()) { - item.toTlv(AnonymousTag, tlvWriter) - } - tlvWriter.endArray() + for (item in value.iterator()) { + item.toTlv(AnonymousTag, tlvWriter) + } + tlvWriter.endArray() val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -172,56 +214,53 @@ class BindingCluster(private val controller: MatterController, private val endpo throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeBindingAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - BindingAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(BindingAttributeSubscriptionState.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) { "Binding attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Binding 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(BindingClusterTargetStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(BindingClusterTargetStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(BindingAttributeSubscriptionState.Success(decodedValue)) } @@ -229,96 +268,97 @@ class BindingCluster(private val controller: MatterController, private val endpo emit(BindingAttributeSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -326,96 +366,97 @@ class BindingCluster(private val controller: MatterController, private val endpo 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -423,94 +464,97 @@ class BindingCluster(private val controller: MatterController, private val endpo 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -518,94 +562,97 @@ class BindingCluster(private val controller: MatterController, private val endpo 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -613,76 +660,81 @@ class BindingCluster(private val controller: MatterController, private val endpo 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -694,77 +746,80 @@ class BindingCluster(private val controller: MatterController, private val endpo 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -777,7 +832,7 @@ class BindingCluster(private val controller: MatterController, private val endpo emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/BooleanStateCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/BooleanStateCluster.kt index f7b13245077204..0c44c4bb081d4a 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/BooleanStateCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/BooleanStateCluster.kt @@ -17,135 +17,173 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.BooleanSubscriptionState import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.UIntSubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState +import matter.controller.UByteSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath +import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader +import matter.tlv.TlvWriter -class BooleanStateCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class GeneratedCommandListAttribute(val value: List) +class BooleanStateCluster(private val controller: MatterController, private val endpointId: UShort) {class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } - - suspend fun readStateValueAttribute(): Boolean { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } +suspend fun readStateValueAttribute(): Boolean {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}") - } + 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) { "Statevalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Statevalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Boolean = tlvReader.getBoolean(AnonymousTag) + return decodedValue } suspend fun subscribeStateValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Statevalue attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Statevalue attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -157,96 +195,97 @@ class BooleanStateCluster( emit(BooleanSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -254,96 +293,97 @@ class BooleanStateCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -351,94 +391,97 @@ class BooleanStateCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -446,94 +489,97 @@ class BooleanStateCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -541,76 +587,81 @@ class BooleanStateCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -622,77 +673,80 @@ class BooleanStateCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -705,7 +759,7 @@ class BooleanStateCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/BooleanStateConfigurationCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/BooleanStateConfigurationCluster.kt index f38f944df17693..a92edf5556e383 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/BooleanStateConfigurationCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/BooleanStateConfigurationCluster.kt @@ -17,177 +17,208 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.cluster.structs.* +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class BooleanStateConfigurationCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class GeneratedCommandListAttribute(val value: List) +class BooleanStateConfigurationCluster(private val controller: MatterController, private val endpointId: UShort) {class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun suppressAlarm(alarmsToSuppress: UByte, timedInvokeTimeout: Duration? = null) { + suspend fun suppressAlarm(alarmsToSuppress: UByte + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_ALARMS_TO_SUPPRESS_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_ALARMS_TO_SUPPRESS_REQ), alarmsToSuppress) + tlvWriter.put(ContextSpecificTag(TAG_ALARMS_TO_SUPPRESS_REQ), alarmsToSuppress) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun enableDisableAlarm( - alarmsToEnableDisable: UByte, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun enableDisableAlarm(alarmsToEnableDisable: UByte + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 1u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_ALARMS_TO_ENABLE_DISABLE_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_ALARMS_TO_ENABLE_DISABLE_REQ), alarmsToEnableDisable) + tlvWriter.put(ContextSpecificTag(TAG_ALARMS_TO_ENABLE_DISABLE_REQ), alarmsToEnableDisable) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - - suspend fun readCurrentSensitivityLevelAttribute(): 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)) - +suspend fun readCurrentSensitivityLevelAttribute(): 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}") - } + 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) { "Currentsensitivitylevel attribute not found in response" } + } + + requireNotNull(attributeData) { + "Currentsensitivitylevel 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun writeCurrentSensitivityLevelAttribute( value: UByte, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -208,798 +239,831 @@ class BooleanStateConfigurationCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeCurrentSensitivityLevelAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Currentsensitivitylevel attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Currentsensitivitylevel 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)) } + 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 readSupportedSensitivityLevelsAttribute(): 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)) - +suspend fun readSupportedSensitivityLevelsAttribute(): 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}") - } + 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) { "Supportedsensitivitylevels attribute not found in response" } + } + + requireNotNull(attributeData) { + "Supportedsensitivitylevels 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeSupportedSensitivityLevelsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Supportedsensitivitylevels attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Supportedsensitivitylevels 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)) } + 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 readDefaultSensitivityLevelAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readDefaultSensitivityLevelAttribute(): UByte? {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}") - } + 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) { "Defaultsensitivitylevel attribute not found in response" } + } + + requireNotNull(attributeData) { + "Defaultsensitivitylevel 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeDefaultSensitivityLevelAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Defaultsensitivitylevel attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Defaultsensitivitylevel 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)) } + 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 readAlarmsActiveAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readAlarmsActiveAttribute(): UByte? {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}") - } + 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) { "Alarmsactive attribute not found in response" } + } + + requireNotNull(attributeData) { + "Alarmsactive 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeAlarmsActiveAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Alarmsactive attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Alarmsactive 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)) } + 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 readAlarmsSuppressedAttribute(): 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)) - +suspend fun readAlarmsSuppressedAttribute(): 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}") - } + 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) { "Alarmssuppressed attribute not found in response" } + } + + requireNotNull(attributeData) { + "Alarmssuppressed 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeAlarmsSuppressedAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Alarmssuppressed attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Alarmssuppressed 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)) } + 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 readAlarmsEnabledAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 5u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readAlarmsEnabledAttribute(): UByte? {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}") - } + 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) { "Alarmsenabled attribute not found in response" } + } + + requireNotNull(attributeData) { + "Alarmsenabled 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeAlarmsEnabledAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Alarmsenabled attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Alarmsenabled 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)) } + 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 readAlarmsSupportedAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 6u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readAlarmsSupportedAttribute(): UByte? {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}") - } + 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) { "Alarmssupported attribute not found in response" } + } + + requireNotNull(attributeData) { + "Alarmssupported 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeAlarmsSupportedAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Alarmssupported attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Alarmssupported 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)) } + 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 readSensorFaultAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 7u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readSensorFaultAttribute(): UShort? {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}") - } + 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) { "Sensorfault attribute not found in response" } + } + + requireNotNull(attributeData) { + "Sensorfault 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeSensorFaultAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Sensorfault attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Sensorfault 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)) } + 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 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1007,96 +1071,97 @@ class BooleanStateConfigurationCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1104,94 +1169,97 @@ class BooleanStateConfigurationCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1199,94 +1267,97 @@ class BooleanStateConfigurationCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1294,76 +1365,81 @@ class BooleanStateConfigurationCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1375,77 +1451,80 @@ class BooleanStateConfigurationCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1458,7 +1537,7 @@ class BooleanStateConfigurationCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/BridgedDeviceBasicInformationCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/BridgedDeviceBasicInformationCluster.kt index 8e56362d8da349..837b3588937ed6 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/BridgedDeviceBasicInformationCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/BridgedDeviceBasicInformationCluster.kt @@ -17,528 +17,587 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration 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.StringSubscriptionState +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.UIntSubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState +import matter.controller.UByteSubscriptionState import matter.controller.UShortSubscriptionState +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.cluster.structs.* +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class BridgedDeviceBasicInformationCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class ProductAppearanceAttribute( +class BridgedDeviceBasicInformationCluster(private val controller: MatterController, private val endpointId: UShort) {class ProductAppearanceAttribute( val value: BridgedDeviceBasicInformationClusterProductAppearanceStruct? ) sealed class ProductAppearanceAttributeSubscriptionState { - data class Success(val value: BridgedDeviceBasicInformationClusterProductAppearanceStruct?) : - ProductAppearanceAttributeSubscriptionState() - + data class Success( + val value: BridgedDeviceBasicInformationClusterProductAppearanceStruct? + ) : ProductAppearanceAttributeSubscriptionState() + data class Error(val exception: Exception) : ProductAppearanceAttributeSubscriptionState() - object SubscriptionEstablished : ProductAppearanceAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : ProductAppearanceAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun keepActive(stayActiveDuration: UInt, timedInvokeTimeout: Duration? = null) { + suspend fun keepActive(stayActiveDuration: UInt + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 128u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_STAY_ACTIVE_DURATION_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_STAY_ACTIVE_DURATION_REQ), stayActiveDuration) + tlvWriter.put(ContextSpecificTag(TAG_STAY_ACTIVE_DURATION_REQ), stayActiveDuration) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - - suspend fun readVendorNameAttribute(): String? { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readVendorNameAttribute(): String? {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}") - } + 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) { "Vendorname attribute not found in response" } + } + + requireNotNull(attributeData) { + "Vendorname attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeVendorNameAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StringSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StringSubscriptionState.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) { "Vendorname attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Vendorname attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(StringSubscriptionState.Success(it)) } + decodedValue?.let { + emit(StringSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readVendorIDAttribute(): 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)) - +suspend fun readVendorIDAttribute(): 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}") - } + 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) { "Vendorid attribute not found in response" } + } + + requireNotNull(attributeData) { + "Vendorid 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeVendorIDAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Vendorid attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Vendorid 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readProductNameAttribute(): String? { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readProductNameAttribute(): String? {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}") - } + 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) { "Productname attribute not found in response" } + } + + requireNotNull(attributeData) { + "Productname attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeProductNameAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StringSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StringSubscriptionState.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) { "Productname attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Productname attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(StringSubscriptionState.Success(it)) } + decodedValue?.let { + emit(StringSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readProductIDAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 4u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readProductIDAttribute(): UShort? {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}") - } + 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) { "Productid attribute not found in response" } + } + + requireNotNull(attributeData) { + "Productid 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeProductIDAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Productid attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Productid 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readNodeLabelAttribute(): String? { - val ATTRIBUTE_ID: UInt = 5u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readNodeLabelAttribute(): String? {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}") - } + 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) { "Nodelabel attribute not found in response" } + } + + requireNotNull(attributeData) { + "Nodelabel attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + return decodedValue } - suspend fun writeNodeLabelAttribute(value: String, timedWriteTimeout: Duration? = null) { + suspend fun writeNodeLabelAttribute( + value: String, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 5u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -559,960 +618,1009 @@ class BridgedDeviceBasicInformationCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNodeLabelAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StringSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StringSubscriptionState.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) { "Nodelabel attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Nodelabel attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(StringSubscriptionState.Success(it)) } + decodedValue?.let { + emit(StringSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readHardwareVersionAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 7u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readHardwareVersionAttribute(): UShort? {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}") - } + 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) { "Hardwareversion attribute not found in response" } + } + + requireNotNull(attributeData) { + "Hardwareversion 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeHardwareVersionAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Hardwareversion attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Hardwareversion 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readHardwareVersionStringAttribute(): String? { - val ATTRIBUTE_ID: UInt = 8u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readHardwareVersionStringAttribute(): String? {val ATTRIBUTE_ID: UInt = 8u + + 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}") - } + 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) { "Hardwareversionstring attribute not found in response" } + } + + requireNotNull(attributeData) { + "Hardwareversionstring attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeHardwareVersionStringAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StringSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StringSubscriptionState.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) { - "Hardwareversionstring attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Hardwareversionstring attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(StringSubscriptionState.Success(it)) } + decodedValue?.let { + emit(StringSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readSoftwareVersionAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 9u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readSoftwareVersionAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 9u + + 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}") - } + 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) { "Softwareversion attribute not found in response" } + } + + requireNotNull(attributeData) { + "Softwareversion attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeSoftwareVersionAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Softwareversion attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Softwareversion attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readSoftwareVersionStringAttribute(): String? { - val ATTRIBUTE_ID: UInt = 10u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readSoftwareVersionStringAttribute(): String? {val ATTRIBUTE_ID: UInt = 10u + + 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}") - } + 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) { "Softwareversionstring attribute not found in response" } + } + + requireNotNull(attributeData) { + "Softwareversionstring attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeSoftwareVersionStringAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StringSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StringSubscriptionState.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) { - "Softwareversionstring attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Softwareversionstring attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(StringSubscriptionState.Success(it)) } + decodedValue?.let { + emit(StringSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readManufacturingDateAttribute(): String? { - val ATTRIBUTE_ID: UInt = 11u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readManufacturingDateAttribute(): String? {val ATTRIBUTE_ID: UInt = 11u + + 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}") - } + 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) { "Manufacturingdate attribute not found in response" } + } + + requireNotNull(attributeData) { + "Manufacturingdate attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeManufacturingDateAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 11u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StringSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StringSubscriptionState.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) { - "Manufacturingdate attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Manufacturingdate attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(StringSubscriptionState.Success(it)) } + decodedValue?.let { + emit(StringSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readPartNumberAttribute(): String? { - val ATTRIBUTE_ID: UInt = 12u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readPartNumberAttribute(): String? {val ATTRIBUTE_ID: UInt = 12u + + 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}") - } + 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) { "Partnumber attribute not found in response" } + } + + requireNotNull(attributeData) { + "Partnumber attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribePartNumberAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 12u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StringSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StringSubscriptionState.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) { "Partnumber attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Partnumber attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(StringSubscriptionState.Success(it)) } + decodedValue?.let { + emit(StringSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readProductURLAttribute(): String? { - val ATTRIBUTE_ID: UInt = 13u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readProductURLAttribute(): String? {val ATTRIBUTE_ID: UInt = 13u + + 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}") - } + 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) { "Producturl attribute not found in response" } + } + + requireNotNull(attributeData) { + "Producturl attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeProductURLAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 13u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StringSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StringSubscriptionState.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) { "Producturl attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Producturl attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(StringSubscriptionState.Success(it)) } + decodedValue?.let { + emit(StringSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readProductLabelAttribute(): String? { - val ATTRIBUTE_ID: UInt = 14u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readProductLabelAttribute(): String? {val ATTRIBUTE_ID: UInt = 14u + + 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}") - } + 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) { "Productlabel attribute not found in response" } + } + + requireNotNull(attributeData) { + "Productlabel attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeProductLabelAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 14u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StringSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StringSubscriptionState.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) { "Productlabel attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Productlabel attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(StringSubscriptionState.Success(it)) } + decodedValue?.let { + emit(StringSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readSerialNumberAttribute(): String? { - val ATTRIBUTE_ID: UInt = 15u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readSerialNumberAttribute(): String? {val ATTRIBUTE_ID: UInt = 15u + + 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}") - } + 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) { "Serialnumber attribute not found in response" } + } + + requireNotNull(attributeData) { + "Serialnumber attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeSerialNumberAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 15u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StringSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StringSubscriptionState.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) { "Serialnumber attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Serialnumber attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(StringSubscriptionState.Success(it)) } + decodedValue?.let { + emit(StringSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readReachableAttribute(): Boolean { - val ATTRIBUTE_ID: UInt = 17u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readReachableAttribute(): Boolean {val ATTRIBUTE_ID: UInt = 17u + + 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}") - } + 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) { "Reachable attribute not found in response" } + } + + requireNotNull(attributeData) { + "Reachable attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Boolean = tlvReader.getBoolean(AnonymousTag) + return decodedValue } suspend fun subscribeReachableAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 17u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Reachable attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Reachable attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -1524,76 +1632,81 @@ class BridgedDeviceBasicInformationCluster( emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readUniqueIDAttribute(): String { - val ATTRIBUTE_ID: UInt = 18u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readUniqueIDAttribute(): String {val ATTRIBUTE_ID: UInt = 18u + + 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}") - } + 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) { "Uniqueid attribute not found in response" } + } + + requireNotNull(attributeData) { + "Uniqueid attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: String = tlvReader.getString(AnonymousTag) + return decodedValue } suspend fun subscribeUniqueIDAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 18u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StringSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StringSubscriptionState.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) { "Uniqueid attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Uniqueid attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -1605,192 +1718,194 @@ class BridgedDeviceBasicInformationCluster( emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readProductAppearanceAttribute(): ProductAppearanceAttribute { - val ATTRIBUTE_ID: UInt = 20u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readProductAppearanceAttribute(): ProductAppearanceAttribute {val ATTRIBUTE_ID: UInt = 20u + + 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}") - } + 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) { "Productappearance attribute not found in response" } + } + + requireNotNull(attributeData) { + "Productappearance attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: BridgedDeviceBasicInformationClusterProductAppearanceStruct? = - if (tlvReader.isNextTag(AnonymousTag)) { - BridgedDeviceBasicInformationClusterProductAppearanceStruct.fromTlv(AnonymousTag, tlvReader) - } else { - null - } + val decodedValue: BridgedDeviceBasicInformationClusterProductAppearanceStruct? = if (tlvReader.isNextTag(AnonymousTag)) { + BridgedDeviceBasicInformationClusterProductAppearanceStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } + return ProductAppearanceAttribute(decodedValue) } suspend fun subscribeProductAppearanceAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 20u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ProductAppearanceAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ProductAppearanceAttributeSubscriptionState.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) { - "Productappearance attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Productappearance attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: BridgedDeviceBasicInformationClusterProductAppearanceStruct? = - if (tlvReader.isNextTag(AnonymousTag)) { - BridgedDeviceBasicInformationClusterProductAppearanceStruct.fromTlv( - AnonymousTag, - tlvReader, - ) - } else { - null - } - - decodedValue?.let { emit(ProductAppearanceAttributeSubscriptionState.Success(it)) } + val decodedValue: BridgedDeviceBasicInformationClusterProductAppearanceStruct? = if (tlvReader.isNextTag(AnonymousTag)) { + BridgedDeviceBasicInformationClusterProductAppearanceStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } + + decodedValue?.let { + emit(ProductAppearanceAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ProductAppearanceAttributeSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1798,96 +1913,97 @@ class BridgedDeviceBasicInformationCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1895,94 +2011,97 @@ class BridgedDeviceBasicInformationCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1990,94 +2109,97 @@ class BridgedDeviceBasicInformationCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -2085,76 +2207,81 @@ class BridgedDeviceBasicInformationCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -2166,77 +2293,80 @@ class BridgedDeviceBasicInformationCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -2249,7 +2379,7 @@ class BridgedDeviceBasicInformationCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/CarbonDioxideConcentrationMeasurementCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/CarbonDioxideConcentrationMeasurementCluster.kt index c3353d6a7a7f8d..32fbbb01553d32 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/CarbonDioxideConcentrationMeasurementCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/CarbonDioxideConcentrationMeasurementCluster.kt @@ -17,1273 +17,1371 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.FloatSubscriptionState import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath +import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader +import matter.tlv.TlvWriter -class CarbonDioxideConcentrationMeasurementCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class MeasuredValueAttribute(val value: Float?) +class CarbonDioxideConcentrationMeasurementCluster(private val controller: MatterController, private val endpointId: UShort) {class MeasuredValueAttribute( + val value: Float? + ) sealed class MeasuredValueAttributeSubscriptionState { - data class Success(val value: Float?) : MeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Float? + ) : MeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() - } - - class MinMeasuredValueAttribute(val value: Float?) + object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() + } +class MinMeasuredValueAttribute( + val value: Float? + ) sealed class MinMeasuredValueAttributeSubscriptionState { - data class Success(val value: Float?) : MinMeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Float? + ) : MinMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MinMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() - } - - class MaxMeasuredValueAttribute(val value: Float?) + object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() + } +class MaxMeasuredValueAttribute( + val value: Float? + ) sealed class MaxMeasuredValueAttributeSubscriptionState { - data class Success(val value: Float?) : MaxMeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Float? + ) : MaxMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MaxMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() - } - - class PeakMeasuredValueAttribute(val value: Float?) + object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() + } +class PeakMeasuredValueAttribute( + val value: Float? + ) sealed class PeakMeasuredValueAttributeSubscriptionState { - data class Success(val value: Float?) : PeakMeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Float? + ) : PeakMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : PeakMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : PeakMeasuredValueAttributeSubscriptionState() - } - - class AverageMeasuredValueAttribute(val value: Float?) + object SubscriptionEstablished : PeakMeasuredValueAttributeSubscriptionState() + } +class AverageMeasuredValueAttribute( + val value: Float? + ) sealed class AverageMeasuredValueAttributeSubscriptionState { - data class Success(val value: Float?) : AverageMeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Float? + ) : AverageMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : AverageMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : AverageMeasuredValueAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : AverageMeasuredValueAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } - - suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } +suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute {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}") - } + 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) { "Measuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Measuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MeasuredValueAttribute(decodedValue) } suspend fun subscribeMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MeasuredValueAttributeSubscriptionState.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) { "Measuredvalue attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Measuredvalue attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute {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}") - } + 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) { "Minmeasuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Minmeasuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MinMeasuredValueAttribute(decodedValue) } suspend fun subscribeMinMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MinMeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MinMeasuredValueAttributeSubscriptionState.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) { - "Minmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Minmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MinMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute {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}") - } + 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) { "Maxmeasuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Maxmeasuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MaxMeasuredValueAttribute(decodedValue) } suspend fun subscribeMaxMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MaxMeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MaxMeasuredValueAttributeSubscriptionState.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) { - "Maxmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Maxmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MaxMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readPeakMeasuredValueAttribute(): PeakMeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readPeakMeasuredValueAttribute(): PeakMeasuredValueAttribute {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}") - } + 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) { "Peakmeasuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Peakmeasuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return PeakMeasuredValueAttribute(decodedValue) } suspend fun subscribePeakMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - PeakMeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(PeakMeasuredValueAttributeSubscriptionState.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) { - "Peakmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Peakmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(PeakMeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(PeakMeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(PeakMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readPeakMeasuredValueWindowAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 4u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readPeakMeasuredValueWindowAttribute(): UInt? {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}") - } + 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) { "Peakmeasuredvaluewindow attribute not found in response" } + } + + requireNotNull(attributeData) { + "Peakmeasuredvaluewindow attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribePeakMeasuredValueWindowAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Peakmeasuredvaluewindow attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Peakmeasuredvaluewindow attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readAverageMeasuredValueAttribute(): AverageMeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 5u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readAverageMeasuredValueAttribute(): AverageMeasuredValueAttribute {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}") - } + 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) { "Averagemeasuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Averagemeasuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return AverageMeasuredValueAttribute(decodedValue) } suspend fun subscribeAverageMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - AverageMeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(AverageMeasuredValueAttributeSubscriptionState.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) { - "Averagemeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Averagemeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(AverageMeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(AverageMeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(AverageMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readAverageMeasuredValueWindowAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 6u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readAverageMeasuredValueWindowAttribute(): UInt? {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}") - } + 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) { "Averagemeasuredvaluewindow attribute not found in response" } + } + + requireNotNull(attributeData) { + "Averagemeasuredvaluewindow attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeAverageMeasuredValueWindowAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Averagemeasuredvaluewindow attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Averagemeasuredvaluewindow attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readUncertaintyAttribute(): Float? { - val ATTRIBUTE_ID: UInt = 7u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readUncertaintyAttribute(): Float? {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}") - } + 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) { "Uncertainty attribute not found in response" } + } + + requireNotNull(attributeData) { + "Uncertainty attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } + val decodedValue: Float? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeUncertaintyAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - FloatSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(FloatSubscriptionState.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) { "Uncertainty attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Uncertainty attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(FloatSubscriptionState.Success(it)) } + val decodedValue: Float? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(FloatSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(FloatSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readMeasurementUnitAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 8u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMeasurementUnitAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 8u + + 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}") - } + 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) { "Measurementunit attribute not found in response" } + } + + requireNotNull(attributeData) { + "Measurementunit 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeMeasurementUnitAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Measurementunit attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Measurementunit 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)) } + 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 readMeasurementMediumAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 9u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMeasurementMediumAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 9u + + 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}") - } + 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) { "Measurementmedium attribute not found in response" } + } + + requireNotNull(attributeData) { + "Measurementmedium 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeMeasurementMediumAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Measurementmedium attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Measurementmedium 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)) } + 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 readLevelValueAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 10u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readLevelValueAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 10u + + 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}") - } + 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) { "Levelvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Levelvalue 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeLevelValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Levelvalue attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Levelvalue 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)) } + 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 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1291,96 +1389,97 @@ class CarbonDioxideConcentrationMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1388,94 +1487,97 @@ class CarbonDioxideConcentrationMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1483,94 +1585,97 @@ class CarbonDioxideConcentrationMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1578,76 +1683,81 @@ class CarbonDioxideConcentrationMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1659,77 +1769,80 @@ class CarbonDioxideConcentrationMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1742,12 +1855,11 @@ class CarbonDioxideConcentrationMeasurementCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { - private val logger = - Logger.getLogger(CarbonDioxideConcentrationMeasurementCluster::class.java.name) + private val logger = Logger.getLogger(CarbonDioxideConcentrationMeasurementCluster::class.java.name) const val CLUSTER_ID: UInt = 1037u } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/CarbonMonoxideConcentrationMeasurementCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/CarbonMonoxideConcentrationMeasurementCluster.kt index 559ccd6f86ca26..c97c2f69df0087 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/CarbonMonoxideConcentrationMeasurementCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/CarbonMonoxideConcentrationMeasurementCluster.kt @@ -17,1273 +17,1371 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.FloatSubscriptionState import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath +import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader +import matter.tlv.TlvWriter -class CarbonMonoxideConcentrationMeasurementCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class MeasuredValueAttribute(val value: Float?) +class CarbonMonoxideConcentrationMeasurementCluster(private val controller: MatterController, private val endpointId: UShort) {class MeasuredValueAttribute( + val value: Float? + ) sealed class MeasuredValueAttributeSubscriptionState { - data class Success(val value: Float?) : MeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Float? + ) : MeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() - } - - class MinMeasuredValueAttribute(val value: Float?) + object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() + } +class MinMeasuredValueAttribute( + val value: Float? + ) sealed class MinMeasuredValueAttributeSubscriptionState { - data class Success(val value: Float?) : MinMeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Float? + ) : MinMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MinMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() - } - - class MaxMeasuredValueAttribute(val value: Float?) + object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() + } +class MaxMeasuredValueAttribute( + val value: Float? + ) sealed class MaxMeasuredValueAttributeSubscriptionState { - data class Success(val value: Float?) : MaxMeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Float? + ) : MaxMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MaxMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() - } - - class PeakMeasuredValueAttribute(val value: Float?) + object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() + } +class PeakMeasuredValueAttribute( + val value: Float? + ) sealed class PeakMeasuredValueAttributeSubscriptionState { - data class Success(val value: Float?) : PeakMeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Float? + ) : PeakMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : PeakMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : PeakMeasuredValueAttributeSubscriptionState() - } - - class AverageMeasuredValueAttribute(val value: Float?) + object SubscriptionEstablished : PeakMeasuredValueAttributeSubscriptionState() + } +class AverageMeasuredValueAttribute( + val value: Float? + ) sealed class AverageMeasuredValueAttributeSubscriptionState { - data class Success(val value: Float?) : AverageMeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Float? + ) : AverageMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : AverageMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : AverageMeasuredValueAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : AverageMeasuredValueAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } - - suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } +suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute {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}") - } + 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) { "Measuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Measuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MeasuredValueAttribute(decodedValue) } suspend fun subscribeMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MeasuredValueAttributeSubscriptionState.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) { "Measuredvalue attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Measuredvalue attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute {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}") - } + 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) { "Minmeasuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Minmeasuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MinMeasuredValueAttribute(decodedValue) } suspend fun subscribeMinMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MinMeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MinMeasuredValueAttributeSubscriptionState.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) { - "Minmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Minmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MinMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute {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}") - } + 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) { "Maxmeasuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Maxmeasuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MaxMeasuredValueAttribute(decodedValue) } suspend fun subscribeMaxMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MaxMeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MaxMeasuredValueAttributeSubscriptionState.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) { - "Maxmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Maxmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MaxMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readPeakMeasuredValueAttribute(): PeakMeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readPeakMeasuredValueAttribute(): PeakMeasuredValueAttribute {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}") - } + 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) { "Peakmeasuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Peakmeasuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return PeakMeasuredValueAttribute(decodedValue) } suspend fun subscribePeakMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - PeakMeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(PeakMeasuredValueAttributeSubscriptionState.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) { - "Peakmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Peakmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(PeakMeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(PeakMeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(PeakMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readPeakMeasuredValueWindowAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 4u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readPeakMeasuredValueWindowAttribute(): UInt? {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}") - } + 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) { "Peakmeasuredvaluewindow attribute not found in response" } + } + + requireNotNull(attributeData) { + "Peakmeasuredvaluewindow attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribePeakMeasuredValueWindowAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Peakmeasuredvaluewindow attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Peakmeasuredvaluewindow attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readAverageMeasuredValueAttribute(): AverageMeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 5u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readAverageMeasuredValueAttribute(): AverageMeasuredValueAttribute {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}") - } + 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) { "Averagemeasuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Averagemeasuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return AverageMeasuredValueAttribute(decodedValue) } suspend fun subscribeAverageMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - AverageMeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(AverageMeasuredValueAttributeSubscriptionState.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) { - "Averagemeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Averagemeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(AverageMeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(AverageMeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(AverageMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readAverageMeasuredValueWindowAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 6u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readAverageMeasuredValueWindowAttribute(): UInt? {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}") - } + 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) { "Averagemeasuredvaluewindow attribute not found in response" } + } + + requireNotNull(attributeData) { + "Averagemeasuredvaluewindow attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeAverageMeasuredValueWindowAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Averagemeasuredvaluewindow attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Averagemeasuredvaluewindow attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readUncertaintyAttribute(): Float? { - val ATTRIBUTE_ID: UInt = 7u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readUncertaintyAttribute(): Float? {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}") - } + 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) { "Uncertainty attribute not found in response" } + } + + requireNotNull(attributeData) { + "Uncertainty attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } + val decodedValue: Float? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeUncertaintyAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - FloatSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(FloatSubscriptionState.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) { "Uncertainty attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Uncertainty attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(FloatSubscriptionState.Success(it)) } + val decodedValue: Float? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(FloatSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(FloatSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readMeasurementUnitAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 8u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMeasurementUnitAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 8u + + 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}") - } + 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) { "Measurementunit attribute not found in response" } + } + + requireNotNull(attributeData) { + "Measurementunit 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeMeasurementUnitAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Measurementunit attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Measurementunit 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)) } + 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 readMeasurementMediumAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 9u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMeasurementMediumAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 9u + + 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}") - } + 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) { "Measurementmedium attribute not found in response" } + } + + requireNotNull(attributeData) { + "Measurementmedium 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeMeasurementMediumAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Measurementmedium attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Measurementmedium 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)) } + 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 readLevelValueAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 10u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readLevelValueAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 10u + + 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}") - } + 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) { "Levelvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Levelvalue 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeLevelValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Levelvalue attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Levelvalue 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)) } + 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 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1291,96 +1389,97 @@ class CarbonMonoxideConcentrationMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1388,94 +1487,97 @@ class CarbonMonoxideConcentrationMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1483,94 +1585,97 @@ class CarbonMonoxideConcentrationMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1578,76 +1683,81 @@ class CarbonMonoxideConcentrationMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1659,77 +1769,80 @@ class CarbonMonoxideConcentrationMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1742,12 +1855,11 @@ class CarbonMonoxideConcentrationMeasurementCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { - private val logger = - Logger.getLogger(CarbonMonoxideConcentrationMeasurementCluster::class.java.name) + private val logger = Logger.getLogger(CarbonMonoxideConcentrationMeasurementCluster::class.java.name) const val CLUSTER_ID: UInt = 1036u } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/ChannelCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/ChannelCluster.kt index 67eccfdb2126b3..f3bee01c8e2643 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/ChannelCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/ChannelCluster.kt @@ -17,127 +17,166 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.UIntSubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState +import matter.controller.UByteSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter class ChannelCluster(private val controller: MatterController, private val endpointId: UShort) { - class ChangeChannelResponse(val status: UByte, val data: String?) + class ChangeChannelResponse( + val status: UByte, + val data: String? + ) class ProgramGuideResponse( - val paging: ChannelClusterChannelPagingStruct, - val programList: List, + val paging: ChannelClusterChannelPagingStruct, + val programList: List + ) +class ChannelListAttribute( + val value: List? ) - - class ChannelListAttribute(val value: List?) sealed class ChannelListAttributeSubscriptionState { - data class Success(val value: List?) : - ChannelListAttributeSubscriptionState() - + data class Success( + val value: List? + ) : ChannelListAttributeSubscriptionState() + data class Error(val exception: Exception) : ChannelListAttributeSubscriptionState() - object SubscriptionEstablished : ChannelListAttributeSubscriptionState() - } - - class LineupAttribute(val value: ChannelClusterLineupInfoStruct?) + object SubscriptionEstablished : ChannelListAttributeSubscriptionState() + } +class LineupAttribute( + val value: ChannelClusterLineupInfoStruct? + ) sealed class LineupAttributeSubscriptionState { - data class Success(val value: ChannelClusterLineupInfoStruct?) : - LineupAttributeSubscriptionState() - + data class Success( + val value: ChannelClusterLineupInfoStruct? + ) : LineupAttributeSubscriptionState() + data class Error(val exception: Exception) : LineupAttributeSubscriptionState() - object SubscriptionEstablished : LineupAttributeSubscriptionState() - } - - class CurrentChannelAttribute(val value: ChannelClusterChannelInfoStruct?) + object SubscriptionEstablished : LineupAttributeSubscriptionState() + } +class CurrentChannelAttribute( + val value: ChannelClusterChannelInfoStruct? + ) sealed class CurrentChannelAttributeSubscriptionState { - data class Success(val value: ChannelClusterChannelInfoStruct?) : - CurrentChannelAttributeSubscriptionState() - + data class Success( + val value: ChannelClusterChannelInfoStruct? + ) : CurrentChannelAttributeSubscriptionState() + data class Error(val exception: Exception) : CurrentChannelAttributeSubscriptionState() - object SubscriptionEstablished : CurrentChannelAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : CurrentChannelAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun changeChannel( - match: String, - timedInvokeTimeout: Duration? = null, - ): ChangeChannelResponse { + suspend fun changeChannel(match: String + ,timedInvokeTimeout: Duration? = null): ChangeChannelResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_MATCH_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_MATCH_REQ), match) + tlvWriter.put(ContextSpecificTag(TAG_MATCH_REQ), match) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -147,48 +186,55 @@ class ChannelCluster(private val controller: MatterController, private val endpo tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_DATA: Int = 1 var data_decoded: String? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_STATUS)) { - status_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_DATA)) { - data_decoded = + + if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_DATA)) {data_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - } - } else { + tlvReader.getString(tag) + } else { + null + } + }} + + + else { tlvReader.skipElement() } } + + if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } + + + tlvReader.exitContainer() - return ChangeChannelResponse(status_decoded, data_decoded) + return ChangeChannelResponse( + status_decoded, + data_decoded + ) } - suspend fun changeChannelByNumber( - majorNumber: UShort, - minorNumber: UShort, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun changeChannelByNumber(majorNumber: UShort + ,minorNumber: UShort + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 2u val tlvWriter = TlvWriter() @@ -198,61 +244,64 @@ class ChannelCluster(private val controller: MatterController, private val endpo tlvWriter.put(ContextSpecificTag(TAG_MAJOR_NUMBER_REQ), majorNumber) val TAG_MINOR_NUMBER_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_MINOR_NUMBER_REQ), minorNumber) + tlvWriter.put(ContextSpecificTag(TAG_MINOR_NUMBER_REQ), minorNumber) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun skipChannel(count: Short, timedInvokeTimeout: Duration? = null) { + suspend fun skipChannel(count: Short + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 3u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_COUNT_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_COUNT_REQ), count) + tlvWriter.put(ContextSpecificTag(TAG_COUNT_REQ), count) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun getProgramGuide( - startTime: UInt?, - endTime: UInt?, - channelList: List?, - pageToken: ChannelClusterPageTokenStruct?, - recordingFlag: UInt?, - externalIDList: List?, - data: ByteArray?, - timedInvokeTimeout: Duration? = null, - ): ProgramGuideResponse { + suspend fun getProgramGuide(startTime: UInt? + ,endTime: UInt? + ,channelList: List? + ,pageToken: ChannelClusterPageTokenStruct? + ,recordingFlag: UInt? + ,externalIDList: List? + ,data: ByteArray? + ,timedInvokeTimeout: Duration? = null): ProgramGuideResponse { val commandId: UInt = 4u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_START_TIME_REQ: Int = 0 - startTime?.let { tlvWriter.put(ContextSpecificTag(TAG_START_TIME_REQ), startTime) } + startTime?.let { + tlvWriter.put(ContextSpecificTag(TAG_START_TIME_REQ), startTime) + } val TAG_END_TIME_REQ: Int = 1 - endTime?.let { tlvWriter.put(ContextSpecificTag(TAG_END_TIME_REQ), endTime) } + endTime?.let { + tlvWriter.put(ContextSpecificTag(TAG_END_TIME_REQ), endTime) + } val TAG_CHANNEL_LIST_REQ: Int = 2 channelList?.let { @@ -264,10 +313,14 @@ class ChannelCluster(private val controller: MatterController, private val endpo } val TAG_PAGE_TOKEN_REQ: Int = 3 - pageToken?.let { pageToken.toTlv(ContextSpecificTag(TAG_PAGE_TOKEN_REQ), tlvWriter) } + pageToken?.let { + pageToken.toTlv(ContextSpecificTag(TAG_PAGE_TOKEN_REQ), tlvWriter) + } val TAG_RECORDING_FLAG_REQ: Int = 4 - recordingFlag?.let { tlvWriter.put(ContextSpecificTag(TAG_RECORDING_FLAG_REQ), recordingFlag) } + recordingFlag?.let { + tlvWriter.put(ContextSpecificTag(TAG_RECORDING_FLAG_REQ), recordingFlag) + } val TAG_EXTERNAL_ID_LIST_REQ: Int = 5 externalIDList?.let { @@ -279,14 +332,16 @@ class ChannelCluster(private val controller: MatterController, private val endpo } val TAG_DATA_REQ: Int = 6 - data?.let { tlvWriter.put(ContextSpecificTag(TAG_DATA_REQ), data) } + data?.let { + tlvWriter.put(ContextSpecificTag(TAG_DATA_REQ), data) + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -296,51 +351,56 @@ class ChannelCluster(private val controller: MatterController, private val endpo tlvReader.enterStructure(AnonymousTag) val TAG_PAGING: Int = 0 var paging_decoded: ChannelClusterChannelPagingStruct? = null - + val TAG_PROGRAM_LIST: Int = 1 var programList_decoded: List? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_PAGING)) { - paging_decoded = ChannelClusterChannelPagingStruct.fromTlv(tag, tlvReader) + + if (tag == ContextSpecificTag(TAG_PAGING)) {paging_decoded = ChannelClusterChannelPagingStruct.fromTlv(tag, tlvReader)} + + if (tag == ContextSpecificTag(TAG_PROGRAM_LIST)) {programList_decoded = buildList { + tlvReader.enterArray(tag) + while(!tlvReader.isEndOfContainer()) { + add(ChannelClusterProgramStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + }} + - if (tag == ContextSpecificTag(TAG_PROGRAM_LIST)) { - programList_decoded = - buildList { - tlvReader.enterArray(tag) - while (!tlvReader.isEndOfContainer()) { - add(ChannelClusterProgramStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { + else { tlvReader.skipElement() } } + + if (paging_decoded == null) { - throw IllegalStateException("paging not found in TLV") + throw IllegalStateException("paging not found in TLV") } - + + if (programList_decoded == null) { - throw IllegalStateException("programList not found in TLV") + throw IllegalStateException("programList not found in TLV") } + tlvReader.exitContainer() - return ProgramGuideResponse(paging_decoded, programList_decoded) + return ProgramGuideResponse( + paging_decoded, + programList_decoded + ) } - suspend fun recordProgram( - programIdentifier: String, - shouldRecordSeries: Boolean, - externalIDList: List, - data: ByteArray, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun recordProgram(programIdentifier: String + ,shouldRecordSeries: Boolean + ,externalIDList: List + ,data: ByteArray + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 6u val tlvWriter = TlvWriter() @@ -354,33 +414,31 @@ class ChannelCluster(private val controller: MatterController, private val endpo val TAG_EXTERNAL_ID_LIST_REQ: Int = 2 tlvWriter.startArray(ContextSpecificTag(TAG_EXTERNAL_ID_LIST_REQ)) - for (item in externalIDList.iterator()) { - item.toTlv(AnonymousTag, tlvWriter) - } - tlvWriter.endArray() + for (item in externalIDList.iterator()) { + item.toTlv(AnonymousTag, tlvWriter) + } + tlvWriter.endArray() val TAG_DATA_REQ: Int = 3 - tlvWriter.put(ContextSpecificTag(TAG_DATA_REQ), data) + tlvWriter.put(ContextSpecificTag(TAG_DATA_REQ), data) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun cancelRecordProgram( - programIdentifier: String, - shouldRecordSeries: Boolean, - externalIDList: List, - data: ByteArray, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun cancelRecordProgram(programIdentifier: String + ,shouldRecordSeries: Boolean + ,externalIDList: List + ,data: ByteArray + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 7u val tlvWriter = TlvWriter() @@ -394,420 +452,437 @@ class ChannelCluster(private val controller: MatterController, private val endpo val TAG_EXTERNAL_ID_LIST_REQ: Int = 2 tlvWriter.startArray(ContextSpecificTag(TAG_EXTERNAL_ID_LIST_REQ)) - for (item in externalIDList.iterator()) { - item.toTlv(AnonymousTag, tlvWriter) - } - tlvWriter.endArray() + for (item in externalIDList.iterator()) { + item.toTlv(AnonymousTag, tlvWriter) + } + tlvWriter.endArray() val TAG_DATA_REQ: Int = 3 - tlvWriter.put(ContextSpecificTag(TAG_DATA_REQ), data) + tlvWriter.put(ContextSpecificTag(TAG_DATA_REQ), data) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - - suspend fun readChannelListAttribute(): ChannelListAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readChannelListAttribute(): ChannelListAttribute {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}") - } + 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) { "Channellist attribute not found in response" } + } + + requireNotNull(attributeData) { + "Channellist attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(ChannelClusterChannelInfoStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(ChannelClusterChannelInfoStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + } else { + null + } + return ChannelListAttribute(decodedValue) } suspend fun subscribeChannelListAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ChannelListAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ChannelListAttributeSubscriptionState.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) { "Channellist attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Channellist attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(ChannelClusterChannelInfoStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { emit(ChannelListAttributeSubscriptionState.Success(it)) } + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(ChannelClusterChannelInfoStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { + emit(ChannelListAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ChannelListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readLineupAttribute(): LineupAttribute { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readLineupAttribute(): LineupAttribute {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}") - } + 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) { "Lineup attribute not found in response" } + } + + requireNotNull(attributeData) { + "Lineup attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ChannelClusterLineupInfoStruct? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - ChannelClusterLineupInfoStruct.fromTlv(AnonymousTag, tlvReader) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ChannelClusterLineupInfoStruct? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + ChannelClusterLineupInfoStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return LineupAttribute(decodedValue) } suspend fun subscribeLineupAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - LineupAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(LineupAttributeSubscriptionState.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) { "Lineup attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Lineup attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ChannelClusterLineupInfoStruct? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - ChannelClusterLineupInfoStruct.fromTlv(AnonymousTag, tlvReader) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(LineupAttributeSubscriptionState.Success(it)) } + val decodedValue: ChannelClusterLineupInfoStruct? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + ChannelClusterLineupInfoStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(LineupAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(LineupAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readCurrentChannelAttribute(): CurrentChannelAttribute { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readCurrentChannelAttribute(): CurrentChannelAttribute {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}") - } + 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) { "Currentchannel attribute not found in response" } + } + + requireNotNull(attributeData) { + "Currentchannel attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ChannelClusterChannelInfoStruct? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - ChannelClusterChannelInfoStruct.fromTlv(AnonymousTag, tlvReader) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ChannelClusterChannelInfoStruct? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + ChannelClusterChannelInfoStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return CurrentChannelAttribute(decodedValue) } suspend fun subscribeCurrentChannelAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - CurrentChannelAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(CurrentChannelAttributeSubscriptionState.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) { - "Currentchannel attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Currentchannel attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ChannelClusterChannelInfoStruct? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - ChannelClusterChannelInfoStruct.fromTlv(AnonymousTag, tlvReader) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(CurrentChannelAttributeSubscriptionState.Success(it)) } + val decodedValue: ChannelClusterChannelInfoStruct? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + ChannelClusterChannelInfoStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(CurrentChannelAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(CurrentChannelAttributeSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -815,96 +890,97 @@ class ChannelCluster(private val controller: MatterController, private val endpo 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -912,94 +988,97 @@ class ChannelCluster(private val controller: MatterController, private val endpo 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1007,94 +1086,97 @@ class ChannelCluster(private val controller: MatterController, private val endpo 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1102,76 +1184,81 @@ class ChannelCluster(private val controller: MatterController, private val endpo 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1183,77 +1270,80 @@ class ChannelCluster(private val controller: MatterController, private val endpo 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1266,7 +1356,7 @@ class ChannelCluster(private val controller: MatterController, private val endpo emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/ColorControlCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/ColorControlCluster.kt index bded0dfd041f7d..22dd04f551f5f8 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/ColorControlCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/ColorControlCluster.kt @@ -17,197 +17,250 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest -import matter.controller.StringSubscriptionState +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.cluster.structs.* +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class ColorControlCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class NumberOfPrimariesAttribute(val value: UByte?) +class ColorControlCluster(private val controller: MatterController, private val endpointId: UShort) {class NumberOfPrimariesAttribute( + val value: UByte? + ) sealed class NumberOfPrimariesAttributeSubscriptionState { - data class Success(val value: UByte?) : NumberOfPrimariesAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : NumberOfPrimariesAttributeSubscriptionState() + data class Error(val exception: Exception) : NumberOfPrimariesAttributeSubscriptionState() - object SubscriptionEstablished : NumberOfPrimariesAttributeSubscriptionState() - } - - class Primary1IntensityAttribute(val value: UByte?) + object SubscriptionEstablished : NumberOfPrimariesAttributeSubscriptionState() + } +class Primary1IntensityAttribute( + val value: UByte? + ) sealed class Primary1IntensityAttributeSubscriptionState { - data class Success(val value: UByte?) : Primary1IntensityAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : Primary1IntensityAttributeSubscriptionState() + data class Error(val exception: Exception) : Primary1IntensityAttributeSubscriptionState() - object SubscriptionEstablished : Primary1IntensityAttributeSubscriptionState() - } - - class Primary2IntensityAttribute(val value: UByte?) + object SubscriptionEstablished : Primary1IntensityAttributeSubscriptionState() + } +class Primary2IntensityAttribute( + val value: UByte? + ) sealed class Primary2IntensityAttributeSubscriptionState { - data class Success(val value: UByte?) : Primary2IntensityAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : Primary2IntensityAttributeSubscriptionState() + data class Error(val exception: Exception) : Primary2IntensityAttributeSubscriptionState() - object SubscriptionEstablished : Primary2IntensityAttributeSubscriptionState() - } - - class Primary3IntensityAttribute(val value: UByte?) + object SubscriptionEstablished : Primary2IntensityAttributeSubscriptionState() + } +class Primary3IntensityAttribute( + val value: UByte? + ) sealed class Primary3IntensityAttributeSubscriptionState { - data class Success(val value: UByte?) : Primary3IntensityAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : Primary3IntensityAttributeSubscriptionState() + data class Error(val exception: Exception) : Primary3IntensityAttributeSubscriptionState() - object SubscriptionEstablished : Primary3IntensityAttributeSubscriptionState() - } - - class Primary4IntensityAttribute(val value: UByte?) + object SubscriptionEstablished : Primary3IntensityAttributeSubscriptionState() + } +class Primary4IntensityAttribute( + val value: UByte? + ) sealed class Primary4IntensityAttributeSubscriptionState { - data class Success(val value: UByte?) : Primary4IntensityAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : Primary4IntensityAttributeSubscriptionState() + data class Error(val exception: Exception) : Primary4IntensityAttributeSubscriptionState() - object SubscriptionEstablished : Primary4IntensityAttributeSubscriptionState() - } - - class Primary5IntensityAttribute(val value: UByte?) + object SubscriptionEstablished : Primary4IntensityAttributeSubscriptionState() + } +class Primary5IntensityAttribute( + val value: UByte? + ) sealed class Primary5IntensityAttributeSubscriptionState { - data class Success(val value: UByte?) : Primary5IntensityAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : Primary5IntensityAttributeSubscriptionState() + data class Error(val exception: Exception) : Primary5IntensityAttributeSubscriptionState() - object SubscriptionEstablished : Primary5IntensityAttributeSubscriptionState() - } - - class Primary6IntensityAttribute(val value: UByte?) + object SubscriptionEstablished : Primary5IntensityAttributeSubscriptionState() + } +class Primary6IntensityAttribute( + val value: UByte? + ) sealed class Primary6IntensityAttributeSubscriptionState { - data class Success(val value: UByte?) : Primary6IntensityAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : Primary6IntensityAttributeSubscriptionState() + data class Error(val exception: Exception) : Primary6IntensityAttributeSubscriptionState() - object SubscriptionEstablished : Primary6IntensityAttributeSubscriptionState() - } - - class ColorPointRIntensityAttribute(val value: UByte?) + object SubscriptionEstablished : Primary6IntensityAttributeSubscriptionState() + } +class ColorPointRIntensityAttribute( + val value: UByte? + ) sealed class ColorPointRIntensityAttributeSubscriptionState { - data class Success(val value: UByte?) : ColorPointRIntensityAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : ColorPointRIntensityAttributeSubscriptionState() + data class Error(val exception: Exception) : ColorPointRIntensityAttributeSubscriptionState() - object SubscriptionEstablished : ColorPointRIntensityAttributeSubscriptionState() - } - - class ColorPointGIntensityAttribute(val value: UByte?) + object SubscriptionEstablished : ColorPointRIntensityAttributeSubscriptionState() + } +class ColorPointGIntensityAttribute( + val value: UByte? + ) sealed class ColorPointGIntensityAttributeSubscriptionState { - data class Success(val value: UByte?) : ColorPointGIntensityAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : ColorPointGIntensityAttributeSubscriptionState() + data class Error(val exception: Exception) : ColorPointGIntensityAttributeSubscriptionState() - object SubscriptionEstablished : ColorPointGIntensityAttributeSubscriptionState() - } - - class ColorPointBIntensityAttribute(val value: UByte?) + object SubscriptionEstablished : ColorPointGIntensityAttributeSubscriptionState() + } +class ColorPointBIntensityAttribute( + val value: UByte? + ) sealed class ColorPointBIntensityAttributeSubscriptionState { - data class Success(val value: UByte?) : ColorPointBIntensityAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : ColorPointBIntensityAttributeSubscriptionState() + data class Error(val exception: Exception) : ColorPointBIntensityAttributeSubscriptionState() - object SubscriptionEstablished : ColorPointBIntensityAttributeSubscriptionState() - } - - class StartUpColorTemperatureMiredsAttribute(val value: UShort?) + object SubscriptionEstablished : ColorPointBIntensityAttributeSubscriptionState() + } +class StartUpColorTemperatureMiredsAttribute( + val value: UShort? + ) sealed class StartUpColorTemperatureMiredsAttributeSubscriptionState { - data class Success(val value: UShort?) : - StartUpColorTemperatureMiredsAttributeSubscriptionState() - - data class Error(val exception: Exception) : - StartUpColorTemperatureMiredsAttributeSubscriptionState() - - object SubscriptionEstablished : StartUpColorTemperatureMiredsAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + data class Success( + val value: UShort? + ) : StartUpColorTemperatureMiredsAttributeSubscriptionState() + + data class Error(val exception: Exception) : StartUpColorTemperatureMiredsAttributeSubscriptionState() + + object SubscriptionEstablished : StartUpColorTemperatureMiredsAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun moveToHue( - hue: UByte, - direction: UByte, - transitionTime: UShort, - optionsMask: UByte, - optionsOverride: UByte, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun moveToHue(hue: UByte + ,direction: UByte + ,transitionTime: UShort + ,optionsMask: UByte + ,optionsOverride: UByte + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() @@ -226,27 +279,25 @@ class ColorControlCluster( tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 4 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun moveHue( - moveMode: UByte, - rate: UByte, - optionsMask: UByte, - optionsOverride: UByte, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun moveHue(moveMode: UByte + ,rate: UByte + ,optionsMask: UByte + ,optionsOverride: UByte + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 1u val tlvWriter = TlvWriter() @@ -262,28 +313,26 @@ class ColorControlCluster( tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 3 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun stepHue( - stepMode: UByte, - stepSize: UByte, - transitionTime: UByte, - optionsMask: UByte, - optionsOverride: UByte, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun stepHue(stepMode: UByte + ,stepSize: UByte + ,transitionTime: UByte + ,optionsMask: UByte + ,optionsOverride: UByte + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 2u val tlvWriter = TlvWriter() @@ -302,27 +351,25 @@ class ColorControlCluster( tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 4 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun moveToSaturation( - saturation: UByte, - transitionTime: UShort, - optionsMask: UByte, - optionsOverride: UByte, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun moveToSaturation(saturation: UByte + ,transitionTime: UShort + ,optionsMask: UByte + ,optionsOverride: UByte + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 3u val tlvWriter = TlvWriter() @@ -338,27 +385,25 @@ class ColorControlCluster( tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 3 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun moveSaturation( - moveMode: UByte, - rate: UByte, - optionsMask: UByte, - optionsOverride: UByte, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun moveSaturation(moveMode: UByte + ,rate: UByte + ,optionsMask: UByte + ,optionsOverride: UByte + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 4u val tlvWriter = TlvWriter() @@ -374,28 +419,26 @@ class ColorControlCluster( tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 3 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun stepSaturation( - stepMode: UByte, - stepSize: UByte, - transitionTime: UByte, - optionsMask: UByte, - optionsOverride: UByte, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun stepSaturation(stepMode: UByte + ,stepSize: UByte + ,transitionTime: UByte + ,optionsMask: UByte + ,optionsOverride: UByte + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 5u val tlvWriter = TlvWriter() @@ -414,28 +457,26 @@ class ColorControlCluster( tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 4 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun moveToHueAndSaturation( - hue: UByte, - saturation: UByte, - transitionTime: UShort, - optionsMask: UByte, - optionsOverride: UByte, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun moveToHueAndSaturation(hue: UByte + ,saturation: UByte + ,transitionTime: UShort + ,optionsMask: UByte + ,optionsOverride: UByte + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 6u val tlvWriter = TlvWriter() @@ -454,28 +495,26 @@ class ColorControlCluster( tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 4 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun moveToColor( - colorX: UShort, - colorY: UShort, - transitionTime: UShort, - optionsMask: UByte, - optionsOverride: UByte, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun moveToColor(colorX: UShort + ,colorY: UShort + ,transitionTime: UShort + ,optionsMask: UByte + ,optionsOverride: UByte + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 7u val tlvWriter = TlvWriter() @@ -494,27 +533,25 @@ class ColorControlCluster( tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 4 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun moveColor( - rateX: Short, - rateY: Short, - optionsMask: UByte, - optionsOverride: UByte, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun moveColor(rateX: Short + ,rateY: Short + ,optionsMask: UByte + ,optionsOverride: UByte + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 8u val tlvWriter = TlvWriter() @@ -530,28 +567,26 @@ class ColorControlCluster( tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 3 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun stepColor( - stepX: Short, - stepY: Short, - transitionTime: UShort, - optionsMask: UByte, - optionsOverride: UByte, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun stepColor(stepX: Short + ,stepY: Short + ,transitionTime: UShort + ,optionsMask: UByte + ,optionsOverride: UByte + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 9u val tlvWriter = TlvWriter() @@ -570,27 +605,25 @@ class ColorControlCluster( tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 4 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun moveToColorTemperature( - colorTemperatureMireds: UShort, - transitionTime: UShort, - optionsMask: UByte, - optionsOverride: UByte, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun moveToColorTemperature(colorTemperatureMireds: UShort + ,transitionTime: UShort + ,optionsMask: UByte + ,optionsOverride: UByte + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 10u val tlvWriter = TlvWriter() @@ -606,28 +639,26 @@ class ColorControlCluster( tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 3 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun enhancedMoveToHue( - enhancedHue: UShort, - direction: UByte, - transitionTime: UShort, - optionsMask: UByte, - optionsOverride: UByte, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun enhancedMoveToHue(enhancedHue: UShort + ,direction: UByte + ,transitionTime: UShort + ,optionsMask: UByte + ,optionsOverride: UByte + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 64u val tlvWriter = TlvWriter() @@ -646,27 +677,25 @@ class ColorControlCluster( tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 4 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun enhancedMoveHue( - moveMode: UByte, - rate: UShort, - optionsMask: UByte, - optionsOverride: UByte, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun enhancedMoveHue(moveMode: UByte + ,rate: UShort + ,optionsMask: UByte + ,optionsOverride: UByte + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 65u val tlvWriter = TlvWriter() @@ -682,28 +711,26 @@ class ColorControlCluster( tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 3 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun enhancedStepHue( - stepMode: UByte, - stepSize: UShort, - transitionTime: UShort, - optionsMask: UByte, - optionsOverride: UByte, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun enhancedStepHue(stepMode: UByte + ,stepSize: UShort + ,transitionTime: UShort + ,optionsMask: UByte + ,optionsOverride: UByte + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 66u val tlvWriter = TlvWriter() @@ -722,28 +749,26 @@ class ColorControlCluster( tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 4 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun enhancedMoveToHueAndSaturation( - enhancedHue: UShort, - saturation: UByte, - transitionTime: UShort, - optionsMask: UByte, - optionsOverride: UByte, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun enhancedMoveToHueAndSaturation(enhancedHue: UShort + ,saturation: UByte + ,transitionTime: UShort + ,optionsMask: UByte + ,optionsOverride: UByte + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 67u val tlvWriter = TlvWriter() @@ -762,30 +787,28 @@ class ColorControlCluster( tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 4 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun colorLoopSet( - updateFlags: UByte, - action: UByte, - direction: UByte, - time: UShort, - startHue: UShort, - optionsMask: UByte, - optionsOverride: UByte, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun colorLoopSet(updateFlags: UByte + ,action: UByte + ,direction: UByte + ,time: UShort + ,startHue: UShort + ,optionsMask: UByte + ,optionsOverride: UByte + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 68u val tlvWriter = TlvWriter() @@ -810,25 +833,23 @@ class ColorControlCluster( tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 6 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun stopMoveStep( - optionsMask: UByte, - optionsOverride: UByte, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun stopMoveStep(optionsMask: UByte + ,optionsOverride: UByte + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 71u val tlvWriter = TlvWriter() @@ -838,29 +859,27 @@ class ColorControlCluster( tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun moveColorTemperature( - moveMode: UByte, - rate: UShort, - colorTemperatureMinimumMireds: UShort, - colorTemperatureMaximumMireds: UShort, - optionsMask: UByte, - optionsOverride: UByte, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun moveColorTemperature(moveMode: UByte + ,rate: UShort + ,colorTemperatureMinimumMireds: UShort + ,colorTemperatureMaximumMireds: UShort + ,optionsMask: UByte + ,optionsOverride: UByte + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 75u val tlvWriter = TlvWriter() @@ -873,45 +892,37 @@ class ColorControlCluster( tlvWriter.put(ContextSpecificTag(TAG_RATE_REQ), rate) val TAG_COLOR_TEMPERATURE_MINIMUM_MIREDS_REQ: Int = 2 - tlvWriter.put( - ContextSpecificTag(TAG_COLOR_TEMPERATURE_MINIMUM_MIREDS_REQ), - colorTemperatureMinimumMireds, - ) + tlvWriter.put(ContextSpecificTag(TAG_COLOR_TEMPERATURE_MINIMUM_MIREDS_REQ), colorTemperatureMinimumMireds) val TAG_COLOR_TEMPERATURE_MAXIMUM_MIREDS_REQ: Int = 3 - tlvWriter.put( - ContextSpecificTag(TAG_COLOR_TEMPERATURE_MAXIMUM_MIREDS_REQ), - colorTemperatureMaximumMireds, - ) + tlvWriter.put(ContextSpecificTag(TAG_COLOR_TEMPERATURE_MAXIMUM_MIREDS_REQ), colorTemperatureMaximumMireds) val TAG_OPTIONS_MASK_REQ: Int = 4 tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 5 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun stepColorTemperature( - stepMode: UByte, - stepSize: UShort, - transitionTime: UShort, - colorTemperatureMinimumMireds: UShort, - colorTemperatureMaximumMireds: UShort, - optionsMask: UByte, - optionsOverride: UByte, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun stepColorTemperature(stepMode: UByte + ,stepSize: UShort + ,transitionTime: UShort + ,colorTemperatureMinimumMireds: UShort + ,colorTemperatureMaximumMireds: UShort + ,optionsMask: UByte + ,optionsOverride: UByte + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 76u val tlvWriter = TlvWriter() @@ -927,838 +938,877 @@ class ColorControlCluster( tlvWriter.put(ContextSpecificTag(TAG_TRANSITION_TIME_REQ), transitionTime) val TAG_COLOR_TEMPERATURE_MINIMUM_MIREDS_REQ: Int = 3 - tlvWriter.put( - ContextSpecificTag(TAG_COLOR_TEMPERATURE_MINIMUM_MIREDS_REQ), - colorTemperatureMinimumMireds, - ) + tlvWriter.put(ContextSpecificTag(TAG_COLOR_TEMPERATURE_MINIMUM_MIREDS_REQ), colorTemperatureMinimumMireds) val TAG_COLOR_TEMPERATURE_MAXIMUM_MIREDS_REQ: Int = 4 - tlvWriter.put( - ContextSpecificTag(TAG_COLOR_TEMPERATURE_MAXIMUM_MIREDS_REQ), - colorTemperatureMaximumMireds, - ) + tlvWriter.put(ContextSpecificTag(TAG_COLOR_TEMPERATURE_MAXIMUM_MIREDS_REQ), colorTemperatureMaximumMireds) val TAG_OPTIONS_MASK_REQ: Int = 5 tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 6 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } +suspend fun readCurrentHueAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 0u - suspend fun readCurrentHueAttribute(): 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 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}") - } + 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) { "Currenthue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Currenthue 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeCurrentHueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Currenthue attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Currenthue 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readCurrentSaturationAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 1u - suspend fun readCurrentSaturationAttribute(): 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 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}") - } + 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) { "Currentsaturation attribute not found in response" } + } + + requireNotNull(attributeData) { + "Currentsaturation 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeCurrentSaturationAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Currentsaturation attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Currentsaturation 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRemainingTimeAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2u - suspend fun readRemainingTimeAttribute(): 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 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}") - } + 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) { "Remainingtime attribute not found in response" } + } + + requireNotNull(attributeData) { + "Remainingtime 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeRemainingTimeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Remainingtime attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Remainingtime 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readCurrentXAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 3u - suspend fun readCurrentXAttribute(): UShort? { - 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 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}") - } + 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) { "Currentx attribute not found in response" } + } + + requireNotNull(attributeData) { + "Currentx 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeCurrentXAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Currentx attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Currentx 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readCurrentYAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 4u - suspend fun readCurrentYAttribute(): UShort? { - 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 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}") - } + 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) { "Currenty attribute not found in response" } + } + + requireNotNull(attributeData) { + "Currenty 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeCurrentYAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Currenty attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Currenty 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readDriftCompensationAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 5u - suspend fun readDriftCompensationAttribute(): UByte? { - 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 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}") - } + 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) { "Driftcompensation attribute not found in response" } + } + + requireNotNull(attributeData) { + "Driftcompensation 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeDriftCompensationAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Driftcompensation attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Driftcompensation 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readCompensationTextAttribute(): String? {val ATTRIBUTE_ID: UInt = 6u - suspend fun readCompensationTextAttribute(): String? { - 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 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}") - } + 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) { "Compensationtext attribute not found in response" } + } + + requireNotNull(attributeData) { + "Compensationtext attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeCompensationTextAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StringSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StringSubscriptionState.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) { - "Compensationtext attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Compensationtext attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(StringSubscriptionState.Success(it)) } + decodedValue?.let { + emit(StringSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readColorTemperatureMiredsAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 7u - suspend fun readColorTemperatureMiredsAttribute(): UShort? { - 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 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}") - } + 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) { "Colortemperaturemireds attribute not found in response" } + } + + requireNotNull(attributeData) { + "Colortemperaturemireds 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeColorTemperatureMiredsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Colortemperaturemireds attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Colortemperaturemireds 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readColorModeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 8u - suspend fun readColorModeAttribute(): UByte { - val ATTRIBUTE_ID: UInt = 8u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Colormode attribute not found in response" } + } + + requireNotNull(attributeData) { + "Colormode 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 subscribeColorModeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Colormode attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Colormode attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -1770,57 +1820,68 @@ class ColorControlCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readOptionsAttribute(): UByte {val ATTRIBUTE_ID: UInt = 15u - suspend fun readOptionsAttribute(): UByte { - val ATTRIBUTE_ID: UInt = 15u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Options attribute not found in response" } + } + + requireNotNull(attributeData) { + "Options 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 writeOptionsAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeOptionsAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 15u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -1841,45 +1902,43 @@ class ColorControlCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeOptionsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 15u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Options attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Options attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -1891,1867 +1950,1977 @@ class ColorControlCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNumberOfPrimariesAttribute(): NumberOfPrimariesAttribute {val ATTRIBUTE_ID: UInt = 16u - suspend fun readNumberOfPrimariesAttribute(): NumberOfPrimariesAttribute { - val ATTRIBUTE_ID: UInt = 16u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Numberofprimaries attribute not found in response" } + } + + requireNotNull(attributeData) { + "Numberofprimaries attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return NumberOfPrimariesAttribute(decodedValue) } suspend fun subscribeNumberOfPrimariesAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - NumberOfPrimariesAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(NumberOfPrimariesAttributeSubscriptionState.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) { - "Numberofprimaries attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Numberofprimaries 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.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(NumberOfPrimariesAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(NumberOfPrimariesAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(NumberOfPrimariesAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readPrimary1XAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 17u - suspend fun readPrimary1XAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 17u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Primary1x attribute not found in response" } + } + + requireNotNull(attributeData) { + "Primary1x 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribePrimary1XAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 17u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Primary1x attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Primary1x 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readPrimary1YAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 18u - suspend fun readPrimary1YAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 18u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Primary1y attribute not found in response" } + } + + requireNotNull(attributeData) { + "Primary1y 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribePrimary1YAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 18u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Primary1y attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Primary1y 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readPrimary1IntensityAttribute(): Primary1IntensityAttribute {val ATTRIBUTE_ID: UInt = 19u - suspend fun readPrimary1IntensityAttribute(): Primary1IntensityAttribute { - val ATTRIBUTE_ID: UInt = 19u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Primary1intensity attribute not found in response" } + } + + requireNotNull(attributeData) { + "Primary1intensity attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return Primary1IntensityAttribute(decodedValue) } suspend fun subscribePrimary1IntensityAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 19u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - Primary1IntensityAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(Primary1IntensityAttributeSubscriptionState.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) { - "Primary1intensity attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Primary1intensity 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(Primary1IntensityAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(Primary1IntensityAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(Primary1IntensityAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readPrimary2XAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 21u - suspend fun readPrimary2XAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 21u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Primary2x attribute not found in response" } + } + + requireNotNull(attributeData) { + "Primary2x 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribePrimary2XAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 21u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Primary2x attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Primary2x 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readPrimary2YAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 22u - suspend fun readPrimary2YAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 22u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Primary2y attribute not found in response" } + } + + requireNotNull(attributeData) { + "Primary2y 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribePrimary2YAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 22u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Primary2y attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Primary2y 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readPrimary2IntensityAttribute(): Primary2IntensityAttribute {val ATTRIBUTE_ID: UInt = 23u - suspend fun readPrimary2IntensityAttribute(): Primary2IntensityAttribute { - val ATTRIBUTE_ID: UInt = 23u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Primary2intensity attribute not found in response" } + } + + requireNotNull(attributeData) { + "Primary2intensity attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return Primary2IntensityAttribute(decodedValue) } suspend fun subscribePrimary2IntensityAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 23u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - Primary2IntensityAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(Primary2IntensityAttributeSubscriptionState.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) { - "Primary2intensity attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Primary2intensity 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(Primary2IntensityAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(Primary2IntensityAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(Primary2IntensityAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readPrimary3XAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 25u - suspend fun readPrimary3XAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 25u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Primary3x attribute not found in response" } + } + + requireNotNull(attributeData) { + "Primary3x 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribePrimary3XAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 25u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Primary3x attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Primary3x 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readPrimary3YAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 26u - suspend fun readPrimary3YAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 26u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Primary3y attribute not found in response" } + } + + requireNotNull(attributeData) { + "Primary3y 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribePrimary3YAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 26u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Primary3y attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Primary3y 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readPrimary3IntensityAttribute(): Primary3IntensityAttribute {val ATTRIBUTE_ID: UInt = 27u - suspend fun readPrimary3IntensityAttribute(): Primary3IntensityAttribute { - val ATTRIBUTE_ID: UInt = 27u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Primary3intensity attribute not found in response" } + } + + requireNotNull(attributeData) { + "Primary3intensity attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return Primary3IntensityAttribute(decodedValue) } suspend fun subscribePrimary3IntensityAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 27u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - Primary3IntensityAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(Primary3IntensityAttributeSubscriptionState.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) { - "Primary3intensity attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Primary3intensity 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(Primary3IntensityAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(Primary3IntensityAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(Primary3IntensityAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readPrimary4XAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 32u - suspend fun readPrimary4XAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 32u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Primary4x attribute not found in response" } + } + + requireNotNull(attributeData) { + "Primary4x 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribePrimary4XAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 32u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Primary4x attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Primary4x 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readPrimary4YAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 33u - suspend fun readPrimary4YAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 33u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Primary4y attribute not found in response" } + } + + requireNotNull(attributeData) { + "Primary4y 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribePrimary4YAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 33u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Primary4y attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Primary4y 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readPrimary4IntensityAttribute(): Primary4IntensityAttribute {val ATTRIBUTE_ID: UInt = 34u - suspend fun readPrimary4IntensityAttribute(): Primary4IntensityAttribute { - val ATTRIBUTE_ID: UInt = 34u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Primary4intensity attribute not found in response" } + } + + requireNotNull(attributeData) { + "Primary4intensity attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return Primary4IntensityAttribute(decodedValue) } suspend fun subscribePrimary4IntensityAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 34u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - Primary4IntensityAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(Primary4IntensityAttributeSubscriptionState.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) { - "Primary4intensity attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Primary4intensity 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(Primary4IntensityAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(Primary4IntensityAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(Primary4IntensityAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readPrimary5XAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 36u - suspend fun readPrimary5XAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 36u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Primary5x attribute not found in response" } + } + + requireNotNull(attributeData) { + "Primary5x 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribePrimary5XAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 36u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Primary5x attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Primary5x 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readPrimary5YAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 37u - suspend fun readPrimary5YAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 37u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Primary5y attribute not found in response" } + } + + requireNotNull(attributeData) { + "Primary5y 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribePrimary5YAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 37u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Primary5y attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Primary5y 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readPrimary5IntensityAttribute(): Primary5IntensityAttribute {val ATTRIBUTE_ID: UInt = 38u - suspend fun readPrimary5IntensityAttribute(): Primary5IntensityAttribute { - val ATTRIBUTE_ID: UInt = 38u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Primary5intensity attribute not found in response" } + } + + requireNotNull(attributeData) { + "Primary5intensity attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return Primary5IntensityAttribute(decodedValue) } suspend fun subscribePrimary5IntensityAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 38u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - Primary5IntensityAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(Primary5IntensityAttributeSubscriptionState.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) { - "Primary5intensity attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Primary5intensity 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(Primary5IntensityAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(Primary5IntensityAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(Primary5IntensityAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readPrimary6XAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 40u - suspend fun readPrimary6XAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 40u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Primary6x attribute not found in response" } + } + + requireNotNull(attributeData) { + "Primary6x 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribePrimary6XAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 40u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Primary6x attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Primary6x 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readPrimary6YAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 41u - suspend fun readPrimary6YAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 41u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Primary6y attribute not found in response" } + } + + requireNotNull(attributeData) { + "Primary6y 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribePrimary6YAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 41u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Primary6y attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Primary6y 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readPrimary6IntensityAttribute(): Primary6IntensityAttribute {val ATTRIBUTE_ID: UInt = 42u - suspend fun readPrimary6IntensityAttribute(): Primary6IntensityAttribute { - val ATTRIBUTE_ID: UInt = 42u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Primary6intensity attribute not found in response" } + } + + requireNotNull(attributeData) { + "Primary6intensity attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return Primary6IntensityAttribute(decodedValue) } suspend fun subscribePrimary6IntensityAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 42u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - Primary6IntensityAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(Primary6IntensityAttributeSubscriptionState.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) { - "Primary6intensity attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Primary6intensity 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(Primary6IntensityAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(Primary6IntensityAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(Primary6IntensityAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readWhitePointXAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 48u - suspend fun readWhitePointXAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 48u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Whitepointx attribute not found in response" } + } + + requireNotNull(attributeData) { + "Whitepointx 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } - suspend fun writeWhitePointXAttribute(value: UShort, timedWriteTimeout: Duration? = null) { + suspend fun writeWhitePointXAttribute( + value: UShort, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 48u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -3772,117 +3941,127 @@ class ColorControlCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeWhitePointXAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 48u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Whitepointx attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Whitepointx 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readWhitePointYAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 49u - suspend fun readWhitePointYAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 49u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Whitepointy attribute not found in response" } + } + + requireNotNull(attributeData) { + "Whitepointy 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } - suspend fun writeWhitePointYAttribute(value: UShort, timedWriteTimeout: Duration? = null) { + suspend fun writeWhitePointYAttribute( + value: UShort, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 49u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -3903,117 +4082,127 @@ class ColorControlCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeWhitePointYAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 49u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Whitepointy attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Whitepointy 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readColorPointRXAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 50u - suspend fun readColorPointRXAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 50u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Colorpointrx attribute not found in response" } + } + + requireNotNull(attributeData) { + "Colorpointrx 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } - suspend fun writeColorPointRXAttribute(value: UShort, timedWriteTimeout: Duration? = null) { + suspend fun writeColorPointRXAttribute( + value: UShort, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 50u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -4034,117 +4223,127 @@ class ColorControlCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeColorPointRXAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 50u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Colorpointrx attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Colorpointrx 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readColorPointRYAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 51u - suspend fun readColorPointRYAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 51u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Colorpointry attribute not found in response" } + } + + requireNotNull(attributeData) { + "Colorpointry 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } - suspend fun writeColorPointRYAttribute(value: UShort, timedWriteTimeout: Duration? = null) { + suspend fun writeColorPointRYAttribute( + value: UShort, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 51u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -4165,125 +4364,132 @@ class ColorControlCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeColorPointRYAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 51u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Colorpointry attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Colorpointry 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readColorPointRIntensityAttribute(): ColorPointRIntensityAttribute {val ATTRIBUTE_ID: UInt = 52u - suspend fun readColorPointRIntensityAttribute(): ColorPointRIntensityAttribute { - val ATTRIBUTE_ID: UInt = 52u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Colorpointrintensity attribute not found in response" } + } + + requireNotNull(attributeData) { + "Colorpointrintensity attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return ColorPointRIntensityAttribute(decodedValue) } suspend fun writeColorPointRIntensityAttribute( value: UByte, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 52u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -4304,124 +4510,132 @@ class ColorControlCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeColorPointRIntensityAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 52u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ColorPointRIntensityAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ColorPointRIntensityAttributeSubscriptionState.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) { - "Colorpointrintensity attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Colorpointrintensity 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(ColorPointRIntensityAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(ColorPointRIntensityAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ColorPointRIntensityAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readColorPointGXAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 54u - suspend fun readColorPointGXAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 54u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Colorpointgx attribute not found in response" } + } + + requireNotNull(attributeData) { + "Colorpointgx 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } - suspend fun writeColorPointGXAttribute(value: UShort, timedWriteTimeout: Duration? = null) { + suspend fun writeColorPointGXAttribute( + value: UShort, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 54u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -4442,117 +4656,127 @@ class ColorControlCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeColorPointGXAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 54u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Colorpointgx attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Colorpointgx 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readColorPointGYAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 55u - suspend fun readColorPointGYAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 55u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Colorpointgy attribute not found in response" } + } + + requireNotNull(attributeData) { + "Colorpointgy 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } - suspend fun writeColorPointGYAttribute(value: UShort, timedWriteTimeout: Duration? = null) { + suspend fun writeColorPointGYAttribute( + value: UShort, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 55u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -4573,125 +4797,132 @@ class ColorControlCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeColorPointGYAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 55u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Colorpointgy attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Colorpointgy 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readColorPointGIntensityAttribute(): ColorPointGIntensityAttribute {val ATTRIBUTE_ID: UInt = 56u - suspend fun readColorPointGIntensityAttribute(): ColorPointGIntensityAttribute { - val ATTRIBUTE_ID: UInt = 56u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Colorpointgintensity attribute not found in response" } + } + + requireNotNull(attributeData) { + "Colorpointgintensity attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return ColorPointGIntensityAttribute(decodedValue) } suspend fun writeColorPointGIntensityAttribute( value: UByte, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 56u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -4712,124 +4943,132 @@ class ColorControlCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeColorPointGIntensityAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 56u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ColorPointGIntensityAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ColorPointGIntensityAttributeSubscriptionState.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) { - "Colorpointgintensity attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Colorpointgintensity 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(ColorPointGIntensityAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(ColorPointGIntensityAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ColorPointGIntensityAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readColorPointBXAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 58u - suspend fun readColorPointBXAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 58u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Colorpointbx attribute not found in response" } + } + + requireNotNull(attributeData) { + "Colorpointbx 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } - suspend fun writeColorPointBXAttribute(value: UShort, timedWriteTimeout: Duration? = null) { + suspend fun writeColorPointBXAttribute( + value: UShort, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 58u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -4850,117 +5089,127 @@ class ColorControlCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeColorPointBXAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 58u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Colorpointbx attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Colorpointbx 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readColorPointBYAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 59u - suspend fun readColorPointBYAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 59u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Colorpointby attribute not found in response" } + } + + requireNotNull(attributeData) { + "Colorpointby 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } - suspend fun writeColorPointBYAttribute(value: UShort, timedWriteTimeout: Duration? = null) { + suspend fun writeColorPointBYAttribute( + value: UShort, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 59u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -4981,125 +5230,132 @@ class ColorControlCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeColorPointBYAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 59u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Colorpointby attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Colorpointby 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readColorPointBIntensityAttribute(): ColorPointBIntensityAttribute {val ATTRIBUTE_ID: UInt = 60u - suspend fun readColorPointBIntensityAttribute(): ColorPointBIntensityAttribute { - val ATTRIBUTE_ID: UInt = 60u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Colorpointbintensity attribute not found in response" } + } + + requireNotNull(attributeData) { + "Colorpointbintensity attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return ColorPointBIntensityAttribute(decodedValue) } suspend fun writeColorPointBIntensityAttribute( value: UByte, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 60u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -5120,232 +5376,237 @@ class ColorControlCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeColorPointBIntensityAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 60u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ColorPointBIntensityAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ColorPointBIntensityAttributeSubscriptionState.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) { - "Colorpointbintensity attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Colorpointbintensity 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(ColorPointBIntensityAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(ColorPointBIntensityAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ColorPointBIntensityAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readEnhancedCurrentHueAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 16384u - suspend fun readEnhancedCurrentHueAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 16384u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Enhancedcurrenthue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Enhancedcurrenthue 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeEnhancedCurrentHueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16384u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Enhancedcurrenthue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Enhancedcurrenthue 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readEnhancedColorModeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 16385u - suspend fun readEnhancedColorModeAttribute(): UByte { - val ATTRIBUTE_ID: UInt = 16385u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Enhancedcolormode attribute not found in response" } + } + + requireNotNull(attributeData) { + "Enhancedcolormode 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 subscribeEnhancedColorModeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16385u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Enhancedcolormode attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Enhancedcolormode attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -5358,540 +5619,565 @@ class ColorControlCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readColorLoopActiveAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 16386u - suspend fun readColorLoopActiveAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 16386u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Colorloopactive attribute not found in response" } + } + + requireNotNull(attributeData) { + "Colorloopactive 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeColorLoopActiveAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16386u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Colorloopactive attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Colorloopactive 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readColorLoopDirectionAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 16387u - suspend fun readColorLoopDirectionAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 16387u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Colorloopdirection attribute not found in response" } + } + + requireNotNull(attributeData) { + "Colorloopdirection 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeColorLoopDirectionAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16387u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Colorloopdirection attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Colorloopdirection 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readColorLoopTimeAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 16388u - suspend fun readColorLoopTimeAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 16388u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Colorlooptime attribute not found in response" } + } + + requireNotNull(attributeData) { + "Colorlooptime 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeColorLoopTimeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16388u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Colorlooptime attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Colorlooptime 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readColorLoopStartEnhancedHueAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 16389u - suspend fun readColorLoopStartEnhancedHueAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 16389u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Colorloopstartenhancedhue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Colorloopstartenhancedhue 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeColorLoopStartEnhancedHueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16389u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Colorloopstartenhancedhue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Colorloopstartenhancedhue 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readColorLoopStoredEnhancedHueAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 16390u - suspend fun readColorLoopStoredEnhancedHueAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 16390u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Colorloopstoredenhancedhue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Colorloopstoredenhancedhue 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeColorLoopStoredEnhancedHueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16390u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Colorloopstoredenhancedhue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Colorloopstoredenhancedhue 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readColorCapabilitiesAttribute(): UShort {val ATTRIBUTE_ID: UInt = 16394u - suspend fun readColorCapabilitiesAttribute(): UShort { - val ATTRIBUTE_ID: UInt = 16394u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Colorcapabilities attribute not found in response" } + } + + requireNotNull(attributeData) { + "Colorcapabilities 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 subscribeColorCapabilitiesAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16394u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Colorcapabilities attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Colorcapabilities attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -5904,353 +6190,368 @@ class ColorControlCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readColorTempPhysicalMinMiredsAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 16395u - suspend fun readColorTempPhysicalMinMiredsAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 16395u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Colortempphysicalminmireds attribute not found in response" } + } + + requireNotNull(attributeData) { + "Colortempphysicalminmireds 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeColorTempPhysicalMinMiredsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16395u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Colortempphysicalminmireds attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Colortempphysicalminmireds 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readColorTempPhysicalMaxMiredsAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 16396u - suspend fun readColorTempPhysicalMaxMiredsAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 16396u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Colortempphysicalmaxmireds attribute not found in response" } + } + + requireNotNull(attributeData) { + "Colortempphysicalmaxmireds 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeColorTempPhysicalMaxMiredsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16396u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Colortempphysicalmaxmireds attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Colortempphysicalmaxmireds 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readCoupleColorTempToLevelMinMiredsAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 16397u - suspend fun readCoupleColorTempToLevelMinMiredsAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 16397u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { - "Couplecolortemptolevelminmireds attribute not found in response" + } + + requireNotNull(attributeData) { + "Couplecolortemptolevelminmireds 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeCoupleColorTempToLevelMinMiredsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16397u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Couplecolortemptolevelminmireds attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Couplecolortemptolevelminmireds 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readStartUpColorTemperatureMiredsAttribute(): StartUpColorTemperatureMiredsAttribute {val ATTRIBUTE_ID: UInt = 16400u - suspend fun readStartUpColorTemperatureMiredsAttribute(): StartUpColorTemperatureMiredsAttribute { - val ATTRIBUTE_ID: UInt = 16400u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { - "Startupcolortemperaturemireds attribute not found in response" + } + + requireNotNull(attributeData) { + "Startupcolortemperaturemireds attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return StartUpColorTemperatureMiredsAttribute(decodedValue) } suspend fun writeStartUpColorTemperatureMiredsAttribute( value: UShort, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16400u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -6271,160 +6572,157 @@ class ColorControlCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeStartUpColorTemperatureMiredsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16400u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StartUpColorTemperatureMiredsAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StartUpColorTemperatureMiredsAttributeSubscriptionState.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) { - "Startupcolortemperaturemireds attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Startupcolortemperaturemireds 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } decodedValue?.let { emit(StartUpColorTemperatureMiredsAttributeSubscriptionState.Success(it)) } + } SubscriptionState.SubscriptionEstablished -> { emit(StartUpColorTemperatureMiredsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65528u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -6432,96 +6730,97 @@ class ColorControlCluster( emit(GeneratedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65529u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -6529,94 +6828,97 @@ class ColorControlCluster( emit(AcceptedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt = 65530u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -6624,94 +6926,97 @@ class ColorControlCluster( emit(EventListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ID: UInt = 65531u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -6719,76 +7024,81 @@ class ColorControlCluster( emit(AttributeListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u - 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 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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -6800,77 +7110,80 @@ class ColorControlCluster( emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 65533u - 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 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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -6883,7 +7196,7 @@ class ColorControlCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/CommissionerControlCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/CommissionerControlCluster.kt index 2daf2b464e948f..e9308706f47f15 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/CommissionerControlCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/CommissionerControlCluster.kt @@ -17,87 +17,114 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.UIntSubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState +import matter.controller.UByteSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class CommissionerControlCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { +class CommissionerControlCluster(private val controller: MatterController, private val endpointId: UShort) { class ReverseOpenCommissioningWindow( - val commissioningTimeout: UShort, - val PAKEPasscodeVerifier: ByteArray, - val discriminator: UShort, - val iterations: UInt, - val salt: ByteArray, + val commissioningTimeout: UShort, + val PAKEPasscodeVerifier: ByteArray, + val discriminator: UShort, + val iterations: UInt, + val salt: ByteArray + ) +class GeneratedCommandListAttribute( + val value: List ) - - class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun requestCommissioningApproval( - requestId: ULong, - vendorId: UShort, - productId: UShort, - label: String?, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun requestCommissioningApproval(requestId: ULong + ,vendorId: UShort + ,productId: UShort + ,label: String? + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() @@ -113,27 +140,27 @@ class CommissionerControlCluster( tlvWriter.put(ContextSpecificTag(TAG_PRODUCT_ID_REQ), productId) val TAG_LABEL_REQ: Int = 3 - label?.let { tlvWriter.put(ContextSpecificTag(TAG_LABEL_REQ), label) } + label?.let { + tlvWriter.put(ContextSpecificTag(TAG_LABEL_REQ), label) + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun commissionNode( - requestId: ULong, - responseTimeoutSeconds: UShort, - ipAddress: ByteArray?, - port: UShort?, - timedInvokeTimeout: Duration? = null, - ): ReverseOpenCommissioningWindow { + suspend fun commissionNode(requestId: ULong + ,responseTimeoutSeconds: UShort + ,ipAddress: ByteArray? + ,port: UShort? + ,timedInvokeTimeout: Duration? = null): ReverseOpenCommissioningWindow { val commandId: UInt = 1u val tlvWriter = TlvWriter() @@ -146,17 +173,21 @@ class CommissionerControlCluster( tlvWriter.put(ContextSpecificTag(TAG_RESPONSE_TIMEOUT_SECONDS_REQ), responseTimeoutSeconds) val TAG_IP_ADDRESS_REQ: Int = 2 - ipAddress?.let { tlvWriter.put(ContextSpecificTag(TAG_IP_ADDRESS_REQ), ipAddress) } + ipAddress?.let { + tlvWriter.put(ContextSpecificTag(TAG_IP_ADDRESS_REQ), ipAddress) + } val TAG_PORT_REQ: Int = 3 - port?.let { tlvWriter.put(ContextSpecificTag(TAG_PORT_REQ), port) } + port?.let { + tlvWriter.put(ContextSpecificTag(TAG_PORT_REQ), port) + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -166,64 +197,66 @@ class CommissionerControlCluster( tlvReader.enterStructure(AnonymousTag) val TAG_COMMISSIONING_TIMEOUT: Int = 0 var commissioningTimeout_decoded: UShort? = null - + val TAG_PAKE_PASSCODE_VERIFIER: Int = 1 var PAKEPasscodeVerifier_decoded: ByteArray? = null - + val TAG_DISCRIMINATOR: Int = 2 var discriminator_decoded: UShort? = null - + val TAG_ITERATIONS: Int = 3 var iterations_decoded: UInt? = null - + val TAG_SALT: Int = 4 var salt_decoded: ByteArray? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_COMMISSIONING_TIMEOUT)) { - commissioningTimeout_decoded = tlvReader.getUShort(tag) - } - - if (tag == ContextSpecificTag(TAG_PAKE_PASSCODE_VERIFIER)) { - PAKEPasscodeVerifier_decoded = tlvReader.getByteArray(tag) - } - - if (tag == ContextSpecificTag(TAG_DISCRIMINATOR)) { - discriminator_decoded = tlvReader.getUShort(tag) - } - - if (tag == ContextSpecificTag(TAG_ITERATIONS)) { - iterations_decoded = tlvReader.getUInt(tag) - } - - if (tag == ContextSpecificTag(TAG_SALT)) { - salt_decoded = tlvReader.getByteArray(tag) - } else { + + if (tag == ContextSpecificTag(TAG_COMMISSIONING_TIMEOUT)) {commissioningTimeout_decoded = tlvReader.getUShort(tag)} + + if (tag == ContextSpecificTag(TAG_PAKE_PASSCODE_VERIFIER)) {PAKEPasscodeVerifier_decoded = tlvReader.getByteArray(tag)} + + if (tag == ContextSpecificTag(TAG_DISCRIMINATOR)) {discriminator_decoded = tlvReader.getUShort(tag)} + + if (tag == ContextSpecificTag(TAG_ITERATIONS)) {iterations_decoded = tlvReader.getUInt(tag)} + + if (tag == ContextSpecificTag(TAG_SALT)) {salt_decoded = tlvReader.getByteArray(tag)} + + + else { tlvReader.skipElement() } } + + if (commissioningTimeout_decoded == null) { - throw IllegalStateException("commissioningTimeout not found in TLV") + throw IllegalStateException("commissioningTimeout not found in TLV") } - + + if (PAKEPasscodeVerifier_decoded == null) { - throw IllegalStateException("PAKEPasscodeVerifier not found in TLV") + throw IllegalStateException("PAKEPasscodeVerifier not found in TLV") } - + + if (discriminator_decoded == null) { - throw IllegalStateException("discriminator not found in TLV") + throw IllegalStateException("discriminator not found in TLV") } - + + if (iterations_decoded == null) { - throw IllegalStateException("iterations not found in TLV") + throw IllegalStateException("iterations not found in TLV") } - + + if (salt_decoded == null) { - throw IllegalStateException("salt not found in TLV") + throw IllegalStateException("salt not found in TLV") } + tlvReader.exitContainer() @@ -232,78 +265,81 @@ class CommissionerControlCluster( PAKEPasscodeVerifier_decoded, discriminator_decoded, iterations_decoded, - salt_decoded, + salt_decoded ) } +suspend fun readSupportedDeviceCategoriesAttribute(): UInt {val ATTRIBUTE_ID: UInt = 0u - suspend fun readSupportedDeviceCategoriesAttribute(): UInt { - 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 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}") - } + 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) { "Supporteddevicecategories attribute not found in response" } + } + + requireNotNull(attributeData) { + "Supporteddevicecategories 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 subscribeSupportedDeviceCategoriesAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Supporteddevicecategories attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Supporteddevicecategories attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -316,96 +352,97 @@ class CommissionerControlCluster( emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65528u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -413,96 +450,97 @@ class CommissionerControlCluster( emit(GeneratedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65529u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -510,94 +548,97 @@ class CommissionerControlCluster( emit(AcceptedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt = 65530u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -605,94 +646,97 @@ class CommissionerControlCluster( emit(EventListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ID: UInt = 65531u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -700,76 +744,81 @@ class CommissionerControlCluster( emit(AttributeListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u - 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 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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -781,77 +830,80 @@ class CommissionerControlCluster( emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 65533u - 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 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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -864,7 +916,7 @@ class CommissionerControlCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/ContentAppObserverCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/ContentAppObserverCluster.kt index bd87b2cef85d47..034e54bd0d2c5a 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/ContentAppObserverCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/ContentAppObserverCluster.kt @@ -17,96 +17,129 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.UIntSubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState +import matter.controller.UByteSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class ContentAppObserverCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class ContentAppMessageResponse(val status: UByte, val data: String?, val encodingHint: String?) - - class GeneratedCommandListAttribute(val value: List) +class ContentAppObserverCluster(private val controller: MatterController, private val endpointId: UShort) { + class ContentAppMessageResponse( + val status: UByte, + val data: String?, + val encodingHint: String? + ) +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun contentAppMessage( - data: String?, - encodingHint: String, - timedInvokeTimeout: Duration? = null, - ): ContentAppMessageResponse { + suspend fun contentAppMessage(data: String? + ,encodingHint: String + ,timedInvokeTimeout: Duration? = null): ContentAppMessageResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_DATA_REQ: Int = 0 - data?.let { tlvWriter.put(ContextSpecificTag(TAG_DATA_REQ), data) } + data?.let { + tlvWriter.put(ContextSpecificTag(TAG_DATA_REQ), data) + } val TAG_ENCODING_HINT_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_ENCODING_HINT_REQ), encodingHint) + tlvWriter.put(ContextSpecificTag(TAG_ENCODING_HINT_REQ), encodingHint) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -116,147 +149,158 @@ class ContentAppObserverCluster( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_DATA: Int = 1 var data_decoded: String? = null - + val TAG_ENCODING_HINT: Int = 2 var encodingHint_decoded: String? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_STATUS)) { - status_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_DATA)) { - data_decoded = + + if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_DATA)) {data_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - } - } - - if (tag == ContextSpecificTag(TAG_ENCODING_HINT)) { - encodingHint_decoded = + tlvReader.getString(tag) + } else { + null + } + }} + + if (tag == ContextSpecificTag(TAG_ENCODING_HINT)) {encodingHint_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - } - } else { + tlvReader.getString(tag) + } else { + null + } + }} + + + else { tlvReader.skipElement() } } + + if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } + + + + + tlvReader.exitContainer() - return ContentAppMessageResponse(status_decoded, data_decoded, encodingHint_decoded) + return ContentAppMessageResponse( + status_decoded, + data_decoded, + encodingHint_decoded + ) } - - 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -264,96 +308,97 @@ class ContentAppObserverCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -361,94 +406,97 @@ class ContentAppObserverCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -456,94 +504,97 @@ class ContentAppObserverCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -551,76 +602,81 @@ class ContentAppObserverCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -632,77 +688,80 @@ class ContentAppObserverCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -715,7 +774,7 @@ class ContentAppObserverCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/ContentControlCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/ContentControlCluster.kt index c2a44834d09481..b9ba76f30449a3 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/ContentControlCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/ContentControlCluster.kt @@ -17,117 +17,153 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration 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.StringSubscriptionState +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.UIntSubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState +import matter.controller.UByteSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class ContentControlCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class ResetPINResponse(val PINCode: String) - - class OnDemandRatingsAttribute(val value: List?) +class ContentControlCluster(private val controller: MatterController, private val endpointId: UShort) { + class ResetPINResponse( + val PINCode: String + ) +class OnDemandRatingsAttribute( + val value: List? + ) sealed class OnDemandRatingsAttributeSubscriptionState { - data class Success(val value: List?) : - OnDemandRatingsAttributeSubscriptionState() - + data class Success( + val value: List? + ) : OnDemandRatingsAttributeSubscriptionState() + data class Error(val exception: Exception) : OnDemandRatingsAttributeSubscriptionState() - object SubscriptionEstablished : OnDemandRatingsAttributeSubscriptionState() - } - - class ScheduledContentRatingsAttribute(val value: List?) + object SubscriptionEstablished : OnDemandRatingsAttributeSubscriptionState() + } +class ScheduledContentRatingsAttribute( + val value: List? + ) sealed class ScheduledContentRatingsAttributeSubscriptionState { - data class Success(val value: List?) : - ScheduledContentRatingsAttributeSubscriptionState() - - data class Error(val exception: Exception) : - ScheduledContentRatingsAttributeSubscriptionState() - - object SubscriptionEstablished : ScheduledContentRatingsAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + data class Success( + val value: List? + ) : ScheduledContentRatingsAttributeSubscriptionState() + + data class Error(val exception: Exception) : ScheduledContentRatingsAttributeSubscriptionState() + + object SubscriptionEstablished : ScheduledContentRatingsAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun updatePIN(oldPIN: String?, newPIN: String, timedInvokeTimeout: Duration? = null) { + suspend fun updatePIN(oldPIN: String? + ,newPIN: String + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_OLD_PIN_REQ: Int = 0 - oldPIN?.let { tlvWriter.put(ContextSpecificTag(TAG_OLD_PIN_REQ), oldPIN) } + oldPIN?.let { + tlvWriter.put(ContextSpecificTag(TAG_OLD_PIN_REQ), oldPIN) + } val TAG_NEW_PIN_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_NEW_PIN_REQ), newPIN) + tlvWriter.put(ContextSpecificTag(TAG_NEW_PIN_REQ), newPIN) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -138,14 +174,14 @@ class ContentControlCluster( val commandId: UInt = 1u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -155,38 +191,46 @@ class ContentControlCluster( tlvReader.enterStructure(AnonymousTag) val TAG_PIN_CODE: Int = 0 var PINCode_decoded: String? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_PIN_CODE)) { - PINCode_decoded = tlvReader.getString(tag) - } else { + + if (tag == ContextSpecificTag(TAG_PIN_CODE)) {PINCode_decoded = tlvReader.getString(tag)} + + + else { tlvReader.skipElement() } } + + if (PINCode_decoded == null) { - throw IllegalStateException("PINCode not found in TLV") + throw IllegalStateException("PINCode not found in TLV") } + tlvReader.exitContainer() - return ResetPINResponse(PINCode_decoded) + return ResetPINResponse( + PINCode_decoded + ) } suspend fun enable(timedInvokeTimeout: Duration? = null) { val commandId: UInt = 3u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -197,63 +241,66 @@ class ContentControlCluster( val commandId: UInt = 4u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun addBonusTime( - PINCode: String?, - bonusTime: UInt?, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun addBonusTime(PINCode: String? + ,bonusTime: UInt? + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 5u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_PIN_CODE_REQ: Int = 0 - PINCode?.let { tlvWriter.put(ContextSpecificTag(TAG_PIN_CODE_REQ), PINCode) } + PINCode?.let { + tlvWriter.put(ContextSpecificTag(TAG_PIN_CODE_REQ), PINCode) + } val TAG_BONUS_TIME_REQ: Int = 1 - bonusTime?.let { tlvWriter.put(ContextSpecificTag(TAG_BONUS_TIME_REQ), bonusTime) } + bonusTime?.let { + tlvWriter.put(ContextSpecificTag(TAG_BONUS_TIME_REQ), bonusTime) + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun setScreenDailyTime(screenTime: UInt, timedInvokeTimeout: Duration? = null) { + suspend fun setScreenDailyTime(screenTime: UInt + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 6u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_SCREEN_TIME_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_SCREEN_TIME_REQ), screenTime) + tlvWriter.put(ContextSpecificTag(TAG_SCREEN_TIME_REQ), screenTime) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -264,14 +311,14 @@ class ContentControlCluster( val commandId: UInt = 7u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -282,132 +329,136 @@ class ContentControlCluster( val commandId: UInt = 8u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun setOnDemandRatingThreshold(rating: String, timedInvokeTimeout: Duration? = null) { + suspend fun setOnDemandRatingThreshold(rating: String + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 9u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_RATING_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_RATING_REQ), rating) + tlvWriter.put(ContextSpecificTag(TAG_RATING_REQ), rating) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun setScheduledContentRatingThreshold( - rating: String, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun setScheduledContentRatingThreshold(rating: String + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 10u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_RATING_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_RATING_REQ), rating) + tlvWriter.put(ContextSpecificTag(TAG_RATING_REQ), rating) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - - suspend fun readEnabledAttribute(): Boolean { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readEnabledAttribute(): Boolean {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}") - } + 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) { "Enabled attribute not found in response" } + } + + requireNotNull(attributeData) { + "Enabled attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Boolean = tlvReader.getBoolean(AnonymousTag) + return decodedValue } suspend fun subscribeEnabledAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Enabled attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Enabled attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -419,660 +470,687 @@ class ContentControlCluster( emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readOnDemandRatingsAttribute(): OnDemandRatingsAttribute { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readOnDemandRatingsAttribute(): OnDemandRatingsAttribute {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}") - } + 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) { "Ondemandratings attribute not found in response" } + } + + requireNotNull(attributeData) { + "Ondemandratings attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(ContentControlClusterRatingNameStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(ContentControlClusterRatingNameStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + } else { + null + } + return OnDemandRatingsAttribute(decodedValue) } suspend fun subscribeOnDemandRatingsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - OnDemandRatingsAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(OnDemandRatingsAttributeSubscriptionState.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) { - "Ondemandratings attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Ondemandratings attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(ContentControlClusterRatingNameStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { emit(OnDemandRatingsAttributeSubscriptionState.Success(it)) } + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(ContentControlClusterRatingNameStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { + emit(OnDemandRatingsAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(OnDemandRatingsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readOnDemandRatingThresholdAttribute(): String? { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readOnDemandRatingThresholdAttribute(): String? {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}") - } + 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) { "Ondemandratingthreshold attribute not found in response" } + } + + requireNotNull(attributeData) { + "Ondemandratingthreshold attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeOnDemandRatingThresholdAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StringSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StringSubscriptionState.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) { - "Ondemandratingthreshold attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Ondemandratingthreshold attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(StringSubscriptionState.Success(it)) } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(StringSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readScheduledContentRatingsAttribute(): ScheduledContentRatingsAttribute { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readScheduledContentRatingsAttribute(): ScheduledContentRatingsAttribute {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}") - } + 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) { "Scheduledcontentratings attribute not found in response" } + } + + requireNotNull(attributeData) { + "Scheduledcontentratings attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(ContentControlClusterRatingNameStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(ContentControlClusterRatingNameStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + } else { + null + } + return ScheduledContentRatingsAttribute(decodedValue) } suspend fun subscribeScheduledContentRatingsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ScheduledContentRatingsAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ScheduledContentRatingsAttributeSubscriptionState.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) { - "Scheduledcontentratings attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Scheduledcontentratings attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(ContentControlClusterRatingNameStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { emit(ScheduledContentRatingsAttributeSubscriptionState.Success(it)) } + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(ContentControlClusterRatingNameStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { + emit(ScheduledContentRatingsAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ScheduledContentRatingsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readScheduledContentRatingThresholdAttribute(): String? { - val ATTRIBUTE_ID: UInt = 4u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readScheduledContentRatingThresholdAttribute(): String? {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}") - } + 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) { - "Scheduledcontentratingthreshold attribute not found in response" + } + + requireNotNull(attributeData) { + "Scheduledcontentratingthreshold attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeScheduledContentRatingThresholdAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StringSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StringSubscriptionState.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) { - "Scheduledcontentratingthreshold attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Scheduledcontentratingthreshold attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(StringSubscriptionState.Success(it)) } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(StringSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readScreenDailyTimeAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 5u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readScreenDailyTimeAttribute(): UInt? {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}") - } + 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) { "Screendailytime attribute not found in response" } + } + + requireNotNull(attributeData) { + "Screendailytime attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeScreenDailyTimeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Screendailytime attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Screendailytime attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readRemainingScreenTimeAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 6u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readRemainingScreenTimeAttribute(): UInt? {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}") - } + 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) { "Remainingscreentime attribute not found in response" } + } + + requireNotNull(attributeData) { + "Remainingscreentime attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeRemainingScreenTimeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Remainingscreentime attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Remainingscreentime attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readBlockUnratedAttribute(): Boolean { - val ATTRIBUTE_ID: UInt = 7u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readBlockUnratedAttribute(): Boolean {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}") - } + 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) { "Blockunrated attribute not found in response" } + } + + requireNotNull(attributeData) { + "Blockunrated attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Boolean = tlvReader.getBoolean(AnonymousTag) + return decodedValue } suspend fun subscribeBlockUnratedAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Blockunrated attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Blockunrated attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -1084,96 +1162,97 @@ class ContentControlCluster( emit(BooleanSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1181,96 +1260,97 @@ class ContentControlCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1278,94 +1358,97 @@ class ContentControlCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1373,94 +1456,97 @@ class ContentControlCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1468,76 +1554,81 @@ class ContentControlCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1549,77 +1640,80 @@ class ContentControlCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1632,7 +1726,7 @@ class ContentControlCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/ContentLauncherCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/ContentLauncherCluster.kt index ae0b6d4935427f..0e0f98b0995f7b 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/ContentLauncherCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/ContentLauncherCluster.kt @@ -17,92 +17,125 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.UIntSubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState +import matter.controller.UByteSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class ContentLauncherCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class LauncherResponse(val status: UByte, val data: String?) - - class AcceptHeaderAttribute(val value: List?) +class ContentLauncherCluster(private val controller: MatterController, private val endpointId: UShort) { + class LauncherResponse( + val status: UByte, + val data: String? + ) +class AcceptHeaderAttribute( + val value: List? + ) sealed class AcceptHeaderAttributeSubscriptionState { - data class Success(val value: List?) : AcceptHeaderAttributeSubscriptionState() - + data class Success( + val value: List? + ) : AcceptHeaderAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptHeaderAttributeSubscriptionState() - object SubscriptionEstablished : AcceptHeaderAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : AcceptHeaderAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun launchContent( - search: ContentLauncherClusterContentSearchStruct, - autoPlay: Boolean, - data: String?, - playbackPreferences: ContentLauncherClusterPlaybackPreferencesStruct?, - useCurrentContext: Boolean?, - timedInvokeTimeout: Duration? = null, - ): LauncherResponse { + suspend fun launchContent(search: ContentLauncherClusterContentSearchStruct + ,autoPlay: Boolean + ,data: String? + ,playbackPreferences: ContentLauncherClusterPlaybackPreferencesStruct? + ,useCurrentContext: Boolean? + ,timedInvokeTimeout: Duration? = null): LauncherResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() @@ -115,7 +148,9 @@ class ContentLauncherCluster( tlvWriter.put(ContextSpecificTag(TAG_AUTO_PLAY_REQ), autoPlay) val TAG_DATA_REQ: Int = 2 - data?.let { tlvWriter.put(ContextSpecificTag(TAG_DATA_REQ), data) } + data?.let { + tlvWriter.put(ContextSpecificTag(TAG_DATA_REQ), data) + } val TAG_PLAYBACK_PREFERENCES_REQ: Int = 3 playbackPreferences?.let { @@ -125,14 +160,14 @@ class ContentLauncherCluster( val TAG_USE_CURRENT_CONTEXT_REQ: Int = 4 useCurrentContext?.let { tlvWriter.put(ContextSpecificTag(TAG_USE_CURRENT_CONTEXT_REQ), useCurrentContext) - } + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -142,49 +177,56 @@ class ContentLauncherCluster( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_DATA: Int = 1 var data_decoded: String? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_STATUS)) { - status_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_DATA)) { - data_decoded = + + if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_DATA)) {data_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - } - } else { + tlvReader.getString(tag) + } else { + null + } + }} + + + else { tlvReader.skipElement() } } + + if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } + + + tlvReader.exitContainer() - return LauncherResponse(status_decoded, data_decoded) + return LauncherResponse( + status_decoded, + data_decoded + ) } - suspend fun launchURL( - contentURL: String, - displayString: String?, - brandingInformation: ContentLauncherClusterBrandingInformationStruct?, - timedInvokeTimeout: Duration? = null, - ): LauncherResponse { + suspend fun launchURL(contentURL: String + ,displayString: String? + ,brandingInformation: ContentLauncherClusterBrandingInformationStruct? + ,timedInvokeTimeout: Duration? = null): LauncherResponse { val commandId: UInt = 1u val tlvWriter = TlvWriter() @@ -194,19 +236,21 @@ class ContentLauncherCluster( tlvWriter.put(ContextSpecificTag(TAG_CONTENT_URL_REQ), contentURL) val TAG_DISPLAY_STRING_REQ: Int = 1 - displayString?.let { tlvWriter.put(ContextSpecificTag(TAG_DISPLAY_STRING_REQ), displayString) } + displayString?.let { + tlvWriter.put(ContextSpecificTag(TAG_DISPLAY_STRING_REQ), displayString) + } val TAG_BRANDING_INFORMATION_REQ: Int = 2 brandingInformation?.let { brandingInformation.toTlv(ContextSpecificTag(TAG_BRANDING_INFORMATION_REQ), tlvWriter) - } + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -216,326 +260,346 @@ class ContentLauncherCluster( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_DATA: Int = 1 var data_decoded: String? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_STATUS)) { - status_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_DATA)) { - data_decoded = + + if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_DATA)) {data_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - } - } else { + tlvReader.getString(tag) + } else { + null + } + }} + + + else { tlvReader.skipElement() } } + + if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } + + + tlvReader.exitContainer() - return LauncherResponse(status_decoded, data_decoded) + return LauncherResponse( + status_decoded, + data_decoded + ) } - - suspend fun readAcceptHeaderAttribute(): AcceptHeaderAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readAcceptHeaderAttribute(): AcceptHeaderAttribute {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}") - } + 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) { "Acceptheader attribute not found in response" } + } + + requireNotNull(attributeData) { + "Acceptheader attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getString(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getString(AnonymousTag)) } + tlvReader.exitContainer() + } + } else { + null + } + return AcceptHeaderAttribute(decodedValue) } suspend fun subscribeAcceptHeaderAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - AcceptHeaderAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(AcceptHeaderAttributeSubscriptionState.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) { "Acceptheader attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Acceptheader attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getString(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { emit(AcceptHeaderAttributeSubscriptionState.Success(it)) } + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getString(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { + emit(AcceptHeaderAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(AcceptHeaderAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readSupportedStreamingProtocolsAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readSupportedStreamingProtocolsAttribute(): UInt? {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}") - } + 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) { "Supportedstreamingprotocols attribute not found in response" } + } + + requireNotNull(attributeData) { + "Supportedstreamingprotocols attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeSupportedStreamingProtocolsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Supportedstreamingprotocols attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Supportedstreamingprotocols attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -543,96 +607,97 @@ class ContentLauncherCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -640,94 +705,97 @@ class ContentLauncherCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -735,94 +803,97 @@ class ContentLauncherCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -830,76 +901,81 @@ class ContentLauncherCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -911,77 +987,80 @@ class ContentLauncherCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -994,7 +1073,7 @@ class ContentLauncherCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/DemandResponseLoadControlCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/DemandResponseLoadControlCluster.kt index ea72cd4cd78068..3ada4bef66c3cf 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/DemandResponseLoadControlCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/DemandResponseLoadControlCluster.kt @@ -17,190 +17,209 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.cluster.structs.* +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class DemandResponseLoadControlCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class LoadControlProgramsAttribute( +class DemandResponseLoadControlCluster(private val controller: MatterController, private val endpointId: UShort) {class LoadControlProgramsAttribute( val value: List ) sealed class LoadControlProgramsAttributeSubscriptionState { - data class Success(val value: List) : - LoadControlProgramsAttributeSubscriptionState() - + data class Success( + val value: List + ) : LoadControlProgramsAttributeSubscriptionState() + data class Error(val exception: Exception) : LoadControlProgramsAttributeSubscriptionState() - object SubscriptionEstablished : LoadControlProgramsAttributeSubscriptionState() - } - - class EventsAttribute(val value: List) + object SubscriptionEstablished : LoadControlProgramsAttributeSubscriptionState() + } +class EventsAttribute( + val value: List + ) sealed class EventsAttributeSubscriptionState { - data class Success(val value: List) : - EventsAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventsAttributeSubscriptionState() + data class Error(val exception: Exception) : EventsAttributeSubscriptionState() - object SubscriptionEstablished : EventsAttributeSubscriptionState() - } - - class ActiveEventsAttribute( + object SubscriptionEstablished : EventsAttributeSubscriptionState() + } +class ActiveEventsAttribute( val value: List ) sealed class ActiveEventsAttributeSubscriptionState { - data class Success(val value: List) : - ActiveEventsAttributeSubscriptionState() - + data class Success( + val value: List + ) : ActiveEventsAttributeSubscriptionState() + data class Error(val exception: Exception) : ActiveEventsAttributeSubscriptionState() - object SubscriptionEstablished : ActiveEventsAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : ActiveEventsAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun registerLoadControlProgramRequest( - loadControlProgram: DemandResponseLoadControlClusterLoadControlProgramStruct, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun registerLoadControlProgramRequest(loadControlProgram: DemandResponseLoadControlClusterLoadControlProgramStruct + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_LOAD_CONTROL_PROGRAM_REQ: Int = 0 - loadControlProgram.toTlv(ContextSpecificTag(TAG_LOAD_CONTROL_PROGRAM_REQ), tlvWriter) + loadControlProgram.toTlv(ContextSpecificTag(TAG_LOAD_CONTROL_PROGRAM_REQ), tlvWriter) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun unregisterLoadControlProgramRequest( - loadControlProgramID: ByteArray, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun unregisterLoadControlProgramRequest(loadControlProgramID: ByteArray + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 1u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_LOAD_CONTROL_PROGRAM_ID_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_LOAD_CONTROL_PROGRAM_ID_REQ), loadControlProgramID) + tlvWriter.put(ContextSpecificTag(TAG_LOAD_CONTROL_PROGRAM_ID_REQ), loadControlProgramID) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun addLoadControlEventRequest( - event: DemandResponseLoadControlClusterLoadControlEventStruct, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun addLoadControlEventRequest(event: DemandResponseLoadControlClusterLoadControlEventStruct + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 2u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_EVENT_REQ: Int = 0 - event.toTlv(ContextSpecificTag(TAG_EVENT_REQ), tlvWriter) + event.toTlv(ContextSpecificTag(TAG_EVENT_REQ), tlvWriter) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun removeLoadControlEventRequest( - eventID: ByteArray, - cancelControl: UShort, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun removeLoadControlEventRequest(eventID: ByteArray + ,cancelControl: UShort + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 3u val tlvWriter = TlvWriter() @@ -210,14 +229,14 @@ class DemandResponseLoadControlCluster( tlvWriter.put(ContextSpecificTag(TAG_EVENT_ID_REQ), eventID) val TAG_CANCEL_CONTROL_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_CANCEL_CONTROL_REQ), cancelControl) + tlvWriter.put(ContextSpecificTag(TAG_CANCEL_CONTROL_REQ), cancelControl) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -228,117 +247,108 @@ class DemandResponseLoadControlCluster( val commandId: UInt = 4u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - - suspend fun readLoadControlProgramsAttribute(): LoadControlProgramsAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readLoadControlProgramsAttribute(): LoadControlProgramsAttribute {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}") - } + 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) { "Loadcontrolprograms attribute not found in response" } + } + + requireNotNull(attributeData) { + "Loadcontrolprograms 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( - DemandResponseLoadControlClusterLoadControlProgramStruct.fromTlv( - AnonymousTag, - tlvReader, - ) - ) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(DemandResponseLoadControlClusterLoadControlProgramStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + return LoadControlProgramsAttribute(decodedValue) } suspend fun subscribeLoadControlProgramsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - LoadControlProgramsAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(LoadControlProgramsAttributeSubscriptionState.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) { - "Loadcontrolprograms attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Loadcontrolprograms 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( - DemandResponseLoadControlClusterLoadControlProgramStruct.fromTlv( - AnonymousTag, - tlvReader, - ) - ) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(DemandResponseLoadControlClusterLoadControlProgramStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(LoadControlProgramsAttributeSubscriptionState.Success(decodedValue)) } @@ -346,77 +356,80 @@ class DemandResponseLoadControlCluster( emit(LoadControlProgramsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readNumberOfLoadControlProgramsAttribute(): 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)) - +suspend fun readNumberOfLoadControlProgramsAttribute(): 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}") - } + 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) { "Numberofloadcontrolprograms attribute not found in response" } + } + + requireNotNull(attributeData) { + "Numberofloadcontrolprograms 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 subscribeNumberOfLoadControlProgramsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Numberofloadcontrolprograms attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Numberofloadcontrolprograms attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -429,101 +442,97 @@ class DemandResponseLoadControlCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readEventsAttribute(): EventsAttribute { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readEventsAttribute(): EventsAttribute {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}") - } + 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) { "Events attribute not found in response" } + } + + requireNotNull(attributeData) { + "Events 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( - DemandResponseLoadControlClusterLoadControlEventStruct.fromTlv(AnonymousTag, tlvReader) - ) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(DemandResponseLoadControlClusterLoadControlEventStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + return EventsAttribute(decodedValue) } suspend fun subscribeEventsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - EventsAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(EventsAttributeSubscriptionState.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) { "Events attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Events 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( - DemandResponseLoadControlClusterLoadControlEventStruct.fromTlv( - AnonymousTag, - tlvReader, - ) - ) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(DemandResponseLoadControlClusterLoadControlEventStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(EventsAttributeSubscriptionState.Success(decodedValue)) } @@ -531,101 +540,97 @@ class DemandResponseLoadControlCluster( emit(EventsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readActiveEventsAttribute(): ActiveEventsAttribute { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readActiveEventsAttribute(): ActiveEventsAttribute {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}") - } + 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) { "Activeevents attribute not found in response" } + } + + requireNotNull(attributeData) { + "Activeevents 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( - DemandResponseLoadControlClusterLoadControlEventStruct.fromTlv(AnonymousTag, tlvReader) - ) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(DemandResponseLoadControlClusterLoadControlEventStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + return ActiveEventsAttribute(decodedValue) } suspend fun subscribeActiveEventsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ActiveEventsAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ActiveEventsAttributeSubscriptionState.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) { "Activeevents attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Activeevents 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( - DemandResponseLoadControlClusterLoadControlEventStruct.fromTlv( - AnonymousTag, - tlvReader, - ) - ) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(DemandResponseLoadControlClusterLoadControlEventStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(ActiveEventsAttributeSubscriptionState.Success(decodedValue)) } @@ -633,77 +638,80 @@ class DemandResponseLoadControlCluster( emit(ActiveEventsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readNumberOfEventsPerProgramAttribute(): 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)) - +suspend fun readNumberOfEventsPerProgramAttribute(): 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}") - } + 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) { "Numberofeventsperprogram attribute not found in response" } + } + + requireNotNull(attributeData) { + "Numberofeventsperprogram 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 subscribeNumberOfEventsPerProgramAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Numberofeventsperprogram attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Numberofeventsperprogram attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -716,77 +724,80 @@ class DemandResponseLoadControlCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readNumberOfTransitionsAttribute(): UByte { - val ATTRIBUTE_ID: UInt = 5u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readNumberOfTransitionsAttribute(): UByte {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}") - } + 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) { "Numberoftransitions attribute not found in response" } + } + + requireNotNull(attributeData) { + "Numberoftransitions 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 subscribeNumberOfTransitionsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Numberoftransitions attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Numberoftransitions attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -799,57 +810,68 @@ class DemandResponseLoadControlCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readDefaultRandomStartAttribute(): UByte { - val ATTRIBUTE_ID: UInt = 6u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readDefaultRandomStartAttribute(): UByte {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}") - } + 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) { "Defaultrandomstart attribute not found in response" } + } + + requireNotNull(attributeData) { + "Defaultrandomstart 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 writeDefaultRandomStartAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeDefaultRandomStartAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 6u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -870,46 +892,42 @@ class DemandResponseLoadControlCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeDefaultRandomStartAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Defaultrandomstart attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Defaultrandomstart attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -922,60 +940,68 @@ class DemandResponseLoadControlCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readDefaultRandomDurationAttribute(): UByte { - val ATTRIBUTE_ID: UInt = 7u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readDefaultRandomDurationAttribute(): UByte {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}") - } + 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) { "Defaultrandomduration attribute not found in response" } + } + + requireNotNull(attributeData) { + "Defaultrandomduration 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 writeDefaultRandomDurationAttribute( value: UByte, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 7u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -996,46 +1022,42 @@ class DemandResponseLoadControlCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeDefaultRandomDurationAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Defaultrandomduration attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Defaultrandomduration attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -1048,96 +1070,97 @@ class DemandResponseLoadControlCluster( emit(UByteSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1145,96 +1168,97 @@ class DemandResponseLoadControlCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1242,94 +1266,97 @@ class DemandResponseLoadControlCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1337,94 +1364,97 @@ class DemandResponseLoadControlCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1432,76 +1462,81 @@ class DemandResponseLoadControlCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1513,77 +1548,80 @@ class DemandResponseLoadControlCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1596,7 +1634,7 @@ class DemandResponseLoadControlCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/DescriptorCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/DescriptorCluster.kt index 0ef479e85a94fc..e5b5a887fd60b2 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/DescriptorCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/DescriptorCluster.kt @@ -17,203 +17,254 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.UIntSubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState +import matter.controller.UByteSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath +import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader +import matter.tlv.TlvWriter -class DescriptorCluster(private val controller: MatterController, private val endpointId: UShort) { - class DeviceTypeListAttribute(val value: List) +class DescriptorCluster(private val controller: MatterController, private val endpointId: UShort) {class DeviceTypeListAttribute( + val value: List + ) sealed class DeviceTypeListAttributeSubscriptionState { - data class Success(val value: List) : - DeviceTypeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : DeviceTypeListAttributeSubscriptionState() + data class Error(val exception: Exception) : DeviceTypeListAttributeSubscriptionState() - object SubscriptionEstablished : DeviceTypeListAttributeSubscriptionState() - } - - class ServerListAttribute(val value: List) + object SubscriptionEstablished : DeviceTypeListAttributeSubscriptionState() + } +class ServerListAttribute( + val value: List + ) sealed class ServerListAttributeSubscriptionState { - data class Success(val value: List) : ServerListAttributeSubscriptionState() - + data class Success( + val value: List + ) : ServerListAttributeSubscriptionState() + data class Error(val exception: Exception) : ServerListAttributeSubscriptionState() - object SubscriptionEstablished : ServerListAttributeSubscriptionState() - } - - class ClientListAttribute(val value: List) + object SubscriptionEstablished : ServerListAttributeSubscriptionState() + } +class ClientListAttribute( + val value: List + ) sealed class ClientListAttributeSubscriptionState { - data class Success(val value: List) : ClientListAttributeSubscriptionState() - + data class Success( + val value: List + ) : ClientListAttributeSubscriptionState() + data class Error(val exception: Exception) : ClientListAttributeSubscriptionState() - object SubscriptionEstablished : ClientListAttributeSubscriptionState() - } - - class PartsListAttribute(val value: List) + object SubscriptionEstablished : ClientListAttributeSubscriptionState() + } +class PartsListAttribute( + val value: List + ) sealed class PartsListAttributeSubscriptionState { - data class Success(val value: List) : PartsListAttributeSubscriptionState() - + data class Success( + val value: List + ) : PartsListAttributeSubscriptionState() + data class Error(val exception: Exception) : PartsListAttributeSubscriptionState() - object SubscriptionEstablished : PartsListAttributeSubscriptionState() - } - - class TagListAttribute(val value: List?) + object SubscriptionEstablished : PartsListAttributeSubscriptionState() + } +class TagListAttribute( + val value: List? + ) sealed class TagListAttributeSubscriptionState { - data class Success(val value: List?) : - TagListAttributeSubscriptionState() - + data class Success( + val value: List? + ) : TagListAttributeSubscriptionState() + data class Error(val exception: Exception) : TagListAttributeSubscriptionState() - object SubscriptionEstablished : TagListAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : TagListAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } - - suspend fun readDeviceTypeListAttribute(): DeviceTypeListAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } +suspend fun readDeviceTypeListAttribute(): DeviceTypeListAttribute {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}") - } + 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) { "Devicetypelist attribute not found in response" } + } + + requireNotNull(attributeData) { + "Devicetypelist 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(DescriptorClusterDeviceTypeStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(DescriptorClusterDeviceTypeStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + return DeviceTypeListAttribute(decodedValue) } suspend fun subscribeDeviceTypeListAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - DeviceTypeListAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(DeviceTypeListAttributeSubscriptionState.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) { - "Devicetypelist attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Devicetypelist 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(DescriptorClusterDeviceTypeStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(DescriptorClusterDeviceTypeStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(DeviceTypeListAttributeSubscriptionState.Success(decodedValue)) } @@ -221,94 +272,97 @@ class DescriptorCluster(private val controller: MatterController, private val en emit(DeviceTypeListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readServerListAttribute(): ServerListAttribute { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readServerListAttribute(): ServerListAttribute {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}") - } + 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) { "Serverlist attribute not found in response" } + } + + requireNotNull(attributeData) { + "Serverlist 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() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) } + tlvReader.exitContainer() + } + return ServerListAttribute(decodedValue) } suspend fun subscribeServerListAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ServerListAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ServerListAttributeSubscriptionState.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) { "Serverlist attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Serverlist 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(ServerListAttributeSubscriptionState.Success(decodedValue)) } @@ -316,94 +370,97 @@ class DescriptorCluster(private val controller: MatterController, private val en emit(ServerListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readClientListAttribute(): ClientListAttribute { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readClientListAttribute(): ClientListAttribute {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}") - } + 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) { "Clientlist attribute not found in response" } + } + + requireNotNull(attributeData) { + "Clientlist 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() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) } + tlvReader.exitContainer() + } + return ClientListAttribute(decodedValue) } suspend fun subscribeClientListAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ClientListAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ClientListAttributeSubscriptionState.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) { "Clientlist attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Clientlist 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(ClientListAttributeSubscriptionState.Success(decodedValue)) } @@ -411,94 +468,97 @@ class DescriptorCluster(private val controller: MatterController, private val en emit(ClientListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readPartsListAttribute(): PartsListAttribute { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readPartsListAttribute(): PartsListAttribute {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}") - } + 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) { "Partslist attribute not found in response" } + } + + requireNotNull(attributeData) { + "Partslist 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.getUShort(AnonymousTag)) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUShort(AnonymousTag)) } + tlvReader.exitContainer() + } + return PartsListAttribute(decodedValue) } suspend fun subscribePartsListAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - PartsListAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(PartsListAttributeSubscriptionState.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) { "Partslist attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Partslist 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.getUShort(AnonymousTag)) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUShort(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(PartsListAttributeSubscriptionState.Success(decodedValue)) } @@ -506,199 +566,206 @@ class DescriptorCluster(private val controller: MatterController, private val en emit(PartsListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readTagListAttribute(): TagListAttribute { - val ATTRIBUTE_ID: UInt = 4u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readTagListAttribute(): TagListAttribute {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}") - } + 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) { "Taglist attribute not found in response" } + } + + requireNotNull(attributeData) { + "Taglist attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(DescriptorClusterSemanticTagStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(DescriptorClusterSemanticTagStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + } else { + null + } + return TagListAttribute(decodedValue) } suspend fun subscribeTagListAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - TagListAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(TagListAttributeSubscriptionState.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) { "Taglist attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Taglist attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(DescriptorClusterSemanticTagStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { emit(TagListAttributeSubscriptionState.Success(it)) } + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(DescriptorClusterSemanticTagStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { + emit(TagListAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(TagListAttributeSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -706,96 +773,97 @@ class DescriptorCluster(private val controller: MatterController, private val en 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -803,94 +871,97 @@ class DescriptorCluster(private val controller: MatterController, private val en 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -898,94 +969,97 @@ class DescriptorCluster(private val controller: MatterController, private val en 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -993,76 +1067,81 @@ class DescriptorCluster(private val controller: MatterController, private val en 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1074,77 +1153,80 @@ class DescriptorCluster(private val controller: MatterController, private val en 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1157,7 +1239,7 @@ class DescriptorCluster(private val controller: MatterController, private val en emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/DeviceEnergyManagementCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/DeviceEnergyManagementCluster.kt index 455b52d4d0853b..92e778b73b7fe1 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/DeviceEnergyManagementCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/DeviceEnergyManagementCluster.kt @@ -17,106 +17,131 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration 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.LongSubscriptionState import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class DeviceEnergyManagementCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class PowerAdjustmentCapabilityAttribute( +class DeviceEnergyManagementCluster(private val controller: MatterController, private val endpointId: UShort) {class PowerAdjustmentCapabilityAttribute( val value: DeviceEnergyManagementClusterPowerAdjustCapabilityStruct? ) sealed class PowerAdjustmentCapabilityAttributeSubscriptionState { - data class Success(val value: DeviceEnergyManagementClusterPowerAdjustCapabilityStruct?) : - PowerAdjustmentCapabilityAttributeSubscriptionState() - - data class Error(val exception: Exception) : - PowerAdjustmentCapabilityAttributeSubscriptionState() - - object SubscriptionEstablished : PowerAdjustmentCapabilityAttributeSubscriptionState() - } - - class ForecastAttribute(val value: DeviceEnergyManagementClusterForecastStruct?) + data class Success( + val value: DeviceEnergyManagementClusterPowerAdjustCapabilityStruct? + ) : PowerAdjustmentCapabilityAttributeSubscriptionState() + + data class Error(val exception: Exception) : PowerAdjustmentCapabilityAttributeSubscriptionState() + + object SubscriptionEstablished : PowerAdjustmentCapabilityAttributeSubscriptionState() + } +class ForecastAttribute( + val value: DeviceEnergyManagementClusterForecastStruct? + ) sealed class ForecastAttributeSubscriptionState { - data class Success(val value: DeviceEnergyManagementClusterForecastStruct?) : - ForecastAttributeSubscriptionState() - + data class Success( + val value: DeviceEnergyManagementClusterForecastStruct? + ) : ForecastAttributeSubscriptionState() + data class Error(val exception: Exception) : ForecastAttributeSubscriptionState() - object SubscriptionEstablished : ForecastAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : ForecastAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun powerAdjustRequest( - power: Long, - duration: UInt, - cause: UByte, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun powerAdjustRequest(power: Long + ,duration: UInt + ,cause: UByte + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() @@ -129,14 +154,14 @@ class DeviceEnergyManagementCluster( tlvWriter.put(ContextSpecificTag(TAG_DURATION_REQ), duration) val TAG_CAUSE_REQ: Int = 2 - tlvWriter.put(ContextSpecificTag(TAG_CAUSE_REQ), cause) + tlvWriter.put(ContextSpecificTag(TAG_CAUSE_REQ), cause) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -147,25 +172,23 @@ class DeviceEnergyManagementCluster( val commandId: UInt = 1u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun startTimeAdjustRequest( - requestedStartTime: UInt, - cause: UByte, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun startTimeAdjustRequest(requestedStartTime: UInt + ,cause: UByte + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 2u val tlvWriter = TlvWriter() @@ -175,21 +198,23 @@ class DeviceEnergyManagementCluster( tlvWriter.put(ContextSpecificTag(TAG_REQUESTED_START_TIME_REQ), requestedStartTime) val TAG_CAUSE_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_CAUSE_REQ), cause) + tlvWriter.put(ContextSpecificTag(TAG_CAUSE_REQ), cause) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun pauseRequest(duration: UInt, cause: UByte, timedInvokeTimeout: Duration? = null) { + suspend fun pauseRequest(duration: UInt + ,cause: UByte + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 3u val tlvWriter = TlvWriter() @@ -199,14 +224,14 @@ class DeviceEnergyManagementCluster( tlvWriter.put(ContextSpecificTag(TAG_DURATION_REQ), duration) val TAG_CAUSE_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_CAUSE_REQ), cause) + tlvWriter.put(ContextSpecificTag(TAG_CAUSE_REQ), cause) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -217,26 +242,24 @@ class DeviceEnergyManagementCluster( val commandId: UInt = 4u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun modifyForecastRequest( - forecastID: UInt, - slotAdjustments: List, - cause: UByte, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun modifyForecastRequest(forecastID: UInt + ,slotAdjustments: List + ,cause: UByte + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 5u val tlvWriter = TlvWriter() @@ -247,31 +270,29 @@ class DeviceEnergyManagementCluster( val TAG_SLOT_ADJUSTMENTS_REQ: Int = 1 tlvWriter.startArray(ContextSpecificTag(TAG_SLOT_ADJUSTMENTS_REQ)) - for (item in slotAdjustments.iterator()) { - item.toTlv(AnonymousTag, tlvWriter) - } - tlvWriter.endArray() + for (item in slotAdjustments.iterator()) { + item.toTlv(AnonymousTag, tlvWriter) + } + tlvWriter.endArray() val TAG_CAUSE_REQ: Int = 2 - tlvWriter.put(ContextSpecificTag(TAG_CAUSE_REQ), cause) + tlvWriter.put(ContextSpecificTag(TAG_CAUSE_REQ), cause) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun requestConstraintBasedForecast( - constraints: List, - cause: UByte, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun requestConstraintBasedForecast(constraints: List + ,cause: UByte + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 6u val tlvWriter = TlvWriter() @@ -279,20 +300,20 @@ class DeviceEnergyManagementCluster( val TAG_CONSTRAINTS_REQ: Int = 0 tlvWriter.startArray(ContextSpecificTag(TAG_CONSTRAINTS_REQ)) - for (item in constraints.iterator()) { - item.toTlv(AnonymousTag, tlvWriter) - } - tlvWriter.endArray() + for (item in constraints.iterator()) { + item.toTlv(AnonymousTag, tlvWriter) + } + tlvWriter.endArray() val TAG_CAUSE_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_CAUSE_REQ), cause) + tlvWriter.put(ContextSpecificTag(TAG_CAUSE_REQ), cause) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -303,87 +324,92 @@ class DeviceEnergyManagementCluster( val commandId: UInt = 7u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - - suspend fun readESATypeAttribute(): 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)) - +suspend fun readESATypeAttribute(): 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}") - } + 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) { "Esatype attribute not found in response" } + } + + requireNotNull(attributeData) { + "Esatype 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 subscribeESATypeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Esatype attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Esatype attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -395,77 +421,80 @@ class DeviceEnergyManagementCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readESACanGenerateAttribute(): Boolean { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readESACanGenerateAttribute(): Boolean {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}") - } + 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) { "Esacangenerate attribute not found in response" } + } + + requireNotNull(attributeData) { + "Esacangenerate attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Boolean = tlvReader.getBoolean(AnonymousTag) + return decodedValue } suspend fun subscribeESACanGenerateAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Esacangenerate attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Esacangenerate attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -478,76 +507,81 @@ class DeviceEnergyManagementCluster( emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readESAStateAttribute(): UByte { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readESAStateAttribute(): UByte {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}") - } + 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) { "Esastate attribute not found in response" } + } + + requireNotNull(attributeData) { + "Esastate 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 subscribeESAStateAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Esastate attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Esastate attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -559,76 +593,81 @@ class DeviceEnergyManagementCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readAbsMinPowerAttribute(): Long { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readAbsMinPowerAttribute(): Long {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}") - } + 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) { "Absminpower attribute not found in response" } + } + + requireNotNull(attributeData) { + "Absminpower attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Long = tlvReader.getLong(AnonymousTag) + return decodedValue } suspend fun subscribeAbsMinPowerAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - LongSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(LongSubscriptionState.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) { "Absminpower attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Absminpower attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -640,76 +679,81 @@ class DeviceEnergyManagementCluster( emit(LongSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readAbsMaxPowerAttribute(): Long { - val ATTRIBUTE_ID: UInt = 4u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readAbsMaxPowerAttribute(): Long {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}") - } + 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) { "Absmaxpower attribute not found in response" } + } + + requireNotNull(attributeData) { + "Absmaxpower attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Long = tlvReader.getLong(AnonymousTag) + return decodedValue } suspend fun subscribeAbsMaxPowerAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - LongSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(LongSubscriptionState.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) { "Absmaxpower attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Absmaxpower attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -721,396 +765,408 @@ class DeviceEnergyManagementCluster( emit(LongSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readPowerAdjustmentCapabilityAttribute(): PowerAdjustmentCapabilityAttribute { - val ATTRIBUTE_ID: UInt = 5u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readPowerAdjustmentCapabilityAttribute(): PowerAdjustmentCapabilityAttribute {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}") - } + 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) { "Poweradjustmentcapability attribute not found in response" } + } + + requireNotNull(attributeData) { + "Poweradjustmentcapability attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: DeviceEnergyManagementClusterPowerAdjustCapabilityStruct? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - DeviceEnergyManagementClusterPowerAdjustCapabilityStruct.fromTlv(AnonymousTag, tlvReader) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: DeviceEnergyManagementClusterPowerAdjustCapabilityStruct? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + DeviceEnergyManagementClusterPowerAdjustCapabilityStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return PowerAdjustmentCapabilityAttribute(decodedValue) } suspend fun subscribePowerAdjustmentCapabilityAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - PowerAdjustmentCapabilityAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(PowerAdjustmentCapabilityAttributeSubscriptionState.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) { - "Poweradjustmentcapability attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Poweradjustmentcapability attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: DeviceEnergyManagementClusterPowerAdjustCapabilityStruct? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - DeviceEnergyManagementClusterPowerAdjustCapabilityStruct.fromTlv( - AnonymousTag, - tlvReader, - ) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: DeviceEnergyManagementClusterPowerAdjustCapabilityStruct? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + DeviceEnergyManagementClusterPowerAdjustCapabilityStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } decodedValue?.let { emit(PowerAdjustmentCapabilityAttributeSubscriptionState.Success(it)) } + } SubscriptionState.SubscriptionEstablished -> { emit(PowerAdjustmentCapabilityAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readForecastAttribute(): ForecastAttribute { - val ATTRIBUTE_ID: UInt = 6u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readForecastAttribute(): ForecastAttribute {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}") - } + 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) { "Forecast attribute not found in response" } + } + + requireNotNull(attributeData) { + "Forecast attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: DeviceEnergyManagementClusterForecastStruct? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - DeviceEnergyManagementClusterForecastStruct.fromTlv(AnonymousTag, tlvReader) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: DeviceEnergyManagementClusterForecastStruct? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + DeviceEnergyManagementClusterForecastStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return ForecastAttribute(decodedValue) } suspend fun subscribeForecastAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ForecastAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ForecastAttributeSubscriptionState.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) { "Forecast attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Forecast attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: DeviceEnergyManagementClusterForecastStruct? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - DeviceEnergyManagementClusterForecastStruct.fromTlv(AnonymousTag, tlvReader) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(ForecastAttributeSubscriptionState.Success(it)) } + val decodedValue: DeviceEnergyManagementClusterForecastStruct? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + DeviceEnergyManagementClusterForecastStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(ForecastAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ForecastAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readOptOutStateAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 7u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readOptOutStateAttribute(): UByte? {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}") - } + 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) { "Optoutstate attribute not found in response" } + } + + requireNotNull(attributeData) { + "Optoutstate 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeOptOutStateAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Optoutstate attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Optoutstate 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)) } + 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 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1118,96 +1174,97 @@ class DeviceEnergyManagementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1215,94 +1272,97 @@ class DeviceEnergyManagementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1310,94 +1370,97 @@ class DeviceEnergyManagementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1405,76 +1468,81 @@ class DeviceEnergyManagementCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1486,77 +1554,80 @@ class DeviceEnergyManagementCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1569,7 +1640,7 @@ class DeviceEnergyManagementCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/DeviceEnergyManagementModeCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/DeviceEnergyManagementModeCluster.kt index 657941cb3f0964..7754d2662184b2 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/DeviceEnergyManagementModeCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/DeviceEnergyManagementModeCluster.kt @@ -17,127 +17,161 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.cluster.structs.* +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class DeviceEnergyManagementModeCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class ChangeToModeResponse(val status: UByte, val statusText: String?) - - class SupportedModesAttribute(val value: List) +class DeviceEnergyManagementModeCluster(private val controller: MatterController, private val endpointId: UShort) { + class ChangeToModeResponse( + val status: UByte, + val statusText: String? + ) +class SupportedModesAttribute( + val value: List + ) sealed class SupportedModesAttributeSubscriptionState { - data class Success(val value: List) : - SupportedModesAttributeSubscriptionState() - + data class Success( + val value: List + ) : SupportedModesAttributeSubscriptionState() + data class Error(val exception: Exception) : SupportedModesAttributeSubscriptionState() - object SubscriptionEstablished : SupportedModesAttributeSubscriptionState() - } - - class StartUpModeAttribute(val value: UByte?) + object SubscriptionEstablished : SupportedModesAttributeSubscriptionState() + } +class StartUpModeAttribute( + val value: UByte? + ) sealed class StartUpModeAttributeSubscriptionState { - data class Success(val value: UByte?) : StartUpModeAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : StartUpModeAttributeSubscriptionState() + data class Error(val exception: Exception) : StartUpModeAttributeSubscriptionState() - object SubscriptionEstablished : StartUpModeAttributeSubscriptionState() - } - - class OnModeAttribute(val value: UByte?) + object SubscriptionEstablished : StartUpModeAttributeSubscriptionState() + } +class OnModeAttribute( + val value: UByte? + ) sealed class OnModeAttributeSubscriptionState { - data class Success(val value: UByte?) : OnModeAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : OnModeAttributeSubscriptionState() + data class Error(val exception: Exception) : OnModeAttributeSubscriptionState() - object SubscriptionEstablished : OnModeAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : OnModeAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun changeToMode( - newMode: UByte, - timedInvokeTimeout: Duration? = null, - ): ChangeToModeResponse { + suspend fun changeToMode(newMode: UByte + ,timedInvokeTimeout: Duration? = null): ChangeToModeResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_NEW_MODE_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_NEW_MODE_REQ), newMode) + tlvWriter.put(ContextSpecificTag(TAG_NEW_MODE_REQ), newMode) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -147,132 +181,140 @@ class DeviceEnergyManagementModeCluster( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_STATUS_TEXT: Int = 1 var statusText_decoded: String? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_STATUS)) { - status_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_STATUS_TEXT)) { - statusText_decoded = + + if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_STATUS_TEXT)) {statusText_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - } - } else { + tlvReader.getString(tag) + } else { + null + } + }} + + + else { tlvReader.skipElement() } } + + if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } + + + tlvReader.exitContainer() - return ChangeToModeResponse(status_decoded, statusText_decoded) + return ChangeToModeResponse( + status_decoded, + statusText_decoded + ) } - - suspend fun readSupportedModesAttribute(): SupportedModesAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readSupportedModesAttribute(): SupportedModesAttribute {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}") - } + 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) { "Supportedmodes attribute not found in response" } + } + + requireNotNull(attributeData) { + "Supportedmodes 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(DeviceEnergyManagementModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(DeviceEnergyManagementModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + return SupportedModesAttribute(decodedValue) } suspend fun subscribeSupportedModesAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - SupportedModesAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(SupportedModesAttributeSubscriptionState.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) { - "Supportedmodes attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Supportedmodes 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( - DeviceEnergyManagementModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader) - ) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(DeviceEnergyManagementModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(SupportedModesAttributeSubscriptionState.Success(decodedValue)) } @@ -280,76 +322,81 @@ class DeviceEnergyManagementModeCluster( emit(SupportedModesAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readCurrentModeAttribute(): 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)) - +suspend fun readCurrentModeAttribute(): 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}") - } + 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) { "Currentmode attribute not found in response" } + } + + requireNotNull(attributeData) { + "Currentmode 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 subscribeCurrentModeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Currentmode attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Currentmode attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -361,67 +408,77 @@ class DeviceEnergyManagementModeCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readStartUpModeAttribute(): StartUpModeAttribute { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readStartUpModeAttribute(): StartUpModeAttribute {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}") - } + 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) { "Startupmode attribute not found in response" } + } + + requireNotNull(attributeData) { + "Startupmode attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return StartUpModeAttribute(decodedValue) } - suspend fun writeStartUpModeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeStartUpModeAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 2u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -442,127 +499,137 @@ class DeviceEnergyManagementModeCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeStartUpModeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StartUpModeAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StartUpModeAttributeSubscriptionState.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) { "Startupmode attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Startupmode 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(StartUpModeAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(StartUpModeAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(StartUpModeAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readOnModeAttribute(): OnModeAttribute { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readOnModeAttribute(): OnModeAttribute {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}") - } + 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) { "Onmode attribute not found in response" } + } + + requireNotNull(attributeData) { + "Onmode attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return OnModeAttribute(decodedValue) } - suspend fun writeOnModeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeOnModeAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 3u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -583,156 +650,157 @@ class DeviceEnergyManagementModeCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeOnModeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - OnModeAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(OnModeAttributeSubscriptionState.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) { "Onmode attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Onmode 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(OnModeAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(OnModeAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(OnModeAttributeSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -740,96 +808,97 @@ class DeviceEnergyManagementModeCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -837,94 +906,97 @@ class DeviceEnergyManagementModeCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -932,94 +1004,97 @@ class DeviceEnergyManagementModeCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1027,76 +1102,81 @@ class DeviceEnergyManagementModeCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1108,77 +1188,80 @@ class DeviceEnergyManagementModeCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1191,7 +1274,7 @@ class DeviceEnergyManagementModeCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/DiagnosticLogsCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/DiagnosticLogsCluster.kt index fb4d455810d966..21693574406ef4 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/DiagnosticLogsCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/DiagnosticLogsCluster.kt @@ -17,85 +17,112 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.UIntSubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState +import matter.controller.UByteSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class DiagnosticLogsCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { +class DiagnosticLogsCluster(private val controller: MatterController, private val endpointId: UShort) { class RetrieveLogsResponse( - val status: UByte, - val logContent: ByteArray, - val UTCTimeStamp: ULong?, - val timeSinceBoot: ULong?, + val status: UByte, + val logContent: ByteArray, + val UTCTimeStamp: ULong?, + val timeSinceBoot: ULong? + ) +class GeneratedCommandListAttribute( + val value: List ) - - class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun retrieveLogsRequest( - intent: UByte, - requestedProtocol: UByte, - transferFileDesignator: String?, - timedInvokeTimeout: Duration? = null, - ): RetrieveLogsResponse { + suspend fun retrieveLogsRequest(intent: UByte + ,requestedProtocol: UByte + ,transferFileDesignator: String? + ,timedInvokeTimeout: Duration? = null): RetrieveLogsResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() @@ -110,14 +137,14 @@ class DiagnosticLogsCluster( val TAG_TRANSFER_FILE_DESIGNATOR_REQ: Int = 2 transferFileDesignator?.let { tlvWriter.put(ContextSpecificTag(TAG_TRANSFER_FILE_DESIGNATOR_REQ), transferFileDesignator) - } + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -127,65 +154,70 @@ class DiagnosticLogsCluster( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_LOG_CONTENT: Int = 1 var logContent_decoded: ByteArray? = null - + val TAG_UTC_TIME_STAMP: Int = 2 var UTCTimeStamp_decoded: ULong? = null - + val TAG_TIME_SINCE_BOOT: Int = 3 var timeSinceBoot_decoded: ULong? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_STATUS)) { - status_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_LOG_CONTENT)) { - logContent_decoded = tlvReader.getByteArray(tag) - } - - if (tag == ContextSpecificTag(TAG_UTC_TIME_STAMP)) { - UTCTimeStamp_decoded = + + if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_LOG_CONTENT)) {logContent_decoded = tlvReader.getByteArray(tag)} + + if (tag == ContextSpecificTag(TAG_UTC_TIME_STAMP)) {UTCTimeStamp_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getULong(tag) - } else { - null - } - } - } - - if (tag == ContextSpecificTag(TAG_TIME_SINCE_BOOT)) { - timeSinceBoot_decoded = + tlvReader.getULong(tag) + } else { + null + } + }} + + if (tag == ContextSpecificTag(TAG_TIME_SINCE_BOOT)) {timeSinceBoot_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getULong(tag) - } else { - null - } - } - } else { + tlvReader.getULong(tag) + } else { + null + } + }} + + + else { tlvReader.skipElement() } } + + if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - + + if (logContent_decoded == null) { - throw IllegalStateException("logContent not found in TLV") + throw IllegalStateException("logContent not found in TLV") } + + + + + tlvReader.exitContainer() @@ -193,97 +225,98 @@ class DiagnosticLogsCluster( status_decoded, logContent_decoded, UTCTimeStamp_decoded, - timeSinceBoot_decoded, + timeSinceBoot_decoded ) } +suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65528u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -291,96 +324,97 @@ class DiagnosticLogsCluster( emit(GeneratedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65529u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -388,94 +422,97 @@ class DiagnosticLogsCluster( emit(AcceptedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt = 65530u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -483,94 +520,97 @@ class DiagnosticLogsCluster( emit(EventListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ID: UInt = 65531u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -578,76 +618,81 @@ class DiagnosticLogsCluster( emit(AttributeListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u - 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 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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -659,77 +704,80 @@ class DiagnosticLogsCluster( emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 65533u - 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 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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -742,7 +790,7 @@ class DiagnosticLogsCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/DishwasherAlarmCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/DishwasherAlarmCluster.kt index 2082aec247699e..75b1724e213003 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/DishwasherAlarmCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/DishwasherAlarmCluster.kt @@ -17,181 +17,217 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.UIntSubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState +import matter.controller.UByteSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class DishwasherAlarmCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class GeneratedCommandListAttribute(val value: List) +class DishwasherAlarmCluster(private val controller: MatterController, private val endpointId: UShort) {class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun reset(alarms: UInt, timedInvokeTimeout: Duration? = null) { + suspend fun reset(alarms: UInt + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_ALARMS_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_ALARMS_REQ), alarms) + tlvWriter.put(ContextSpecificTag(TAG_ALARMS_REQ), alarms) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun modifyEnabledAlarms(mask: UInt, timedInvokeTimeout: Duration? = null) { + suspend fun modifyEnabledAlarms(mask: UInt + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 1u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_MASK_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_MASK_REQ), mask) + tlvWriter.put(ContextSpecificTag(TAG_MASK_REQ), mask) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - - suspend fun readMaskAttribute(): UInt { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMaskAttribute(): UInt {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}") - } + 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) { "Mask attribute not found in response" } + } + + requireNotNull(attributeData) { + "Mask 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 subscribeMaskAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Mask attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Mask attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -203,167 +239,178 @@ class DishwasherAlarmCluster( emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readLatchAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readLatchAttribute(): UInt? {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}") - } + 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) { "Latch attribute not found in response" } + } + + requireNotNull(attributeData) { + "Latch attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeLatchAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Latch attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Latch attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readStateAttribute(): UInt { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readStateAttribute(): UInt {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}") - } + 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) { "State attribute not found in response" } + } + + requireNotNull(attributeData) { + "State 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 subscribeStateAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "State attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "State attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -375,76 +422,81 @@ class DishwasherAlarmCluster( emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readSupportedAttribute(): UInt { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readSupportedAttribute(): UInt {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}") - } + 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) { "Supported attribute not found in response" } + } + + requireNotNull(attributeData) { + "Supported 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 subscribeSupportedAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Supported attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Supported attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -456,96 +508,97 @@ class DishwasherAlarmCluster( emit(UIntSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -553,96 +606,97 @@ class DishwasherAlarmCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -650,94 +704,97 @@ class DishwasherAlarmCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -745,94 +802,97 @@ class DishwasherAlarmCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -840,76 +900,81 @@ class DishwasherAlarmCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -921,77 +986,80 @@ class DishwasherAlarmCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1004,7 +1072,7 @@ class DishwasherAlarmCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/DishwasherModeCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/DishwasherModeCluster.kt index 4d57444fe65fba..b9223830ec6740 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/DishwasherModeCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/DishwasherModeCluster.kt @@ -17,127 +17,161 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.cluster.structs.* +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class DishwasherModeCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class ChangeToModeResponse(val status: UByte, val statusText: String?) - - class SupportedModesAttribute(val value: List) +class DishwasherModeCluster(private val controller: MatterController, private val endpointId: UShort) { + class ChangeToModeResponse( + val status: UByte, + val statusText: String? + ) +class SupportedModesAttribute( + val value: List + ) sealed class SupportedModesAttributeSubscriptionState { - data class Success(val value: List) : - SupportedModesAttributeSubscriptionState() - + data class Success( + val value: List + ) : SupportedModesAttributeSubscriptionState() + data class Error(val exception: Exception) : SupportedModesAttributeSubscriptionState() - object SubscriptionEstablished : SupportedModesAttributeSubscriptionState() - } - - class StartUpModeAttribute(val value: UByte?) + object SubscriptionEstablished : SupportedModesAttributeSubscriptionState() + } +class StartUpModeAttribute( + val value: UByte? + ) sealed class StartUpModeAttributeSubscriptionState { - data class Success(val value: UByte?) : StartUpModeAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : StartUpModeAttributeSubscriptionState() + data class Error(val exception: Exception) : StartUpModeAttributeSubscriptionState() - object SubscriptionEstablished : StartUpModeAttributeSubscriptionState() - } - - class OnModeAttribute(val value: UByte?) + object SubscriptionEstablished : StartUpModeAttributeSubscriptionState() + } +class OnModeAttribute( + val value: UByte? + ) sealed class OnModeAttributeSubscriptionState { - data class Success(val value: UByte?) : OnModeAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : OnModeAttributeSubscriptionState() + data class Error(val exception: Exception) : OnModeAttributeSubscriptionState() - object SubscriptionEstablished : OnModeAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : OnModeAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun changeToMode( - newMode: UByte, - timedInvokeTimeout: Duration? = null, - ): ChangeToModeResponse { + suspend fun changeToMode(newMode: UByte + ,timedInvokeTimeout: Duration? = null): ChangeToModeResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_NEW_MODE_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_NEW_MODE_REQ), newMode) + tlvWriter.put(ContextSpecificTag(TAG_NEW_MODE_REQ), newMode) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -147,130 +181,140 @@ class DishwasherModeCluster( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_STATUS_TEXT: Int = 1 var statusText_decoded: String? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_STATUS)) { - status_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_STATUS_TEXT)) { - statusText_decoded = + + if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_STATUS_TEXT)) {statusText_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - } - } else { + tlvReader.getString(tag) + } else { + null + } + }} + + + else { tlvReader.skipElement() } } + + if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } + + + tlvReader.exitContainer() - return ChangeToModeResponse(status_decoded, statusText_decoded) + return ChangeToModeResponse( + status_decoded, + statusText_decoded + ) } - - suspend fun readSupportedModesAttribute(): SupportedModesAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readSupportedModesAttribute(): SupportedModesAttribute {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}") - } + 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) { "Supportedmodes attribute not found in response" } + } + + requireNotNull(attributeData) { + "Supportedmodes 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(DishwasherModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(DishwasherModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + return SupportedModesAttribute(decodedValue) } suspend fun subscribeSupportedModesAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - SupportedModesAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(SupportedModesAttributeSubscriptionState.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) { - "Supportedmodes attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Supportedmodes 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(DishwasherModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(DishwasherModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(SupportedModesAttributeSubscriptionState.Success(decodedValue)) } @@ -278,76 +322,81 @@ class DishwasherModeCluster( emit(SupportedModesAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readCurrentModeAttribute(): 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)) - +suspend fun readCurrentModeAttribute(): 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}") - } + 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) { "Currentmode attribute not found in response" } + } + + requireNotNull(attributeData) { + "Currentmode 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 subscribeCurrentModeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Currentmode attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Currentmode attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -359,67 +408,77 @@ class DishwasherModeCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readStartUpModeAttribute(): StartUpModeAttribute { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readStartUpModeAttribute(): StartUpModeAttribute {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}") - } + 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) { "Startupmode attribute not found in response" } + } + + requireNotNull(attributeData) { + "Startupmode attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return StartUpModeAttribute(decodedValue) } - suspend fun writeStartUpModeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeStartUpModeAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 2u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -440,127 +499,137 @@ class DishwasherModeCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeStartUpModeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StartUpModeAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StartUpModeAttributeSubscriptionState.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) { "Startupmode attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Startupmode 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(StartUpModeAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(StartUpModeAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(StartUpModeAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readOnModeAttribute(): OnModeAttribute { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readOnModeAttribute(): OnModeAttribute {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}") - } + 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) { "Onmode attribute not found in response" } + } + + requireNotNull(attributeData) { + "Onmode attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return OnModeAttribute(decodedValue) } - suspend fun writeOnModeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeOnModeAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 3u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -581,156 +650,157 @@ class DishwasherModeCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeOnModeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - OnModeAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(OnModeAttributeSubscriptionState.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) { "Onmode attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Onmode 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(OnModeAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(OnModeAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(OnModeAttributeSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -738,96 +808,97 @@ class DishwasherModeCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -835,94 +906,97 @@ class DishwasherModeCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -930,94 +1004,97 @@ class DishwasherModeCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1025,76 +1102,81 @@ class DishwasherModeCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1106,77 +1188,80 @@ class DishwasherModeCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1189,7 +1274,7 @@ class DishwasherModeCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/DoorLockCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/DoorLockCluster.kt index ff0525a58d8c27..41016b4a66ccb9 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/DoorLockCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/DoorLockCluster.kt @@ -17,257 +17,297 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.BooleanSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest -import matter.controller.StringSubscriptionState +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.cluster.structs.* +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter class DoorLockCluster(private val controller: MatterController, private val endpointId: UShort) { class GetWeekDayScheduleResponse( - val weekDayIndex: UByte, - val userIndex: UShort, - val status: UByte, - val daysMask: UByte?, - val startHour: UByte?, - val startMinute: UByte?, - val endHour: UByte?, - val endMinute: UByte?, + val weekDayIndex: UByte, + val userIndex: UShort, + val status: UByte, + val daysMask: UByte?, + val startHour: UByte?, + val startMinute: UByte?, + val endHour: UByte?, + val endMinute: UByte? ) class GetYearDayScheduleResponse( - val yearDayIndex: UByte, - val userIndex: UShort, - val status: UByte, - val localStartTime: UInt?, - val localEndTime: UInt?, + val yearDayIndex: UByte, + val userIndex: UShort, + val status: UByte, + val localStartTime: UInt?, + val localEndTime: UInt? ) class GetHolidayScheduleResponse( - val holidayIndex: UByte, - val status: UByte, - val localStartTime: UInt?, - val localEndTime: UInt?, - val operatingMode: UByte?, + val holidayIndex: UByte, + val status: UByte, + val localStartTime: UInt?, + val localEndTime: UInt?, + val operatingMode: UByte? ) class GetUserResponse( - val userIndex: UShort, - val userName: String?, - val userUniqueID: UInt?, - val userStatus: UByte?, - val userType: UByte?, - val credentialRule: UByte?, - val credentials: List?, - val creatorFabricIndex: UByte?, - val lastModifiedFabricIndex: UByte?, - val nextUserIndex: UShort?, + val userIndex: UShort, + val userName: String?, + val userUniqueID: UInt?, + val userStatus: UByte?, + val userType: UByte?, + val credentialRule: UByte?, + val credentials: List?, + val creatorFabricIndex: UByte?, + val lastModifiedFabricIndex: UByte?, + val nextUserIndex: UShort? ) class SetCredentialResponse( - val status: UByte, - val userIndex: UShort?, - val nextCredentialIndex: UShort?, + val status: UByte, + val userIndex: UShort?, + val nextCredentialIndex: UShort? ) class GetCredentialStatusResponse( - val credentialExists: Boolean, - val userIndex: UShort?, - val creatorFabricIndex: UByte?, - val lastModifiedFabricIndex: UByte?, - val nextCredentialIndex: UShort?, + val credentialExists: Boolean, + val userIndex: UShort?, + val creatorFabricIndex: UByte?, + val lastModifiedFabricIndex: UByte?, + val nextCredentialIndex: UShort? + ) +class LockStateAttribute( + val value: UByte? ) - - class LockStateAttribute(val value: UByte?) sealed class LockStateAttributeSubscriptionState { - data class Success(val value: UByte?) : LockStateAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : LockStateAttributeSubscriptionState() + data class Error(val exception: Exception) : LockStateAttributeSubscriptionState() - object SubscriptionEstablished : LockStateAttributeSubscriptionState() - } - - class DoorStateAttribute(val value: UByte?) + object SubscriptionEstablished : LockStateAttributeSubscriptionState() + } +class DoorStateAttribute( + val value: UByte? + ) sealed class DoorStateAttributeSubscriptionState { - data class Success(val value: UByte?) : DoorStateAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : DoorStateAttributeSubscriptionState() + data class Error(val exception: Exception) : DoorStateAttributeSubscriptionState() - object SubscriptionEstablished : DoorStateAttributeSubscriptionState() - } - - class AliroReaderVerificationKeyAttribute(val value: ByteArray?) + object SubscriptionEstablished : DoorStateAttributeSubscriptionState() + } +class AliroReaderVerificationKeyAttribute( + val value: ByteArray? + ) sealed class AliroReaderVerificationKeyAttributeSubscriptionState { - data class Success(val value: ByteArray?) : - AliroReaderVerificationKeyAttributeSubscriptionState() - - data class Error(val exception: Exception) : - AliroReaderVerificationKeyAttributeSubscriptionState() - - object SubscriptionEstablished : AliroReaderVerificationKeyAttributeSubscriptionState() - } - - class AliroReaderGroupIdentifierAttribute(val value: ByteArray?) + data class Success( + val value: ByteArray? + ) : AliroReaderVerificationKeyAttributeSubscriptionState() + + data class Error(val exception: Exception) : AliroReaderVerificationKeyAttributeSubscriptionState() + + object SubscriptionEstablished : AliroReaderVerificationKeyAttributeSubscriptionState() + } +class AliroReaderGroupIdentifierAttribute( + val value: ByteArray? + ) sealed class AliroReaderGroupIdentifierAttributeSubscriptionState { - data class Success(val value: ByteArray?) : - AliroReaderGroupIdentifierAttributeSubscriptionState() - - data class Error(val exception: Exception) : - AliroReaderGroupIdentifierAttributeSubscriptionState() - - object SubscriptionEstablished : AliroReaderGroupIdentifierAttributeSubscriptionState() - } - - class AliroExpeditedTransactionSupportedProtocolVersionsAttribute(val value: List?) + data class Success( + val value: ByteArray? + ) : AliroReaderGroupIdentifierAttributeSubscriptionState() + + data class Error(val exception: Exception) : AliroReaderGroupIdentifierAttributeSubscriptionState() + + object SubscriptionEstablished : AliroReaderGroupIdentifierAttributeSubscriptionState() + } +class AliroExpeditedTransactionSupportedProtocolVersionsAttribute( + val value: List? + ) sealed class AliroExpeditedTransactionSupportedProtocolVersionsAttributeSubscriptionState { - data class Success(val value: List?) : - AliroExpeditedTransactionSupportedProtocolVersionsAttributeSubscriptionState() - - data class Error(val exception: Exception) : - AliroExpeditedTransactionSupportedProtocolVersionsAttributeSubscriptionState() - - object SubscriptionEstablished : - AliroExpeditedTransactionSupportedProtocolVersionsAttributeSubscriptionState() - } - - class AliroGroupResolvingKeyAttribute(val value: ByteArray?) + data class Success( + val value: List? + ) : AliroExpeditedTransactionSupportedProtocolVersionsAttributeSubscriptionState() + + data class Error(val exception: Exception) : AliroExpeditedTransactionSupportedProtocolVersionsAttributeSubscriptionState() + + object SubscriptionEstablished : AliroExpeditedTransactionSupportedProtocolVersionsAttributeSubscriptionState() + } +class AliroGroupResolvingKeyAttribute( + val value: ByteArray? + ) sealed class AliroGroupResolvingKeyAttributeSubscriptionState { - data class Success(val value: ByteArray?) : AliroGroupResolvingKeyAttributeSubscriptionState() - + data class Success( + val value: ByteArray? + ) : AliroGroupResolvingKeyAttributeSubscriptionState() + data class Error(val exception: Exception) : AliroGroupResolvingKeyAttributeSubscriptionState() - object SubscriptionEstablished : AliroGroupResolvingKeyAttributeSubscriptionState() - } - - class AliroSupportedBLEUWBProtocolVersionsAttribute(val value: List?) + object SubscriptionEstablished : AliroGroupResolvingKeyAttributeSubscriptionState() + } +class AliroSupportedBLEUWBProtocolVersionsAttribute( + val value: List? + ) sealed class AliroSupportedBLEUWBProtocolVersionsAttributeSubscriptionState { - data class Success(val value: List?) : - AliroSupportedBLEUWBProtocolVersionsAttributeSubscriptionState() - - data class Error(val exception: Exception) : - AliroSupportedBLEUWBProtocolVersionsAttributeSubscriptionState() - - object SubscriptionEstablished : - AliroSupportedBLEUWBProtocolVersionsAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + data class Success( + val value: List? + ) : AliroSupportedBLEUWBProtocolVersionsAttributeSubscriptionState() + + data class Error(val exception: Exception) : AliroSupportedBLEUWBProtocolVersionsAttributeSubscriptionState() + + object SubscriptionEstablished : AliroSupportedBLEUWBProtocolVersionsAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun lockDoor(PINCode: ByteArray?, timedInvokeTimeout: Duration) { + suspend fun lockDoor(PINCode: ByteArray? + ,timedInvokeTimeout: Duration) { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_PIN_CODE_REQ: Int = 0 - PINCode?.let { tlvWriter.put(ContextSpecificTag(TAG_PIN_CODE_REQ), PINCode) } + PINCode?.let { + tlvWriter.put(ContextSpecificTag(TAG_PIN_CODE_REQ), PINCode) + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun unlockDoor(PINCode: ByteArray?, timedInvokeTimeout: Duration) { + suspend fun unlockDoor(PINCode: ByteArray? + ,timedInvokeTimeout: Duration) { val commandId: UInt = 1u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_PIN_CODE_REQ: Int = 0 - PINCode?.let { tlvWriter.put(ContextSpecificTag(TAG_PIN_CODE_REQ), PINCode) } + PINCode?.let { + tlvWriter.put(ContextSpecificTag(TAG_PIN_CODE_REQ), PINCode) + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun unlockWithTimeout( - timeout: UShort, - PINCode: ByteArray?, - timedInvokeTimeout: Duration, - ) { + suspend fun unlockWithTimeout(timeout: UShort + ,PINCode: ByteArray? + ,timedInvokeTimeout: Duration) { val commandId: UInt = 3u val tlvWriter = TlvWriter() @@ -277,30 +317,30 @@ class DoorLockCluster(private val controller: MatterController, private val endp tlvWriter.put(ContextSpecificTag(TAG_TIMEOUT_REQ), timeout) val TAG_PIN_CODE_REQ: Int = 1 - PINCode?.let { tlvWriter.put(ContextSpecificTag(TAG_PIN_CODE_REQ), PINCode) } + PINCode?.let { + tlvWriter.put(ContextSpecificTag(TAG_PIN_CODE_REQ), PINCode) + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun setWeekDaySchedule( - weekDayIndex: UByte, - userIndex: UShort, - daysMask: UByte, - startHour: UByte, - startMinute: UByte, - endHour: UByte, - endMinute: UByte, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun setWeekDaySchedule(weekDayIndex: UByte + ,userIndex: UShort + ,daysMask: UByte + ,startHour: UByte + ,startMinute: UByte + ,endHour: UByte + ,endMinute: UByte + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 11u val tlvWriter = TlvWriter() @@ -325,25 +365,23 @@ class DoorLockCluster(private val controller: MatterController, private val endp tlvWriter.put(ContextSpecificTag(TAG_END_HOUR_REQ), endHour) val TAG_END_MINUTE_REQ: Int = 6 - tlvWriter.put(ContextSpecificTag(TAG_END_MINUTE_REQ), endMinute) + tlvWriter.put(ContextSpecificTag(TAG_END_MINUTE_REQ), endMinute) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun getWeekDaySchedule( - weekDayIndex: UByte, - userIndex: UShort, - timedInvokeTimeout: Duration? = null, - ): GetWeekDayScheduleResponse { + suspend fun getWeekDaySchedule(weekDayIndex: UByte + ,userIndex: UShort + ,timedInvokeTimeout: Duration? = null): GetWeekDayScheduleResponse { val commandId: UInt = 12u val tlvWriter = TlvWriter() @@ -353,14 +391,14 @@ class DoorLockCluster(private val controller: MatterController, private val endp tlvWriter.put(ContextSpecificTag(TAG_WEEK_DAY_INDEX_REQ), weekDayIndex) val TAG_USER_INDEX_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_USER_INDEX_REQ), userIndex) + tlvWriter.put(ContextSpecificTag(TAG_USER_INDEX_REQ), userIndex) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -370,127 +408,131 @@ class DoorLockCluster(private val controller: MatterController, private val endp tlvReader.enterStructure(AnonymousTag) val TAG_WEEK_DAY_INDEX: Int = 0 var weekDayIndex_decoded: UByte? = null - + val TAG_USER_INDEX: Int = 1 var userIndex_decoded: UShort? = null - + val TAG_STATUS: Int = 2 var status_decoded: UByte? = null - + val TAG_DAYS_MASK: Int = 3 var daysMask_decoded: UByte? = null - + val TAG_START_HOUR: Int = 4 var startHour_decoded: UByte? = null - + val TAG_START_MINUTE: Int = 5 var startMinute_decoded: UByte? = null - + val TAG_END_HOUR: Int = 6 var endHour_decoded: UByte? = null - + val TAG_END_MINUTE: Int = 7 var endMinute_decoded: UByte? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_WEEK_DAY_INDEX)) { - weekDayIndex_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_USER_INDEX)) { - userIndex_decoded = tlvReader.getUShort(tag) - } - - if (tag == ContextSpecificTag(TAG_STATUS)) { - status_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_DAYS_MASK)) { - daysMask_decoded = + + if (tag == ContextSpecificTag(TAG_WEEK_DAY_INDEX)) {weekDayIndex_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_USER_INDEX)) {userIndex_decoded = tlvReader.getUShort(tag)} + + if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_DAYS_MASK)) {daysMask_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getUByte(tag) - } else { - null - } - } - } - - if (tag == ContextSpecificTag(TAG_START_HOUR)) { - startHour_decoded = + tlvReader.getUByte(tag) + } else { + null + } + }} + + if (tag == ContextSpecificTag(TAG_START_HOUR)) {startHour_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getUByte(tag) - } else { - null - } - } - } - - if (tag == ContextSpecificTag(TAG_START_MINUTE)) { - startMinute_decoded = + tlvReader.getUByte(tag) + } else { + null + } + }} + + if (tag == ContextSpecificTag(TAG_START_MINUTE)) {startMinute_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getUByte(tag) - } else { - null - } - } - } - - if (tag == ContextSpecificTag(TAG_END_HOUR)) { - endHour_decoded = + tlvReader.getUByte(tag) + } else { + null + } + }} + + if (tag == ContextSpecificTag(TAG_END_HOUR)) {endHour_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getUByte(tag) - } else { - null - } - } - } - - if (tag == ContextSpecificTag(TAG_END_MINUTE)) { - endMinute_decoded = + tlvReader.getUByte(tag) + } else { + null + } + }} + + if (tag == ContextSpecificTag(TAG_END_MINUTE)) {endMinute_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getUByte(tag) - } else { - null - } - } - } else { + tlvReader.getUByte(tag) + } else { + null + } + }} + + + else { tlvReader.skipElement() } } + + if (weekDayIndex_decoded == null) { - throw IllegalStateException("weekDayIndex not found in TLV") + throw IllegalStateException("weekDayIndex not found in TLV") } - + + if (userIndex_decoded == null) { - throw IllegalStateException("userIndex not found in TLV") + throw IllegalStateException("userIndex not found in TLV") } - + + if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") - } + throw IllegalStateException("status not found in TLV") + } + + + + + + + + + + + tlvReader.exitContainer() @@ -502,15 +544,13 @@ class DoorLockCluster(private val controller: MatterController, private val endp startHour_decoded, startMinute_decoded, endHour_decoded, - endMinute_decoded, + endMinute_decoded ) } - suspend fun clearWeekDaySchedule( - weekDayIndex: UByte, - userIndex: UShort, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun clearWeekDaySchedule(weekDayIndex: UByte + ,userIndex: UShort + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 13u val tlvWriter = TlvWriter() @@ -520,27 +560,25 @@ class DoorLockCluster(private val controller: MatterController, private val endp tlvWriter.put(ContextSpecificTag(TAG_WEEK_DAY_INDEX_REQ), weekDayIndex) val TAG_USER_INDEX_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_USER_INDEX_REQ), userIndex) + tlvWriter.put(ContextSpecificTag(TAG_USER_INDEX_REQ), userIndex) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun setYearDaySchedule( - yearDayIndex: UByte, - userIndex: UShort, - localStartTime: UInt, - localEndTime: UInt, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun setYearDaySchedule(yearDayIndex: UByte + ,userIndex: UShort + ,localStartTime: UInt + ,localEndTime: UInt + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 14u val tlvWriter = TlvWriter() @@ -556,25 +594,23 @@ class DoorLockCluster(private val controller: MatterController, private val endp tlvWriter.put(ContextSpecificTag(TAG_LOCAL_START_TIME_REQ), localStartTime) val TAG_LOCAL_END_TIME_REQ: Int = 3 - tlvWriter.put(ContextSpecificTag(TAG_LOCAL_END_TIME_REQ), localEndTime) + tlvWriter.put(ContextSpecificTag(TAG_LOCAL_END_TIME_REQ), localEndTime) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun getYearDaySchedule( - yearDayIndex: UByte, - userIndex: UShort, - timedInvokeTimeout: Duration? = null, - ): GetYearDayScheduleResponse { + suspend fun getYearDaySchedule(yearDayIndex: UByte + ,userIndex: UShort + ,timedInvokeTimeout: Duration? = null): GetYearDayScheduleResponse { val commandId: UInt = 15u val tlvWriter = TlvWriter() @@ -584,14 +620,14 @@ class DoorLockCluster(private val controller: MatterController, private val endp tlvWriter.put(ContextSpecificTag(TAG_YEAR_DAY_INDEX_REQ), yearDayIndex) val TAG_USER_INDEX_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_USER_INDEX_REQ), userIndex) + tlvWriter.put(ContextSpecificTag(TAG_USER_INDEX_REQ), userIndex) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -601,76 +637,80 @@ class DoorLockCluster(private val controller: MatterController, private val endp tlvReader.enterStructure(AnonymousTag) val TAG_YEAR_DAY_INDEX: Int = 0 var yearDayIndex_decoded: UByte? = null - + val TAG_USER_INDEX: Int = 1 var userIndex_decoded: UShort? = null - + val TAG_STATUS: Int = 2 var status_decoded: UByte? = null - + val TAG_LOCAL_START_TIME: Int = 3 var localStartTime_decoded: UInt? = null - + val TAG_LOCAL_END_TIME: Int = 4 var localEndTime_decoded: UInt? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_YEAR_DAY_INDEX)) { - yearDayIndex_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_USER_INDEX)) { - userIndex_decoded = tlvReader.getUShort(tag) - } - - if (tag == ContextSpecificTag(TAG_STATUS)) { - status_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_LOCAL_START_TIME)) { - localStartTime_decoded = + + if (tag == ContextSpecificTag(TAG_YEAR_DAY_INDEX)) {yearDayIndex_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_USER_INDEX)) {userIndex_decoded = tlvReader.getUShort(tag)} + + if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_LOCAL_START_TIME)) {localStartTime_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getUInt(tag) - } else { - null - } - } - } - - if (tag == ContextSpecificTag(TAG_LOCAL_END_TIME)) { - localEndTime_decoded = + tlvReader.getUInt(tag) + } else { + null + } + }} + + if (tag == ContextSpecificTag(TAG_LOCAL_END_TIME)) {localEndTime_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getUInt(tag) - } else { - null - } - } - } else { + tlvReader.getUInt(tag) + } else { + null + } + }} + + + else { tlvReader.skipElement() } } + + if (yearDayIndex_decoded == null) { - throw IllegalStateException("yearDayIndex not found in TLV") + throw IllegalStateException("yearDayIndex not found in TLV") } - + + if (userIndex_decoded == null) { - throw IllegalStateException("userIndex not found in TLV") + throw IllegalStateException("userIndex not found in TLV") } - + + if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } + + + + + tlvReader.exitContainer() @@ -679,15 +719,13 @@ class DoorLockCluster(private val controller: MatterController, private val endp userIndex_decoded, status_decoded, localStartTime_decoded, - localEndTime_decoded, + localEndTime_decoded ) } - suspend fun clearYearDaySchedule( - yearDayIndex: UByte, - userIndex: UShort, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun clearYearDaySchedule(yearDayIndex: UByte + ,userIndex: UShort + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 16u val tlvWriter = TlvWriter() @@ -697,27 +735,25 @@ class DoorLockCluster(private val controller: MatterController, private val endp tlvWriter.put(ContextSpecificTag(TAG_YEAR_DAY_INDEX_REQ), yearDayIndex) val TAG_USER_INDEX_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_USER_INDEX_REQ), userIndex) + tlvWriter.put(ContextSpecificTag(TAG_USER_INDEX_REQ), userIndex) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun setHolidaySchedule( - holidayIndex: UByte, - localStartTime: UInt, - localEndTime: UInt, - operatingMode: UByte, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun setHolidaySchedule(holidayIndex: UByte + ,localStartTime: UInt + ,localEndTime: UInt + ,operatingMode: UByte + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 17u val tlvWriter = TlvWriter() @@ -733,38 +769,36 @@ class DoorLockCluster(private val controller: MatterController, private val endp tlvWriter.put(ContextSpecificTag(TAG_LOCAL_END_TIME_REQ), localEndTime) val TAG_OPERATING_MODE_REQ: Int = 3 - tlvWriter.put(ContextSpecificTag(TAG_OPERATING_MODE_REQ), operatingMode) + tlvWriter.put(ContextSpecificTag(TAG_OPERATING_MODE_REQ), operatingMode) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun getHolidaySchedule( - holidayIndex: UByte, - timedInvokeTimeout: Duration? = null, - ): GetHolidayScheduleResponse { + suspend fun getHolidaySchedule(holidayIndex: UByte + ,timedInvokeTimeout: Duration? = null): GetHolidayScheduleResponse { val commandId: UInt = 18u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_HOLIDAY_INDEX_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_HOLIDAY_INDEX_REQ), holidayIndex) + tlvWriter.put(ContextSpecificTag(TAG_HOLIDAY_INDEX_REQ), holidayIndex) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -774,82 +808,87 @@ class DoorLockCluster(private val controller: MatterController, private val endp tlvReader.enterStructure(AnonymousTag) val TAG_HOLIDAY_INDEX: Int = 0 var holidayIndex_decoded: UByte? = null - + val TAG_STATUS: Int = 1 var status_decoded: UByte? = null - + val TAG_LOCAL_START_TIME: Int = 2 var localStartTime_decoded: UInt? = null - + val TAG_LOCAL_END_TIME: Int = 3 var localEndTime_decoded: UInt? = null - + val TAG_OPERATING_MODE: Int = 4 var operatingMode_decoded: UByte? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_HOLIDAY_INDEX)) { - holidayIndex_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_STATUS)) { - status_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_LOCAL_START_TIME)) { - localStartTime_decoded = + + if (tag == ContextSpecificTag(TAG_HOLIDAY_INDEX)) {holidayIndex_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_LOCAL_START_TIME)) {localStartTime_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getUInt(tag) - } else { - null - } - } - } - - if (tag == ContextSpecificTag(TAG_LOCAL_END_TIME)) { - localEndTime_decoded = + tlvReader.getUInt(tag) + } else { + null + } + }} + + if (tag == ContextSpecificTag(TAG_LOCAL_END_TIME)) {localEndTime_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getUInt(tag) - } else { - null - } - } - } - - if (tag == ContextSpecificTag(TAG_OPERATING_MODE)) { - operatingMode_decoded = + tlvReader.getUInt(tag) + } else { + null + } + }} + + if (tag == ContextSpecificTag(TAG_OPERATING_MODE)) {operatingMode_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getUByte(tag) - } else { - null - } - } - } else { + tlvReader.getUByte(tag) + } else { + null + } + }} + + + else { tlvReader.skipElement() } } + + if (holidayIndex_decoded == null) { - throw IllegalStateException("holidayIndex not found in TLV") + throw IllegalStateException("holidayIndex not found in TLV") } - + + if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } + + + + + + + tlvReader.exitContainer() @@ -858,41 +897,40 @@ class DoorLockCluster(private val controller: MatterController, private val endp status_decoded, localStartTime_decoded, localEndTime_decoded, - operatingMode_decoded, + operatingMode_decoded ) } - suspend fun clearHolidaySchedule(holidayIndex: UByte, timedInvokeTimeout: Duration? = null) { + suspend fun clearHolidaySchedule(holidayIndex: UByte + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 19u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_HOLIDAY_INDEX_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_HOLIDAY_INDEX_REQ), holidayIndex) + tlvWriter.put(ContextSpecificTag(TAG_HOLIDAY_INDEX_REQ), holidayIndex) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun setUser( - operationType: UByte, - userIndex: UShort, - userName: String?, - userUniqueID: UInt?, - userStatus: UByte?, - userType: UByte?, - credentialRule: UByte?, - timedInvokeTimeout: Duration, - ) { + suspend fun setUser(operationType: UByte + ,userIndex: UShort + ,userName: String? + ,userUniqueID: UInt? + ,userStatus: UByte? + ,userType: UByte? + ,credentialRule: UByte? + ,timedInvokeTimeout: Duration) { val commandId: UInt = 26u val tlvWriter = TlvWriter() @@ -905,49 +943,58 @@ class DoorLockCluster(private val controller: MatterController, private val endp tlvWriter.put(ContextSpecificTag(TAG_USER_INDEX_REQ), userIndex) val TAG_USER_NAME_REQ: Int = 2 - userName?.let { tlvWriter.put(ContextSpecificTag(TAG_USER_NAME_REQ), userName) } + userName?.let { + tlvWriter.put(ContextSpecificTag(TAG_USER_NAME_REQ), userName) + } val TAG_USER_UNIQUE_ID_REQ: Int = 3 - userUniqueID?.let { tlvWriter.put(ContextSpecificTag(TAG_USER_UNIQUE_ID_REQ), userUniqueID) } + userUniqueID?.let { + tlvWriter.put(ContextSpecificTag(TAG_USER_UNIQUE_ID_REQ), userUniqueID) + } val TAG_USER_STATUS_REQ: Int = 4 - userStatus?.let { tlvWriter.put(ContextSpecificTag(TAG_USER_STATUS_REQ), userStatus) } + userStatus?.let { + tlvWriter.put(ContextSpecificTag(TAG_USER_STATUS_REQ), userStatus) + } val TAG_USER_TYPE_REQ: Int = 5 - userType?.let { tlvWriter.put(ContextSpecificTag(TAG_USER_TYPE_REQ), userType) } + userType?.let { + tlvWriter.put(ContextSpecificTag(TAG_USER_TYPE_REQ), userType) + } val TAG_CREDENTIAL_RULE_REQ: Int = 6 credentialRule?.let { tlvWriter.put(ContextSpecificTag(TAG_CREDENTIAL_RULE_REQ), credentialRule) - } + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun getUser(userIndex: UShort, timedInvokeTimeout: Duration? = null): GetUserResponse { + suspend fun getUser(userIndex: UShort + ,timedInvokeTimeout: Duration? = null): GetUserResponse { val commandId: UInt = 27u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_USER_INDEX_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_USER_INDEX_REQ), userIndex) + tlvWriter.put(ContextSpecificTag(TAG_USER_INDEX_REQ), userIndex) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -957,188 +1004,194 @@ class DoorLockCluster(private val controller: MatterController, private val endp tlvReader.enterStructure(AnonymousTag) val TAG_USER_INDEX: Int = 0 var userIndex_decoded: UShort? = null - + val TAG_USER_NAME: Int = 1 var userName_decoded: String? = null - + val TAG_USER_UNIQUE_ID: Int = 2 var userUniqueID_decoded: UInt? = null - + val TAG_USER_STATUS: Int = 3 var userStatus_decoded: UByte? = null - + val TAG_USER_TYPE: Int = 4 var userType_decoded: UByte? = null - + val TAG_CREDENTIAL_RULE: Int = 5 var credentialRule_decoded: UByte? = null - + val TAG_CREDENTIALS: Int = 6 var credentials_decoded: List? = null - + val TAG_CREATOR_FABRIC_INDEX: Int = 7 var creatorFabricIndex_decoded: UByte? = null - + val TAG_LAST_MODIFIED_FABRIC_INDEX: Int = 8 var lastModifiedFabricIndex_decoded: UByte? = null - + val TAG_NEXT_USER_INDEX: Int = 9 var nextUserIndex_decoded: UShort? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_USER_INDEX)) { - userIndex_decoded = tlvReader.getUShort(tag) - } - - if (tag == ContextSpecificTag(TAG_USER_NAME)) { - userName_decoded = + + if (tag == ContextSpecificTag(TAG_USER_INDEX)) {userIndex_decoded = tlvReader.getUShort(tag)} + + if (tag == ContextSpecificTag(TAG_USER_NAME)) {userName_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (!tlvReader.isNull()) { - tlvReader.getString(tag) - } else { - tlvReader.getNull(tag) - null - } - } - } - - if (tag == ContextSpecificTag(TAG_USER_UNIQUE_ID)) { - userUniqueID_decoded = + tlvReader.getString(tag) + } else { + tlvReader.getNull(tag) + null + } + }} + + if (tag == ContextSpecificTag(TAG_USER_UNIQUE_ID)) {userUniqueID_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (!tlvReader.isNull()) { - tlvReader.getUInt(tag) - } else { - tlvReader.getNull(tag) - null - } - } - } - - if (tag == ContextSpecificTag(TAG_USER_STATUS)) { - userStatus_decoded = + tlvReader.getUInt(tag) + } else { + tlvReader.getNull(tag) + null + } + }} + + if (tag == ContextSpecificTag(TAG_USER_STATUS)) {userStatus_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (!tlvReader.isNull()) { - tlvReader.getUByte(tag) - } else { - tlvReader.getNull(tag) - null - } - } - } - - if (tag == ContextSpecificTag(TAG_USER_TYPE)) { - userType_decoded = + tlvReader.getUByte(tag) + } else { + tlvReader.getNull(tag) + null + } + }} + + if (tag == ContextSpecificTag(TAG_USER_TYPE)) {userType_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (!tlvReader.isNull()) { - tlvReader.getUByte(tag) - } else { - tlvReader.getNull(tag) - null - } - } - } - - if (tag == ContextSpecificTag(TAG_CREDENTIAL_RULE)) { - credentialRule_decoded = + tlvReader.getUByte(tag) + } else { + tlvReader.getNull(tag) + null + } + }} + + if (tag == ContextSpecificTag(TAG_CREDENTIAL_RULE)) {credentialRule_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (!tlvReader.isNull()) { - tlvReader.getUByte(tag) - } else { - tlvReader.getNull(tag) - null - } - } - } - - if (tag == ContextSpecificTag(TAG_CREDENTIALS)) { - credentials_decoded = + tlvReader.getUByte(tag) + } else { + tlvReader.getNull(tag) + null + } + }} + + if (tag == ContextSpecificTag(TAG_CREDENTIALS)) {credentials_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (!tlvReader.isNull()) { - buildList { - tlvReader.enterArray(tag) - while (!tlvReader.isEndOfContainer()) { - add(DoorLockClusterCredentialStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - tlvReader.getNull(tag) - null - } - } - } - - if (tag == ContextSpecificTag(TAG_CREATOR_FABRIC_INDEX)) { - creatorFabricIndex_decoded = + buildList { + tlvReader.enterArray(tag) + while(!tlvReader.isEndOfContainer()) { + add(DoorLockClusterCredentialStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + tlvReader.getNull(tag) + null + } + }} + + if (tag == ContextSpecificTag(TAG_CREATOR_FABRIC_INDEX)) {creatorFabricIndex_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (!tlvReader.isNull()) { - tlvReader.getUByte(tag) - } else { - tlvReader.getNull(tag) - null - } - } - } - - if (tag == ContextSpecificTag(TAG_LAST_MODIFIED_FABRIC_INDEX)) { - lastModifiedFabricIndex_decoded = + tlvReader.getUByte(tag) + } else { + tlvReader.getNull(tag) + null + } + }} + + if (tag == ContextSpecificTag(TAG_LAST_MODIFIED_FABRIC_INDEX)) {lastModifiedFabricIndex_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (!tlvReader.isNull()) { - tlvReader.getUByte(tag) - } else { - tlvReader.getNull(tag) - null - } - } - } - - if (tag == ContextSpecificTag(TAG_NEXT_USER_INDEX)) { - nextUserIndex_decoded = + tlvReader.getUByte(tag) + } else { + tlvReader.getNull(tag) + null + } + }} + + if (tag == ContextSpecificTag(TAG_NEXT_USER_INDEX)) {nextUserIndex_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (!tlvReader.isNull()) { - tlvReader.getUShort(tag) - } else { - tlvReader.getNull(tag) - null - } - } - } else { + tlvReader.getUShort(tag) + } else { + tlvReader.getNull(tag) + null + } + }} + + + else { tlvReader.skipElement() } } + + if (userIndex_decoded == null) { - throw IllegalStateException("userIndex not found in TLV") - } + throw IllegalStateException("userIndex not found in TLV") + } + + + + + + + + + + + + + + + + + + + tlvReader.exitContainer() @@ -1152,40 +1205,39 @@ class DoorLockCluster(private val controller: MatterController, private val endp credentials_decoded, creatorFabricIndex_decoded, lastModifiedFabricIndex_decoded, - nextUserIndex_decoded, + nextUserIndex_decoded ) } - suspend fun clearUser(userIndex: UShort, timedInvokeTimeout: Duration) { + suspend fun clearUser(userIndex: UShort + ,timedInvokeTimeout: Duration) { val commandId: UInt = 29u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_USER_INDEX_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_USER_INDEX_REQ), userIndex) + tlvWriter.put(ContextSpecificTag(TAG_USER_INDEX_REQ), userIndex) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun setCredential( - operationType: UByte, - credential: DoorLockClusterCredentialStruct, - credentialData: ByteArray, - userIndex: UShort?, - userStatus: UByte?, - userType: UByte?, - timedInvokeTimeout: Duration, - ): SetCredentialResponse { + suspend fun setCredential(operationType: UByte + ,credential: DoorLockClusterCredentialStruct + ,credentialData: ByteArray + ,userIndex: UShort? + ,userStatus: UByte? + ,userType: UByte? + ,timedInvokeTimeout: Duration): SetCredentialResponse { val commandId: UInt = 34u val tlvWriter = TlvWriter() @@ -1201,20 +1253,26 @@ class DoorLockCluster(private val controller: MatterController, private val endp tlvWriter.put(ContextSpecificTag(TAG_CREDENTIAL_DATA_REQ), credentialData) val TAG_USER_INDEX_REQ: Int = 3 - userIndex?.let { tlvWriter.put(ContextSpecificTag(TAG_USER_INDEX_REQ), userIndex) } + userIndex?.let { + tlvWriter.put(ContextSpecificTag(TAG_USER_INDEX_REQ), userIndex) + } val TAG_USER_STATUS_REQ: Int = 4 - userStatus?.let { tlvWriter.put(ContextSpecificTag(TAG_USER_STATUS_REQ), userStatus) } + userStatus?.let { + tlvWriter.put(ContextSpecificTag(TAG_USER_STATUS_REQ), userStatus) + } val TAG_USER_TYPE_REQ: Int = 5 - userType?.let { tlvWriter.put(ContextSpecificTag(TAG_USER_TYPE_REQ), userType) } + userType?.let { + tlvWriter.put(ContextSpecificTag(TAG_USER_TYPE_REQ), userType) + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -1224,80 +1282,88 @@ class DoorLockCluster(private val controller: MatterController, private val endp tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_USER_INDEX: Int = 1 var userIndex_decoded: UShort? = null - + val TAG_NEXT_CREDENTIAL_INDEX: Int = 2 var nextCredentialIndex_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_USER_INDEX)) { - userIndex_decoded = + + if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_USER_INDEX)) {userIndex_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (!tlvReader.isNull()) { - tlvReader.getUShort(tag) - } else { - tlvReader.getNull(tag) - null - } - } - } - - if (tag == ContextSpecificTag(TAG_NEXT_CREDENTIAL_INDEX)) { - nextCredentialIndex_decoded = + tlvReader.getUShort(tag) + } else { + tlvReader.getNull(tag) + null + } + }} + + if (tag == ContextSpecificTag(TAG_NEXT_CREDENTIAL_INDEX)) {nextCredentialIndex_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (!tlvReader.isNull()) { - tlvReader.getUShort(tag) - } else { - tlvReader.getNull(tag) - null - } - } - } else { + tlvReader.getUShort(tag) + } else { + tlvReader.getNull(tag) + null + } + }} + + + else { tlvReader.skipElement() } } + + if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } + + + + + tlvReader.exitContainer() - return SetCredentialResponse(status_decoded, userIndex_decoded, nextCredentialIndex_decoded) + return SetCredentialResponse( + status_decoded, + userIndex_decoded, + nextCredentialIndex_decoded + ) } - suspend fun getCredentialStatus( - credential: DoorLockClusterCredentialStruct, - timedInvokeTimeout: Duration? = null, - ): GetCredentialStatusResponse { + suspend fun getCredentialStatus(credential: DoorLockClusterCredentialStruct + ,timedInvokeTimeout: Duration? = null): GetCredentialStatusResponse { val commandId: UInt = 36u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_CREDENTIAL_REQ: Int = 0 - credential.toTlv(ContextSpecificTag(TAG_CREDENTIAL_REQ), tlvWriter) + credential.toTlv(ContextSpecificTag(TAG_CREDENTIAL_REQ), tlvWriter) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -1307,92 +1373,98 @@ class DoorLockCluster(private val controller: MatterController, private val endp tlvReader.enterStructure(AnonymousTag) val TAG_CREDENTIAL_EXISTS: Int = 0 var credentialExists_decoded: Boolean? = null - + val TAG_USER_INDEX: Int = 1 var userIndex_decoded: UShort? = null - + val TAG_CREATOR_FABRIC_INDEX: Int = 2 var creatorFabricIndex_decoded: UByte? = null - + val TAG_LAST_MODIFIED_FABRIC_INDEX: Int = 3 var lastModifiedFabricIndex_decoded: UByte? = null - + val TAG_NEXT_CREDENTIAL_INDEX: Int = 4 var nextCredentialIndex_decoded: UShort? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_CREDENTIAL_EXISTS)) { - credentialExists_decoded = tlvReader.getBoolean(tag) - } - - if (tag == ContextSpecificTag(TAG_USER_INDEX)) { - userIndex_decoded = + + if (tag == ContextSpecificTag(TAG_CREDENTIAL_EXISTS)) {credentialExists_decoded = tlvReader.getBoolean(tag)} + + if (tag == ContextSpecificTag(TAG_USER_INDEX)) {userIndex_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (!tlvReader.isNull()) { - tlvReader.getUShort(tag) - } else { - tlvReader.getNull(tag) - null - } - } - } - - if (tag == ContextSpecificTag(TAG_CREATOR_FABRIC_INDEX)) { - creatorFabricIndex_decoded = + tlvReader.getUShort(tag) + } else { + tlvReader.getNull(tag) + null + } + }} + + if (tag == ContextSpecificTag(TAG_CREATOR_FABRIC_INDEX)) {creatorFabricIndex_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (!tlvReader.isNull()) { - tlvReader.getUByte(tag) - } else { - tlvReader.getNull(tag) - null - } - } - } - - if (tag == ContextSpecificTag(TAG_LAST_MODIFIED_FABRIC_INDEX)) { - lastModifiedFabricIndex_decoded = + tlvReader.getUByte(tag) + } else { + tlvReader.getNull(tag) + null + } + }} + + if (tag == ContextSpecificTag(TAG_LAST_MODIFIED_FABRIC_INDEX)) {lastModifiedFabricIndex_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (!tlvReader.isNull()) { - tlvReader.getUByte(tag) - } else { - tlvReader.getNull(tag) - null - } - } - } - - if (tag == ContextSpecificTag(TAG_NEXT_CREDENTIAL_INDEX)) { - nextCredentialIndex_decoded = + tlvReader.getUByte(tag) + } else { + tlvReader.getNull(tag) + null + } + }} + + if (tag == ContextSpecificTag(TAG_NEXT_CREDENTIAL_INDEX)) {nextCredentialIndex_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (!tlvReader.isNull()) { - tlvReader.getUShort(tag) - } else { - tlvReader.getNull(tag) - null - } - } - } else { + tlvReader.getUShort(tag) + } else { + tlvReader.getNull(tag) + null + } + }} + + + else { tlvReader.skipElement() } } + + if (credentialExists_decoded == null) { - throw IllegalStateException("credentialExists not found in TLV") - } + throw IllegalStateException("credentialExists not found in TLV") + } + + + + + + + + + tlvReader.exitContainer() @@ -1401,62 +1473,63 @@ class DoorLockCluster(private val controller: MatterController, private val endp userIndex_decoded, creatorFabricIndex_decoded, lastModifiedFabricIndex_decoded, - nextCredentialIndex_decoded, + nextCredentialIndex_decoded ) } - suspend fun clearCredential( - credential: DoorLockClusterCredentialStruct?, - timedInvokeTimeout: Duration, - ) { + suspend fun clearCredential(credential: DoorLockClusterCredentialStruct? + ,timedInvokeTimeout: Duration) { val commandId: UInt = 38u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_CREDENTIAL_REQ: Int = 0 - credential?.let { credential.toTlv(ContextSpecificTag(TAG_CREDENTIAL_REQ), tlvWriter) } + credential?.let { + credential.toTlv(ContextSpecificTag(TAG_CREDENTIAL_REQ), tlvWriter) + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun unboltDoor(PINCode: ByteArray?, timedInvokeTimeout: Duration) { + suspend fun unboltDoor(PINCode: ByteArray? + ,timedInvokeTimeout: Duration) { val commandId: UInt = 39u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_PIN_CODE_REQ: Int = 0 - PINCode?.let { tlvWriter.put(ContextSpecificTag(TAG_PIN_CODE_REQ), PINCode) } + PINCode?.let { + tlvWriter.put(ContextSpecificTag(TAG_PIN_CODE_REQ), PINCode) + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun setAliroReaderConfig( - signingKey: ByteArray, - verificationKey: ByteArray, - groupIdentifier: ByteArray, - groupResolvingKey: ByteArray?, - timedInvokeTimeout: Duration, - ) { + suspend fun setAliroReaderConfig(signingKey: ByteArray + ,verificationKey: ByteArray + ,groupIdentifier: ByteArray + ,groupResolvingKey: ByteArray? + ,timedInvokeTimeout: Duration) { val commandId: UInt = 40u val tlvWriter = TlvWriter() @@ -1474,14 +1547,14 @@ class DoorLockCluster(private val controller: MatterController, private val endp val TAG_GROUP_RESOLVING_KEY_REQ: Int = 3 groupResolvingKey?.let { tlvWriter.put(ContextSpecificTag(TAG_GROUP_RESOLVING_KEY_REQ), groupResolvingKey) - } + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -1492,180 +1565,191 @@ class DoorLockCluster(private val controller: MatterController, private val endp val commandId: UInt = 41u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } +suspend fun readLockStateAttribute(): LockStateAttribute {val ATTRIBUTE_ID: UInt = 0u - suspend fun readLockStateAttribute(): LockStateAttribute { - 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 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}") - } + 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) { "Lockstate attribute not found in response" } + } + + requireNotNull(attributeData) { + "Lockstate attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return LockStateAttribute(decodedValue) } suspend fun subscribeLockStateAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - LockStateAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(LockStateAttributeSubscriptionState.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) { "Lockstate attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Lockstate 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.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(LockStateAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(LockStateAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(LockStateAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readLockTypeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 1u - suspend fun readLockTypeAttribute(): 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 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}") - } + 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) { "Locktype attribute not found in response" } + } + + requireNotNull(attributeData) { + "Locktype 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 subscribeLockTypeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Locktype attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Locktype attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -1677,77 +1761,80 @@ class DoorLockCluster(private val controller: MatterController, private val endp emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readActuatorEnabledAttribute(): Boolean {val ATTRIBUTE_ID: UInt = 2u - suspend fun readActuatorEnabledAttribute(): Boolean { - val ATTRIBUTE_ID: UInt = 2u + val attributePath = AttributePath( + endpointId = endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ) - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - - val response = controller.read(readRequest) + 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}") - } + 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) { "Actuatorenabled attribute not found in response" } + } + + requireNotNull(attributeData) { + "Actuatorenabled attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Boolean = tlvReader.getBoolean(AnonymousTag) + return decodedValue } suspend fun subscribeActuatorEnabledAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Actuatorenabled attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Actuatorenabled attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -1760,163 +1847,179 @@ class DoorLockCluster(private val controller: MatterController, private val endp emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readDoorStateAttribute(): DoorStateAttribute {val ATTRIBUTE_ID: UInt = 3u - suspend fun readDoorStateAttribute(): DoorStateAttribute { - 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 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}") - } + 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) { "Doorstate attribute not found in response" } + } + + requireNotNull(attributeData) { + "Doorstate attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return DoorStateAttribute(decodedValue) } suspend fun subscribeDoorStateAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - DoorStateAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(DoorStateAttributeSubscriptionState.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) { "Doorstate attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Doorstate 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(DoorStateAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(DoorStateAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(DoorStateAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readDoorOpenEventsAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 4u - suspend fun readDoorOpenEventsAttribute(): UInt? { - 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 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}") - } + 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) { "Dooropenevents attribute not found in response" } + } + + requireNotNull(attributeData) { + "Dooropenevents attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } - suspend fun writeDoorOpenEventsAttribute(value: UInt, timedWriteTimeout: Duration? = null) { + suspend fun writeDoorOpenEventsAttribute( + value: UInt, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 4u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -1937,119 +2040,127 @@ class DoorLockCluster(private val controller: MatterController, private val endp throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeDoorOpenEventsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Dooropenevents attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Dooropenevents attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readDoorClosedEventsAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 5u - suspend fun readDoorClosedEventsAttribute(): UInt? { - 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 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}") - } + 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) { "Doorclosedevents attribute not found in response" } + } + + requireNotNull(attributeData) { + "Doorclosedevents attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } - suspend fun writeDoorClosedEventsAttribute(value: UInt, timedWriteTimeout: Duration? = null) { + suspend fun writeDoorClosedEventsAttribute( + value: UInt, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 5u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -2070,119 +2181,127 @@ class DoorLockCluster(private val controller: MatterController, private val endp throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeDoorClosedEventsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Doorclosedevents attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Doorclosedevents attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readOpenPeriodAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 6u - suspend fun readOpenPeriodAttribute(): 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 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}") - } + 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) { "Openperiod attribute not found in response" } + } + + requireNotNull(attributeData) { + "Openperiod 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } - suspend fun writeOpenPeriodAttribute(value: UShort, timedWriteTimeout: Duration? = null) { + suspend fun writeOpenPeriodAttribute( + value: UShort, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 6u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -2203,1241 +2322,1291 @@ class DoorLockCluster(private val controller: MatterController, private val endp throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeOpenPeriodAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Openperiod attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Openperiod 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNumberOfTotalUsersSupportedAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 17u - suspend fun readNumberOfTotalUsersSupportedAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 17u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Numberoftotaluserssupported attribute not found in response" } + } + + requireNotNull(attributeData) { + "Numberoftotaluserssupported 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeNumberOfTotalUsersSupportedAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 17u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Numberoftotaluserssupported attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Numberoftotaluserssupported 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNumberOfPINUsersSupportedAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 18u - suspend fun readNumberOfPINUsersSupportedAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 18u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Numberofpinuserssupported attribute not found in response" } + } + + requireNotNull(attributeData) { + "Numberofpinuserssupported 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeNumberOfPINUsersSupportedAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 18u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Numberofpinuserssupported attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Numberofpinuserssupported 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNumberOfRFIDUsersSupportedAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 19u - suspend fun readNumberOfRFIDUsersSupportedAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 19u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Numberofrfiduserssupported attribute not found in response" } + } + + requireNotNull(attributeData) { + "Numberofrfiduserssupported 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeNumberOfRFIDUsersSupportedAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 19u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Numberofrfiduserssupported attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Numberofrfiduserssupported 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNumberOfWeekDaySchedulesSupportedPerUserAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 20u - suspend fun readNumberOfWeekDaySchedulesSupportedPerUserAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 20u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { - "Numberofweekdayschedulessupportedperuser attribute not found in response" + } + + requireNotNull(attributeData) { + "Numberofweekdayschedulessupportedperuser 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeNumberOfWeekDaySchedulesSupportedPerUserAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 20u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Numberofweekdayschedulessupportedperuser attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Numberofweekdayschedulessupportedperuser 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNumberOfYearDaySchedulesSupportedPerUserAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 21u - suspend fun readNumberOfYearDaySchedulesSupportedPerUserAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 21u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { - "Numberofyeardayschedulessupportedperuser attribute not found in response" + } + + requireNotNull(attributeData) { + "Numberofyeardayschedulessupportedperuser 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeNumberOfYearDaySchedulesSupportedPerUserAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 21u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Numberofyeardayschedulessupportedperuser attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Numberofyeardayschedulessupportedperuser 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNumberOfHolidaySchedulesSupportedAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 22u - suspend fun readNumberOfHolidaySchedulesSupportedAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 22u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { - "Numberofholidayschedulessupported attribute not found in response" + } + + requireNotNull(attributeData) { + "Numberofholidayschedulessupported 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeNumberOfHolidaySchedulesSupportedAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 22u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Numberofholidayschedulessupported attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Numberofholidayschedulessupported 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readMaxPINCodeLengthAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 23u - suspend fun readMaxPINCodeLengthAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 23u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Maxpincodelength attribute not found in response" } + } + + requireNotNull(attributeData) { + "Maxpincodelength 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeMaxPINCodeLengthAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 23u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Maxpincodelength attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Maxpincodelength 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readMinPINCodeLengthAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 24u - suspend fun readMinPINCodeLengthAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 24u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Minpincodelength attribute not found in response" } + } + + requireNotNull(attributeData) { + "Minpincodelength 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeMinPINCodeLengthAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 24u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Minpincodelength attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Minpincodelength 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readMaxRFIDCodeLengthAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 25u - suspend fun readMaxRFIDCodeLengthAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 25u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Maxrfidcodelength attribute not found in response" } + } + + requireNotNull(attributeData) { + "Maxrfidcodelength 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeMaxRFIDCodeLengthAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 25u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Maxrfidcodelength attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Maxrfidcodelength 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readMinRFIDCodeLengthAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 26u - suspend fun readMinRFIDCodeLengthAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 26u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Minrfidcodelength attribute not found in response" } + } + + requireNotNull(attributeData) { + "Minrfidcodelength 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeMinRFIDCodeLengthAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 26u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Minrfidcodelength attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Minrfidcodelength 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readCredentialRulesSupportAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 27u - suspend fun readCredentialRulesSupportAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 27u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Credentialrulessupport attribute not found in response" } + } + + requireNotNull(attributeData) { + "Credentialrulessupport 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeCredentialRulesSupportAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 27u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Credentialrulessupport attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Credentialrulessupport 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNumberOfCredentialsSupportedPerUserAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 28u - suspend fun readNumberOfCredentialsSupportedPerUserAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 28u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { - "Numberofcredentialssupportedperuser attribute not found in response" + } + + requireNotNull(attributeData) { + "Numberofcredentialssupportedperuser 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeNumberOfCredentialsSupportedPerUserAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 28u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Numberofcredentialssupportedperuser attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Numberofcredentialssupportedperuser 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readLanguageAttribute(): String? {val ATTRIBUTE_ID: UInt = 33u - suspend fun readLanguageAttribute(): String? { - val ATTRIBUTE_ID: UInt = 33u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Language attribute not found in response" } + } + + requireNotNull(attributeData) { + "Language attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + return decodedValue } - suspend fun writeLanguageAttribute(value: String, timedWriteTimeout: Duration? = null) { + suspend fun writeLanguageAttribute( + value: String, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 33u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -3458,117 +3627,127 @@ class DoorLockCluster(private val controller: MatterController, private val endp throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeLanguageAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 33u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StringSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StringSubscriptionState.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) { "Language attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Language attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(StringSubscriptionState.Success(it)) } + decodedValue?.let { + emit(StringSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readLEDSettingsAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 34u - suspend fun readLEDSettingsAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 34u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Ledsettings attribute not found in response" } + } + + requireNotNull(attributeData) { + "Ledsettings 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } - suspend fun writeLEDSettingsAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeLEDSettingsAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 34u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -3589,117 +3768,127 @@ class DoorLockCluster(private val controller: MatterController, private val endp throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeLEDSettingsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 34u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Ledsettings attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Ledsettings 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAutoRelockTimeAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 35u - suspend fun readAutoRelockTimeAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 35u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Autorelocktime attribute not found in response" } + } + + requireNotNull(attributeData) { + "Autorelocktime attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } - suspend fun writeAutoRelockTimeAttribute(value: UInt, timedWriteTimeout: Duration? = null) { + suspend fun writeAutoRelockTimeAttribute( + value: UInt, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 35u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -3720,119 +3909,127 @@ class DoorLockCluster(private val controller: MatterController, private val endp throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeAutoRelockTimeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 35u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Autorelocktime attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Autorelocktime attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readSoundVolumeAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 36u - suspend fun readSoundVolumeAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 36u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Soundvolume attribute not found in response" } + } + + requireNotNull(attributeData) { + "Soundvolume 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } - suspend fun writeSoundVolumeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeSoundVolumeAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 36u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -3853,112 +4050,123 @@ class DoorLockCluster(private val controller: MatterController, private val endp throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeSoundVolumeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 36u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Soundvolume attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Soundvolume 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readOperatingModeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 37u - suspend fun readOperatingModeAttribute(): UByte { - val ATTRIBUTE_ID: UInt = 37u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Operatingmode attribute not found in response" } + } + + requireNotNull(attributeData) { + "Operatingmode 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 writeOperatingModeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeOperatingModeAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 37u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -3979,45 +4187,43 @@ class DoorLockCluster(private val controller: MatterController, private val endp throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeOperatingModeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 37u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Operatingmode attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Operatingmode attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -4029,77 +4235,80 @@ class DoorLockCluster(private val controller: MatterController, private val endp emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readSupportedOperatingModesAttribute(): UShort {val ATTRIBUTE_ID: UInt = 38u - suspend fun readSupportedOperatingModesAttribute(): UShort { - val ATTRIBUTE_ID: UInt = 38u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Supportedoperatingmodes attribute not found in response" } + } + + requireNotNull(attributeData) { + "Supportedoperatingmodes 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 subscribeSupportedOperatingModesAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 38u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Supportedoperatingmodes attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Supportedoperatingmodes attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -4112,158 +4321,169 @@ class DoorLockCluster(private val controller: MatterController, private val endp emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readDefaultConfigurationRegisterAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 39u - suspend fun readDefaultConfigurationRegisterAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 39u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Defaultconfigurationregister attribute not found in response" } + } + + requireNotNull(attributeData) { + "Defaultconfigurationregister 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeDefaultConfigurationRegisterAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 39u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Defaultconfigurationregister attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Defaultconfigurationregister 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readEnableLocalProgrammingAttribute(): Boolean? {val ATTRIBUTE_ID: UInt = 40u - suspend fun readEnableLocalProgrammingAttribute(): Boolean? { - val ATTRIBUTE_ID: UInt = 40u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Enablelocalprogramming attribute not found in response" } + } + + requireNotNull(attributeData) { + "Enablelocalprogramming 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 - } + val decodedValue: Boolean? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun writeEnableLocalProgrammingAttribute( value: Boolean, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 40u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -4284,122 +4504,127 @@ class DoorLockCluster(private val controller: MatterController, private val endp throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeEnableLocalProgrammingAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 40u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Enablelocalprogramming attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Enablelocalprogramming 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 - } + val decodedValue: Boolean? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(BooleanSubscriptionState.Success(it)) } + decodedValue?.let { + emit(BooleanSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readEnableOneTouchLockingAttribute(): Boolean? {val ATTRIBUTE_ID: UInt = 41u - suspend fun readEnableOneTouchLockingAttribute(): Boolean? { - val ATTRIBUTE_ID: UInt = 41u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Enableonetouchlocking attribute not found in response" } + } + + requireNotNull(attributeData) { + "Enableonetouchlocking 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 - } + val decodedValue: Boolean? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun writeEnableOneTouchLockingAttribute( value: Boolean, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 41u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -4420,122 +4645,127 @@ class DoorLockCluster(private val controller: MatterController, private val endp throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeEnableOneTouchLockingAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 41u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Enableonetouchlocking attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Enableonetouchlocking 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 - } + val decodedValue: Boolean? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(BooleanSubscriptionState.Success(it)) } + decodedValue?.let { + emit(BooleanSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readEnableInsideStatusLEDAttribute(): Boolean? {val ATTRIBUTE_ID: UInt = 42u - suspend fun readEnableInsideStatusLEDAttribute(): Boolean? { - val ATTRIBUTE_ID: UInt = 42u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Enableinsidestatusled attribute not found in response" } + } + + requireNotNull(attributeData) { + "Enableinsidestatusled 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 - } + val decodedValue: Boolean? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun writeEnableInsideStatusLEDAttribute( value: Boolean, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 42u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -4556,122 +4786,127 @@ class DoorLockCluster(private val controller: MatterController, private val endp throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeEnableInsideStatusLEDAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 42u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Enableinsidestatusled attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Enableinsidestatusled 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 - } + val decodedValue: Boolean? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(BooleanSubscriptionState.Success(it)) } + decodedValue?.let { + emit(BooleanSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readEnablePrivacyModeButtonAttribute(): Boolean? {val ATTRIBUTE_ID: UInt = 43u - suspend fun readEnablePrivacyModeButtonAttribute(): Boolean? { - val ATTRIBUTE_ID: UInt = 43u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Enableprivacymodebutton attribute not found in response" } + } + + requireNotNull(attributeData) { + "Enableprivacymodebutton 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 - } + val decodedValue: Boolean? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun writeEnablePrivacyModeButtonAttribute( value: Boolean, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 43u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -4692,122 +4927,127 @@ class DoorLockCluster(private val controller: MatterController, private val endp throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeEnablePrivacyModeButtonAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 43u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Enableprivacymodebutton attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Enableprivacymodebutton 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 - } + val decodedValue: Boolean? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(BooleanSubscriptionState.Success(it)) } + decodedValue?.let { + emit(BooleanSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readLocalProgrammingFeaturesAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 44u - suspend fun readLocalProgrammingFeaturesAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 44u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Localprogrammingfeatures attribute not found in response" } + } + + requireNotNull(attributeData) { + "Localprogrammingfeatures 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun writeLocalProgrammingFeaturesAttribute( value: UByte, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 44u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -4828,119 +5068,127 @@ class DoorLockCluster(private val controller: MatterController, private val endp throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeLocalProgrammingFeaturesAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 44u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Localprogrammingfeatures attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Localprogrammingfeatures 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readWrongCodeEntryLimitAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 48u - suspend fun readWrongCodeEntryLimitAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 48u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Wrongcodeentrylimit attribute not found in response" } + } + + requireNotNull(attributeData) { + "Wrongcodeentrylimit 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } - suspend fun writeWrongCodeEntryLimitAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeWrongCodeEntryLimitAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 48u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -4961,122 +5209,127 @@ class DoorLockCluster(private val controller: MatterController, private val endp throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeWrongCodeEntryLimitAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 48u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Wrongcodeentrylimit attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Wrongcodeentrylimit 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readUserCodeTemporaryDisableTimeAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 49u - suspend fun readUserCodeTemporaryDisableTimeAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 49u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Usercodetemporarydisabletime attribute not found in response" } + } + + requireNotNull(attributeData) { + "Usercodetemporarydisabletime 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun writeUserCodeTemporaryDisableTimeAttribute( value: UByte, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 49u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -5097,119 +5350,127 @@ class DoorLockCluster(private val controller: MatterController, private val endp throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeUserCodeTemporaryDisableTimeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 49u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Usercodetemporarydisabletime attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Usercodetemporarydisabletime 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readSendPINOverTheAirAttribute(): Boolean? {val ATTRIBUTE_ID: UInt = 50u - suspend fun readSendPINOverTheAirAttribute(): Boolean? { - val ATTRIBUTE_ID: UInt = 50u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Sendpinovertheair attribute not found in response" } + } + + requireNotNull(attributeData) { + "Sendpinovertheair 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 - } + val decodedValue: Boolean? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } + return decodedValue } - suspend fun writeSendPINOverTheAirAttribute(value: Boolean, timedWriteTimeout: Duration? = null) { + suspend fun writeSendPINOverTheAirAttribute( + value: Boolean, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 50u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -5230,122 +5491,127 @@ class DoorLockCluster(private val controller: MatterController, private val endp throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeSendPINOverTheAirAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 50u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Sendpinovertheair attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Sendpinovertheair 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 - } + val decodedValue: Boolean? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(BooleanSubscriptionState.Success(it)) } + decodedValue?.let { + emit(BooleanSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRequirePINforRemoteOperationAttribute(): Boolean? {val ATTRIBUTE_ID: UInt = 51u - suspend fun readRequirePINforRemoteOperationAttribute(): Boolean? { - val ATTRIBUTE_ID: UInt = 51u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Requirepinforremoteoperation attribute not found in response" } + } + + requireNotNull(attributeData) { + "Requirepinforremoteoperation 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 - } + val decodedValue: Boolean? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun writeRequirePINforRemoteOperationAttribute( value: Boolean, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 51u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -5366,122 +5632,127 @@ class DoorLockCluster(private val controller: MatterController, private val endp throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeRequirePINforRemoteOperationAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 51u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Requirepinforremoteoperation attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Requirepinforremoteoperation 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 - } + val decodedValue: Boolean? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(BooleanSubscriptionState.Success(it)) } + decodedValue?.let { + emit(BooleanSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readExpiringUserTimeoutAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 53u - suspend fun readExpiringUserTimeoutAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 53u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Expiringusertimeout attribute not found in response" } + } + + requireNotNull(attributeData) { + "Expiringusertimeout 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun writeExpiringUserTimeoutAttribute( value: UShort, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 53u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -5502,1073 +5773,1079 @@ class DoorLockCluster(private val controller: MatterController, private val endp throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeExpiringUserTimeoutAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 53u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Expiringusertimeout attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Expiringusertimeout 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAliroReaderVerificationKeyAttribute(): AliroReaderVerificationKeyAttribute {val ATTRIBUTE_ID: UInt = 128u - suspend fun readAliroReaderVerificationKeyAttribute(): AliroReaderVerificationKeyAttribute { - val ATTRIBUTE_ID: UInt = 128u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Aliroreaderverificationkey attribute not found in response" } + } + + requireNotNull(attributeData) { + "Aliroreaderverificationkey attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByteArray(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ByteArray? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByteArray(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return AliroReaderVerificationKeyAttribute(decodedValue) } suspend fun subscribeAliroReaderVerificationKeyAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 128u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - AliroReaderVerificationKeyAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(AliroReaderVerificationKeyAttributeSubscriptionState.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) { - "Aliroreaderverificationkey attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Aliroreaderverificationkey attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByteArray(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ByteArray? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByteArray(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } decodedValue?.let { emit(AliroReaderVerificationKeyAttributeSubscriptionState.Success(it)) } + } SubscriptionState.SubscriptionEstablished -> { emit(AliroReaderVerificationKeyAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAliroReaderGroupIdentifierAttribute(): AliroReaderGroupIdentifierAttribute {val ATTRIBUTE_ID: UInt = 129u - suspend fun readAliroReaderGroupIdentifierAttribute(): AliroReaderGroupIdentifierAttribute { - val ATTRIBUTE_ID: UInt = 129u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Aliroreadergroupidentifier attribute not found in response" } + } + + requireNotNull(attributeData) { + "Aliroreadergroupidentifier attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByteArray(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ByteArray? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByteArray(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return AliroReaderGroupIdentifierAttribute(decodedValue) } suspend fun subscribeAliroReaderGroupIdentifierAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 129u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - AliroReaderGroupIdentifierAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(AliroReaderGroupIdentifierAttributeSubscriptionState.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) { - "Aliroreadergroupidentifier attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Aliroreadergroupidentifier attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByteArray(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ByteArray? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByteArray(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } decodedValue?.let { emit(AliroReaderGroupIdentifierAttributeSubscriptionState.Success(it)) } + } SubscriptionState.SubscriptionEstablished -> { emit(AliroReaderGroupIdentifierAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAliroReaderGroupSubIdentifierAttribute(): ByteArray? {val ATTRIBUTE_ID: UInt = 130u - suspend fun readAliroReaderGroupSubIdentifierAttribute(): ByteArray? { - val ATTRIBUTE_ID: UInt = 130u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { - "Aliroreadergroupsubidentifier attribute not found in response" + } + + requireNotNull(attributeData) { + "Aliroreadergroupsubidentifier attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByteArray(AnonymousTag) - } else { - null - } + val decodedValue: ByteArray? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByteArray(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeAliroReaderGroupSubIdentifierAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 130u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ByteArraySubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ByteArraySubscriptionState.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) { - "Aliroreadergroupsubidentifier attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Aliroreadergroupsubidentifier attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByteArray(AnonymousTag) - } else { - null - } + val decodedValue: ByteArray? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByteArray(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ByteArraySubscriptionState.Success(it)) } + decodedValue?.let { + emit(ByteArraySubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ByteArraySubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAliroExpeditedTransactionSupportedProtocolVersionsAttribute(): AliroExpeditedTransactionSupportedProtocolVersionsAttribute {val ATTRIBUTE_ID: UInt = 131u - suspend fun readAliroExpeditedTransactionSupportedProtocolVersionsAttribute(): - AliroExpeditedTransactionSupportedProtocolVersionsAttribute { - val ATTRIBUTE_ID: UInt = 131u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { - "Aliroexpeditedtransactionsupportedprotocolversions attribute not found in response" + } + + requireNotNull(attributeData) { + "Aliroexpeditedtransactionsupportedprotocolversions attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getByteArray(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getByteArray(AnonymousTag)) } + tlvReader.exitContainer() + } + } else { + null + } + return AliroExpeditedTransactionSupportedProtocolVersionsAttribute(decodedValue) } suspend fun subscribeAliroExpeditedTransactionSupportedProtocolVersionsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 131u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - AliroExpeditedTransactionSupportedProtocolVersionsAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(AliroExpeditedTransactionSupportedProtocolVersionsAttributeSubscriptionState.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) { - "Aliroexpeditedtransactionsupportedprotocolversions attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Aliroexpeditedtransactionsupportedprotocolversions attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getByteArray(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null - } + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getByteArray(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null + } decodedValue?.let { - emit( - AliroExpeditedTransactionSupportedProtocolVersionsAttributeSubscriptionState.Success( - it - ) - ) + emit(AliroExpeditedTransactionSupportedProtocolVersionsAttributeSubscriptionState.Success(it)) } + } SubscriptionState.SubscriptionEstablished -> { - emit( - AliroExpeditedTransactionSupportedProtocolVersionsAttributeSubscriptionState - .SubscriptionEstablished - ) + emit(AliroExpeditedTransactionSupportedProtocolVersionsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAliroGroupResolvingKeyAttribute(): AliroGroupResolvingKeyAttribute {val ATTRIBUTE_ID: UInt = 132u - suspend fun readAliroGroupResolvingKeyAttribute(): AliroGroupResolvingKeyAttribute { - val ATTRIBUTE_ID: UInt = 132u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Alirogroupresolvingkey attribute not found in response" } + } + + requireNotNull(attributeData) { + "Alirogroupresolvingkey attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByteArray(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ByteArray? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByteArray(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return AliroGroupResolvingKeyAttribute(decodedValue) } suspend fun subscribeAliroGroupResolvingKeyAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 132u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - AliroGroupResolvingKeyAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(AliroGroupResolvingKeyAttributeSubscriptionState.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) { - "Alirogroupresolvingkey attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Alirogroupresolvingkey attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByteArray(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(AliroGroupResolvingKeyAttributeSubscriptionState.Success(it)) } + val decodedValue: ByteArray? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByteArray(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(AliroGroupResolvingKeyAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(AliroGroupResolvingKeyAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAliroSupportedBLEUWBProtocolVersionsAttribute(): AliroSupportedBLEUWBProtocolVersionsAttribute {val ATTRIBUTE_ID: UInt = 133u - suspend fun readAliroSupportedBLEUWBProtocolVersionsAttribute(): - AliroSupportedBLEUWBProtocolVersionsAttribute { - val ATTRIBUTE_ID: UInt = 133u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { - "Alirosupportedbleuwbprotocolversions attribute not found in response" + } + + requireNotNull(attributeData) { + "Alirosupportedbleuwbprotocolversions attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getByteArray(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getByteArray(AnonymousTag)) } + tlvReader.exitContainer() + } + } else { + null + } + return AliroSupportedBLEUWBProtocolVersionsAttribute(decodedValue) } suspend fun subscribeAliroSupportedBLEUWBProtocolVersionsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 133u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - AliroSupportedBLEUWBProtocolVersionsAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(AliroSupportedBLEUWBProtocolVersionsAttributeSubscriptionState.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) { - "Alirosupportedbleuwbprotocolversions attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Alirosupportedbleuwbprotocolversions attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getByteArray(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null - } + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getByteArray(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null + } decodedValue?.let { emit(AliroSupportedBLEUWBProtocolVersionsAttributeSubscriptionState.Success(it)) } + } SubscriptionState.SubscriptionEstablished -> { - emit( - AliroSupportedBLEUWBProtocolVersionsAttributeSubscriptionState.SubscriptionEstablished - ) + emit(AliroSupportedBLEUWBProtocolVersionsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAliroBLEAdvertisingVersionAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 134u - suspend fun readAliroBLEAdvertisingVersionAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 134u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Alirobleadvertisingversion attribute not found in response" } + } + + requireNotNull(attributeData) { + "Alirobleadvertisingversion 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeAliroBLEAdvertisingVersionAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 134u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Alirobleadvertisingversion attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Alirobleadvertisingversion 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNumberOfAliroCredentialIssuerKeysSupportedAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 135u - suspend fun readNumberOfAliroCredentialIssuerKeysSupportedAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 135u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { - "Numberofalirocredentialissuerkeyssupported attribute not found in response" + } + + requireNotNull(attributeData) { + "Numberofalirocredentialissuerkeyssupported 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeNumberOfAliroCredentialIssuerKeysSupportedAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 135u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Numberofalirocredentialissuerkeyssupported attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Numberofalirocredentialissuerkeyssupported 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNumberOfAliroEndpointKeysSupportedAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 136u - suspend fun readNumberOfAliroEndpointKeysSupportedAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 136u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { - "Numberofaliroendpointkeyssupported attribute not found in response" + } + + requireNotNull(attributeData) { + "Numberofaliroendpointkeyssupported 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeNumberOfAliroEndpointKeysSupportedAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 136u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Numberofaliroendpointkeyssupported attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Numberofaliroendpointkeyssupported 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65528u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -6576,96 +6853,97 @@ class DoorLockCluster(private val controller: MatterController, private val endp emit(GeneratedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65529u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -6673,94 +6951,97 @@ class DoorLockCluster(private val controller: MatterController, private val endp emit(AcceptedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt = 65530u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -6768,94 +7049,97 @@ class DoorLockCluster(private val controller: MatterController, private val endp emit(EventListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ID: UInt = 65531u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -6863,76 +7147,81 @@ class DoorLockCluster(private val controller: MatterController, private val endp emit(AttributeListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u - 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 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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -6944,77 +7233,80 @@ class DoorLockCluster(private val controller: MatterController, private val endp emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 65533u - 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 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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -7027,7 +7319,7 @@ class DoorLockCluster(private val controller: MatterController, private val endp emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/EcosystemInformationCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/EcosystemInformationCluster.kt index 5dfa4a7f8067ef..cbf93654da7199 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/EcosystemInformationCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/EcosystemInformationCluster.kt @@ -17,291 +17,335 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.UIntSubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState +import matter.controller.UByteSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath +import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader +import matter.tlv.TlvWriter -class EcosystemInformationCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class RemovedOnAttribute(val value: ULong?) +class EcosystemInformationCluster(private val controller: MatterController, private val endpointId: UShort) {class RemovedOnAttribute( + val value: ULong? + ) sealed class RemovedOnAttributeSubscriptionState { - data class Success(val value: ULong?) : RemovedOnAttributeSubscriptionState() - + data class Success( + val value: ULong? + ) : RemovedOnAttributeSubscriptionState() + data class Error(val exception: Exception) : RemovedOnAttributeSubscriptionState() - object SubscriptionEstablished : RemovedOnAttributeSubscriptionState() - } - - class DeviceDirectoryAttribute(val value: List) + object SubscriptionEstablished : RemovedOnAttributeSubscriptionState() + } +class DeviceDirectoryAttribute( + val value: List + ) sealed class DeviceDirectoryAttributeSubscriptionState { - data class Success(val value: List) : - DeviceDirectoryAttributeSubscriptionState() - + data class Success( + val value: List + ) : DeviceDirectoryAttributeSubscriptionState() + data class Error(val exception: Exception) : DeviceDirectoryAttributeSubscriptionState() - object SubscriptionEstablished : DeviceDirectoryAttributeSubscriptionState() - } - - class LocationDirectoryAttribute( + object SubscriptionEstablished : DeviceDirectoryAttributeSubscriptionState() + } +class LocationDirectoryAttribute( val value: List ) sealed class LocationDirectoryAttributeSubscriptionState { - data class Success(val value: List) : - LocationDirectoryAttributeSubscriptionState() - + data class Success( + val value: List + ) : LocationDirectoryAttributeSubscriptionState() + data class Error(val exception: Exception) : LocationDirectoryAttributeSubscriptionState() - object SubscriptionEstablished : LocationDirectoryAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : LocationDirectoryAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } - - suspend fun readRemovedOnAttribute(): RemovedOnAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } +suspend fun readRemovedOnAttribute(): RemovedOnAttribute {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}") - } + 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) { "Removedon attribute not found in response" } + } + + requireNotNull(attributeData) { + "Removedon 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 - } + val decodedValue: ULong? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return RemovedOnAttribute(decodedValue) } suspend fun subscribeRemovedOnAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - RemovedOnAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(RemovedOnAttributeSubscriptionState.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) { "Removedon attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Removedon 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(RemovedOnAttributeSubscriptionState.Success(it)) } + val decodedValue: ULong? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(RemovedOnAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(RemovedOnAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readDeviceDirectoryAttribute(): DeviceDirectoryAttribute { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readDeviceDirectoryAttribute(): DeviceDirectoryAttribute {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}") - } + 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) { "Devicedirectory attribute not found in response" } + } + + requireNotNull(attributeData) { + "Devicedirectory 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(EcosystemInformationClusterEcosystemDeviceStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(EcosystemInformationClusterEcosystemDeviceStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + return DeviceDirectoryAttribute(decodedValue) } suspend fun subscribeDeviceDirectoryAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - DeviceDirectoryAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(DeviceDirectoryAttributeSubscriptionState.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) { - "Devicedirectory attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Devicedirectory 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( - EcosystemInformationClusterEcosystemDeviceStruct.fromTlv(AnonymousTag, tlvReader) - ) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(EcosystemInformationClusterEcosystemDeviceStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(DeviceDirectoryAttributeSubscriptionState.Success(decodedValue)) } @@ -309,101 +353,97 @@ class EcosystemInformationCluster( emit(DeviceDirectoryAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readLocationDirectoryAttribute(): LocationDirectoryAttribute { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readLocationDirectoryAttribute(): LocationDirectoryAttribute {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}") - } + 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) { "Locationdirectory attribute not found in response" } + } + + requireNotNull(attributeData) { + "Locationdirectory 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(EcosystemInformationClusterEcosystemLocationStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(EcosystemInformationClusterEcosystemLocationStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + return LocationDirectoryAttribute(decodedValue) } suspend fun subscribeLocationDirectoryAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - LocationDirectoryAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(LocationDirectoryAttributeSubscriptionState.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) { - "Locationdirectory attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Locationdirectory 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( - EcosystemInformationClusterEcosystemLocationStruct.fromTlv( - AnonymousTag, - tlvReader, - ) - ) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(EcosystemInformationClusterEcosystemLocationStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(LocationDirectoryAttributeSubscriptionState.Success(decodedValue)) } @@ -411,96 +451,97 @@ class EcosystemInformationCluster( emit(LocationDirectoryAttributeSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -508,96 +549,97 @@ class EcosystemInformationCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -605,94 +647,97 @@ class EcosystemInformationCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -700,94 +745,97 @@ class EcosystemInformationCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -795,76 +843,81 @@ class EcosystemInformationCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -876,77 +929,80 @@ class EcosystemInformationCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -959,7 +1015,7 @@ class EcosystemInformationCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/ElectricalEnergyMeasurementCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/ElectricalEnergyMeasurementCluster.kt index e23cc2d91b6c98..e8ee567241b398 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/ElectricalEnergyMeasurementCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/ElectricalEnergyMeasurementCluster.kt @@ -17,221 +17,255 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.UIntSubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState +import matter.controller.UByteSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath +import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader +import matter.tlv.TlvWriter -class ElectricalEnergyMeasurementCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class AccuracyAttribute(val value: ElectricalEnergyMeasurementClusterMeasurementAccuracyStruct) +class ElectricalEnergyMeasurementCluster(private val controller: MatterController, private val endpointId: UShort) {class AccuracyAttribute( + val value: ElectricalEnergyMeasurementClusterMeasurementAccuracyStruct + ) sealed class AccuracyAttributeSubscriptionState { - data class Success(val value: ElectricalEnergyMeasurementClusterMeasurementAccuracyStruct) : - AccuracyAttributeSubscriptionState() - + data class Success( + val value: ElectricalEnergyMeasurementClusterMeasurementAccuracyStruct + ) : AccuracyAttributeSubscriptionState() + data class Error(val exception: Exception) : AccuracyAttributeSubscriptionState() - object SubscriptionEstablished : AccuracyAttributeSubscriptionState() - } - - class CumulativeEnergyImportedAttribute( + object SubscriptionEstablished : AccuracyAttributeSubscriptionState() + } +class CumulativeEnergyImportedAttribute( val value: ElectricalEnergyMeasurementClusterEnergyMeasurementStruct? ) sealed class CumulativeEnergyImportedAttributeSubscriptionState { - data class Success(val value: ElectricalEnergyMeasurementClusterEnergyMeasurementStruct?) : - CumulativeEnergyImportedAttributeSubscriptionState() - - data class Error(val exception: Exception) : - CumulativeEnergyImportedAttributeSubscriptionState() - - object SubscriptionEstablished : CumulativeEnergyImportedAttributeSubscriptionState() - } + data class Success( + val value: ElectricalEnergyMeasurementClusterEnergyMeasurementStruct? + ) : CumulativeEnergyImportedAttributeSubscriptionState() + + data class Error(val exception: Exception) : CumulativeEnergyImportedAttributeSubscriptionState() - class CumulativeEnergyExportedAttribute( + object SubscriptionEstablished : CumulativeEnergyImportedAttributeSubscriptionState() + } +class CumulativeEnergyExportedAttribute( val value: ElectricalEnergyMeasurementClusterEnergyMeasurementStruct? ) sealed class CumulativeEnergyExportedAttributeSubscriptionState { - data class Success(val value: ElectricalEnergyMeasurementClusterEnergyMeasurementStruct?) : - CumulativeEnergyExportedAttributeSubscriptionState() - - data class Error(val exception: Exception) : - CumulativeEnergyExportedAttributeSubscriptionState() - - object SubscriptionEstablished : CumulativeEnergyExportedAttributeSubscriptionState() - } + data class Success( + val value: ElectricalEnergyMeasurementClusterEnergyMeasurementStruct? + ) : CumulativeEnergyExportedAttributeSubscriptionState() + + data class Error(val exception: Exception) : CumulativeEnergyExportedAttributeSubscriptionState() - class PeriodicEnergyImportedAttribute( + object SubscriptionEstablished : CumulativeEnergyExportedAttributeSubscriptionState() + } +class PeriodicEnergyImportedAttribute( val value: ElectricalEnergyMeasurementClusterEnergyMeasurementStruct? ) sealed class PeriodicEnergyImportedAttributeSubscriptionState { - data class Success(val value: ElectricalEnergyMeasurementClusterEnergyMeasurementStruct?) : - PeriodicEnergyImportedAttributeSubscriptionState() - + data class Success( + val value: ElectricalEnergyMeasurementClusterEnergyMeasurementStruct? + ) : PeriodicEnergyImportedAttributeSubscriptionState() + data class Error(val exception: Exception) : PeriodicEnergyImportedAttributeSubscriptionState() - object SubscriptionEstablished : PeriodicEnergyImportedAttributeSubscriptionState() - } - - class PeriodicEnergyExportedAttribute( + object SubscriptionEstablished : PeriodicEnergyImportedAttributeSubscriptionState() + } +class PeriodicEnergyExportedAttribute( val value: ElectricalEnergyMeasurementClusterEnergyMeasurementStruct? ) sealed class PeriodicEnergyExportedAttributeSubscriptionState { - data class Success(val value: ElectricalEnergyMeasurementClusterEnergyMeasurementStruct?) : - PeriodicEnergyExportedAttributeSubscriptionState() - + data class Success( + val value: ElectricalEnergyMeasurementClusterEnergyMeasurementStruct? + ) : PeriodicEnergyExportedAttributeSubscriptionState() + data class Error(val exception: Exception) : PeriodicEnergyExportedAttributeSubscriptionState() - object SubscriptionEstablished : PeriodicEnergyExportedAttributeSubscriptionState() - } - - class CumulativeEnergyResetAttribute( + object SubscriptionEstablished : PeriodicEnergyExportedAttributeSubscriptionState() + } +class CumulativeEnergyResetAttribute( val value: ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct? ) sealed class CumulativeEnergyResetAttributeSubscriptionState { - data class Success(val value: ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct?) : - CumulativeEnergyResetAttributeSubscriptionState() - + data class Success( + val value: ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct? + ) : CumulativeEnergyResetAttributeSubscriptionState() + data class Error(val exception: Exception) : CumulativeEnergyResetAttributeSubscriptionState() - object SubscriptionEstablished : CumulativeEnergyResetAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : CumulativeEnergyResetAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } - - suspend fun readAccuracyAttribute(): AccuracyAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } +suspend fun readAccuracyAttribute(): AccuracyAttribute {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}") - } + 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) { "Accuracy attribute not found in response" } + } + + 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) + val decodedValue: ElectricalEnergyMeasurementClusterMeasurementAccuracyStruct = ElectricalEnergyMeasurementClusterMeasurementAccuracyStruct.fromTlv(AnonymousTag, tlvReader) + return AccuracyAttribute(decodedValue) } suspend fun subscribeAccuracyAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - AccuracyAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(AccuracyAttributeSubscriptionState.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) { "Accuracy attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Accuracy attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ElectricalEnergyMeasurementClusterMeasurementAccuracyStruct = - ElectricalEnergyMeasurementClusterMeasurementAccuracyStruct.fromTlv( - AnonymousTag, - tlvReader, - ) + val decodedValue: ElectricalEnergyMeasurementClusterMeasurementAccuracyStruct = ElectricalEnergyMeasurementClusterMeasurementAccuracyStruct.fromTlv(AnonymousTag, tlvReader) emit(AccuracyAttributeSubscriptionState.Success(decodedValue)) } @@ -239,629 +273,632 @@ class ElectricalEnergyMeasurementCluster( emit(AccuracyAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readCumulativeEnergyImportedAttribute(): CumulativeEnergyImportedAttribute { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readCumulativeEnergyImportedAttribute(): CumulativeEnergyImportedAttribute {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}") - } + 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" } + } + + 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 - } + 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 subscribeCumulativeEnergyImportedAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - CumulativeEnergyImportedAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(CumulativeEnergyImportedAttributeSubscriptionState.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) { - "Cumulativeenergyimported attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Cumulativeenergyimported attribute not found in Node State update" } // 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 - } - - decodedValue?.let { emit(CumulativeEnergyImportedAttributeSubscriptionState.Success(it)) } + val decodedValue: ElectricalEnergyMeasurementClusterEnergyMeasurementStruct? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + ElectricalEnergyMeasurementClusterEnergyMeasurementStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(CumulativeEnergyImportedAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(CumulativeEnergyImportedAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readCumulativeEnergyExportedAttribute(): CumulativeEnergyExportedAttribute { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readCumulativeEnergyExportedAttribute(): CumulativeEnergyExportedAttribute {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}") - } + 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) { "Cumulativeenergyexported attribute not found in response" } + } + + 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 - } + 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 subscribeCumulativeEnergyExportedAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - CumulativeEnergyExportedAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(CumulativeEnergyExportedAttributeSubscriptionState.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) { - "Cumulativeenergyexported attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Cumulativeenergyexported attribute not found in Node State update" } // 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 - } - - decodedValue?.let { emit(CumulativeEnergyExportedAttributeSubscriptionState.Success(it)) } + val decodedValue: ElectricalEnergyMeasurementClusterEnergyMeasurementStruct? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + ElectricalEnergyMeasurementClusterEnergyMeasurementStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(CumulativeEnergyExportedAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(CumulativeEnergyExportedAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readPeriodicEnergyImportedAttribute(): PeriodicEnergyImportedAttribute { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readPeriodicEnergyImportedAttribute(): PeriodicEnergyImportedAttribute {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}") - } + 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) { "Periodicenergyimported attribute not found in response" } + } + + 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 - } + 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 subscribePeriodicEnergyImportedAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - PeriodicEnergyImportedAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(PeriodicEnergyImportedAttributeSubscriptionState.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) { - "Periodicenergyimported attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Periodicenergyimported attribute not found in Node State update" } // 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 - } - - decodedValue?.let { emit(PeriodicEnergyImportedAttributeSubscriptionState.Success(it)) } + val decodedValue: ElectricalEnergyMeasurementClusterEnergyMeasurementStruct? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + ElectricalEnergyMeasurementClusterEnergyMeasurementStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(PeriodicEnergyImportedAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(PeriodicEnergyImportedAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readPeriodicEnergyExportedAttribute(): PeriodicEnergyExportedAttribute { - val ATTRIBUTE_ID: UInt = 4u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readPeriodicEnergyExportedAttribute(): PeriodicEnergyExportedAttribute {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}") - } + 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" } + } + + 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 - } + 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 subscribePeriodicEnergyExportedAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - PeriodicEnergyExportedAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(PeriodicEnergyExportedAttributeSubscriptionState.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) { - "Periodicenergyexported attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Periodicenergyexported attribute not found in Node State update" } // 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 - } - - decodedValue?.let { emit(PeriodicEnergyExportedAttributeSubscriptionState.Success(it)) } + val decodedValue: ElectricalEnergyMeasurementClusterEnergyMeasurementStruct? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + ElectricalEnergyMeasurementClusterEnergyMeasurementStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(PeriodicEnergyExportedAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(PeriodicEnergyExportedAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readCumulativeEnergyResetAttribute(): CumulativeEnergyResetAttribute { - val ATTRIBUTE_ID: UInt = 5u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readCumulativeEnergyResetAttribute(): CumulativeEnergyResetAttribute {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}") - } + 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) { "Cumulativeenergyreset attribute not found in response" } + } + + requireNotNull(attributeData) { + "Cumulativeenergyreset attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct.fromTlv( - AnonymousTag, - tlvReader, - ) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return CumulativeEnergyResetAttribute(decodedValue) } suspend fun subscribeCumulativeEnergyResetAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - CumulativeEnergyResetAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(CumulativeEnergyResetAttributeSubscriptionState.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) { - "Cumulativeenergyreset attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Cumulativeenergyreset attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct.fromTlv( - AnonymousTag, - tlvReader, - ) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(CumulativeEnergyResetAttributeSubscriptionState.Success(it)) } + val decodedValue: ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(CumulativeEnergyResetAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(CumulativeEnergyResetAttributeSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -869,96 +906,97 @@ class ElectricalEnergyMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -966,94 +1004,97 @@ class ElectricalEnergyMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1061,94 +1102,97 @@ class ElectricalEnergyMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1156,76 +1200,81 @@ class ElectricalEnergyMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1237,77 +1286,80 @@ class ElectricalEnergyMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1320,7 +1372,7 @@ class ElectricalEnergyMeasurementCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/ElectricalMeasurementCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/ElectricalMeasurementCluster.kt index 7c564d94f7738c..0fec4dc6624459 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/ElectricalMeasurementCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/ElectricalMeasurementCluster.kt @@ -17,103 +17,123 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.ByteSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest -import matter.controller.ShortSubscriptionState +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.cluster.structs.* +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class ElectricalMeasurementCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class GeneratedCommandListAttribute(val value: List) +class ElectricalMeasurementCluster(private val controller: MatterController, private val endpointId: UShort) {class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } suspend fun getProfileInfoCommand(timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun getMeasurementProfileCommand( - attributeId: UShort, - startTime: UInt, - numberOfIntervals: UByte, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun getMeasurementProfileCommand(attributeId: UShort + ,startTime: UInt + ,numberOfIntervals: UByte + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 1u val tlvWriter = TlvWriter() @@ -126,5444 +146,5709 @@ class ElectricalMeasurementCluster( tlvWriter.put(ContextSpecificTag(TAG_START_TIME_REQ), startTime) val TAG_NUMBER_OF_INTERVALS_REQ: Int = 2 - tlvWriter.put(ContextSpecificTag(TAG_NUMBER_OF_INTERVALS_REQ), numberOfIntervals) + tlvWriter.put(ContextSpecificTag(TAG_NUMBER_OF_INTERVALS_REQ), numberOfIntervals) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } +suspend fun readMeasurementTypeAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 0u - suspend fun readMeasurementTypeAttribute(): UInt? { - 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 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}") - } + 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) { "Measurementtype attribute not found in response" } + } + + requireNotNull(attributeData) { + "Measurementtype attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeMeasurementTypeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Measurementtype attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Measurementtype attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readDcVoltageAttribute(): Short? {val ATTRIBUTE_ID: UInt = 256u - suspend fun readDcVoltageAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 256u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Dcvoltage attribute not found in response" } + } + + requireNotNull(attributeData) { + "Dcvoltage attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeDcVoltageAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 256u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { "Dcvoltage attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Dcvoltage attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readDcVoltageMinAttribute(): Short? {val ATTRIBUTE_ID: UInt = 257u - suspend fun readDcVoltageMinAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 257u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Dcvoltagemin attribute not found in response" } + } + + requireNotNull(attributeData) { + "Dcvoltagemin attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeDcVoltageMinAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 257u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { "Dcvoltagemin attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Dcvoltagemin attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readDcVoltageMaxAttribute(): Short? {val ATTRIBUTE_ID: UInt = 258u - suspend fun readDcVoltageMaxAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 258u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Dcvoltagemax attribute not found in response" } + } + + requireNotNull(attributeData) { + "Dcvoltagemax attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeDcVoltageMaxAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 258u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { "Dcvoltagemax attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Dcvoltagemax attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readDcCurrentAttribute(): Short? {val ATTRIBUTE_ID: UInt = 259u - suspend fun readDcCurrentAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 259u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Dccurrent attribute not found in response" } + } + + requireNotNull(attributeData) { + "Dccurrent attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeDcCurrentAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 259u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { "Dccurrent attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Dccurrent attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readDcCurrentMinAttribute(): Short? {val ATTRIBUTE_ID: UInt = 260u - suspend fun readDcCurrentMinAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 260u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Dccurrentmin attribute not found in response" } + } + + requireNotNull(attributeData) { + "Dccurrentmin attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeDcCurrentMinAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 260u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { "Dccurrentmin attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Dccurrentmin attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readDcCurrentMaxAttribute(): Short? {val ATTRIBUTE_ID: UInt = 261u - suspend fun readDcCurrentMaxAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 261u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Dccurrentmax attribute not found in response" } + } + + requireNotNull(attributeData) { + "Dccurrentmax attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeDcCurrentMaxAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 261u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { "Dccurrentmax attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Dccurrentmax attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readDcPowerAttribute(): Short? {val ATTRIBUTE_ID: UInt = 262u - suspend fun readDcPowerAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 262u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Dcpower attribute not found in response" } + } + + requireNotNull(attributeData) { + "Dcpower attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeDcPowerAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 262u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { "Dcpower attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Dcpower attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readDcPowerMinAttribute(): Short? {val ATTRIBUTE_ID: UInt = 263u - suspend fun readDcPowerMinAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 263u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Dcpowermin attribute not found in response" } + } + + requireNotNull(attributeData) { + "Dcpowermin attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeDcPowerMinAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 263u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { "Dcpowermin attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Dcpowermin attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readDcPowerMaxAttribute(): Short? {val ATTRIBUTE_ID: UInt = 264u - suspend fun readDcPowerMaxAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 264u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Dcpowermax attribute not found in response" } + } + + requireNotNull(attributeData) { + "Dcpowermax attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeDcPowerMaxAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 264u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { "Dcpowermax attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Dcpowermax attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readDcVoltageMultiplierAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 512u - suspend fun readDcVoltageMultiplierAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 512u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Dcvoltagemultiplier attribute not found in response" } + } + + requireNotNull(attributeData) { + "Dcvoltagemultiplier 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeDcVoltageMultiplierAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 512u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Dcvoltagemultiplier attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Dcvoltagemultiplier 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readDcVoltageDivisorAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 513u - suspend fun readDcVoltageDivisorAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 513u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Dcvoltagedivisor attribute not found in response" } + } + + requireNotNull(attributeData) { + "Dcvoltagedivisor 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeDcVoltageDivisorAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 513u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Dcvoltagedivisor attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Dcvoltagedivisor 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readDcCurrentMultiplierAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 514u - suspend fun readDcCurrentMultiplierAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 514u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Dccurrentmultiplier attribute not found in response" } + } + + requireNotNull(attributeData) { + "Dccurrentmultiplier 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeDcCurrentMultiplierAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 514u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Dccurrentmultiplier attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Dccurrentmultiplier 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readDcCurrentDivisorAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 515u - suspend fun readDcCurrentDivisorAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 515u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Dccurrentdivisor attribute not found in response" } + } + + requireNotNull(attributeData) { + "Dccurrentdivisor 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeDcCurrentDivisorAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 515u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Dccurrentdivisor attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Dccurrentdivisor 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readDcPowerMultiplierAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 516u - suspend fun readDcPowerMultiplierAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 516u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Dcpowermultiplier attribute not found in response" } + } + + requireNotNull(attributeData) { + "Dcpowermultiplier 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeDcPowerMultiplierAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 516u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Dcpowermultiplier attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Dcpowermultiplier 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readDcPowerDivisorAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 517u - suspend fun readDcPowerDivisorAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 517u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Dcpowerdivisor attribute not found in response" } + } + + requireNotNull(attributeData) { + "Dcpowerdivisor 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeDcPowerDivisorAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 517u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Dcpowerdivisor attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Dcpowerdivisor 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAcFrequencyAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 768u - suspend fun readAcFrequencyAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 768u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Acfrequency attribute not found in response" } + } + + requireNotNull(attributeData) { + "Acfrequency 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeAcFrequencyAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 768u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Acfrequency attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Acfrequency 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAcFrequencyMinAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 769u - suspend fun readAcFrequencyMinAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 769u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Acfrequencymin attribute not found in response" } + } + + requireNotNull(attributeData) { + "Acfrequencymin 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeAcFrequencyMinAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 769u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Acfrequencymin attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Acfrequencymin 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAcFrequencyMaxAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 770u - suspend fun readAcFrequencyMaxAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 770u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Acfrequencymax attribute not found in response" } + } + + requireNotNull(attributeData) { + "Acfrequencymax 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeAcFrequencyMaxAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 770u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Acfrequencymax attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Acfrequencymax 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNeutralCurrentAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 771u - suspend fun readNeutralCurrentAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 771u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Neutralcurrent attribute not found in response" } + } + + requireNotNull(attributeData) { + "Neutralcurrent 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeNeutralCurrentAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 771u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Neutralcurrent attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Neutralcurrent 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readTotalActivePowerAttribute(): Int? {val ATTRIBUTE_ID: UInt = 772u - suspend fun readTotalActivePowerAttribute(): Int? { - val ATTRIBUTE_ID: UInt = 772u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Totalactivepower attribute not found in response" } + } + + requireNotNull(attributeData) { + "Totalactivepower attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Int? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getInt(AnonymousTag) - } else { - null - } + val decodedValue: Int? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeTotalActivePowerAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 772u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - IntSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(IntSubscriptionState.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) { - "Totalactivepower attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Totalactivepower attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Int? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getInt(AnonymousTag) - } else { - null - } + val decodedValue: Int? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getInt(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(IntSubscriptionState.Success(it)) } + decodedValue?.let { + emit(IntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(IntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readTotalReactivePowerAttribute(): Int? {val ATTRIBUTE_ID: UInt = 773u - suspend fun readTotalReactivePowerAttribute(): Int? { - val ATTRIBUTE_ID: UInt = 773u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Totalreactivepower attribute not found in response" } + } + + requireNotNull(attributeData) { + "Totalreactivepower attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Int? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getInt(AnonymousTag) - } else { - null - } + val decodedValue: Int? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeTotalReactivePowerAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 773u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - IntSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(IntSubscriptionState.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) { - "Totalreactivepower attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Totalreactivepower attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Int? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getInt(AnonymousTag) - } else { - null - } + val decodedValue: Int? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getInt(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(IntSubscriptionState.Success(it)) } + decodedValue?.let { + emit(IntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(IntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readTotalApparentPowerAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 774u - suspend fun readTotalApparentPowerAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 774u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Totalapparentpower attribute not found in response" } + } + + requireNotNull(attributeData) { + "Totalapparentpower attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeTotalApparentPowerAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 774u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Totalapparentpower attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Totalapparentpower attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readMeasured1stHarmonicCurrentAttribute(): Short? {val ATTRIBUTE_ID: UInt = 775u - suspend fun readMeasured1stHarmonicCurrentAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 775u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Measured1stharmoniccurrent attribute not found in response" } + } + + requireNotNull(attributeData) { + "Measured1stharmoniccurrent attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeMeasured1stHarmonicCurrentAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 775u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Measured1stharmoniccurrent attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Measured1stharmoniccurrent attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readMeasured3rdHarmonicCurrentAttribute(): Short? {val ATTRIBUTE_ID: UInt = 776u - suspend fun readMeasured3rdHarmonicCurrentAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 776u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Measured3rdharmoniccurrent attribute not found in response" } + } + + requireNotNull(attributeData) { + "Measured3rdharmoniccurrent attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeMeasured3rdHarmonicCurrentAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 776u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Measured3rdharmoniccurrent attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Measured3rdharmoniccurrent attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readMeasured5thHarmonicCurrentAttribute(): Short? {val ATTRIBUTE_ID: UInt = 777u - suspend fun readMeasured5thHarmonicCurrentAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 777u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Measured5thharmoniccurrent attribute not found in response" } + } + + requireNotNull(attributeData) { + "Measured5thharmoniccurrent attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeMeasured5thHarmonicCurrentAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 777u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Measured5thharmoniccurrent attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Measured5thharmoniccurrent attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readMeasured7thHarmonicCurrentAttribute(): Short? {val ATTRIBUTE_ID: UInt = 778u - suspend fun readMeasured7thHarmonicCurrentAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 778u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Measured7thharmoniccurrent attribute not found in response" } + } + + requireNotNull(attributeData) { + "Measured7thharmoniccurrent attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeMeasured7thHarmonicCurrentAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 778u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Measured7thharmoniccurrent attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Measured7thharmoniccurrent attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readMeasured9thHarmonicCurrentAttribute(): Short? {val ATTRIBUTE_ID: UInt = 779u - suspend fun readMeasured9thHarmonicCurrentAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 779u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Measured9thharmoniccurrent attribute not found in response" } + } + + requireNotNull(attributeData) { + "Measured9thharmoniccurrent attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeMeasured9thHarmonicCurrentAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 779u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Measured9thharmoniccurrent attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Measured9thharmoniccurrent attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readMeasured11thHarmonicCurrentAttribute(): Short? {val ATTRIBUTE_ID: UInt = 780u - suspend fun readMeasured11thHarmonicCurrentAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 780u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Measured11thharmoniccurrent attribute not found in response" } + } + + requireNotNull(attributeData) { + "Measured11thharmoniccurrent attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeMeasured11thHarmonicCurrentAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 780u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Measured11thharmoniccurrent attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Measured11thharmoniccurrent attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readMeasuredPhase1stHarmonicCurrentAttribute(): Short? {val ATTRIBUTE_ID: UInt = 781u - suspend fun readMeasuredPhase1stHarmonicCurrentAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 781u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { - "Measuredphase1stharmoniccurrent attribute not found in response" + } + + requireNotNull(attributeData) { + "Measuredphase1stharmoniccurrent attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeMeasuredPhase1stHarmonicCurrentAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 781u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Measuredphase1stharmoniccurrent attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Measuredphase1stharmoniccurrent attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readMeasuredPhase3rdHarmonicCurrentAttribute(): Short? {val ATTRIBUTE_ID: UInt = 782u - suspend fun readMeasuredPhase3rdHarmonicCurrentAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 782u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { - "Measuredphase3rdharmoniccurrent attribute not found in response" + } + + requireNotNull(attributeData) { + "Measuredphase3rdharmoniccurrent attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeMeasuredPhase3rdHarmonicCurrentAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 782u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Measuredphase3rdharmoniccurrent attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Measuredphase3rdharmoniccurrent attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readMeasuredPhase5thHarmonicCurrentAttribute(): Short? {val ATTRIBUTE_ID: UInt = 783u - suspend fun readMeasuredPhase5thHarmonicCurrentAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 783u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { - "Measuredphase5thharmoniccurrent attribute not found in response" + } + + requireNotNull(attributeData) { + "Measuredphase5thharmoniccurrent attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeMeasuredPhase5thHarmonicCurrentAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 783u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Measuredphase5thharmoniccurrent attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Measuredphase5thharmoniccurrent attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readMeasuredPhase7thHarmonicCurrentAttribute(): Short? {val ATTRIBUTE_ID: UInt = 784u - suspend fun readMeasuredPhase7thHarmonicCurrentAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 784u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { - "Measuredphase7thharmoniccurrent attribute not found in response" + } + + requireNotNull(attributeData) { + "Measuredphase7thharmoniccurrent attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeMeasuredPhase7thHarmonicCurrentAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 784u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Measuredphase7thharmoniccurrent attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Measuredphase7thharmoniccurrent attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readMeasuredPhase9thHarmonicCurrentAttribute(): Short? {val ATTRIBUTE_ID: UInt = 785u - suspend fun readMeasuredPhase9thHarmonicCurrentAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 785u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { - "Measuredphase9thharmoniccurrent attribute not found in response" + } + + requireNotNull(attributeData) { + "Measuredphase9thharmoniccurrent attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeMeasuredPhase9thHarmonicCurrentAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 785u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Measuredphase9thharmoniccurrent attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Measuredphase9thharmoniccurrent attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readMeasuredPhase11thHarmonicCurrentAttribute(): Short? {val ATTRIBUTE_ID: UInt = 786u - suspend fun readMeasuredPhase11thHarmonicCurrentAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 786u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { - "Measuredphase11thharmoniccurrent attribute not found in response" + } + + requireNotNull(attributeData) { + "Measuredphase11thharmoniccurrent attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeMeasuredPhase11thHarmonicCurrentAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 786u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Measuredphase11thharmoniccurrent attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Measuredphase11thharmoniccurrent attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAcFrequencyMultiplierAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 1024u - suspend fun readAcFrequencyMultiplierAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 1024u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Acfrequencymultiplier attribute not found in response" } + } + + requireNotNull(attributeData) { + "Acfrequencymultiplier 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeAcFrequencyMultiplierAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1024u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Acfrequencymultiplier attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Acfrequencymultiplier 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAcFrequencyDivisorAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 1025u - suspend fun readAcFrequencyDivisorAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 1025u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Acfrequencydivisor attribute not found in response" } + } + + requireNotNull(attributeData) { + "Acfrequencydivisor 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeAcFrequencyDivisorAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1025u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Acfrequencydivisor attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Acfrequencydivisor 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readPowerMultiplierAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 1026u - suspend fun readPowerMultiplierAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 1026u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Powermultiplier attribute not found in response" } + } + + requireNotNull(attributeData) { + "Powermultiplier attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribePowerMultiplierAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1026u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Powermultiplier attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Powermultiplier attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readPowerDivisorAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 1027u - suspend fun readPowerDivisorAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 1027u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Powerdivisor attribute not found in response" } + } + + requireNotNull(attributeData) { + "Powerdivisor attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribePowerDivisorAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1027u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Powerdivisor attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Powerdivisor attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readHarmonicCurrentMultiplierAttribute(): Byte? {val ATTRIBUTE_ID: UInt = 1028u - suspend fun readHarmonicCurrentMultiplierAttribute(): Byte? { - val ATTRIBUTE_ID: UInt = 1028u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Harmoniccurrentmultiplier attribute not found in response" } + } + + requireNotNull(attributeData) { + "Harmoniccurrentmultiplier attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Byte? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByte(AnonymousTag) - } else { - null - } + val decodedValue: Byte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeHarmonicCurrentMultiplierAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1028u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ByteSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ByteSubscriptionState.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) { - "Harmoniccurrentmultiplier attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Harmoniccurrentmultiplier attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Byte? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByte(AnonymousTag) - } else { - null - } + val decodedValue: Byte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readPhaseHarmonicCurrentMultiplierAttribute(): Byte? {val ATTRIBUTE_ID: UInt = 1029u - suspend fun readPhaseHarmonicCurrentMultiplierAttribute(): Byte? { - val ATTRIBUTE_ID: UInt = 1029u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { - "Phaseharmoniccurrentmultiplier attribute not found in response" + } + + requireNotNull(attributeData) { + "Phaseharmoniccurrentmultiplier attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Byte? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByte(AnonymousTag) - } else { - null - } + val decodedValue: Byte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribePhaseHarmonicCurrentMultiplierAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1029u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ByteSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ByteSubscriptionState.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) { - "Phaseharmoniccurrentmultiplier attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Phaseharmoniccurrentmultiplier attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Byte? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByte(AnonymousTag) - } else { - null - } + val decodedValue: Byte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readInstantaneousVoltageAttribute(): Short? {val ATTRIBUTE_ID: UInt = 1280u - suspend fun readInstantaneousVoltageAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 1280u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Instantaneousvoltage attribute not found in response" } + } + + requireNotNull(attributeData) { + "Instantaneousvoltage attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeInstantaneousVoltageAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1280u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Instantaneousvoltage attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Instantaneousvoltage attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readInstantaneousLineCurrentAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 1281u - suspend fun readInstantaneousLineCurrentAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 1281u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Instantaneouslinecurrent attribute not found in response" } + } + + requireNotNull(attributeData) { + "Instantaneouslinecurrent 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeInstantaneousLineCurrentAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1281u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Instantaneouslinecurrent attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Instantaneouslinecurrent 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readInstantaneousActiveCurrentAttribute(): Short? {val ATTRIBUTE_ID: UInt = 1282u - suspend fun readInstantaneousActiveCurrentAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 1282u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Instantaneousactivecurrent attribute not found in response" } + } + + requireNotNull(attributeData) { + "Instantaneousactivecurrent attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeInstantaneousActiveCurrentAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1282u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Instantaneousactivecurrent attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Instantaneousactivecurrent attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readInstantaneousReactiveCurrentAttribute(): Short? {val ATTRIBUTE_ID: UInt = 1283u - suspend fun readInstantaneousReactiveCurrentAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 1283u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Instantaneousreactivecurrent attribute not found in response" } + } + + requireNotNull(attributeData) { + "Instantaneousreactivecurrent attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeInstantaneousReactiveCurrentAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1283u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Instantaneousreactivecurrent attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Instantaneousreactivecurrent attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readInstantaneousPowerAttribute(): Short? {val ATTRIBUTE_ID: UInt = 1284u - suspend fun readInstantaneousPowerAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 1284u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Instantaneouspower attribute not found in response" } + } + + requireNotNull(attributeData) { + "Instantaneouspower attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeInstantaneousPowerAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1284u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Instantaneouspower attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Instantaneouspower attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRmsVoltageAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 1285u - suspend fun readRmsVoltageAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 1285u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rmsvoltage attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rmsvoltage 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeRmsVoltageAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1285u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Rmsvoltage attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rmsvoltage 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRmsVoltageMinAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 1286u - suspend fun readRmsVoltageMinAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 1286u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rmsvoltagemin attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rmsvoltagemin 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeRmsVoltageMinAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1286u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Rmsvoltagemin attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rmsvoltagemin 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRmsVoltageMaxAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 1287u - suspend fun readRmsVoltageMaxAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 1287u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rmsvoltagemax attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rmsvoltagemax 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeRmsVoltageMaxAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1287u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Rmsvoltagemax attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rmsvoltagemax 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRmsCurrentAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 1288u - suspend fun readRmsCurrentAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 1288u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rmscurrent attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rmscurrent 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeRmsCurrentAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1288u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Rmscurrent attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rmscurrent 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRmsCurrentMinAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 1289u - suspend fun readRmsCurrentMinAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 1289u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rmscurrentmin attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rmscurrentmin 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeRmsCurrentMinAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1289u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Rmscurrentmin attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rmscurrentmin 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRmsCurrentMaxAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 1290u - suspend fun readRmsCurrentMaxAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 1290u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rmscurrentmax attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rmscurrentmax 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeRmsCurrentMaxAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1290u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Rmscurrentmax attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rmscurrentmax 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readActivePowerAttribute(): Short? {val ATTRIBUTE_ID: UInt = 1291u - suspend fun readActivePowerAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 1291u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Activepower attribute not found in response" } + } + + requireNotNull(attributeData) { + "Activepower attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeActivePowerAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1291u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { "Activepower attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Activepower attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readActivePowerMinAttribute(): Short? {val ATTRIBUTE_ID: UInt = 1292u - suspend fun readActivePowerMinAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 1292u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Activepowermin attribute not found in response" } + } + + requireNotNull(attributeData) { + "Activepowermin attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeActivePowerMinAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1292u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Activepowermin attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Activepowermin attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readActivePowerMaxAttribute(): Short? {val ATTRIBUTE_ID: UInt = 1293u - suspend fun readActivePowerMaxAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 1293u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Activepowermax attribute not found in response" } + } + + requireNotNull(attributeData) { + "Activepowermax attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeActivePowerMaxAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1293u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Activepowermax attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Activepowermax attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readReactivePowerAttribute(): Short? {val ATTRIBUTE_ID: UInt = 1294u - suspend fun readReactivePowerAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 1294u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Reactivepower attribute not found in response" } + } + + requireNotNull(attributeData) { + "Reactivepower attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeReactivePowerAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1294u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { "Reactivepower attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Reactivepower attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readApparentPowerAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 1295u - suspend fun readApparentPowerAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 1295u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Apparentpower attribute not found in response" } + } + + requireNotNull(attributeData) { + "Apparentpower 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeApparentPowerAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1295u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Apparentpower attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Apparentpower 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readPowerFactorAttribute(): Byte? {val ATTRIBUTE_ID: UInt = 1296u - suspend fun readPowerFactorAttribute(): Byte? { - val ATTRIBUTE_ID: UInt = 1296u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Powerfactor attribute not found in response" } + } + + requireNotNull(attributeData) { + "Powerfactor attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Byte? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByte(AnonymousTag) - } else { - null - } + val decodedValue: Byte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribePowerFactorAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1296u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ByteSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ByteSubscriptionState.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) { "Powerfactor attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Powerfactor attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Byte? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByte(AnonymousTag) - } else { - null - } + val decodedValue: Byte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAverageRmsVoltageMeasurementPeriodAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 1297u - suspend fun readAverageRmsVoltageMeasurementPeriodAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 1297u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { - "Averagermsvoltagemeasurementperiod attribute not found in response" + } + + requireNotNull(attributeData) { + "Averagermsvoltagemeasurementperiod 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun writeAverageRmsVoltageMeasurementPeriodAttribute( value: UShort, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 1297u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -5584,124 +5869,127 @@ class ElectricalMeasurementCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeAverageRmsVoltageMeasurementPeriodAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1297u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Averagermsvoltagemeasurementperiod attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Averagermsvoltagemeasurementperiod 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAverageRmsUnderVoltageCounterAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 1299u - suspend fun readAverageRmsUnderVoltageCounterAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 1299u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { - "Averagermsundervoltagecounter attribute not found in response" + } + + requireNotNull(attributeData) { + "Averagermsundervoltagecounter 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun writeAverageRmsUnderVoltageCounterAttribute( value: UShort, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 1299u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -5722,122 +6010,127 @@ class ElectricalMeasurementCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeAverageRmsUnderVoltageCounterAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1299u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Averagermsundervoltagecounter attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Averagermsundervoltagecounter 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRmsExtremeOverVoltagePeriodAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 1300u - suspend fun readRmsExtremeOverVoltagePeriodAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 1300u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rmsextremeovervoltageperiod attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rmsextremeovervoltageperiod 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun writeRmsExtremeOverVoltagePeriodAttribute( value: UShort, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 1300u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -5858,122 +6151,127 @@ class ElectricalMeasurementCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeRmsExtremeOverVoltagePeriodAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1300u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Rmsextremeovervoltageperiod attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rmsextremeovervoltageperiod 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRmsExtremeUnderVoltagePeriodAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 1301u - suspend fun readRmsExtremeUnderVoltagePeriodAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 1301u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rmsextremeundervoltageperiod attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rmsextremeundervoltageperiod 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun writeRmsExtremeUnderVoltagePeriodAttribute( value: UShort, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 1301u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -5994,122 +6292,127 @@ class ElectricalMeasurementCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeRmsExtremeUnderVoltagePeriodAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1301u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Rmsextremeundervoltageperiod attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rmsextremeundervoltageperiod 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRmsVoltageSagPeriodAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 1302u - suspend fun readRmsVoltageSagPeriodAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 1302u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rmsvoltagesagperiod attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rmsvoltagesagperiod 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun writeRmsVoltageSagPeriodAttribute( value: UShort, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 1302u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -6130,122 +6433,127 @@ class ElectricalMeasurementCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeRmsVoltageSagPeriodAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1302u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Rmsvoltagesagperiod attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rmsvoltagesagperiod 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRmsVoltageSwellPeriodAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 1303u - suspend fun readRmsVoltageSwellPeriodAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 1303u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rmsvoltageswellperiod attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rmsvoltageswellperiod 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun writeRmsVoltageSwellPeriodAttribute( value: UShort, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 1303u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -6266,677 +6574,709 @@ class ElectricalMeasurementCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeRmsVoltageSwellPeriodAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1303u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Rmsvoltageswellperiod attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rmsvoltageswellperiod 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAcVoltageMultiplierAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 1536u - suspend fun readAcVoltageMultiplierAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 1536u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Acvoltagemultiplier attribute not found in response" } + } + + requireNotNull(attributeData) { + "Acvoltagemultiplier 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeAcVoltageMultiplierAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1536u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Acvoltagemultiplier attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Acvoltagemultiplier 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAcVoltageDivisorAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 1537u - suspend fun readAcVoltageDivisorAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 1537u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Acvoltagedivisor attribute not found in response" } + } + + requireNotNull(attributeData) { + "Acvoltagedivisor 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeAcVoltageDivisorAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1537u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Acvoltagedivisor attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Acvoltagedivisor 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAcCurrentMultiplierAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 1538u - suspend fun readAcCurrentMultiplierAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 1538u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Accurrentmultiplier attribute not found in response" } + } + + requireNotNull(attributeData) { + "Accurrentmultiplier 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeAcCurrentMultiplierAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1538u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Accurrentmultiplier attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Accurrentmultiplier 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAcCurrentDivisorAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 1539u - suspend fun readAcCurrentDivisorAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 1539u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Accurrentdivisor attribute not found in response" } + } + + requireNotNull(attributeData) { + "Accurrentdivisor 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeAcCurrentDivisorAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1539u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Accurrentdivisor attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Accurrentdivisor 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAcPowerMultiplierAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 1540u - suspend fun readAcPowerMultiplierAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 1540u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Acpowermultiplier attribute not found in response" } + } + + requireNotNull(attributeData) { + "Acpowermultiplier 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeAcPowerMultiplierAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1540u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Acpowermultiplier attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Acpowermultiplier 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAcPowerDivisorAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 1541u - suspend fun readAcPowerDivisorAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 1541u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Acpowerdivisor attribute not found in response" } + } + + requireNotNull(attributeData) { + "Acpowerdivisor 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeAcPowerDivisorAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1541u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Acpowerdivisor attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Acpowerdivisor 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readOverloadAlarmsMaskAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 1792u - suspend fun readOverloadAlarmsMaskAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 1792u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Overloadalarmsmask attribute not found in response" } + } + + requireNotNull(attributeData) { + "Overloadalarmsmask 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } - suspend fun writeOverloadAlarmsMaskAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeOverloadAlarmsMaskAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 1792u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -6957,308 +7297,321 @@ class ElectricalMeasurementCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeOverloadAlarmsMaskAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1792u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Overloadalarmsmask attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Overloadalarmsmask 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readVoltageOverloadAttribute(): Short? {val ATTRIBUTE_ID: UInt = 1793u - suspend fun readVoltageOverloadAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 1793u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Voltageoverload attribute not found in response" } + } + + requireNotNull(attributeData) { + "Voltageoverload attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeVoltageOverloadAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1793u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Voltageoverload attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Voltageoverload attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readCurrentOverloadAttribute(): Short? {val ATTRIBUTE_ID: UInt = 1794u - suspend fun readCurrentOverloadAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 1794u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Currentoverload attribute not found in response" } + } + + requireNotNull(attributeData) { + "Currentoverload attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeCurrentOverloadAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1794u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Currentoverload attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Currentoverload attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAcOverloadAlarmsMaskAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2048u - suspend fun readAcOverloadAlarmsMaskAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 2048u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Acoverloadalarmsmask attribute not found in response" } + } + + requireNotNull(attributeData) { + "Acoverloadalarmsmask 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun writeAcOverloadAlarmsMaskAttribute( value: UShort, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 2048u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -7279,5193 +7632,5390 @@ class ElectricalMeasurementCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeAcOverloadAlarmsMaskAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2048u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Acoverloadalarmsmask attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Acoverloadalarmsmask 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAcVoltageOverloadAttribute(): Short? {val ATTRIBUTE_ID: UInt = 2049u - suspend fun readAcVoltageOverloadAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 2049u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Acvoltageoverload attribute not found in response" } + } + + requireNotNull(attributeData) { + "Acvoltageoverload attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeAcVoltageOverloadAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2049u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Acvoltageoverload attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Acvoltageoverload attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAcCurrentOverloadAttribute(): Short? {val ATTRIBUTE_ID: UInt = 2050u - suspend fun readAcCurrentOverloadAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 2050u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Accurrentoverload attribute not found in response" } + } + + requireNotNull(attributeData) { + "Accurrentoverload attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeAcCurrentOverloadAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2050u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Accurrentoverload attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Accurrentoverload attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAcActivePowerOverloadAttribute(): Short? {val ATTRIBUTE_ID: UInt = 2051u - suspend fun readAcActivePowerOverloadAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 2051u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Acactivepoweroverload attribute not found in response" } + } + + requireNotNull(attributeData) { + "Acactivepoweroverload attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeAcActivePowerOverloadAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2051u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Acactivepoweroverload attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Acactivepoweroverload attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAcReactivePowerOverloadAttribute(): Short? {val ATTRIBUTE_ID: UInt = 2052u - suspend fun readAcReactivePowerOverloadAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 2052u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Acreactivepoweroverload attribute not found in response" } + } + + requireNotNull(attributeData) { + "Acreactivepoweroverload attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeAcReactivePowerOverloadAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2052u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Acreactivepoweroverload attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Acreactivepoweroverload attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAverageRmsOverVoltageAttribute(): Short? {val ATTRIBUTE_ID: UInt = 2053u - suspend fun readAverageRmsOverVoltageAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 2053u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Averagermsovervoltage attribute not found in response" } + } + + requireNotNull(attributeData) { + "Averagermsovervoltage attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeAverageRmsOverVoltageAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2053u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Averagermsovervoltage attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Averagermsovervoltage attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAverageRmsUnderVoltageAttribute(): Short? {val ATTRIBUTE_ID: UInt = 2054u - suspend fun readAverageRmsUnderVoltageAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 2054u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Averagermsundervoltage attribute not found in response" } + } + + requireNotNull(attributeData) { + "Averagermsundervoltage attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeAverageRmsUnderVoltageAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2054u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Averagermsundervoltage attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Averagermsundervoltage attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRmsExtremeOverVoltageAttribute(): Short? {val ATTRIBUTE_ID: UInt = 2055u - suspend fun readRmsExtremeOverVoltageAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 2055u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rmsextremeovervoltage attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rmsextremeovervoltage attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeRmsExtremeOverVoltageAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2055u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Rmsextremeovervoltage attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rmsextremeovervoltage attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRmsExtremeUnderVoltageAttribute(): Short? {val ATTRIBUTE_ID: UInt = 2056u - suspend fun readRmsExtremeUnderVoltageAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 2056u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rmsextremeundervoltage attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rmsextremeundervoltage attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeRmsExtremeUnderVoltageAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2056u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Rmsextremeundervoltage attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rmsextremeundervoltage attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRmsVoltageSagAttribute(): Short? {val ATTRIBUTE_ID: UInt = 2057u - suspend fun readRmsVoltageSagAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 2057u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rmsvoltagesag attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rmsvoltagesag attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeRmsVoltageSagAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2057u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { "Rmsvoltagesag attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rmsvoltagesag attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRmsVoltageSwellAttribute(): Short? {val ATTRIBUTE_ID: UInt = 2058u - suspend fun readRmsVoltageSwellAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 2058u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rmsvoltageswell attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rmsvoltageswell attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeRmsVoltageSwellAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2058u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Rmsvoltageswell attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rmsvoltageswell attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readLineCurrentPhaseBAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2305u - suspend fun readLineCurrentPhaseBAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 2305u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Linecurrentphaseb attribute not found in response" } + } + + requireNotNull(attributeData) { + "Linecurrentphaseb 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeLineCurrentPhaseBAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2305u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Linecurrentphaseb attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Linecurrentphaseb 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } - } - } - } - - suspend fun readActiveCurrentPhaseBAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 2306u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + } + } + } +suspend fun readActiveCurrentPhaseBAttribute(): Short? {val ATTRIBUTE_ID: UInt = 2306u - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Activecurrentphaseb attribute not found in response" } + } + + requireNotNull(attributeData) { + "Activecurrentphaseb attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeActiveCurrentPhaseBAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2306u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Activecurrentphaseb attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Activecurrentphaseb attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readReactiveCurrentPhaseBAttribute(): Short? {val ATTRIBUTE_ID: UInt = 2307u - suspend fun readReactiveCurrentPhaseBAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 2307u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Reactivecurrentphaseb attribute not found in response" } + } + + requireNotNull(attributeData) { + "Reactivecurrentphaseb attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeReactiveCurrentPhaseBAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2307u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Reactivecurrentphaseb attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Reactivecurrentphaseb attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRmsVoltagePhaseBAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2309u - suspend fun readRmsVoltagePhaseBAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 2309u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rmsvoltagephaseb attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rmsvoltagephaseb 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeRmsVoltagePhaseBAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2309u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Rmsvoltagephaseb attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rmsvoltagephaseb 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRmsVoltageMinPhaseBAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2310u - suspend fun readRmsVoltageMinPhaseBAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 2310u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rmsvoltageminphaseb attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rmsvoltageminphaseb 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeRmsVoltageMinPhaseBAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2310u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Rmsvoltageminphaseb attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rmsvoltageminphaseb 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRmsVoltageMaxPhaseBAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2311u - suspend fun readRmsVoltageMaxPhaseBAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 2311u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rmsvoltagemaxphaseb attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rmsvoltagemaxphaseb 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeRmsVoltageMaxPhaseBAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2311u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Rmsvoltagemaxphaseb attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rmsvoltagemaxphaseb 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRmsCurrentPhaseBAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2312u - suspend fun readRmsCurrentPhaseBAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 2312u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rmscurrentphaseb attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rmscurrentphaseb 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeRmsCurrentPhaseBAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2312u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Rmscurrentphaseb attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rmscurrentphaseb 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRmsCurrentMinPhaseBAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2313u - suspend fun readRmsCurrentMinPhaseBAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 2313u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rmscurrentminphaseb attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rmscurrentminphaseb 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeRmsCurrentMinPhaseBAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2313u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Rmscurrentminphaseb attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rmscurrentminphaseb 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRmsCurrentMaxPhaseBAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2314u - suspend fun readRmsCurrentMaxPhaseBAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 2314u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rmscurrentmaxphaseb attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rmscurrentmaxphaseb 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeRmsCurrentMaxPhaseBAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2314u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Rmscurrentmaxphaseb attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rmscurrentmaxphaseb 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readActivePowerPhaseBAttribute(): Short? {val ATTRIBUTE_ID: UInt = 2315u - suspend fun readActivePowerPhaseBAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 2315u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Activepowerphaseb attribute not found in response" } + } + + requireNotNull(attributeData) { + "Activepowerphaseb attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeActivePowerPhaseBAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2315u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Activepowerphaseb attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Activepowerphaseb attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readActivePowerMinPhaseBAttribute(): Short? {val ATTRIBUTE_ID: UInt = 2316u - suspend fun readActivePowerMinPhaseBAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 2316u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Activepowerminphaseb attribute not found in response" } + } + + requireNotNull(attributeData) { + "Activepowerminphaseb attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeActivePowerMinPhaseBAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2316u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Activepowerminphaseb attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Activepowerminphaseb attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readActivePowerMaxPhaseBAttribute(): Short? {val ATTRIBUTE_ID: UInt = 2317u - suspend fun readActivePowerMaxPhaseBAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 2317u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Activepowermaxphaseb attribute not found in response" } + } + + requireNotNull(attributeData) { + "Activepowermaxphaseb attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeActivePowerMaxPhaseBAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2317u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Activepowermaxphaseb attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Activepowermaxphaseb attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readReactivePowerPhaseBAttribute(): Short? {val ATTRIBUTE_ID: UInt = 2318u - suspend fun readReactivePowerPhaseBAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 2318u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Reactivepowerphaseb attribute not found in response" } + } + + requireNotNull(attributeData) { + "Reactivepowerphaseb attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeReactivePowerPhaseBAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2318u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Reactivepowerphaseb attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Reactivepowerphaseb attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readApparentPowerPhaseBAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2319u - suspend fun readApparentPowerPhaseBAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 2319u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Apparentpowerphaseb attribute not found in response" } + } + + requireNotNull(attributeData) { + "Apparentpowerphaseb 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeApparentPowerPhaseBAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2319u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Apparentpowerphaseb attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Apparentpowerphaseb 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readPowerFactorPhaseBAttribute(): Byte? {val ATTRIBUTE_ID: UInt = 2320u - suspend fun readPowerFactorPhaseBAttribute(): Byte? { - val ATTRIBUTE_ID: UInt = 2320u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Powerfactorphaseb attribute not found in response" } + } + + requireNotNull(attributeData) { + "Powerfactorphaseb attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Byte? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByte(AnonymousTag) - } else { - null - } + val decodedValue: Byte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribePowerFactorPhaseBAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2320u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ByteSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ByteSubscriptionState.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) { - "Powerfactorphaseb attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Powerfactorphaseb attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Byte? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByte(AnonymousTag) - } else { - null - } + val decodedValue: Byte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAverageRmsVoltageMeasurementPeriodPhaseBAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2321u - suspend fun readAverageRmsVoltageMeasurementPeriodPhaseBAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 2321u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { - "Averagermsvoltagemeasurementperiodphaseb attribute not found in response" + } + + requireNotNull(attributeData) { + "Averagermsvoltagemeasurementperiodphaseb 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeAverageRmsVoltageMeasurementPeriodPhaseBAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2321u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Averagermsvoltagemeasurementperiodphaseb attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Averagermsvoltagemeasurementperiodphaseb 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAverageRmsOverVoltageCounterPhaseBAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2322u - suspend fun readAverageRmsOverVoltageCounterPhaseBAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 2322u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { - "Averagermsovervoltagecounterphaseb attribute not found in response" + } + + requireNotNull(attributeData) { + "Averagermsovervoltagecounterphaseb 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeAverageRmsOverVoltageCounterPhaseBAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2322u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Averagermsovervoltagecounterphaseb attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Averagermsovervoltagecounterphaseb 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAverageRmsUnderVoltageCounterPhaseBAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2323u - suspend fun readAverageRmsUnderVoltageCounterPhaseBAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 2323u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { - "Averagermsundervoltagecounterphaseb attribute not found in response" + } + + requireNotNull(attributeData) { + "Averagermsundervoltagecounterphaseb 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeAverageRmsUnderVoltageCounterPhaseBAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2323u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Averagermsundervoltagecounterphaseb attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Averagermsundervoltagecounterphaseb 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRmsExtremeOverVoltagePeriodPhaseBAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2324u - suspend fun readRmsExtremeOverVoltagePeriodPhaseBAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 2324u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { - "Rmsextremeovervoltageperiodphaseb attribute not found in response" + } + + requireNotNull(attributeData) { + "Rmsextremeovervoltageperiodphaseb 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeRmsExtremeOverVoltagePeriodPhaseBAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2324u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Rmsextremeovervoltageperiodphaseb attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rmsextremeovervoltageperiodphaseb 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRmsExtremeUnderVoltagePeriodPhaseBAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2325u - suspend fun readRmsExtremeUnderVoltagePeriodPhaseBAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 2325u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { - "Rmsextremeundervoltageperiodphaseb attribute not found in response" + } + + requireNotNull(attributeData) { + "Rmsextremeundervoltageperiodphaseb 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeRmsExtremeUnderVoltagePeriodPhaseBAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2325u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Rmsextremeundervoltageperiodphaseb attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rmsextremeundervoltageperiodphaseb 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRmsVoltageSagPeriodPhaseBAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2326u - suspend fun readRmsVoltageSagPeriodPhaseBAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 2326u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rmsvoltagesagperiodphaseb attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rmsvoltagesagperiodphaseb 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeRmsVoltageSagPeriodPhaseBAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2326u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Rmsvoltagesagperiodphaseb attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rmsvoltagesagperiodphaseb 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRmsVoltageSwellPeriodPhaseBAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2327u - suspend fun readRmsVoltageSwellPeriodPhaseBAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 2327u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rmsvoltageswellperiodphaseb attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rmsvoltageswellperiodphaseb 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeRmsVoltageSwellPeriodPhaseBAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2327u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Rmsvoltageswellperiodphaseb attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rmsvoltageswellperiodphaseb 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readLineCurrentPhaseCAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2561u - suspend fun readLineCurrentPhaseCAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 2561u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Linecurrentphasec attribute not found in response" } + } + + requireNotNull(attributeData) { + "Linecurrentphasec 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeLineCurrentPhaseCAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2561u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Linecurrentphasec attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Linecurrentphasec 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readActiveCurrentPhaseCAttribute(): Short? {val ATTRIBUTE_ID: UInt = 2562u - suspend fun readActiveCurrentPhaseCAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 2562u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Activecurrentphasec attribute not found in response" } + } + + requireNotNull(attributeData) { + "Activecurrentphasec attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeActiveCurrentPhaseCAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2562u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Activecurrentphasec attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Activecurrentphasec attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readReactiveCurrentPhaseCAttribute(): Short? {val ATTRIBUTE_ID: UInt = 2563u - suspend fun readReactiveCurrentPhaseCAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 2563u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Reactivecurrentphasec attribute not found in response" } + } + + requireNotNull(attributeData) { + "Reactivecurrentphasec attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeReactiveCurrentPhaseCAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2563u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Reactivecurrentphasec attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Reactivecurrentphasec attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRmsVoltagePhaseCAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2565u - suspend fun readRmsVoltagePhaseCAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 2565u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rmsvoltagephasec attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rmsvoltagephasec 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeRmsVoltagePhaseCAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2565u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Rmsvoltagephasec attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rmsvoltagephasec 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRmsVoltageMinPhaseCAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2566u - suspend fun readRmsVoltageMinPhaseCAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 2566u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rmsvoltageminphasec attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rmsvoltageminphasec 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeRmsVoltageMinPhaseCAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2566u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Rmsvoltageminphasec attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rmsvoltageminphasec 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRmsVoltageMaxPhaseCAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2567u - suspend fun readRmsVoltageMaxPhaseCAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 2567u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rmsvoltagemaxphasec attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rmsvoltagemaxphasec 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeRmsVoltageMaxPhaseCAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2567u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Rmsvoltagemaxphasec attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rmsvoltagemaxphasec 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRmsCurrentPhaseCAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2568u - suspend fun readRmsCurrentPhaseCAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 2568u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rmscurrentphasec attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rmscurrentphasec 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeRmsCurrentPhaseCAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2568u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Rmscurrentphasec attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rmscurrentphasec 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRmsCurrentMinPhaseCAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2569u - suspend fun readRmsCurrentMinPhaseCAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 2569u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rmscurrentminphasec attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rmscurrentminphasec 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeRmsCurrentMinPhaseCAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2569u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Rmscurrentminphasec attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rmscurrentminphasec 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRmsCurrentMaxPhaseCAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2570u - suspend fun readRmsCurrentMaxPhaseCAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 2570u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rmscurrentmaxphasec attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rmscurrentmaxphasec 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeRmsCurrentMaxPhaseCAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2570u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Rmscurrentmaxphasec attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rmscurrentmaxphasec 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readActivePowerPhaseCAttribute(): Short? {val ATTRIBUTE_ID: UInt = 2571u - suspend fun readActivePowerPhaseCAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 2571u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Activepowerphasec attribute not found in response" } + } + + requireNotNull(attributeData) { + "Activepowerphasec attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeActivePowerPhaseCAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2571u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Activepowerphasec attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Activepowerphasec attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readActivePowerMinPhaseCAttribute(): Short? {val ATTRIBUTE_ID: UInt = 2572u - suspend fun readActivePowerMinPhaseCAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 2572u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Activepowerminphasec attribute not found in response" } + } + + requireNotNull(attributeData) { + "Activepowerminphasec attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeActivePowerMinPhaseCAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2572u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Activepowerminphasec attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Activepowerminphasec attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readActivePowerMaxPhaseCAttribute(): Short? {val ATTRIBUTE_ID: UInt = 2573u - suspend fun readActivePowerMaxPhaseCAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 2573u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Activepowermaxphasec attribute not found in response" } + } + + requireNotNull(attributeData) { + "Activepowermaxphasec attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeActivePowerMaxPhaseCAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2573u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Activepowermaxphasec attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Activepowermaxphasec attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readReactivePowerPhaseCAttribute(): Short? {val ATTRIBUTE_ID: UInt = 2574u - suspend fun readReactivePowerPhaseCAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 2574u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Reactivepowerphasec attribute not found in response" } + } + + requireNotNull(attributeData) { + "Reactivepowerphasec attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeReactivePowerPhaseCAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2574u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Reactivepowerphasec attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Reactivepowerphasec attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readApparentPowerPhaseCAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2575u - suspend fun readApparentPowerPhaseCAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 2575u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Apparentpowerphasec attribute not found in response" } + } + + requireNotNull(attributeData) { + "Apparentpowerphasec 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeApparentPowerPhaseCAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2575u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Apparentpowerphasec attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Apparentpowerphasec 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readPowerFactorPhaseCAttribute(): Byte? {val ATTRIBUTE_ID: UInt = 2576u - suspend fun readPowerFactorPhaseCAttribute(): Byte? { - val ATTRIBUTE_ID: UInt = 2576u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Powerfactorphasec attribute not found in response" } + } + + requireNotNull(attributeData) { + "Powerfactorphasec attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Byte? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByte(AnonymousTag) - } else { - null - } + val decodedValue: Byte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribePowerFactorPhaseCAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2576u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ByteSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ByteSubscriptionState.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) { - "Powerfactorphasec attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Powerfactorphasec attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Byte? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByte(AnonymousTag) - } else { - null - } + val decodedValue: Byte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAverageRmsVoltageMeasurementPeriodPhaseCAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2577u - suspend fun readAverageRmsVoltageMeasurementPeriodPhaseCAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 2577u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { - "Averagermsvoltagemeasurementperiodphasec attribute not found in response" + } + + requireNotNull(attributeData) { + "Averagermsvoltagemeasurementperiodphasec 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeAverageRmsVoltageMeasurementPeriodPhaseCAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2577u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Averagermsvoltagemeasurementperiodphasec attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Averagermsvoltagemeasurementperiodphasec 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAverageRmsOverVoltageCounterPhaseCAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2578u - suspend fun readAverageRmsOverVoltageCounterPhaseCAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 2578u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { - "Averagermsovervoltagecounterphasec attribute not found in response" + } + + requireNotNull(attributeData) { + "Averagermsovervoltagecounterphasec 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeAverageRmsOverVoltageCounterPhaseCAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2578u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Averagermsovervoltagecounterphasec attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Averagermsovervoltagecounterphasec 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAverageRmsUnderVoltageCounterPhaseCAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2579u - suspend fun readAverageRmsUnderVoltageCounterPhaseCAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 2579u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { - "Averagermsundervoltagecounterphasec attribute not found in response" + } + + requireNotNull(attributeData) { + "Averagermsundervoltagecounterphasec 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeAverageRmsUnderVoltageCounterPhaseCAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2579u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Averagermsundervoltagecounterphasec attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Averagermsundervoltagecounterphasec 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRmsExtremeOverVoltagePeriodPhaseCAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2580u - suspend fun readRmsExtremeOverVoltagePeriodPhaseCAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 2580u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { - "Rmsextremeovervoltageperiodphasec attribute not found in response" + } + + requireNotNull(attributeData) { + "Rmsextremeovervoltageperiodphasec 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeRmsExtremeOverVoltagePeriodPhaseCAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2580u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Rmsextremeovervoltageperiodphasec attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rmsextremeovervoltageperiodphasec 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRmsExtremeUnderVoltagePeriodPhaseCAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2581u - suspend fun readRmsExtremeUnderVoltagePeriodPhaseCAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 2581u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { - "Rmsextremeundervoltageperiodphasec attribute not found in response" + } + + requireNotNull(attributeData) { + "Rmsextremeundervoltageperiodphasec 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeRmsExtremeUnderVoltagePeriodPhaseCAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2581u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Rmsextremeundervoltageperiodphasec attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rmsextremeundervoltageperiodphasec 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRmsVoltageSagPeriodPhaseCAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2582u - suspend fun readRmsVoltageSagPeriodPhaseCAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 2582u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rmsvoltagesagperiodphasec attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rmsvoltagesagperiodphasec 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeRmsVoltageSagPeriodPhaseCAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2582u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Rmsvoltagesagperiodphasec attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rmsvoltagesagperiodphasec 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRmsVoltageSwellPeriodPhaseCAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2583u - suspend fun readRmsVoltageSwellPeriodPhaseCAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 2583u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rmsvoltageswellperiodphasec attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rmsvoltageswellperiodphasec 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeRmsVoltageSwellPeriodPhaseCAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2583u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Rmsvoltageswellperiodphasec attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rmsvoltageswellperiodphasec 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65528u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -12473,96 +13023,97 @@ class ElectricalMeasurementCluster( emit(GeneratedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65529u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -12570,94 +13121,97 @@ class ElectricalMeasurementCluster( emit(AcceptedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt = 65530u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -12665,94 +13219,97 @@ class ElectricalMeasurementCluster( emit(EventListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ID: UInt = 65531u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -12760,76 +13317,81 @@ class ElectricalMeasurementCluster( emit(AttributeListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u - 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 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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -12841,77 +13403,80 @@ class ElectricalMeasurementCluster( emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 65533u - 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 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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -12924,7 +13489,7 @@ class ElectricalMeasurementCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/ElectricalPowerMeasurementCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/ElectricalPowerMeasurementCluster.kt index 98db5789b43596..4856287ee65db5 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/ElectricalPowerMeasurementCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/ElectricalPowerMeasurementCluster.kt @@ -17,318 +17,394 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath +import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader +import matter.tlv.TlvWriter -class ElectricalPowerMeasurementCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class AccuracyAttribute( +class ElectricalPowerMeasurementCluster(private val controller: MatterController, private val endpointId: UShort) {class AccuracyAttribute( val value: List ) sealed class AccuracyAttributeSubscriptionState { data class Success( - val value: List + val value: List ) : AccuracyAttributeSubscriptionState() - + data class Error(val exception: Exception) : AccuracyAttributeSubscriptionState() - object SubscriptionEstablished : AccuracyAttributeSubscriptionState() - } - - class RangesAttribute(val value: List?) + object SubscriptionEstablished : AccuracyAttributeSubscriptionState() + } +class RangesAttribute( + val value: List? + ) sealed class RangesAttributeSubscriptionState { - data class Success(val value: List?) : - RangesAttributeSubscriptionState() - + data class Success( + val value: List? + ) : RangesAttributeSubscriptionState() + data class Error(val exception: Exception) : RangesAttributeSubscriptionState() - object SubscriptionEstablished : RangesAttributeSubscriptionState() - } - - class VoltageAttribute(val value: Long?) + object SubscriptionEstablished : RangesAttributeSubscriptionState() + } +class VoltageAttribute( + val value: Long? + ) sealed class VoltageAttributeSubscriptionState { - data class Success(val value: Long?) : VoltageAttributeSubscriptionState() - + data class Success( + val value: Long? + ) : VoltageAttributeSubscriptionState() + data class Error(val exception: Exception) : VoltageAttributeSubscriptionState() - object SubscriptionEstablished : VoltageAttributeSubscriptionState() - } - - class ActiveCurrentAttribute(val value: Long?) + object SubscriptionEstablished : VoltageAttributeSubscriptionState() + } +class ActiveCurrentAttribute( + val value: Long? + ) sealed class ActiveCurrentAttributeSubscriptionState { - data class Success(val value: Long?) : ActiveCurrentAttributeSubscriptionState() - + data class Success( + val value: Long? + ) : ActiveCurrentAttributeSubscriptionState() + data class Error(val exception: Exception) : ActiveCurrentAttributeSubscriptionState() - object SubscriptionEstablished : ActiveCurrentAttributeSubscriptionState() - } - - class ReactiveCurrentAttribute(val value: Long?) + object SubscriptionEstablished : ActiveCurrentAttributeSubscriptionState() + } +class ReactiveCurrentAttribute( + val value: Long? + ) sealed class ReactiveCurrentAttributeSubscriptionState { - data class Success(val value: Long?) : ReactiveCurrentAttributeSubscriptionState() - + data class Success( + val value: Long? + ) : ReactiveCurrentAttributeSubscriptionState() + data class Error(val exception: Exception) : ReactiveCurrentAttributeSubscriptionState() - object SubscriptionEstablished : ReactiveCurrentAttributeSubscriptionState() - } - - class ApparentCurrentAttribute(val value: Long?) + object SubscriptionEstablished : ReactiveCurrentAttributeSubscriptionState() + } +class ApparentCurrentAttribute( + val value: Long? + ) sealed class ApparentCurrentAttributeSubscriptionState { - data class Success(val value: Long?) : ApparentCurrentAttributeSubscriptionState() - + data class Success( + val value: Long? + ) : ApparentCurrentAttributeSubscriptionState() + data class Error(val exception: Exception) : ApparentCurrentAttributeSubscriptionState() - object SubscriptionEstablished : ApparentCurrentAttributeSubscriptionState() - } - - class ActivePowerAttribute(val value: Long?) + object SubscriptionEstablished : ApparentCurrentAttributeSubscriptionState() + } +class ActivePowerAttribute( + val value: Long? + ) sealed class ActivePowerAttributeSubscriptionState { - data class Success(val value: Long?) : ActivePowerAttributeSubscriptionState() - + data class Success( + val value: Long? + ) : ActivePowerAttributeSubscriptionState() + data class Error(val exception: Exception) : ActivePowerAttributeSubscriptionState() - object SubscriptionEstablished : ActivePowerAttributeSubscriptionState() - } - - class ReactivePowerAttribute(val value: Long?) + object SubscriptionEstablished : ActivePowerAttributeSubscriptionState() + } +class ReactivePowerAttribute( + val value: Long? + ) sealed class ReactivePowerAttributeSubscriptionState { - data class Success(val value: Long?) : ReactivePowerAttributeSubscriptionState() - + data class Success( + val value: Long? + ) : ReactivePowerAttributeSubscriptionState() + data class Error(val exception: Exception) : ReactivePowerAttributeSubscriptionState() - object SubscriptionEstablished : ReactivePowerAttributeSubscriptionState() - } - - class ApparentPowerAttribute(val value: Long?) + object SubscriptionEstablished : ReactivePowerAttributeSubscriptionState() + } +class ApparentPowerAttribute( + val value: Long? + ) sealed class ApparentPowerAttributeSubscriptionState { - data class Success(val value: Long?) : ApparentPowerAttributeSubscriptionState() - + data class Success( + val value: Long? + ) : ApparentPowerAttributeSubscriptionState() + data class Error(val exception: Exception) : ApparentPowerAttributeSubscriptionState() - object SubscriptionEstablished : ApparentPowerAttributeSubscriptionState() - } - - class RMSVoltageAttribute(val value: Long?) + object SubscriptionEstablished : ApparentPowerAttributeSubscriptionState() + } +class RMSVoltageAttribute( + val value: Long? + ) sealed class RMSVoltageAttributeSubscriptionState { - data class Success(val value: Long?) : RMSVoltageAttributeSubscriptionState() - + data class Success( + val value: Long? + ) : RMSVoltageAttributeSubscriptionState() + data class Error(val exception: Exception) : RMSVoltageAttributeSubscriptionState() - object SubscriptionEstablished : RMSVoltageAttributeSubscriptionState() - } - - class RMSCurrentAttribute(val value: Long?) + object SubscriptionEstablished : RMSVoltageAttributeSubscriptionState() + } +class RMSCurrentAttribute( + val value: Long? + ) sealed class RMSCurrentAttributeSubscriptionState { - data class Success(val value: Long?) : RMSCurrentAttributeSubscriptionState() - + data class Success( + val value: Long? + ) : RMSCurrentAttributeSubscriptionState() + data class Error(val exception: Exception) : RMSCurrentAttributeSubscriptionState() - object SubscriptionEstablished : RMSCurrentAttributeSubscriptionState() - } - - class RMSPowerAttribute(val value: Long?) + object SubscriptionEstablished : RMSCurrentAttributeSubscriptionState() + } +class RMSPowerAttribute( + val value: Long? + ) sealed class RMSPowerAttributeSubscriptionState { - data class Success(val value: Long?) : RMSPowerAttributeSubscriptionState() - + data class Success( + val value: Long? + ) : RMSPowerAttributeSubscriptionState() + data class Error(val exception: Exception) : RMSPowerAttributeSubscriptionState() - object SubscriptionEstablished : RMSPowerAttributeSubscriptionState() - } - - class FrequencyAttribute(val value: Long?) + object SubscriptionEstablished : RMSPowerAttributeSubscriptionState() + } +class FrequencyAttribute( + val value: Long? + ) sealed class FrequencyAttributeSubscriptionState { - data class Success(val value: Long?) : FrequencyAttributeSubscriptionState() - + data class Success( + val value: Long? + ) : FrequencyAttributeSubscriptionState() + data class Error(val exception: Exception) : FrequencyAttributeSubscriptionState() - object SubscriptionEstablished : FrequencyAttributeSubscriptionState() - } - - class HarmonicCurrentsAttribute( + object SubscriptionEstablished : FrequencyAttributeSubscriptionState() + } +class HarmonicCurrentsAttribute( val value: List? ) sealed class HarmonicCurrentsAttributeSubscriptionState { data class Success( - val value: List? + val value: List? ) : HarmonicCurrentsAttributeSubscriptionState() - + data class Error(val exception: Exception) : HarmonicCurrentsAttributeSubscriptionState() - object SubscriptionEstablished : HarmonicCurrentsAttributeSubscriptionState() - } - - class HarmonicPhasesAttribute( + object SubscriptionEstablished : HarmonicCurrentsAttributeSubscriptionState() + } +class HarmonicPhasesAttribute( val value: List? ) sealed class HarmonicPhasesAttributeSubscriptionState { data class Success( - val value: List? + val value: List? ) : HarmonicPhasesAttributeSubscriptionState() - + data class Error(val exception: Exception) : HarmonicPhasesAttributeSubscriptionState() - object SubscriptionEstablished : HarmonicPhasesAttributeSubscriptionState() - } - - class PowerFactorAttribute(val value: Long?) + object SubscriptionEstablished : HarmonicPhasesAttributeSubscriptionState() + } +class PowerFactorAttribute( + val value: Long? + ) sealed class PowerFactorAttributeSubscriptionState { - data class Success(val value: Long?) : PowerFactorAttributeSubscriptionState() - + data class Success( + val value: Long? + ) : PowerFactorAttributeSubscriptionState() + data class Error(val exception: Exception) : PowerFactorAttributeSubscriptionState() - object SubscriptionEstablished : PowerFactorAttributeSubscriptionState() - } - - class NeutralCurrentAttribute(val value: Long?) + object SubscriptionEstablished : PowerFactorAttributeSubscriptionState() + } +class NeutralCurrentAttribute( + val value: Long? + ) sealed class NeutralCurrentAttributeSubscriptionState { - data class Success(val value: Long?) : NeutralCurrentAttributeSubscriptionState() - + data class Success( + val value: Long? + ) : NeutralCurrentAttributeSubscriptionState() + data class Error(val exception: Exception) : NeutralCurrentAttributeSubscriptionState() - object SubscriptionEstablished : NeutralCurrentAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : NeutralCurrentAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } - - suspend fun readPowerModeAttribute(): 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)) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } +suspend fun readPowerModeAttribute(): 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}") - } + 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) { "Powermode attribute not found in response" } + } + + requireNotNull(attributeData) { + "Powermode 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 subscribePowerModeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Powermode attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Powermode attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -340,77 +416,80 @@ class ElectricalPowerMeasurementCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNumberOfMeasurementTypesAttribute(): UByte {val ATTRIBUTE_ID: UInt = 1u - suspend fun readNumberOfMeasurementTypesAttribute(): 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 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}") - } + 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) { "Numberofmeasurementtypes attribute not found in response" } + } + + requireNotNull(attributeData) { + "Numberofmeasurementtypes 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 subscribeNumberOfMeasurementTypesAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Numberofmeasurementtypes attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Numberofmeasurementtypes attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -423,104 +502,97 @@ class ElectricalPowerMeasurementCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAccuracyAttribute(): AccuracyAttribute {val ATTRIBUTE_ID: UInt = 2u - suspend fun readAccuracyAttribute(): AccuracyAttribute { - 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 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}") - } + 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) { "Accuracy attribute not found in response" } + } + + requireNotNull(attributeData) { + "Accuracy 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( - ElectricalPowerMeasurementClusterMeasurementAccuracyStruct.fromTlv( - AnonymousTag, - tlvReader, - ) - ) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(ElectricalPowerMeasurementClusterMeasurementAccuracyStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + return AccuracyAttribute(decodedValue) } suspend fun subscribeAccuracyAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - AccuracyAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(AccuracyAttributeSubscriptionState.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) { "Accuracy attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Accuracy 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( - ElectricalPowerMeasurementClusterMeasurementAccuracyStruct.fromTlv( - AnonymousTag, - tlvReader, - ) - ) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(ElectricalPowerMeasurementClusterMeasurementAccuracyStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(AccuracyAttributeSubscriptionState.Success(decodedValue)) } @@ -528,1770 +600,1827 @@ class ElectricalPowerMeasurementCluster( emit(AccuracyAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRangesAttribute(): RangesAttribute {val ATTRIBUTE_ID: UInt = 3u - suspend fun readRangesAttribute(): RangesAttribute { - 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 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}") - } + 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) { "Ranges attribute not found in response" } + } + + requireNotNull(attributeData) { + "Ranges attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add( - ElectricalPowerMeasurementClusterMeasurementRangeStruct.fromTlv( - AnonymousTag, - tlvReader, - ) - ) - } - tlvReader.exitContainer() - } - } else { - null + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(ElectricalPowerMeasurementClusterMeasurementRangeStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + } else { + null + } + return RangesAttribute(decodedValue) } suspend fun subscribeRangesAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - RangesAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(RangesAttributeSubscriptionState.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) { "Ranges attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Ranges attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add( - ElectricalPowerMeasurementClusterMeasurementRangeStruct.fromTlv( - AnonymousTag, - tlvReader, - ) - ) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { emit(RangesAttributeSubscriptionState.Success(it)) } + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(ElectricalPowerMeasurementClusterMeasurementRangeStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { + emit(RangesAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(RangesAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readVoltageAttribute(): VoltageAttribute {val ATTRIBUTE_ID: UInt = 4u - suspend fun readVoltageAttribute(): VoltageAttribute { - 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 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}") - } + 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) { "Voltage attribute not found in response" } + } + + requireNotNull(attributeData) { + "Voltage attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Long? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return VoltageAttribute(decodedValue) } suspend fun subscribeVoltageAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - VoltageAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(VoltageAttributeSubscriptionState.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) { "Voltage attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Voltage attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(VoltageAttributeSubscriptionState.Success(it)) } + val decodedValue: Long? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(VoltageAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(VoltageAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readActiveCurrentAttribute(): ActiveCurrentAttribute {val ATTRIBUTE_ID: UInt = 5u - suspend fun readActiveCurrentAttribute(): ActiveCurrentAttribute { - 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 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}") - } + 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) { "Activecurrent attribute not found in response" } + } + + requireNotNull(attributeData) { + "Activecurrent attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Long? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return ActiveCurrentAttribute(decodedValue) } suspend fun subscribeActiveCurrentAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ActiveCurrentAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ActiveCurrentAttributeSubscriptionState.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) { "Activecurrent attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Activecurrent attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(ActiveCurrentAttributeSubscriptionState.Success(it)) } + val decodedValue: Long? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(ActiveCurrentAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ActiveCurrentAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readReactiveCurrentAttribute(): ReactiveCurrentAttribute {val ATTRIBUTE_ID: UInt = 6u - suspend fun readReactiveCurrentAttribute(): ReactiveCurrentAttribute { - 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 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}") - } + 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) { "Reactivecurrent attribute not found in response" } + } + + requireNotNull(attributeData) { + "Reactivecurrent attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Long? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return ReactiveCurrentAttribute(decodedValue) } suspend fun subscribeReactiveCurrentAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ReactiveCurrentAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ReactiveCurrentAttributeSubscriptionState.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) { - "Reactivecurrent attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Reactivecurrent attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(ReactiveCurrentAttributeSubscriptionState.Success(it)) } + val decodedValue: Long? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(ReactiveCurrentAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ReactiveCurrentAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readApparentCurrentAttribute(): ApparentCurrentAttribute {val ATTRIBUTE_ID: UInt = 7u - suspend fun readApparentCurrentAttribute(): ApparentCurrentAttribute { - 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 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}") - } + 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) { "Apparentcurrent attribute not found in response" } + } + + requireNotNull(attributeData) { + "Apparentcurrent attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Long? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return ApparentCurrentAttribute(decodedValue) } suspend fun subscribeApparentCurrentAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ApparentCurrentAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ApparentCurrentAttributeSubscriptionState.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) { - "Apparentcurrent attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Apparentcurrent attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(ApparentCurrentAttributeSubscriptionState.Success(it)) } + val decodedValue: Long? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(ApparentCurrentAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ApparentCurrentAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readActivePowerAttribute(): ActivePowerAttribute {val ATTRIBUTE_ID: UInt = 8u - suspend fun readActivePowerAttribute(): ActivePowerAttribute { - val ATTRIBUTE_ID: UInt = 8u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Activepower attribute not found in response" } + } + + requireNotNull(attributeData) { + "Activepower attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = - if (!tlvReader.isNull()) { - tlvReader.getLong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Long? = if (!tlvReader.isNull()) { + tlvReader.getLong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return ActivePowerAttribute(decodedValue) } suspend fun subscribeActivePowerAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ActivePowerAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ActivePowerAttributeSubscriptionState.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) { "Activepower attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Activepower attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = - if (!tlvReader.isNull()) { - tlvReader.getLong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Long? = if (!tlvReader.isNull()) { + tlvReader.getLong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(ActivePowerAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ActivePowerAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ActivePowerAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readReactivePowerAttribute(): ReactivePowerAttribute {val ATTRIBUTE_ID: UInt = 9u - suspend fun readReactivePowerAttribute(): ReactivePowerAttribute { - val ATTRIBUTE_ID: UInt = 9u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Reactivepower attribute not found in response" } + } + + requireNotNull(attributeData) { + "Reactivepower attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Long? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return ReactivePowerAttribute(decodedValue) } suspend fun subscribeReactivePowerAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ReactivePowerAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ReactivePowerAttributeSubscriptionState.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) { "Reactivepower attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Reactivepower attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(ReactivePowerAttributeSubscriptionState.Success(it)) } + val decodedValue: Long? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(ReactivePowerAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ReactivePowerAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readApparentPowerAttribute(): ApparentPowerAttribute {val ATTRIBUTE_ID: UInt = 10u - suspend fun readApparentPowerAttribute(): ApparentPowerAttribute { - val ATTRIBUTE_ID: UInt = 10u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Apparentpower attribute not found in response" } + } + + requireNotNull(attributeData) { + "Apparentpower attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Long? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return ApparentPowerAttribute(decodedValue) } suspend fun subscribeApparentPowerAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ApparentPowerAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ApparentPowerAttributeSubscriptionState.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) { "Apparentpower attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Apparentpower attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(ApparentPowerAttributeSubscriptionState.Success(it)) } + val decodedValue: Long? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(ApparentPowerAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ApparentPowerAttributeSubscriptionState.SubscriptionEstablished) } } - } - } - - suspend fun readRMSVoltageAttribute(): RMSVoltageAttribute { - val ATTRIBUTE_ID: UInt = 11u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + } + } +suspend fun readRMSVoltageAttribute(): RMSVoltageAttribute {val ATTRIBUTE_ID: UInt = 11u - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rmsvoltage attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rmsvoltage attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Long? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return RMSVoltageAttribute(decodedValue) } suspend fun subscribeRMSVoltageAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 11u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - RMSVoltageAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(RMSVoltageAttributeSubscriptionState.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) { "Rmsvoltage attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rmsvoltage attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(RMSVoltageAttributeSubscriptionState.Success(it)) } + val decodedValue: Long? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(RMSVoltageAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(RMSVoltageAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRMSCurrentAttribute(): RMSCurrentAttribute {val ATTRIBUTE_ID: UInt = 12u - suspend fun readRMSCurrentAttribute(): RMSCurrentAttribute { - val ATTRIBUTE_ID: UInt = 12u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rmscurrent attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rmscurrent attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Long? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return RMSCurrentAttribute(decodedValue) } suspend fun subscribeRMSCurrentAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 12u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - RMSCurrentAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(RMSCurrentAttributeSubscriptionState.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) { "Rmscurrent attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rmscurrent attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(RMSCurrentAttributeSubscriptionState.Success(it)) } + val decodedValue: Long? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(RMSCurrentAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(RMSCurrentAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRMSPowerAttribute(): RMSPowerAttribute {val ATTRIBUTE_ID: UInt = 13u - suspend fun readRMSPowerAttribute(): RMSPowerAttribute { - val ATTRIBUTE_ID: UInt = 13u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rmspower attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rmspower attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Long? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return RMSPowerAttribute(decodedValue) } suspend fun subscribeRMSPowerAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 13u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - RMSPowerAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(RMSPowerAttributeSubscriptionState.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) { "Rmspower attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rmspower attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(RMSPowerAttributeSubscriptionState.Success(it)) } + val decodedValue: Long? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(RMSPowerAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(RMSPowerAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readFrequencyAttribute(): FrequencyAttribute {val ATTRIBUTE_ID: UInt = 14u - suspend fun readFrequencyAttribute(): FrequencyAttribute { - val ATTRIBUTE_ID: UInt = 14u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Frequency attribute not found in response" } + } + + requireNotNull(attributeData) { + "Frequency attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Long? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return FrequencyAttribute(decodedValue) } suspend fun subscribeFrequencyAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 14u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - FrequencyAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(FrequencyAttributeSubscriptionState.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) { "Frequency attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Frequency attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(FrequencyAttributeSubscriptionState.Success(it)) } + val decodedValue: Long? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(FrequencyAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(FrequencyAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readHarmonicCurrentsAttribute(): HarmonicCurrentsAttribute {val ATTRIBUTE_ID: UInt = 15u - suspend fun readHarmonicCurrentsAttribute(): HarmonicCurrentsAttribute { - val ATTRIBUTE_ID: UInt = 15u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Harmoniccurrents attribute not found in response" } + } + + requireNotNull(attributeData) { + "Harmoniccurrents attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add( - ElectricalPowerMeasurementClusterHarmonicMeasurementStruct.fromTlv( - AnonymousTag, - tlvReader, - ) - ) - } - tlvReader.exitContainer() - } - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null + val decodedValue: List? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(ElectricalPowerMeasurementClusterHarmonicMeasurementStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return HarmonicCurrentsAttribute(decodedValue) } suspend fun subscribeHarmonicCurrentsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 15u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - HarmonicCurrentsAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(HarmonicCurrentsAttributeSubscriptionState.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) { - "Harmoniccurrents attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Harmoniccurrents attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add( - ElectricalPowerMeasurementClusterHarmonicMeasurementStruct.fromTlv( - AnonymousTag, - tlvReader, - ) - ) - } - tlvReader.exitContainer() - } - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(HarmonicCurrentsAttributeSubscriptionState.Success(it)) } + val decodedValue: List? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(ElectricalPowerMeasurementClusterHarmonicMeasurementStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(HarmonicCurrentsAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(HarmonicCurrentsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readHarmonicPhasesAttribute(): HarmonicPhasesAttribute {val ATTRIBUTE_ID: UInt = 16u - suspend fun readHarmonicPhasesAttribute(): HarmonicPhasesAttribute { - val ATTRIBUTE_ID: UInt = 16u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Harmonicphases attribute not found in response" } + } + + requireNotNull(attributeData) { + "Harmonicphases attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add( - ElectricalPowerMeasurementClusterHarmonicMeasurementStruct.fromTlv( - AnonymousTag, - tlvReader, - ) - ) - } - tlvReader.exitContainer() - } - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null + val decodedValue: List? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(ElectricalPowerMeasurementClusterHarmonicMeasurementStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return HarmonicPhasesAttribute(decodedValue) } suspend fun subscribeHarmonicPhasesAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - HarmonicPhasesAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(HarmonicPhasesAttributeSubscriptionState.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) { - "Harmonicphases attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Harmonicphases attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add( - ElectricalPowerMeasurementClusterHarmonicMeasurementStruct.fromTlv( - AnonymousTag, - tlvReader, - ) - ) - } - tlvReader.exitContainer() - } - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(HarmonicPhasesAttributeSubscriptionState.Success(it)) } + val decodedValue: List? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(ElectricalPowerMeasurementClusterHarmonicMeasurementStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(HarmonicPhasesAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(HarmonicPhasesAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readPowerFactorAttribute(): PowerFactorAttribute {val ATTRIBUTE_ID: UInt = 17u - suspend fun readPowerFactorAttribute(): PowerFactorAttribute { - val ATTRIBUTE_ID: UInt = 17u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Powerfactor attribute not found in response" } + } + + requireNotNull(attributeData) { + "Powerfactor attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Long? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return PowerFactorAttribute(decodedValue) } suspend fun subscribePowerFactorAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 17u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - PowerFactorAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(PowerFactorAttributeSubscriptionState.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) { "Powerfactor attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Powerfactor attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(PowerFactorAttributeSubscriptionState.Success(it)) } + val decodedValue: Long? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(PowerFactorAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(PowerFactorAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNeutralCurrentAttribute(): NeutralCurrentAttribute {val ATTRIBUTE_ID: UInt = 18u - suspend fun readNeutralCurrentAttribute(): NeutralCurrentAttribute { - val ATTRIBUTE_ID: UInt = 18u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Neutralcurrent attribute not found in response" } + } + + requireNotNull(attributeData) { + "Neutralcurrent attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Long? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return NeutralCurrentAttribute(decodedValue) } suspend fun subscribeNeutralCurrentAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 18u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - NeutralCurrentAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(NeutralCurrentAttributeSubscriptionState.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) { - "Neutralcurrent attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Neutralcurrent attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(NeutralCurrentAttributeSubscriptionState.Success(it)) } + val decodedValue: Long? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(NeutralCurrentAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(NeutralCurrentAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65528u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -2299,96 +2428,97 @@ class ElectricalPowerMeasurementCluster( emit(GeneratedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65529u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -2396,94 +2526,97 @@ class ElectricalPowerMeasurementCluster( emit(AcceptedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt = 65530u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -2491,94 +2624,97 @@ class ElectricalPowerMeasurementCluster( emit(EventListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ID: UInt = 65531u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -2586,76 +2722,81 @@ class ElectricalPowerMeasurementCluster( emit(AttributeListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u - 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 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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -2667,77 +2808,80 @@ class ElectricalPowerMeasurementCluster( emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 65533u - 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 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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -2750,7 +2894,7 @@ class ElectricalPowerMeasurementCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/EnergyEvseCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/EnergyEvseCluster.kt index 747300fe68f86c..0d532702cc4872 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/EnergyEvseCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/EnergyEvseCluster.kt @@ -17,30 +17,45 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse -import matter.controller.LongSubscriptionState import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.cluster.structs.* +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter @@ -48,225 +63,276 @@ class EnergyEvseCluster(private val controller: MatterController, private val en class GetTargetsResponse( val chargingTargetSchedules: List ) - - class StateAttribute(val value: UByte?) +class StateAttribute( + val value: UByte? + ) sealed class StateAttributeSubscriptionState { - data class Success(val value: UByte?) : StateAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : StateAttributeSubscriptionState() + data class Error(val exception: Exception) : StateAttributeSubscriptionState() - object SubscriptionEstablished : StateAttributeSubscriptionState() - } - - class ChargingEnabledUntilAttribute(val value: UInt?) + object SubscriptionEstablished : StateAttributeSubscriptionState() + } +class ChargingEnabledUntilAttribute( + val value: UInt? + ) sealed class ChargingEnabledUntilAttributeSubscriptionState { - data class Success(val value: UInt?) : ChargingEnabledUntilAttributeSubscriptionState() - + data class Success( + val value: UInt? + ) : ChargingEnabledUntilAttributeSubscriptionState() + data class Error(val exception: Exception) : ChargingEnabledUntilAttributeSubscriptionState() - object SubscriptionEstablished : ChargingEnabledUntilAttributeSubscriptionState() - } - - class DischargingEnabledUntilAttribute(val value: UInt?) + object SubscriptionEstablished : ChargingEnabledUntilAttributeSubscriptionState() + } +class DischargingEnabledUntilAttribute( + val value: UInt? + ) sealed class DischargingEnabledUntilAttributeSubscriptionState { - data class Success(val value: UInt?) : DischargingEnabledUntilAttributeSubscriptionState() - - data class Error(val exception: Exception) : - DischargingEnabledUntilAttributeSubscriptionState() - - object SubscriptionEstablished : DischargingEnabledUntilAttributeSubscriptionState() - } - - class NextChargeStartTimeAttribute(val value: UInt?) + data class Success( + val value: UInt? + ) : DischargingEnabledUntilAttributeSubscriptionState() + + data class Error(val exception: Exception) : DischargingEnabledUntilAttributeSubscriptionState() + + object SubscriptionEstablished : DischargingEnabledUntilAttributeSubscriptionState() + } +class NextChargeStartTimeAttribute( + val value: UInt? + ) sealed class NextChargeStartTimeAttributeSubscriptionState { - data class Success(val value: UInt?) : NextChargeStartTimeAttributeSubscriptionState() - + data class Success( + val value: UInt? + ) : NextChargeStartTimeAttributeSubscriptionState() + data class Error(val exception: Exception) : NextChargeStartTimeAttributeSubscriptionState() - object SubscriptionEstablished : NextChargeStartTimeAttributeSubscriptionState() - } - - class NextChargeTargetTimeAttribute(val value: UInt?) + object SubscriptionEstablished : NextChargeStartTimeAttributeSubscriptionState() + } +class NextChargeTargetTimeAttribute( + val value: UInt? + ) sealed class NextChargeTargetTimeAttributeSubscriptionState { - data class Success(val value: UInt?) : NextChargeTargetTimeAttributeSubscriptionState() - + data class Success( + val value: UInt? + ) : NextChargeTargetTimeAttributeSubscriptionState() + data class Error(val exception: Exception) : NextChargeTargetTimeAttributeSubscriptionState() - object SubscriptionEstablished : NextChargeTargetTimeAttributeSubscriptionState() - } - - class NextChargeRequiredEnergyAttribute(val value: Long?) + object SubscriptionEstablished : NextChargeTargetTimeAttributeSubscriptionState() + } +class NextChargeRequiredEnergyAttribute( + val value: Long? + ) sealed class NextChargeRequiredEnergyAttributeSubscriptionState { - data class Success(val value: Long?) : NextChargeRequiredEnergyAttributeSubscriptionState() - - data class Error(val exception: Exception) : - NextChargeRequiredEnergyAttributeSubscriptionState() - - object SubscriptionEstablished : NextChargeRequiredEnergyAttributeSubscriptionState() - } - - class NextChargeTargetSoCAttribute(val value: UByte?) + data class Success( + val value: Long? + ) : NextChargeRequiredEnergyAttributeSubscriptionState() + + data class Error(val exception: Exception) : NextChargeRequiredEnergyAttributeSubscriptionState() + + object SubscriptionEstablished : NextChargeRequiredEnergyAttributeSubscriptionState() + } +class NextChargeTargetSoCAttribute( + val value: UByte? + ) sealed class NextChargeTargetSoCAttributeSubscriptionState { - data class Success(val value: UByte?) : NextChargeTargetSoCAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : NextChargeTargetSoCAttributeSubscriptionState() + data class Error(val exception: Exception) : NextChargeTargetSoCAttributeSubscriptionState() - object SubscriptionEstablished : NextChargeTargetSoCAttributeSubscriptionState() - } - - class ApproximateEVEfficiencyAttribute(val value: UShort?) + object SubscriptionEstablished : NextChargeTargetSoCAttributeSubscriptionState() + } +class ApproximateEVEfficiencyAttribute( + val value: UShort? + ) sealed class ApproximateEVEfficiencyAttributeSubscriptionState { - data class Success(val value: UShort?) : ApproximateEVEfficiencyAttributeSubscriptionState() - - data class Error(val exception: Exception) : - ApproximateEVEfficiencyAttributeSubscriptionState() - - object SubscriptionEstablished : ApproximateEVEfficiencyAttributeSubscriptionState() - } - - class StateOfChargeAttribute(val value: UByte?) + data class Success( + val value: UShort? + ) : ApproximateEVEfficiencyAttributeSubscriptionState() + + data class Error(val exception: Exception) : ApproximateEVEfficiencyAttributeSubscriptionState() + + object SubscriptionEstablished : ApproximateEVEfficiencyAttributeSubscriptionState() + } +class StateOfChargeAttribute( + val value: UByte? + ) sealed class StateOfChargeAttributeSubscriptionState { - data class Success(val value: UByte?) : StateOfChargeAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : StateOfChargeAttributeSubscriptionState() + data class Error(val exception: Exception) : StateOfChargeAttributeSubscriptionState() - object SubscriptionEstablished : StateOfChargeAttributeSubscriptionState() - } - - class BatteryCapacityAttribute(val value: Long?) + object SubscriptionEstablished : StateOfChargeAttributeSubscriptionState() + } +class BatteryCapacityAttribute( + val value: Long? + ) sealed class BatteryCapacityAttributeSubscriptionState { - data class Success(val value: Long?) : BatteryCapacityAttributeSubscriptionState() - + data class Success( + val value: Long? + ) : BatteryCapacityAttributeSubscriptionState() + data class Error(val exception: Exception) : BatteryCapacityAttributeSubscriptionState() - object SubscriptionEstablished : BatteryCapacityAttributeSubscriptionState() - } - - class VehicleIDAttribute(val value: String?) + object SubscriptionEstablished : BatteryCapacityAttributeSubscriptionState() + } +class VehicleIDAttribute( + val value: String? + ) sealed class VehicleIDAttributeSubscriptionState { - data class Success(val value: String?) : VehicleIDAttributeSubscriptionState() - + data class Success( + val value: String? + ) : VehicleIDAttributeSubscriptionState() + data class Error(val exception: Exception) : VehicleIDAttributeSubscriptionState() - object SubscriptionEstablished : VehicleIDAttributeSubscriptionState() - } - - class SessionIDAttribute(val value: UInt?) + object SubscriptionEstablished : VehicleIDAttributeSubscriptionState() + } +class SessionIDAttribute( + val value: UInt? + ) sealed class SessionIDAttributeSubscriptionState { - data class Success(val value: UInt?) : SessionIDAttributeSubscriptionState() - + data class Success( + val value: UInt? + ) : SessionIDAttributeSubscriptionState() + data class Error(val exception: Exception) : SessionIDAttributeSubscriptionState() - object SubscriptionEstablished : SessionIDAttributeSubscriptionState() - } - - class SessionDurationAttribute(val value: UInt?) + object SubscriptionEstablished : SessionIDAttributeSubscriptionState() + } +class SessionDurationAttribute( + val value: UInt? + ) sealed class SessionDurationAttributeSubscriptionState { - data class Success(val value: UInt?) : SessionDurationAttributeSubscriptionState() - + data class Success( + val value: UInt? + ) : SessionDurationAttributeSubscriptionState() + data class Error(val exception: Exception) : SessionDurationAttributeSubscriptionState() - object SubscriptionEstablished : SessionDurationAttributeSubscriptionState() - } - - class SessionEnergyChargedAttribute(val value: Long?) + object SubscriptionEstablished : SessionDurationAttributeSubscriptionState() + } +class SessionEnergyChargedAttribute( + val value: Long? + ) sealed class SessionEnergyChargedAttributeSubscriptionState { - data class Success(val value: Long?) : SessionEnergyChargedAttributeSubscriptionState() - + data class Success( + val value: Long? + ) : SessionEnergyChargedAttributeSubscriptionState() + data class Error(val exception: Exception) : SessionEnergyChargedAttributeSubscriptionState() - object SubscriptionEstablished : SessionEnergyChargedAttributeSubscriptionState() - } - - class SessionEnergyDischargedAttribute(val value: Long?) + object SubscriptionEstablished : SessionEnergyChargedAttributeSubscriptionState() + } +class SessionEnergyDischargedAttribute( + val value: Long? + ) sealed class SessionEnergyDischargedAttributeSubscriptionState { - data class Success(val value: Long?) : SessionEnergyDischargedAttributeSubscriptionState() - - data class Error(val exception: Exception) : - SessionEnergyDischargedAttributeSubscriptionState() - - object SubscriptionEstablished : SessionEnergyDischargedAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + data class Success( + val value: Long? + ) : SessionEnergyDischargedAttributeSubscriptionState() + + data class Error(val exception: Exception) : SessionEnergyDischargedAttributeSubscriptionState() + + object SubscriptionEstablished : SessionEnergyDischargedAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } suspend fun disable(timedInvokeTimeout: Duration) { val commandId: UInt = 1u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun enableCharging( - chargingEnabledUntil: UInt?, - minimumChargeCurrent: Long, - maximumChargeCurrent: Long, - timedInvokeTimeout: Duration, - ) { + suspend fun enableCharging(chargingEnabledUntil: UInt? + ,minimumChargeCurrent: Long + ,maximumChargeCurrent: Long + ,timedInvokeTimeout: Duration) { val commandId: UInt = 2u val tlvWriter = TlvWriter() @@ -281,25 +347,23 @@ class EnergyEvseCluster(private val controller: MatterController, private val en tlvWriter.put(ContextSpecificTag(TAG_MINIMUM_CHARGE_CURRENT_REQ), minimumChargeCurrent) val TAG_MAXIMUM_CHARGE_CURRENT_REQ: Int = 2 - tlvWriter.put(ContextSpecificTag(TAG_MAXIMUM_CHARGE_CURRENT_REQ), maximumChargeCurrent) + tlvWriter.put(ContextSpecificTag(TAG_MAXIMUM_CHARGE_CURRENT_REQ), maximumChargeCurrent) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun enableDischarging( - dischargingEnabledUntil: UInt?, - maximumDischargeCurrent: Long, - timedInvokeTimeout: Duration, - ) { + suspend fun enableDischarging(dischargingEnabledUntil: UInt? + ,maximumDischargeCurrent: Long + ,timedInvokeTimeout: Duration) { val commandId: UInt = 3u val tlvWriter = TlvWriter() @@ -311,14 +375,14 @@ class EnergyEvseCluster(private val controller: MatterController, private val en } val TAG_MAXIMUM_DISCHARGE_CURRENT_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_MAXIMUM_DISCHARGE_CURRENT_REQ), maximumDischargeCurrent) + tlvWriter.put(ContextSpecificTag(TAG_MAXIMUM_DISCHARGE_CURRENT_REQ), maximumDischargeCurrent) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -329,24 +393,22 @@ class EnergyEvseCluster(private val controller: MatterController, private val en val commandId: UInt = 4u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun setTargets( - chargingTargetSchedules: List, - timedInvokeTimeout: Duration, - ) { + suspend fun setTargets(chargingTargetSchedules: List + ,timedInvokeTimeout: Duration) { val commandId: UInt = 5u val tlvWriter = TlvWriter() @@ -354,17 +416,17 @@ class EnergyEvseCluster(private val controller: MatterController, private val en val TAG_CHARGING_TARGET_SCHEDULES_REQ: Int = 0 tlvWriter.startArray(ContextSpecificTag(TAG_CHARGING_TARGET_SCHEDULES_REQ)) - for (item in chargingTargetSchedules.iterator()) { - item.toTlv(AnonymousTag, tlvWriter) - } - tlvWriter.endArray() + for (item in chargingTargetSchedules.iterator()) { + item.toTlv(AnonymousTag, tlvWriter) + } + tlvWriter.endArray() tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -375,14 +437,14 @@ class EnergyEvseCluster(private val controller: MatterController, private val en val commandId: UInt = 6u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -392,211 +454,229 @@ class EnergyEvseCluster(private val controller: MatterController, private val en tlvReader.enterStructure(AnonymousTag) val TAG_CHARGING_TARGET_SCHEDULES: Int = 0 var chargingTargetSchedules_decoded: List? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_CHARGING_TARGET_SCHEDULES)) { - chargingTargetSchedules_decoded = - buildList { - tlvReader.enterArray(tag) - while (!tlvReader.isEndOfContainer()) { - add(EnergyEvseClusterChargingTargetScheduleStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { + + if (tag == ContextSpecificTag(TAG_CHARGING_TARGET_SCHEDULES)) {chargingTargetSchedules_decoded = buildList { + tlvReader.enterArray(tag) + while(!tlvReader.isEndOfContainer()) { + add(EnergyEvseClusterChargingTargetScheduleStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + }} + + + else { tlvReader.skipElement() } } + + if (chargingTargetSchedules_decoded == null) { - throw IllegalStateException("chargingTargetSchedules not found in TLV") + throw IllegalStateException("chargingTargetSchedules not found in TLV") } + tlvReader.exitContainer() - return GetTargetsResponse(chargingTargetSchedules_decoded) + return GetTargetsResponse( + chargingTargetSchedules_decoded + ) } suspend fun clearTargets(timedInvokeTimeout: Duration) { val commandId: UInt = 7u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } +suspend fun readStateAttribute(): StateAttribute {val ATTRIBUTE_ID: UInt = 0u - suspend fun readStateAttribute(): StateAttribute { - 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 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}") - } + 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) { "State attribute not found in response" } + } + + requireNotNull(attributeData) { + "State attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return StateAttribute(decodedValue) } suspend fun subscribeStateAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StateAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StateAttributeSubscriptionState.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) { "State attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "State 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.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(StateAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(StateAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(StateAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readSupplyStateAttribute(): UByte {val ATTRIBUTE_ID: UInt = 1u - suspend fun readSupplyStateAttribute(): 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 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}") - } + 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) { "Supplystate attribute not found in response" } + } + + requireNotNull(attributeData) { + "Supplystate 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 subscribeSupplyStateAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Supplystate attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Supplystate attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -608,76 +688,81 @@ class EnergyEvseCluster(private val controller: MatterController, private val en emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readFaultStateAttribute(): UByte {val ATTRIBUTE_ID: UInt = 2u - suspend fun readFaultStateAttribute(): UByte { - 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 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}") - } + 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) { "Faultstate attribute not found in response" } + } + + requireNotNull(attributeData) { + "Faultstate 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 subscribeFaultStateAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Faultstate attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Faultstate attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -689,275 +774,286 @@ class EnergyEvseCluster(private val controller: MatterController, private val en emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readChargingEnabledUntilAttribute(): ChargingEnabledUntilAttribute {val ATTRIBUTE_ID: UInt = 3u - suspend fun readChargingEnabledUntilAttribute(): ChargingEnabledUntilAttribute { - 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 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}") - } + 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) { "Chargingenableduntil attribute not found in response" } + } + + requireNotNull(attributeData) { + "Chargingenableduntil attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - tlvReader.getUInt(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + tlvReader.getUInt(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return ChargingEnabledUntilAttribute(decodedValue) } suspend fun subscribeChargingEnabledUntilAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ChargingEnabledUntilAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ChargingEnabledUntilAttributeSubscriptionState.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) { - "Chargingenableduntil attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Chargingenableduntil attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - tlvReader.getUInt(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + tlvReader.getUInt(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(ChargingEnabledUntilAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ChargingEnabledUntilAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ChargingEnabledUntilAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readDischargingEnabledUntilAttribute(): DischargingEnabledUntilAttribute {val ATTRIBUTE_ID: UInt = 4u - suspend fun readDischargingEnabledUntilAttribute(): DischargingEnabledUntilAttribute { - 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 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}") - } + 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) { "Dischargingenableduntil attribute not found in response" } + } + + requireNotNull(attributeData) { + "Dischargingenableduntil attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return DischargingEnabledUntilAttribute(decodedValue) } suspend fun subscribeDischargingEnabledUntilAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - DischargingEnabledUntilAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(DischargingEnabledUntilAttributeSubscriptionState.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) { - "Dischargingenableduntil attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Dischargingenableduntil attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(DischargingEnabledUntilAttributeSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(DischargingEnabledUntilAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(DischargingEnabledUntilAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readCircuitCapacityAttribute(): Long {val ATTRIBUTE_ID: UInt = 5u - suspend fun readCircuitCapacityAttribute(): Long { - 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 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}") - } + 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) { "Circuitcapacity attribute not found in response" } + } + + requireNotNull(attributeData) { + "Circuitcapacity attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Long = tlvReader.getLong(AnonymousTag) + return decodedValue } suspend fun subscribeCircuitCapacityAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - LongSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(LongSubscriptionState.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) { - "Circuitcapacity attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Circuitcapacity attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -970,77 +1066,80 @@ class EnergyEvseCluster(private val controller: MatterController, private val en emit(LongSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readMinimumChargeCurrentAttribute(): Long {val ATTRIBUTE_ID: UInt = 6u - suspend fun readMinimumChargeCurrentAttribute(): Long { - 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 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}") - } + 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) { "Minimumchargecurrent attribute not found in response" } + } + + requireNotNull(attributeData) { + "Minimumchargecurrent attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Long = tlvReader.getLong(AnonymousTag) + return decodedValue } suspend fun subscribeMinimumChargeCurrentAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - LongSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(LongSubscriptionState.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) { - "Minimumchargecurrent attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Minimumchargecurrent attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -1053,77 +1152,80 @@ class EnergyEvseCluster(private val controller: MatterController, private val en emit(LongSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readMaximumChargeCurrentAttribute(): Long {val ATTRIBUTE_ID: UInt = 7u - suspend fun readMaximumChargeCurrentAttribute(): Long { - 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 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}") - } + 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) { "Maximumchargecurrent attribute not found in response" } + } + + requireNotNull(attributeData) { + "Maximumchargecurrent attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Long = tlvReader.getLong(AnonymousTag) + return decodedValue } suspend fun subscribeMaximumChargeCurrentAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - LongSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(LongSubscriptionState.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) { - "Maximumchargecurrent attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Maximumchargecurrent attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -1136,158 +1238,169 @@ class EnergyEvseCluster(private val controller: MatterController, private val en emit(LongSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readMaximumDischargeCurrentAttribute(): Long? {val ATTRIBUTE_ID: UInt = 8u - suspend fun readMaximumDischargeCurrentAttribute(): Long? { - val ATTRIBUTE_ID: UInt = 8u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Maximumdischargecurrent attribute not found in response" } + } + + requireNotNull(attributeData) { + "Maximumdischargecurrent attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } + val decodedValue: Long? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeMaximumDischargeCurrentAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - LongSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(LongSubscriptionState.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) { - "Maximumdischargecurrent attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Maximumdischargecurrent attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } + val decodedValue: Long? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(LongSubscriptionState.Success(it)) } + decodedValue?.let { + emit(LongSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(LongSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readUserMaximumChargeCurrentAttribute(): Long? {val ATTRIBUTE_ID: UInt = 9u - suspend fun readUserMaximumChargeCurrentAttribute(): Long? { - val ATTRIBUTE_ID: UInt = 9u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Usermaximumchargecurrent attribute not found in response" } + } + + requireNotNull(attributeData) { + "Usermaximumchargecurrent attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } + val decodedValue: Long? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun writeUserMaximumChargeCurrentAttribute( value: Long, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 9u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -1308,122 +1421,127 @@ class EnergyEvseCluster(private val controller: MatterController, private val en throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeUserMaximumChargeCurrentAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - LongSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(LongSubscriptionState.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) { - "Usermaximumchargecurrent attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Usermaximumchargecurrent attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } + val decodedValue: Long? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(LongSubscriptionState.Success(it)) } + decodedValue?.let { + emit(LongSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(LongSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRandomizationDelayWindowAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 10u - suspend fun readRandomizationDelayWindowAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 10u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Randomizationdelaywindow attribute not found in response" } + } + + requireNotNull(attributeData) { + "Randomizationdelaywindow attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun writeRandomizationDelayWindowAttribute( value: UInt, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 10u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -1444,539 +1562,560 @@ class EnergyEvseCluster(private val controller: MatterController, private val en throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeRandomizationDelayWindowAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Randomizationdelaywindow attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Randomizationdelaywindow attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNextChargeStartTimeAttribute(): NextChargeStartTimeAttribute {val ATTRIBUTE_ID: UInt = 35u - suspend fun readNextChargeStartTimeAttribute(): NextChargeStartTimeAttribute { - val ATTRIBUTE_ID: UInt = 35u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Nextchargestarttime attribute not found in response" } + } + + requireNotNull(attributeData) { + "Nextchargestarttime attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return NextChargeStartTimeAttribute(decodedValue) } suspend fun subscribeNextChargeStartTimeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 35u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - NextChargeStartTimeAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(NextChargeStartTimeAttributeSubscriptionState.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) { - "Nextchargestarttime attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Nextchargestarttime attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(NextChargeStartTimeAttributeSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(NextChargeStartTimeAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(NextChargeStartTimeAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNextChargeTargetTimeAttribute(): NextChargeTargetTimeAttribute {val ATTRIBUTE_ID: UInt = 36u - suspend fun readNextChargeTargetTimeAttribute(): NextChargeTargetTimeAttribute { - val ATTRIBUTE_ID: UInt = 36u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Nextchargetargettime attribute not found in response" } + } + + requireNotNull(attributeData) { + "Nextchargetargettime attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return NextChargeTargetTimeAttribute(decodedValue) } suspend fun subscribeNextChargeTargetTimeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 36u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - NextChargeTargetTimeAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(NextChargeTargetTimeAttributeSubscriptionState.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) { - "Nextchargetargettime attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Nextchargetargettime attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(NextChargeTargetTimeAttributeSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(NextChargeTargetTimeAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(NextChargeTargetTimeAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNextChargeRequiredEnergyAttribute(): NextChargeRequiredEnergyAttribute {val ATTRIBUTE_ID: UInt = 37u - suspend fun readNextChargeRequiredEnergyAttribute(): NextChargeRequiredEnergyAttribute { - val ATTRIBUTE_ID: UInt = 37u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Nextchargerequiredenergy attribute not found in response" } + } + + requireNotNull(attributeData) { + "Nextchargerequiredenergy attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Long? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return NextChargeRequiredEnergyAttribute(decodedValue) } suspend fun subscribeNextChargeRequiredEnergyAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 37u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - NextChargeRequiredEnergyAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(NextChargeRequiredEnergyAttributeSubscriptionState.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) { - "Nextchargerequiredenergy attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Nextchargerequiredenergy attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(NextChargeRequiredEnergyAttributeSubscriptionState.Success(it)) } + val decodedValue: Long? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(NextChargeRequiredEnergyAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(NextChargeRequiredEnergyAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNextChargeTargetSoCAttribute(): NextChargeTargetSoCAttribute {val ATTRIBUTE_ID: UInt = 38u - suspend fun readNextChargeTargetSoCAttribute(): NextChargeTargetSoCAttribute { - val ATTRIBUTE_ID: UInt = 38u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Nextchargetargetsoc attribute not found in response" } + } + + requireNotNull(attributeData) { + "Nextchargetargetsoc attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return NextChargeTargetSoCAttribute(decodedValue) } suspend fun subscribeNextChargeTargetSoCAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 38u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - NextChargeTargetSoCAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(NextChargeTargetSoCAttributeSubscriptionState.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) { - "Nextchargetargetsoc attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Nextchargetargetsoc 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(NextChargeTargetSoCAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(NextChargeTargetSoCAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(NextChargeTargetSoCAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readApproximateEVEfficiencyAttribute(): ApproximateEVEfficiencyAttribute {val ATTRIBUTE_ID: UInt = 39u - suspend fun readApproximateEVEfficiencyAttribute(): ApproximateEVEfficiencyAttribute { - val ATTRIBUTE_ID: UInt = 39u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Approximateevefficiency attribute not found in response" } + } + + requireNotNull(attributeData) { + "Approximateevefficiency attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return ApproximateEVEfficiencyAttribute(decodedValue) } suspend fun writeApproximateEVEfficiencyAttribute( value: UShort, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 39u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -1997,849 +2136,882 @@ class EnergyEvseCluster(private val controller: MatterController, private val en throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeApproximateEVEfficiencyAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 39u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ApproximateEVEfficiencyAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ApproximateEVEfficiencyAttributeSubscriptionState.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) { - "Approximateevefficiency attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Approximateevefficiency 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(ApproximateEVEfficiencyAttributeSubscriptionState.Success(it)) } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(ApproximateEVEfficiencyAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ApproximateEVEfficiencyAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readStateOfChargeAttribute(): StateOfChargeAttribute {val ATTRIBUTE_ID: UInt = 48u - suspend fun readStateOfChargeAttribute(): StateOfChargeAttribute { - val ATTRIBUTE_ID: UInt = 48u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Stateofcharge attribute not found in response" } + } + + requireNotNull(attributeData) { + "Stateofcharge attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return StateOfChargeAttribute(decodedValue) } suspend fun subscribeStateOfChargeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 48u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StateOfChargeAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StateOfChargeAttributeSubscriptionState.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) { "Stateofcharge attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Stateofcharge 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(StateOfChargeAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(StateOfChargeAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(StateOfChargeAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readBatteryCapacityAttribute(): BatteryCapacityAttribute {val ATTRIBUTE_ID: UInt = 49u - suspend fun readBatteryCapacityAttribute(): BatteryCapacityAttribute { - val ATTRIBUTE_ID: UInt = 49u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Batterycapacity attribute not found in response" } + } + + requireNotNull(attributeData) { + "Batterycapacity attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Long? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return BatteryCapacityAttribute(decodedValue) } suspend fun subscribeBatteryCapacityAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 49u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - BatteryCapacityAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(BatteryCapacityAttributeSubscriptionState.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) { - "Batterycapacity attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Batterycapacity attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(BatteryCapacityAttributeSubscriptionState.Success(it)) } + val decodedValue: Long? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(BatteryCapacityAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(BatteryCapacityAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readVehicleIDAttribute(): VehicleIDAttribute {val ATTRIBUTE_ID: UInt = 50u - suspend fun readVehicleIDAttribute(): VehicleIDAttribute { - val ATTRIBUTE_ID: UInt = 50u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Vehicleid attribute not found in response" } + } + + requireNotNull(attributeData) { + "Vehicleid attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: String? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return VehicleIDAttribute(decodedValue) } suspend fun subscribeVehicleIDAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 50u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - VehicleIDAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(VehicleIDAttributeSubscriptionState.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) { "Vehicleid attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Vehicleid attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(VehicleIDAttributeSubscriptionState.Success(it)) } + val decodedValue: String? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(VehicleIDAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(VehicleIDAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readSessionIDAttribute(): SessionIDAttribute {val ATTRIBUTE_ID: UInt = 64u - suspend fun readSessionIDAttribute(): SessionIDAttribute { - val ATTRIBUTE_ID: UInt = 64u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Sessionid attribute not found in response" } + } + + requireNotNull(attributeData) { + "Sessionid attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - tlvReader.getUInt(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + tlvReader.getUInt(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return SessionIDAttribute(decodedValue) } suspend fun subscribeSessionIDAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 64u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - SessionIDAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(SessionIDAttributeSubscriptionState.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) { "Sessionid attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Sessionid attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - tlvReader.getUInt(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + tlvReader.getUInt(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(SessionIDAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(SessionIDAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(SessionIDAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readSessionDurationAttribute(): SessionDurationAttribute {val ATTRIBUTE_ID: UInt = 65u - suspend fun readSessionDurationAttribute(): SessionDurationAttribute { - val ATTRIBUTE_ID: UInt = 65u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Sessionduration attribute not found in response" } + } + + requireNotNull(attributeData) { + "Sessionduration attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - tlvReader.getUInt(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + tlvReader.getUInt(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return SessionDurationAttribute(decodedValue) } suspend fun subscribeSessionDurationAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - SessionDurationAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(SessionDurationAttributeSubscriptionState.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) { - "Sessionduration attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Sessionduration attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - tlvReader.getUInt(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + tlvReader.getUInt(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(SessionDurationAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(SessionDurationAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(SessionDurationAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readSessionEnergyChargedAttribute(): SessionEnergyChargedAttribute {val ATTRIBUTE_ID: UInt = 66u - suspend fun readSessionEnergyChargedAttribute(): SessionEnergyChargedAttribute { - val ATTRIBUTE_ID: UInt = 66u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Sessionenergycharged attribute not found in response" } + } + + requireNotNull(attributeData) { + "Sessionenergycharged attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = - if (!tlvReader.isNull()) { - tlvReader.getLong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Long? = if (!tlvReader.isNull()) { + tlvReader.getLong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return SessionEnergyChargedAttribute(decodedValue) } suspend fun subscribeSessionEnergyChargedAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 66u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - SessionEnergyChargedAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(SessionEnergyChargedAttributeSubscriptionState.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) { - "Sessionenergycharged attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Sessionenergycharged attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = - if (!tlvReader.isNull()) { - tlvReader.getLong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Long? = if (!tlvReader.isNull()) { + tlvReader.getLong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(SessionEnergyChargedAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(SessionEnergyChargedAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(SessionEnergyChargedAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readSessionEnergyDischargedAttribute(): SessionEnergyDischargedAttribute {val ATTRIBUTE_ID: UInt = 67u - suspend fun readSessionEnergyDischargedAttribute(): SessionEnergyDischargedAttribute { - val ATTRIBUTE_ID: UInt = 67u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Sessionenergydischarged attribute not found in response" } + } + + requireNotNull(attributeData) { + "Sessionenergydischarged attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Long? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return SessionEnergyDischargedAttribute(decodedValue) } suspend fun subscribeSessionEnergyDischargedAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 67u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - SessionEnergyDischargedAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(SessionEnergyDischargedAttributeSubscriptionState.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) { - "Sessionenergydischarged attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Sessionenergydischarged attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(SessionEnergyDischargedAttributeSubscriptionState.Success(it)) } + val decodedValue: Long? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(SessionEnergyDischargedAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(SessionEnergyDischargedAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65528u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -2847,96 +3019,97 @@ class EnergyEvseCluster(private val controller: MatterController, private val en emit(GeneratedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65529u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -2944,94 +3117,97 @@ class EnergyEvseCluster(private val controller: MatterController, private val en emit(AcceptedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt = 65530u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -3039,94 +3215,97 @@ class EnergyEvseCluster(private val controller: MatterController, private val en emit(EventListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ID: UInt = 65531u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -3134,76 +3313,81 @@ class EnergyEvseCluster(private val controller: MatterController, private val en emit(AttributeListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u - 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 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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -3215,77 +3399,80 @@ class EnergyEvseCluster(private val controller: MatterController, private val en emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 65533u - 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 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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -3298,7 +3485,7 @@ class EnergyEvseCluster(private val controller: MatterController, private val en emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/EnergyEvseModeCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/EnergyEvseModeCluster.kt index a854ec8d1f71b4..43af7f34e08ac7 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/EnergyEvseModeCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/EnergyEvseModeCluster.kt @@ -17,127 +17,161 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.cluster.structs.* +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class EnergyEvseModeCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class ChangeToModeResponse(val status: UByte, val statusText: String?) - - class SupportedModesAttribute(val value: List) +class EnergyEvseModeCluster(private val controller: MatterController, private val endpointId: UShort) { + class ChangeToModeResponse( + val status: UByte, + val statusText: String? + ) +class SupportedModesAttribute( + val value: List + ) sealed class SupportedModesAttributeSubscriptionState { - data class Success(val value: List) : - SupportedModesAttributeSubscriptionState() - + data class Success( + val value: List + ) : SupportedModesAttributeSubscriptionState() + data class Error(val exception: Exception) : SupportedModesAttributeSubscriptionState() - object SubscriptionEstablished : SupportedModesAttributeSubscriptionState() - } - - class StartUpModeAttribute(val value: UByte?) + object SubscriptionEstablished : SupportedModesAttributeSubscriptionState() + } +class StartUpModeAttribute( + val value: UByte? + ) sealed class StartUpModeAttributeSubscriptionState { - data class Success(val value: UByte?) : StartUpModeAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : StartUpModeAttributeSubscriptionState() + data class Error(val exception: Exception) : StartUpModeAttributeSubscriptionState() - object SubscriptionEstablished : StartUpModeAttributeSubscriptionState() - } - - class OnModeAttribute(val value: UByte?) + object SubscriptionEstablished : StartUpModeAttributeSubscriptionState() + } +class OnModeAttribute( + val value: UByte? + ) sealed class OnModeAttributeSubscriptionState { - data class Success(val value: UByte?) : OnModeAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : OnModeAttributeSubscriptionState() + data class Error(val exception: Exception) : OnModeAttributeSubscriptionState() - object SubscriptionEstablished : OnModeAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : OnModeAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun changeToMode( - newMode: UByte, - timedInvokeTimeout: Duration? = null, - ): ChangeToModeResponse { + suspend fun changeToMode(newMode: UByte + ,timedInvokeTimeout: Duration? = null): ChangeToModeResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_NEW_MODE_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_NEW_MODE_REQ), newMode) + tlvWriter.put(ContextSpecificTag(TAG_NEW_MODE_REQ), newMode) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -147,130 +181,140 @@ class EnergyEvseModeCluster( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_STATUS_TEXT: Int = 1 var statusText_decoded: String? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_STATUS)) { - status_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_STATUS_TEXT)) { - statusText_decoded = + + if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_STATUS_TEXT)) {statusText_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - } - } else { + tlvReader.getString(tag) + } else { + null + } + }} + + + else { tlvReader.skipElement() } } + + if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } + + + tlvReader.exitContainer() - return ChangeToModeResponse(status_decoded, statusText_decoded) + return ChangeToModeResponse( + status_decoded, + statusText_decoded + ) } - - suspend fun readSupportedModesAttribute(): SupportedModesAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readSupportedModesAttribute(): SupportedModesAttribute {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}") - } + 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) { "Supportedmodes attribute not found in response" } + } + + requireNotNull(attributeData) { + "Supportedmodes 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(EnergyEvseModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(EnergyEvseModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + return SupportedModesAttribute(decodedValue) } suspend fun subscribeSupportedModesAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - SupportedModesAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(SupportedModesAttributeSubscriptionState.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) { - "Supportedmodes attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Supportedmodes 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(EnergyEvseModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(EnergyEvseModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(SupportedModesAttributeSubscriptionState.Success(decodedValue)) } @@ -278,76 +322,81 @@ class EnergyEvseModeCluster( emit(SupportedModesAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readCurrentModeAttribute(): 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)) - +suspend fun readCurrentModeAttribute(): 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}") - } + 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) { "Currentmode attribute not found in response" } + } + + requireNotNull(attributeData) { + "Currentmode 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 subscribeCurrentModeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Currentmode attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Currentmode attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -359,67 +408,77 @@ class EnergyEvseModeCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readStartUpModeAttribute(): StartUpModeAttribute { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readStartUpModeAttribute(): StartUpModeAttribute {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}") - } + 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) { "Startupmode attribute not found in response" } + } + + requireNotNull(attributeData) { + "Startupmode attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return StartUpModeAttribute(decodedValue) } - suspend fun writeStartUpModeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeStartUpModeAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 2u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -440,127 +499,137 @@ class EnergyEvseModeCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeStartUpModeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StartUpModeAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StartUpModeAttributeSubscriptionState.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) { "Startupmode attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Startupmode 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(StartUpModeAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(StartUpModeAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(StartUpModeAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readOnModeAttribute(): OnModeAttribute { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readOnModeAttribute(): OnModeAttribute {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}") - } + 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) { "Onmode attribute not found in response" } + } + + requireNotNull(attributeData) { + "Onmode attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return OnModeAttribute(decodedValue) } - suspend fun writeOnModeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeOnModeAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 3u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -581,156 +650,157 @@ class EnergyEvseModeCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeOnModeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - OnModeAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(OnModeAttributeSubscriptionState.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) { "Onmode attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Onmode 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(OnModeAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(OnModeAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(OnModeAttributeSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -738,96 +808,97 @@ class EnergyEvseModeCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -835,94 +906,97 @@ class EnergyEvseModeCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -930,94 +1004,97 @@ class EnergyEvseModeCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1025,76 +1102,81 @@ class EnergyEvseModeCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1106,77 +1188,80 @@ class EnergyEvseModeCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1189,7 +1274,7 @@ class EnergyEvseModeCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/EnergyPreferenceCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/EnergyPreferenceCluster.kt index 7944f2640f66e1..0ac2734058b8eb 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/EnergyPreferenceCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/EnergyPreferenceCluster.kt @@ -17,266 +17,312 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.cluster.structs.* +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath +import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class EnergyPreferenceCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class EnergyBalancesAttribute(val value: List?) +class EnergyPreferenceCluster(private val controller: MatterController, private val endpointId: UShort) {class EnergyBalancesAttribute( + val value: List? + ) sealed class EnergyBalancesAttributeSubscriptionState { - data class Success(val value: List?) : - EnergyBalancesAttributeSubscriptionState() - + data class Success( + val value: List? + ) : EnergyBalancesAttributeSubscriptionState() + data class Error(val exception: Exception) : EnergyBalancesAttributeSubscriptionState() - object SubscriptionEstablished : EnergyBalancesAttributeSubscriptionState() - } - - class EnergyPrioritiesAttribute(val value: List?) + object SubscriptionEstablished : EnergyBalancesAttributeSubscriptionState() + } +class EnergyPrioritiesAttribute( + val value: List? + ) sealed class EnergyPrioritiesAttributeSubscriptionState { - data class Success(val value: List?) : EnergyPrioritiesAttributeSubscriptionState() - + data class Success( + val value: List? + ) : EnergyPrioritiesAttributeSubscriptionState() + data class Error(val exception: Exception) : EnergyPrioritiesAttributeSubscriptionState() - object SubscriptionEstablished : EnergyPrioritiesAttributeSubscriptionState() - } - - class LowPowerModeSensitivitiesAttribute(val value: List?) + object SubscriptionEstablished : EnergyPrioritiesAttributeSubscriptionState() + } +class LowPowerModeSensitivitiesAttribute( + val value: List? + ) sealed class LowPowerModeSensitivitiesAttributeSubscriptionState { - data class Success(val value: List?) : - LowPowerModeSensitivitiesAttributeSubscriptionState() - - data class Error(val exception: Exception) : - LowPowerModeSensitivitiesAttributeSubscriptionState() - - object SubscriptionEstablished : LowPowerModeSensitivitiesAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + data class Success( + val value: List? + ) : LowPowerModeSensitivitiesAttributeSubscriptionState() + + data class Error(val exception: Exception) : LowPowerModeSensitivitiesAttributeSubscriptionState() + + object SubscriptionEstablished : LowPowerModeSensitivitiesAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } - - suspend fun readEnergyBalancesAttribute(): EnergyBalancesAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } +suspend fun readEnergyBalancesAttribute(): EnergyBalancesAttribute {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}") - } + 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) { "Energybalances attribute not found in response" } + } + + requireNotNull(attributeData) { + "Energybalances attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(EnergyPreferenceClusterBalanceStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(EnergyPreferenceClusterBalanceStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + } else { + null + } + return EnergyBalancesAttribute(decodedValue) } suspend fun subscribeEnergyBalancesAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - EnergyBalancesAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(EnergyBalancesAttributeSubscriptionState.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) { - "Energybalances attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Energybalances attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(EnergyPreferenceClusterBalanceStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { emit(EnergyBalancesAttributeSubscriptionState.Success(it)) } + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(EnergyPreferenceClusterBalanceStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { + emit(EnergyBalancesAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(EnergyBalancesAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readCurrentEnergyBalanceAttribute(): 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)) - +suspend fun readCurrentEnergyBalanceAttribute(): 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}") - } + 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) { "Currentenergybalance attribute not found in response" } + } + + requireNotNull(attributeData) { + "Currentenergybalance 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun writeCurrentEnergyBalanceAttribute( value: UByte, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 1u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -297,336 +343,345 @@ class EnergyPreferenceCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeCurrentEnergyBalanceAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Currentenergybalance attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Currentenergybalance 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)) } + 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 readEnergyPrioritiesAttribute(): EnergyPrioritiesAttribute { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readEnergyPrioritiesAttribute(): EnergyPrioritiesAttribute {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}") - } + 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) { "Energypriorities attribute not found in response" } + } + + requireNotNull(attributeData) { + "Energypriorities attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) } + tlvReader.exitContainer() + } + } else { + null + } + return EnergyPrioritiesAttribute(decodedValue) } suspend fun subscribeEnergyPrioritiesAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - EnergyPrioritiesAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(EnergyPrioritiesAttributeSubscriptionState.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) { - "Energypriorities attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Energypriorities attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { emit(EnergyPrioritiesAttributeSubscriptionState.Success(it)) } + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { + emit(EnergyPrioritiesAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(EnergyPrioritiesAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readLowPowerModeSensitivitiesAttribute(): LowPowerModeSensitivitiesAttribute { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readLowPowerModeSensitivitiesAttribute(): LowPowerModeSensitivitiesAttribute {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}") - } + 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) { "Lowpowermodesensitivities attribute not found in response" } + } + + requireNotNull(attributeData) { + "Lowpowermodesensitivities attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(EnergyPreferenceClusterBalanceStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(EnergyPreferenceClusterBalanceStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + } else { + null + } + return LowPowerModeSensitivitiesAttribute(decodedValue) } suspend fun subscribeLowPowerModeSensitivitiesAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - LowPowerModeSensitivitiesAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(LowPowerModeSensitivitiesAttributeSubscriptionState.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) { - "Lowpowermodesensitivities attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Lowpowermodesensitivities attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(EnergyPreferenceClusterBalanceStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null - } + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(EnergyPreferenceClusterBalanceStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null + } decodedValue?.let { emit(LowPowerModeSensitivitiesAttributeSubscriptionState.Success(it)) } + } SubscriptionState.SubscriptionEstablished -> { emit(LowPowerModeSensitivitiesAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readCurrentLowPowerModeSensitivityAttribute(): 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)) - +suspend fun readCurrentLowPowerModeSensitivityAttribute(): 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}") - } + 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) { - "Currentlowpowermodesensitivity attribute not found in response" + } + + requireNotNull(attributeData) { + "Currentlowpowermodesensitivity 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun writeCurrentLowPowerModeSensitivityAttribute( value: UByte, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 4u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -647,153 +702,152 @@ class EnergyPreferenceCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeCurrentLowPowerModeSensitivityAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Currentlowpowermodesensitivity attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Currentlowpowermodesensitivity 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)) } + 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 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -801,96 +855,97 @@ class EnergyPreferenceCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -898,94 +953,97 @@ class EnergyPreferenceCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -993,94 +1051,97 @@ class EnergyPreferenceCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1088,76 +1149,81 @@ class EnergyPreferenceCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1169,77 +1235,80 @@ class EnergyPreferenceCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1252,7 +1321,7 @@ class EnergyPreferenceCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/EthernetNetworkDiagnosticsCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/EthernetNetworkDiagnosticsCluster.kt index 219b842b46a746..296db7e7974d5b 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/EthernetNetworkDiagnosticsCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/EthernetNetworkDiagnosticsCluster.kt @@ -17,1060 +17,1149 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState +import matter.controller.UByteSubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState import matter.controller.ULongSubscriptionState -import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class EthernetNetworkDiagnosticsCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class PHYRateAttribute(val value: UByte?) +class EthernetNetworkDiagnosticsCluster(private val controller: MatterController, private val endpointId: UShort) {class PHYRateAttribute( + val value: UByte? + ) sealed class PHYRateAttributeSubscriptionState { - data class Success(val value: UByte?) : PHYRateAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : PHYRateAttributeSubscriptionState() + data class Error(val exception: Exception) : PHYRateAttributeSubscriptionState() - object SubscriptionEstablished : PHYRateAttributeSubscriptionState() - } - - class FullDuplexAttribute(val value: Boolean?) + object SubscriptionEstablished : PHYRateAttributeSubscriptionState() + } +class FullDuplexAttribute( + val value: Boolean? + ) sealed class FullDuplexAttributeSubscriptionState { - data class Success(val value: Boolean?) : FullDuplexAttributeSubscriptionState() - + data class Success( + val value: Boolean? + ) : FullDuplexAttributeSubscriptionState() + data class Error(val exception: Exception) : FullDuplexAttributeSubscriptionState() - object SubscriptionEstablished : FullDuplexAttributeSubscriptionState() - } - - class CarrierDetectAttribute(val value: Boolean?) + object SubscriptionEstablished : FullDuplexAttributeSubscriptionState() + } +class CarrierDetectAttribute( + val value: Boolean? + ) sealed class CarrierDetectAttributeSubscriptionState { - data class Success(val value: Boolean?) : CarrierDetectAttributeSubscriptionState() - + data class Success( + val value: Boolean? + ) : CarrierDetectAttributeSubscriptionState() + data class Error(val exception: Exception) : CarrierDetectAttributeSubscriptionState() - object SubscriptionEstablished : CarrierDetectAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : CarrierDetectAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } suspend fun resetCounts(timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - - suspend fun readPHYRateAttribute(): PHYRateAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readPHYRateAttribute(): PHYRateAttribute {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}") - } + 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) { "Phyrate attribute not found in response" } + } + + requireNotNull(attributeData) { + "Phyrate attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return PHYRateAttribute(decodedValue) } suspend fun subscribePHYRateAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - PHYRateAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(PHYRateAttributeSubscriptionState.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) { "Phyrate attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Phyrate 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(PHYRateAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(PHYRateAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(PHYRateAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readFullDuplexAttribute(): FullDuplexAttribute { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readFullDuplexAttribute(): FullDuplexAttribute {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}") - } + 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) { "Fullduplex attribute not found in response" } + } + + requireNotNull(attributeData) { + "Fullduplex attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Boolean? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getBoolean(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Boolean? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return FullDuplexAttribute(decodedValue) } suspend fun subscribeFullDuplexAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - FullDuplexAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(FullDuplexAttributeSubscriptionState.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) { "Fullduplex attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Fullduplex 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getBoolean(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(FullDuplexAttributeSubscriptionState.Success(it)) } + val decodedValue: Boolean? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(FullDuplexAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(FullDuplexAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readPacketRxCountAttribute(): ULong? { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readPacketRxCountAttribute(): ULong? {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}") - } + 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) { "Packetrxcount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Packetrxcount attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ULong? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getULong(AnonymousTag) - } else { - null - } + val decodedValue: ULong? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribePacketRxCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ULongSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ULongSubscriptionState.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) { "Packetrxcount attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Packetrxcount 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.isNextTag(AnonymousTag)) { - tlvReader.getULong(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(ULongSubscriptionState.Success(it)) } + val decodedValue: ULong? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(ULongSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ULongSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readPacketTxCountAttribute(): ULong? { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readPacketTxCountAttribute(): ULong? {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}") - } + 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) { "Packettxcount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Packettxcount attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ULong? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getULong(AnonymousTag) - } else { - null - } + val decodedValue: ULong? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribePacketTxCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ULongSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ULongSubscriptionState.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) { "Packettxcount attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Packettxcount 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.isNextTag(AnonymousTag)) { - tlvReader.getULong(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(ULongSubscriptionState.Success(it)) } + val decodedValue: ULong? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(ULongSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ULongSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readTxErrCountAttribute(): ULong? { - val ATTRIBUTE_ID: UInt = 4u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readTxErrCountAttribute(): ULong? {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}") - } + 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) { "Txerrcount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Txerrcount attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ULong? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getULong(AnonymousTag) - } else { - null - } + val decodedValue: ULong? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeTxErrCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ULongSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ULongSubscriptionState.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) { "Txerrcount attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Txerrcount 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.isNextTag(AnonymousTag)) { - tlvReader.getULong(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(ULongSubscriptionState.Success(it)) } + val decodedValue: ULong? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(ULongSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ULongSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readCollisionCountAttribute(): ULong? { - val ATTRIBUTE_ID: UInt = 5u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readCollisionCountAttribute(): ULong? {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}") - } + 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) { "Collisioncount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Collisioncount attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ULong? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getULong(AnonymousTag) - } else { - null - } + val decodedValue: ULong? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeCollisionCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ULongSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ULongSubscriptionState.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) { - "Collisioncount attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Collisioncount 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.isNextTag(AnonymousTag)) { - tlvReader.getULong(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(ULongSubscriptionState.Success(it)) } + val decodedValue: ULong? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(ULongSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ULongSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readOverrunCountAttribute(): ULong? { - val ATTRIBUTE_ID: UInt = 6u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readOverrunCountAttribute(): ULong? {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}") - } + 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) { "Overruncount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Overruncount attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ULong? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getULong(AnonymousTag) - } else { - null - } + val decodedValue: ULong? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeOverrunCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ULongSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ULongSubscriptionState.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) { "Overruncount attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Overruncount 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.isNextTag(AnonymousTag)) { - tlvReader.getULong(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(ULongSubscriptionState.Success(it)) } + val decodedValue: ULong? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(ULongSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ULongSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readCarrierDetectAttribute(): CarrierDetectAttribute { - val ATTRIBUTE_ID: UInt = 7u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readCarrierDetectAttribute(): CarrierDetectAttribute {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}") - } + 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) { "Carrierdetect attribute not found in response" } + } + + requireNotNull(attributeData) { + "Carrierdetect attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Boolean? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getBoolean(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Boolean? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return CarrierDetectAttribute(decodedValue) } suspend fun subscribeCarrierDetectAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - CarrierDetectAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(CarrierDetectAttributeSubscriptionState.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) { "Carrierdetect attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Carrierdetect 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getBoolean(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(CarrierDetectAttributeSubscriptionState.Success(it)) } + val decodedValue: Boolean? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(CarrierDetectAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(CarrierDetectAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readTimeSinceResetAttribute(): ULong? { - val ATTRIBUTE_ID: UInt = 8u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readTimeSinceResetAttribute(): ULong? {val ATTRIBUTE_ID: UInt = 8u + + 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}") - } + 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) { "Timesincereset attribute not found in response" } + } + + requireNotNull(attributeData) { + "Timesincereset attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ULong? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getULong(AnonymousTag) - } else { - null - } + val decodedValue: ULong? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeTimeSinceResetAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ULongSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ULongSubscriptionState.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) { - "Timesincereset attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Timesincereset 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.isNextTag(AnonymousTag)) { - tlvReader.getULong(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(ULongSubscriptionState.Success(it)) } + val decodedValue: ULong? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(ULongSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ULongSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1078,96 +1167,97 @@ class EthernetNetworkDiagnosticsCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1175,94 +1265,97 @@ class EthernetNetworkDiagnosticsCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1270,94 +1363,97 @@ class EthernetNetworkDiagnosticsCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1365,76 +1461,81 @@ class EthernetNetworkDiagnosticsCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1446,77 +1547,80 @@ class EthernetNetworkDiagnosticsCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1529,7 +1633,7 @@ class EthernetNetworkDiagnosticsCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/FanControlCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/FanControlCluster.kt index 7f29906d1bc0be..6d0e58a6d5b9b2 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/FanControlCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/FanControlCluster.kt @@ -17,99 +17,131 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.cluster.structs.* +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class FanControlCluster(private val controller: MatterController, private val endpointId: UShort) { - class PercentSettingAttribute(val value: UByte?) +class FanControlCluster(private val controller: MatterController, private val endpointId: UShort) {class PercentSettingAttribute( + val value: UByte? + ) sealed class PercentSettingAttributeSubscriptionState { - data class Success(val value: UByte?) : PercentSettingAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : PercentSettingAttributeSubscriptionState() + data class Error(val exception: Exception) : PercentSettingAttributeSubscriptionState() - object SubscriptionEstablished : PercentSettingAttributeSubscriptionState() - } - - class SpeedSettingAttribute(val value: UByte?) + object SubscriptionEstablished : PercentSettingAttributeSubscriptionState() + } +class SpeedSettingAttribute( + val value: UByte? + ) sealed class SpeedSettingAttributeSubscriptionState { - data class Success(val value: UByte?) : SpeedSettingAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : SpeedSettingAttributeSubscriptionState() + data class Error(val exception: Exception) : SpeedSettingAttributeSubscriptionState() - object SubscriptionEstablished : SpeedSettingAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : SpeedSettingAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun step( - direction: UByte, - wrap: Boolean?, - lowestOff: Boolean?, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun step(direction: UByte + ,wrap: Boolean? + ,lowestOff: Boolean? + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() @@ -119,71 +151,86 @@ class FanControlCluster(private val controller: MatterController, private val en tlvWriter.put(ContextSpecificTag(TAG_DIRECTION_REQ), direction) val TAG_WRAP_REQ: Int = 1 - wrap?.let { tlvWriter.put(ContextSpecificTag(TAG_WRAP_REQ), wrap) } + wrap?.let { + tlvWriter.put(ContextSpecificTag(TAG_WRAP_REQ), wrap) + } val TAG_LOWEST_OFF_REQ: Int = 2 - lowestOff?.let { tlvWriter.put(ContextSpecificTag(TAG_LOWEST_OFF_REQ), lowestOff) } + lowestOff?.let { + tlvWriter.put(ContextSpecificTag(TAG_LOWEST_OFF_REQ), lowestOff) + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - - suspend fun readFanModeAttribute(): 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)) - +suspend fun readFanModeAttribute(): 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}") - } + 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) { "Fanmode attribute not found in response" } + } + + requireNotNull(attributeData) { + "Fanmode 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 writeFanModeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeFanModeAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -204,45 +251,43 @@ class FanControlCluster(private val controller: MatterController, private val en throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeFanModeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Fanmode attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Fanmode attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -254,77 +299,80 @@ class FanControlCluster(private val controller: MatterController, private val en emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readFanModeSequenceAttribute(): 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)) - +suspend fun readFanModeSequenceAttribute(): 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}") - } + 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) { "Fanmodesequence attribute not found in response" } + } + + requireNotNull(attributeData) { + "Fanmodesequence 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 subscribeFanModeSequenceAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Fanmodesequence attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Fanmodesequence attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -337,63 +385,73 @@ class FanControlCluster(private val controller: MatterController, private val en emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readPercentSettingAttribute(): PercentSettingAttribute { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readPercentSettingAttribute(): PercentSettingAttribute {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}") - } + 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) { "Percentsetting attribute not found in response" } + } + + requireNotNull(attributeData) { + "Percentsetting attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return PercentSettingAttribute(decodedValue) } - suspend fun writePercentSettingAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writePercentSettingAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 2u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -414,135 +472,136 @@ class FanControlCluster(private val controller: MatterController, private val en throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribePercentSettingAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - PercentSettingAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(PercentSettingAttributeSubscriptionState.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) { - "Percentsetting attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Percentsetting 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.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(PercentSettingAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(PercentSettingAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(PercentSettingAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readPercentCurrentAttribute(): UByte { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readPercentCurrentAttribute(): UByte {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}") - } + 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) { "Percentcurrent attribute not found in response" } + } + + requireNotNull(attributeData) { + "Percentcurrent 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 subscribePercentCurrentAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Percentcurrent attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Percentcurrent attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -555,158 +614,174 @@ class FanControlCluster(private val controller: MatterController, private val en emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readSpeedMaxAttribute(): 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)) - +suspend fun readSpeedMaxAttribute(): 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}") - } + 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) { "Speedmax attribute not found in response" } + } + + requireNotNull(attributeData) { + "Speedmax 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeSpeedMaxAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Speedmax attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Speedmax 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)) } + 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 readSpeedSettingAttribute(): SpeedSettingAttribute { - val ATTRIBUTE_ID: UInt = 5u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readSpeedSettingAttribute(): SpeedSettingAttribute {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}") - } + 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) { "Speedsetting attribute not found in response" } + } + + requireNotNull(attributeData) { + "Speedsetting attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return SpeedSettingAttribute(decodedValue) } - suspend fun writeSpeedSettingAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeSpeedSettingAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 5u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -727,304 +802,326 @@ class FanControlCluster(private val controller: MatterController, private val en throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeSpeedSettingAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - SpeedSettingAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(SpeedSettingAttributeSubscriptionState.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) { "Speedsetting attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Speedsetting 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(SpeedSettingAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(SpeedSettingAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(SpeedSettingAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readSpeedCurrentAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 6u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readSpeedCurrentAttribute(): UByte? {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}") - } + 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) { "Speedcurrent attribute not found in response" } + } + + requireNotNull(attributeData) { + "Speedcurrent 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeSpeedCurrentAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Speedcurrent attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Speedcurrent 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)) } + 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 readRockSupportAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 7u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readRockSupportAttribute(): UByte? {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}") - } + 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) { "Rocksupport attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rocksupport 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeRockSupportAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Rocksupport attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rocksupport 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)) } + 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 readRockSettingAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 8u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readRockSettingAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 8u + + 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}") - } + 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) { "Rocksetting attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rocksetting 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } - suspend fun writeRockSettingAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeRockSettingAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 8u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -1045,208 +1142,224 @@ class FanControlCluster(private val controller: MatterController, private val en throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeRockSettingAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Rocksetting attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rocksetting 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)) } + 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 readWindSupportAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 9u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readWindSupportAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 9u + + 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}") - } + 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) { "Windsupport attribute not found in response" } + } + + requireNotNull(attributeData) { + "Windsupport 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeWindSupportAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Windsupport attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Windsupport 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)) } + 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 readWindSettingAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 10u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readWindSettingAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 10u + + 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}") - } + 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) { "Windsetting attribute not found in response" } + } + + requireNotNull(attributeData) { + "Windsetting 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } - suspend fun writeWindSettingAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeWindSettingAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 10u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -1267,117 +1380,127 @@ class FanControlCluster(private val controller: MatterController, private val en throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeWindSettingAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Windsetting attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Windsetting 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)) } + 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 readAirflowDirectionAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 11u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readAirflowDirectionAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 11u + + 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}") - } + 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) { "Airflowdirection attribute not found in response" } + } + + requireNotNull(attributeData) { + "Airflowdirection 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } - suspend fun writeAirflowDirectionAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeAirflowDirectionAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 11u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -1398,153 +1521,152 @@ class FanControlCluster(private val controller: MatterController, private val en throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeAirflowDirectionAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 11u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Airflowdirection attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Airflowdirection 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)) } + 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 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1552,96 +1674,97 @@ class FanControlCluster(private val controller: MatterController, private val en 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1649,94 +1772,97 @@ class FanControlCluster(private val controller: MatterController, private val en 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1744,94 +1870,97 @@ class FanControlCluster(private val controller: MatterController, private val en 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1839,76 +1968,81 @@ class FanControlCluster(private val controller: MatterController, private val en 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1920,77 +2054,80 @@ class FanControlCluster(private val controller: MatterController, private val en 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -2003,7 +2140,7 @@ class FanControlCluster(private val controller: MatterController, private val en emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/FaultInjectionCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/FaultInjectionCluster.kt index 3543b5258d020a..cd6627c787c57a 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/FaultInjectionCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/FaultInjectionCluster.kt @@ -17,80 +17,107 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.UIntSubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState +import matter.controller.UByteSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class FaultInjectionCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class GeneratedCommandListAttribute(val value: List) +class FaultInjectionCluster(private val controller: MatterController, private val endpointId: UShort) {class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun failAtFault( - type: UByte, - id: UInt, - numCallsToSkip: UInt, - numCallsToFail: UInt, - takeMutex: Boolean, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun failAtFault(type: UByte + ,id: UInt + ,numCallsToSkip: UInt + ,numCallsToFail: UInt + ,takeMutex: Boolean + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() @@ -109,26 +136,24 @@ class FaultInjectionCluster( tlvWriter.put(ContextSpecificTag(TAG_NUM_CALLS_TO_FAIL_REQ), numCallsToFail) val TAG_TAKE_MUTEX_REQ: Int = 4 - tlvWriter.put(ContextSpecificTag(TAG_TAKE_MUTEX_REQ), takeMutex) + tlvWriter.put(ContextSpecificTag(TAG_TAKE_MUTEX_REQ), takeMutex) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun failRandomlyAtFault( - type: UByte, - id: UInt, - percentage: UByte, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun failRandomlyAtFault(type: UByte + ,id: UInt + ,percentage: UByte + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 1u val tlvWriter = TlvWriter() @@ -141,107 +166,108 @@ class FaultInjectionCluster( tlvWriter.put(ContextSpecificTag(TAG_ID_REQ), id) val TAG_PERCENTAGE_REQ: Int = 2 - tlvWriter.put(ContextSpecificTag(TAG_PERCENTAGE_REQ), percentage) + tlvWriter.put(ContextSpecificTag(TAG_PERCENTAGE_REQ), percentage) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - - 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -249,96 +275,97 @@ class FaultInjectionCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -346,94 +373,97 @@ class FaultInjectionCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -441,94 +471,97 @@ class FaultInjectionCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -536,76 +569,81 @@ class FaultInjectionCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -617,77 +655,80 @@ class FaultInjectionCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -700,7 +741,7 @@ class FaultInjectionCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/FixedLabelCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/FixedLabelCluster.kt index 0b246557c49442..f36bab66f10935 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/FixedLabelCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/FixedLabelCluster.kt @@ -17,160 +17,202 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.UIntSubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState +import matter.controller.UByteSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath +import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader +import matter.tlv.TlvWriter -class FixedLabelCluster(private val controller: MatterController, private val endpointId: UShort) { - class LabelListAttribute(val value: List) +class FixedLabelCluster(private val controller: MatterController, private val endpointId: UShort) {class LabelListAttribute( + val value: List + ) sealed class LabelListAttributeSubscriptionState { - data class Success(val value: List) : - LabelListAttributeSubscriptionState() - + data class Success( + val value: List + ) : LabelListAttributeSubscriptionState() + data class Error(val exception: Exception) : LabelListAttributeSubscriptionState() - object SubscriptionEstablished : LabelListAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : LabelListAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } - - suspend fun readLabelListAttribute(): LabelListAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } +suspend fun readLabelListAttribute(): LabelListAttribute {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}") - } + 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) { "Labellist attribute not found in response" } + } + + requireNotNull(attributeData) { + "Labellist 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(FixedLabelClusterLabelStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(FixedLabelClusterLabelStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + return LabelListAttribute(decodedValue) } suspend fun subscribeLabelListAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - LabelListAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(LabelListAttributeSubscriptionState.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) { "Labellist attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Labellist 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(FixedLabelClusterLabelStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(FixedLabelClusterLabelStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(LabelListAttributeSubscriptionState.Success(decodedValue)) } @@ -178,96 +220,97 @@ class FixedLabelCluster(private val controller: MatterController, private val en emit(LabelListAttributeSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -275,96 +318,97 @@ class FixedLabelCluster(private val controller: MatterController, private val en 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -372,94 +416,97 @@ class FixedLabelCluster(private val controller: MatterController, private val en 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -467,94 +514,97 @@ class FixedLabelCluster(private val controller: MatterController, private val en 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -562,76 +612,81 @@ class FixedLabelCluster(private val controller: MatterController, private val en 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -643,77 +698,80 @@ class FixedLabelCluster(private val controller: MatterController, private val en 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -726,7 +784,7 @@ class FixedLabelCluster(private val controller: MatterController, private val en emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/FlowMeasurementCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/FlowMeasurementCluster.kt index 7587d7a243c65f..4987d915eb1c39 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/FlowMeasurementCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/FlowMeasurementCluster.kt @@ -17,558 +17,622 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.UIntSubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState +import matter.controller.UByteSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath +import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader +import matter.tlv.TlvWriter -class FlowMeasurementCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class MeasuredValueAttribute(val value: UShort?) +class FlowMeasurementCluster(private val controller: MatterController, private val endpointId: UShort) {class MeasuredValueAttribute( + val value: UShort? + ) sealed class MeasuredValueAttributeSubscriptionState { - data class Success(val value: UShort?) : MeasuredValueAttributeSubscriptionState() - + data class Success( + val value: UShort? + ) : MeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() - } - - class MinMeasuredValueAttribute(val value: UShort?) + object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() + } +class MinMeasuredValueAttribute( + val value: UShort? + ) sealed class MinMeasuredValueAttributeSubscriptionState { - data class Success(val value: UShort?) : MinMeasuredValueAttributeSubscriptionState() - + data class Success( + val value: UShort? + ) : MinMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MinMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() - } - - class MaxMeasuredValueAttribute(val value: UShort?) + object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() + } +class MaxMeasuredValueAttribute( + val value: UShort? + ) sealed class MaxMeasuredValueAttributeSubscriptionState { - data class Success(val value: UShort?) : MaxMeasuredValueAttributeSubscriptionState() - + data class Success( + val value: UShort? + ) : MaxMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MaxMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } - - suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } +suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute {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}") - } + 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) { "Measuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Measuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = - if (!tlvReader.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MeasuredValueAttribute(decodedValue) } suspend fun subscribeMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MeasuredValueAttributeSubscriptionState.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) { "Measuredvalue attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Measuredvalue 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.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute {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}") - } + 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) { "Minmeasuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Minmeasuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = - if (!tlvReader.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MinMeasuredValueAttribute(decodedValue) } suspend fun subscribeMinMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MinMeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MinMeasuredValueAttributeSubscriptionState.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) { - "Minmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Minmeasuredvalue 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.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MinMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute {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}") - } + 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) { "Maxmeasuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Maxmeasuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = - if (!tlvReader.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MaxMeasuredValueAttribute(decodedValue) } suspend fun subscribeMaxMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MaxMeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MaxMeasuredValueAttributeSubscriptionState.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) { - "Maxmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Maxmeasuredvalue 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.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MaxMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readToleranceAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readToleranceAttribute(): UShort? {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}") - } + 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) { "Tolerance attribute not found in response" } + } + + requireNotNull(attributeData) { + "Tolerance 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeToleranceAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Tolerance attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Tolerance 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)) } + 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 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -576,96 +640,97 @@ class FlowMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -673,94 +738,97 @@ class FlowMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -768,94 +836,97 @@ class FlowMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -863,76 +934,81 @@ class FlowMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -944,77 +1020,80 @@ class FlowMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1027,7 +1106,7 @@ class FlowMeasurementCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/FormaldehydeConcentrationMeasurementCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/FormaldehydeConcentrationMeasurementCluster.kt index 40c38c1089e743..472a14b09e3fea 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/FormaldehydeConcentrationMeasurementCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/FormaldehydeConcentrationMeasurementCluster.kt @@ -17,1273 +17,1371 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.FloatSubscriptionState import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath +import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader +import matter.tlv.TlvWriter -class FormaldehydeConcentrationMeasurementCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class MeasuredValueAttribute(val value: Float?) +class FormaldehydeConcentrationMeasurementCluster(private val controller: MatterController, private val endpointId: UShort) {class MeasuredValueAttribute( + val value: Float? + ) sealed class MeasuredValueAttributeSubscriptionState { - data class Success(val value: Float?) : MeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Float? + ) : MeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() - } - - class MinMeasuredValueAttribute(val value: Float?) + object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() + } +class MinMeasuredValueAttribute( + val value: Float? + ) sealed class MinMeasuredValueAttributeSubscriptionState { - data class Success(val value: Float?) : MinMeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Float? + ) : MinMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MinMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() - } - - class MaxMeasuredValueAttribute(val value: Float?) + object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() + } +class MaxMeasuredValueAttribute( + val value: Float? + ) sealed class MaxMeasuredValueAttributeSubscriptionState { - data class Success(val value: Float?) : MaxMeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Float? + ) : MaxMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MaxMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() - } - - class PeakMeasuredValueAttribute(val value: Float?) + object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() + } +class PeakMeasuredValueAttribute( + val value: Float? + ) sealed class PeakMeasuredValueAttributeSubscriptionState { - data class Success(val value: Float?) : PeakMeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Float? + ) : PeakMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : PeakMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : PeakMeasuredValueAttributeSubscriptionState() - } - - class AverageMeasuredValueAttribute(val value: Float?) + object SubscriptionEstablished : PeakMeasuredValueAttributeSubscriptionState() + } +class AverageMeasuredValueAttribute( + val value: Float? + ) sealed class AverageMeasuredValueAttributeSubscriptionState { - data class Success(val value: Float?) : AverageMeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Float? + ) : AverageMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : AverageMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : AverageMeasuredValueAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : AverageMeasuredValueAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } - - suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } +suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute {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}") - } + 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) { "Measuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Measuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MeasuredValueAttribute(decodedValue) } suspend fun subscribeMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MeasuredValueAttributeSubscriptionState.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) { "Measuredvalue attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Measuredvalue attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute {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}") - } + 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) { "Minmeasuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Minmeasuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MinMeasuredValueAttribute(decodedValue) } suspend fun subscribeMinMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MinMeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MinMeasuredValueAttributeSubscriptionState.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) { - "Minmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Minmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MinMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute {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}") - } + 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) { "Maxmeasuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Maxmeasuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MaxMeasuredValueAttribute(decodedValue) } suspend fun subscribeMaxMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MaxMeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MaxMeasuredValueAttributeSubscriptionState.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) { - "Maxmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Maxmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MaxMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readPeakMeasuredValueAttribute(): PeakMeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readPeakMeasuredValueAttribute(): PeakMeasuredValueAttribute {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}") - } + 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) { "Peakmeasuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Peakmeasuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return PeakMeasuredValueAttribute(decodedValue) } suspend fun subscribePeakMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - PeakMeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(PeakMeasuredValueAttributeSubscriptionState.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) { - "Peakmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Peakmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(PeakMeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(PeakMeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(PeakMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readPeakMeasuredValueWindowAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 4u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readPeakMeasuredValueWindowAttribute(): UInt? {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}") - } + 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) { "Peakmeasuredvaluewindow attribute not found in response" } + } + + requireNotNull(attributeData) { + "Peakmeasuredvaluewindow attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribePeakMeasuredValueWindowAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Peakmeasuredvaluewindow attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Peakmeasuredvaluewindow attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readAverageMeasuredValueAttribute(): AverageMeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 5u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readAverageMeasuredValueAttribute(): AverageMeasuredValueAttribute {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}") - } + 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) { "Averagemeasuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Averagemeasuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return AverageMeasuredValueAttribute(decodedValue) } suspend fun subscribeAverageMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - AverageMeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(AverageMeasuredValueAttributeSubscriptionState.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) { - "Averagemeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Averagemeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(AverageMeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(AverageMeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(AverageMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readAverageMeasuredValueWindowAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 6u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readAverageMeasuredValueWindowAttribute(): UInt? {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}") - } + 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) { "Averagemeasuredvaluewindow attribute not found in response" } + } + + requireNotNull(attributeData) { + "Averagemeasuredvaluewindow attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeAverageMeasuredValueWindowAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Averagemeasuredvaluewindow attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Averagemeasuredvaluewindow attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readUncertaintyAttribute(): Float? { - val ATTRIBUTE_ID: UInt = 7u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readUncertaintyAttribute(): Float? {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}") - } + 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) { "Uncertainty attribute not found in response" } + } + + requireNotNull(attributeData) { + "Uncertainty attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } + val decodedValue: Float? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeUncertaintyAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - FloatSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(FloatSubscriptionState.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) { "Uncertainty attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Uncertainty attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(FloatSubscriptionState.Success(it)) } + val decodedValue: Float? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(FloatSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(FloatSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readMeasurementUnitAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 8u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMeasurementUnitAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 8u + + 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}") - } + 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) { "Measurementunit attribute not found in response" } + } + + requireNotNull(attributeData) { + "Measurementunit 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeMeasurementUnitAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Measurementunit attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Measurementunit 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)) } + 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 readMeasurementMediumAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 9u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMeasurementMediumAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 9u + + 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}") - } + 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) { "Measurementmedium attribute not found in response" } + } + + requireNotNull(attributeData) { + "Measurementmedium 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeMeasurementMediumAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Measurementmedium attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Measurementmedium 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)) } + 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 readLevelValueAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 10u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readLevelValueAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 10u + + 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}") - } + 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) { "Levelvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Levelvalue 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeLevelValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Levelvalue attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Levelvalue 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)) } + 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 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1291,96 +1389,97 @@ class FormaldehydeConcentrationMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1388,94 +1487,97 @@ class FormaldehydeConcentrationMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1483,94 +1585,97 @@ class FormaldehydeConcentrationMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1578,76 +1683,81 @@ class FormaldehydeConcentrationMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1659,77 +1769,80 @@ class FormaldehydeConcentrationMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1742,12 +1855,11 @@ class FormaldehydeConcentrationMeasurementCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { - private val logger = - Logger.getLogger(FormaldehydeConcentrationMeasurementCluster::class.java.name) + private val logger = Logger.getLogger(FormaldehydeConcentrationMeasurementCluster::class.java.name) const val CLUSTER_ID: UInt = 1067u } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/GeneralCommissioningCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/GeneralCommissioningCluster.kt index 92e76e250f0eca..7fd6f12433d2fa 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/GeneralCommissioningCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/GeneralCommissioningCluster.kt @@ -17,104 +17,136 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration 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.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState import matter.controller.ULongSubscriptionState -import matter.controller.UShortSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.cluster.structs.* +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class GeneralCommissioningCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class ArmFailSafeResponse(val errorCode: UByte, val debugText: String) - - class SetRegulatoryConfigResponse(val errorCode: UByte, val debugText: String) +class GeneralCommissioningCluster(private val controller: MatterController, private val endpointId: UShort) { + class ArmFailSafeResponse( + val errorCode: UByte, + val debugText: String + ) - class CommissioningCompleteResponse(val errorCode: UByte, val debugText: String) + class SetRegulatoryConfigResponse( + val errorCode: UByte, + val debugText: String + ) - class SetTCAcknowledgementsResponse(val errorCode: UByte) + class CommissioningCompleteResponse( + val errorCode: UByte, + val debugText: String + ) - class BasicCommissioningInfoAttribute( + class SetTCAcknowledgementsResponse( + val errorCode: UByte + ) +class BasicCommissioningInfoAttribute( val value: GeneralCommissioningClusterBasicCommissioningInfo ) sealed class BasicCommissioningInfoAttributeSubscriptionState { - data class Success(val value: GeneralCommissioningClusterBasicCommissioningInfo) : - BasicCommissioningInfoAttributeSubscriptionState() - + data class Success( + val value: GeneralCommissioningClusterBasicCommissioningInfo + ) : BasicCommissioningInfoAttributeSubscriptionState() + data class Error(val exception: Exception) : BasicCommissioningInfoAttributeSubscriptionState() - object SubscriptionEstablished : BasicCommissioningInfoAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : BasicCommissioningInfoAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun armFailSafe( - expiryLengthSeconds: UShort, - breadcrumb: ULong, - timedInvokeTimeout: Duration? = null, - ): ArmFailSafeResponse { + suspend fun armFailSafe(expiryLengthSeconds: UShort + ,breadcrumb: ULong + ,timedInvokeTimeout: Duration? = null): ArmFailSafeResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() @@ -124,14 +156,14 @@ class GeneralCommissioningCluster( tlvWriter.put(ContextSpecificTag(TAG_EXPIRY_LENGTH_SECONDS_REQ), expiryLengthSeconds) val TAG_BREADCRUMB_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_BREADCRUMB_REQ), breadcrumb) + tlvWriter.put(ContextSpecificTag(TAG_BREADCRUMB_REQ), breadcrumb) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -141,43 +173,49 @@ class GeneralCommissioningCluster( tlvReader.enterStructure(AnonymousTag) val TAG_ERROR_CODE: Int = 0 var errorCode_decoded: UByte? = null - + val TAG_DEBUG_TEXT: Int = 1 var debugText_decoded: String? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_ERROR_CODE)) { - errorCode_decoded = tlvReader.getUByte(tag) - } + + if (tag == ContextSpecificTag(TAG_ERROR_CODE)) {errorCode_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_DEBUG_TEXT)) {debugText_decoded = tlvReader.getString(tag)} + - if (tag == ContextSpecificTag(TAG_DEBUG_TEXT)) { - debugText_decoded = tlvReader.getString(tag) - } else { + else { tlvReader.skipElement() } } + + if (errorCode_decoded == null) { - throw IllegalStateException("errorCode not found in TLV") + throw IllegalStateException("errorCode not found in TLV") } - + + if (debugText_decoded == null) { - throw IllegalStateException("debugText not found in TLV") + throw IllegalStateException("debugText not found in TLV") } + tlvReader.exitContainer() - return ArmFailSafeResponse(errorCode_decoded, debugText_decoded) + return ArmFailSafeResponse( + errorCode_decoded, + debugText_decoded + ) } - suspend fun setRegulatoryConfig( - newRegulatoryConfig: UByte, - countryCode: String, - breadcrumb: ULong, - timedInvokeTimeout: Duration? = null, - ): SetRegulatoryConfigResponse { + suspend fun setRegulatoryConfig(newRegulatoryConfig: UByte + ,countryCode: String + ,breadcrumb: ULong + ,timedInvokeTimeout: Duration? = null): SetRegulatoryConfigResponse { val commandId: UInt = 2u val tlvWriter = TlvWriter() @@ -190,14 +228,14 @@ class GeneralCommissioningCluster( tlvWriter.put(ContextSpecificTag(TAG_COUNTRY_CODE_REQ), countryCode) val TAG_BREADCRUMB_REQ: Int = 2 - tlvWriter.put(ContextSpecificTag(TAG_BREADCRUMB_REQ), breadcrumb) + tlvWriter.put(ContextSpecificTag(TAG_BREADCRUMB_REQ), breadcrumb) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -207,51 +245,57 @@ class GeneralCommissioningCluster( tlvReader.enterStructure(AnonymousTag) val TAG_ERROR_CODE: Int = 0 var errorCode_decoded: UByte? = null - + val TAG_DEBUG_TEXT: Int = 1 var debugText_decoded: String? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_ERROR_CODE)) { - errorCode_decoded = tlvReader.getUByte(tag) - } + + if (tag == ContextSpecificTag(TAG_ERROR_CODE)) {errorCode_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_DEBUG_TEXT)) {debugText_decoded = tlvReader.getString(tag)} + - if (tag == ContextSpecificTag(TAG_DEBUG_TEXT)) { - debugText_decoded = tlvReader.getString(tag) - } else { + else { tlvReader.skipElement() } } + + if (errorCode_decoded == null) { - throw IllegalStateException("errorCode not found in TLV") + throw IllegalStateException("errorCode not found in TLV") } - + + if (debugText_decoded == null) { - throw IllegalStateException("debugText not found in TLV") + throw IllegalStateException("debugText not found in TLV") } + tlvReader.exitContainer() - return SetRegulatoryConfigResponse(errorCode_decoded, debugText_decoded) + return SetRegulatoryConfigResponse( + errorCode_decoded, + debugText_decoded + ) } - suspend fun commissioningComplete( - timedInvokeTimeout: Duration? = null - ): CommissioningCompleteResponse { + suspend fun commissioningComplete(timedInvokeTimeout: Duration? = null): CommissioningCompleteResponse { val commandId: UInt = 4u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -261,42 +305,48 @@ class GeneralCommissioningCluster( tlvReader.enterStructure(AnonymousTag) val TAG_ERROR_CODE: Int = 0 var errorCode_decoded: UByte? = null - + val TAG_DEBUG_TEXT: Int = 1 var debugText_decoded: String? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_ERROR_CODE)) { - errorCode_decoded = tlvReader.getUByte(tag) - } + + if (tag == ContextSpecificTag(TAG_ERROR_CODE)) {errorCode_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_DEBUG_TEXT)) {debugText_decoded = tlvReader.getString(tag)} + - if (tag == ContextSpecificTag(TAG_DEBUG_TEXT)) { - debugText_decoded = tlvReader.getString(tag) - } else { + else { tlvReader.skipElement() } } + + if (errorCode_decoded == null) { - throw IllegalStateException("errorCode not found in TLV") + throw IllegalStateException("errorCode not found in TLV") } - + + if (debugText_decoded == null) { - throw IllegalStateException("debugText not found in TLV") + throw IllegalStateException("debugText not found in TLV") } + tlvReader.exitContainer() - return CommissioningCompleteResponse(errorCode_decoded, debugText_decoded) + return CommissioningCompleteResponse( + errorCode_decoded, + debugText_decoded + ) } - suspend fun setTCAcknowledgements( - TCVersion: UShort, - TCUserResponse: UShort, - timedInvokeTimeout: Duration? = null, - ): SetTCAcknowledgementsResponse { + suspend fun setTCAcknowledgements(TCVersion: UShort + ,TCUserResponse: UShort + ,timedInvokeTimeout: Duration? = null): SetTCAcknowledgementsResponse { val commandId: UInt = 6u val tlvWriter = TlvWriter() @@ -306,14 +356,14 @@ class GeneralCommissioningCluster( tlvWriter.put(ContextSpecificTag(TAG_TC_VERSION_REQ), TCVersion) val TAG_TC_USER_RESPONSE_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_TC_USER_RESPONSE_REQ), TCUserResponse) + tlvWriter.put(ContextSpecificTag(TAG_TC_USER_RESPONSE_REQ), TCUserResponse) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -323,74 +373,93 @@ class GeneralCommissioningCluster( tlvReader.enterStructure(AnonymousTag) val TAG_ERROR_CODE: Int = 0 var errorCode_decoded: UByte? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_ERROR_CODE)) { - errorCode_decoded = tlvReader.getUByte(tag) - } else { + + if (tag == ContextSpecificTag(TAG_ERROR_CODE)) {errorCode_decoded = tlvReader.getUByte(tag)} + + + else { tlvReader.skipElement() } } + + if (errorCode_decoded == null) { - throw IllegalStateException("errorCode not found in TLV") + throw IllegalStateException("errorCode not found in TLV") } + tlvReader.exitContainer() - return SetTCAcknowledgementsResponse(errorCode_decoded) + return SetTCAcknowledgementsResponse( + errorCode_decoded + ) } - - suspend fun readBreadcrumbAttribute(): ULong { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readBreadcrumbAttribute(): ULong {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}") - } + 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) { "Breadcrumb attribute not found in response" } + } + + requireNotNull(attributeData) { + "Breadcrumb attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: ULong = tlvReader.getULong(AnonymousTag) + return decodedValue } - suspend fun writeBreadcrumbAttribute(value: ULong, timedWriteTimeout: Duration? = null) { + suspend fun writeBreadcrumbAttribute( + value: ULong, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -411,45 +480,43 @@ class GeneralCommissioningCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeBreadcrumbAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ULongSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ULongSubscriptionState.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) { "Breadcrumb attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Breadcrumb attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -461,84 +528,85 @@ class GeneralCommissioningCluster( emit(ULongSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readBasicCommissioningInfoAttribute(): BasicCommissioningInfoAttribute { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readBasicCommissioningInfoAttribute(): BasicCommissioningInfoAttribute {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}") - } + 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) { "Basiccommissioninginfo attribute not found in response" } + } + + requireNotNull(attributeData) { + "Basiccommissioninginfo attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: GeneralCommissioningClusterBasicCommissioningInfo = - GeneralCommissioningClusterBasicCommissioningInfo.fromTlv(AnonymousTag, tlvReader) + val decodedValue: GeneralCommissioningClusterBasicCommissioningInfo = GeneralCommissioningClusterBasicCommissioningInfo.fromTlv(AnonymousTag, tlvReader) + return BasicCommissioningInfoAttribute(decodedValue) } suspend fun subscribeBasicCommissioningInfoAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - BasicCommissioningInfoAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(BasicCommissioningInfoAttributeSubscriptionState.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) { - "Basiccommissioninginfo attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Basiccommissioninginfo attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: GeneralCommissioningClusterBasicCommissioningInfo = - GeneralCommissioningClusterBasicCommissioningInfo.fromTlv(AnonymousTag, tlvReader) + val decodedValue: GeneralCommissioningClusterBasicCommissioningInfo = GeneralCommissioningClusterBasicCommissioningInfo.fromTlv(AnonymousTag, tlvReader) emit(BasicCommissioningInfoAttributeSubscriptionState.Success(decodedValue)) } @@ -546,77 +614,80 @@ class GeneralCommissioningCluster( emit(BasicCommissioningInfoAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readRegulatoryConfigAttribute(): UByte { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readRegulatoryConfigAttribute(): UByte {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}") - } + 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) { "Regulatoryconfig attribute not found in response" } + } + + requireNotNull(attributeData) { + "Regulatoryconfig 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 subscribeRegulatoryConfigAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Regulatoryconfig attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Regulatoryconfig attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -629,77 +700,80 @@ class GeneralCommissioningCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readLocationCapabilityAttribute(): UByte { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readLocationCapabilityAttribute(): UByte {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}") - } + 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) { "Locationcapability attribute not found in response" } + } + + requireNotNull(attributeData) { + "Locationcapability 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 subscribeLocationCapabilityAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Locationcapability attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Locationcapability attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -712,77 +786,80 @@ class GeneralCommissioningCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readSupportsConcurrentConnectionAttribute(): Boolean { - val ATTRIBUTE_ID: UInt = 4u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readSupportsConcurrentConnectionAttribute(): Boolean {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}") - } + 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) { "Supportsconcurrentconnection attribute not found in response" } + } + + requireNotNull(attributeData) { + "Supportsconcurrentconnection attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Boolean = tlvReader.getBoolean(AnonymousTag) + return decodedValue } suspend fun subscribeSupportsConcurrentConnectionAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Supportsconcurrentconnection attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Supportsconcurrentconnection attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -795,468 +872,485 @@ class GeneralCommissioningCluster( emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readTCAcceptedVersionAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 5u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readTCAcceptedVersionAttribute(): UShort? {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}") - } + 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) { "Tcacceptedversion attribute not found in response" } + } + + requireNotNull(attributeData) { + "Tcacceptedversion 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeTCAcceptedVersionAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Tcacceptedversion attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Tcacceptedversion 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)) } + 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 readTCMinRequiredVersionAttribute(): 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)) - +suspend fun readTCMinRequiredVersionAttribute(): 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}") - } + 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) { "Tcminrequiredversion attribute not found in response" } + } + + requireNotNull(attributeData) { + "Tcminrequiredversion 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeTCMinRequiredVersionAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Tcminrequiredversion attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Tcminrequiredversion 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)) } + 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 readTCAcknowledgementsAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 7u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readTCAcknowledgementsAttribute(): UShort? {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}") - } + 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) { "Tcacknowledgements attribute not found in response" } + } + + requireNotNull(attributeData) { + "Tcacknowledgements 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeTCAcknowledgementsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Tcacknowledgements attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Tcacknowledgements 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)) } + 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 readTCAcknowledgementsRequiredAttribute(): Boolean? { - val ATTRIBUTE_ID: UInt = 8u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readTCAcknowledgementsRequiredAttribute(): Boolean? {val ATTRIBUTE_ID: UInt = 8u + + 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}") - } + 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) { "Tcacknowledgementsrequired attribute not found in response" } + } + + requireNotNull(attributeData) { + "Tcacknowledgementsrequired 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 - } + val decodedValue: Boolean? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeTCAcknowledgementsRequiredAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Tcacknowledgementsrequired attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Tcacknowledgementsrequired 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)) } + 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 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1264,96 +1358,97 @@ class GeneralCommissioningCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1361,94 +1456,97 @@ class GeneralCommissioningCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1456,94 +1554,97 @@ class GeneralCommissioningCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1551,76 +1652,81 @@ class GeneralCommissioningCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1632,77 +1738,80 @@ class GeneralCommissioningCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1715,7 +1824,7 @@ class GeneralCommissioningCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/GeneralDiagnosticsCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/GeneralDiagnosticsCluster.kt index 93bab933864e0e..b930fde5339fde 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/GeneralDiagnosticsCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/GeneralDiagnosticsCluster.kt @@ -17,125 +17,165 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration 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.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState import matter.controller.ULongSubscriptionState -import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class GeneralDiagnosticsCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class TimeSnapshotResponse(val systemTimeMs: ULong, val posixTimeMs: ULong?) - - class PayloadTestResponse(val payload: ByteArray) +class GeneralDiagnosticsCluster(private val controller: MatterController, private val endpointId: UShort) { + class TimeSnapshotResponse( + val systemTimeMs: ULong, + val posixTimeMs: ULong? + ) - class NetworkInterfacesAttribute(val value: List) + class PayloadTestResponse( + val payload: ByteArray + ) +class NetworkInterfacesAttribute( + val value: List + ) sealed class NetworkInterfacesAttributeSubscriptionState { - data class Success(val value: List) : - NetworkInterfacesAttributeSubscriptionState() - + data class Success( + val value: List + ) : NetworkInterfacesAttributeSubscriptionState() + data class Error(val exception: Exception) : NetworkInterfacesAttributeSubscriptionState() - object SubscriptionEstablished : NetworkInterfacesAttributeSubscriptionState() - } - - class ActiveHardwareFaultsAttribute(val value: List?) + object SubscriptionEstablished : NetworkInterfacesAttributeSubscriptionState() + } +class ActiveHardwareFaultsAttribute( + val value: List? + ) sealed class ActiveHardwareFaultsAttributeSubscriptionState { - data class Success(val value: List?) : ActiveHardwareFaultsAttributeSubscriptionState() - + data class Success( + val value: List? + ) : ActiveHardwareFaultsAttributeSubscriptionState() + data class Error(val exception: Exception) : ActiveHardwareFaultsAttributeSubscriptionState() - object SubscriptionEstablished : ActiveHardwareFaultsAttributeSubscriptionState() - } - - class ActiveRadioFaultsAttribute(val value: List?) + object SubscriptionEstablished : ActiveHardwareFaultsAttributeSubscriptionState() + } +class ActiveRadioFaultsAttribute( + val value: List? + ) sealed class ActiveRadioFaultsAttributeSubscriptionState { - data class Success(val value: List?) : ActiveRadioFaultsAttributeSubscriptionState() - + data class Success( + val value: List? + ) : ActiveRadioFaultsAttributeSubscriptionState() + data class Error(val exception: Exception) : ActiveRadioFaultsAttributeSubscriptionState() - object SubscriptionEstablished : ActiveRadioFaultsAttributeSubscriptionState() - } - - class ActiveNetworkFaultsAttribute(val value: List?) + object SubscriptionEstablished : ActiveRadioFaultsAttributeSubscriptionState() + } +class ActiveNetworkFaultsAttribute( + val value: List? + ) sealed class ActiveNetworkFaultsAttributeSubscriptionState { - data class Success(val value: List?) : ActiveNetworkFaultsAttributeSubscriptionState() - + data class Success( + val value: List? + ) : ActiveNetworkFaultsAttributeSubscriptionState() + data class Error(val exception: Exception) : ActiveNetworkFaultsAttributeSubscriptionState() - object SubscriptionEstablished : ActiveNetworkFaultsAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : ActiveNetworkFaultsAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun testEventTrigger( - enableKey: ByteArray, - eventTrigger: ULong, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun testEventTrigger(enableKey: ByteArray + ,eventTrigger: ULong + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() @@ -145,14 +185,14 @@ class GeneralDiagnosticsCluster( tlvWriter.put(ContextSpecificTag(TAG_ENABLE_KEY_REQ), enableKey) val TAG_EVENT_TRIGGER_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_EVENT_TRIGGER_REQ), eventTrigger) + tlvWriter.put(ContextSpecificTag(TAG_EVENT_TRIGGER_REQ), eventTrigger) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -163,14 +203,14 @@ class GeneralDiagnosticsCluster( val commandId: UInt = 1u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -180,50 +220,57 @@ class GeneralDiagnosticsCluster( tlvReader.enterStructure(AnonymousTag) val TAG_SYSTEM_TIME_MS: Int = 0 var systemTimeMs_decoded: ULong? = null - + val TAG_POSIX_TIME_MS: Int = 1 var posixTimeMs_decoded: ULong? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_SYSTEM_TIME_MS)) { - systemTimeMs_decoded = tlvReader.getULong(tag) - } - - if (tag == ContextSpecificTag(TAG_POSIX_TIME_MS)) { - posixTimeMs_decoded = + + if (tag == ContextSpecificTag(TAG_SYSTEM_TIME_MS)) {systemTimeMs_decoded = tlvReader.getULong(tag)} + + if (tag == ContextSpecificTag(TAG_POSIX_TIME_MS)) {posixTimeMs_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (!tlvReader.isNull()) { - tlvReader.getULong(tag) - } else { - tlvReader.getNull(tag) - null - } - } - } else { + tlvReader.getULong(tag) + } else { + tlvReader.getNull(tag) + null + } + }} + + + else { tlvReader.skipElement() } } + + if (systemTimeMs_decoded == null) { - throw IllegalStateException("systemTimeMs not found in TLV") + throw IllegalStateException("systemTimeMs not found in TLV") } + + + tlvReader.exitContainer() - return TimeSnapshotResponse(systemTimeMs_decoded, posixTimeMs_decoded) + return TimeSnapshotResponse( + systemTimeMs_decoded, + posixTimeMs_decoded + ) } - suspend fun payloadTestRequest( - enableKey: ByteArray, - value: UByte, - count: UShort, - timedInvokeTimeout: Duration? = null, - ): PayloadTestResponse { + suspend fun payloadTestRequest(enableKey: ByteArray + ,value: UByte + ,count: UShort + ,timedInvokeTimeout: Duration? = null): PayloadTestResponse { val commandId: UInt = 3u val tlvWriter = TlvWriter() @@ -236,14 +283,14 @@ class GeneralDiagnosticsCluster( tlvWriter.put(ContextSpecificTag(TAG_VALUE_REQ), value) val TAG_COUNT_REQ: Int = 2 - tlvWriter.put(ContextSpecificTag(TAG_COUNT_REQ), count) + tlvWriter.put(ContextSpecificTag(TAG_COUNT_REQ), count) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -253,113 +300,122 @@ class GeneralDiagnosticsCluster( tlvReader.enterStructure(AnonymousTag) val TAG_PAYLOAD: Int = 0 var payload_decoded: ByteArray? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_PAYLOAD)) { - payload_decoded = tlvReader.getByteArray(tag) - } else { + + if (tag == ContextSpecificTag(TAG_PAYLOAD)) {payload_decoded = tlvReader.getByteArray(tag)} + + + else { tlvReader.skipElement() } } + + if (payload_decoded == null) { - throw IllegalStateException("payload not found in TLV") + throw IllegalStateException("payload not found in TLV") } + tlvReader.exitContainer() - return PayloadTestResponse(payload_decoded) + return PayloadTestResponse( + payload_decoded + ) } - - suspend fun readNetworkInterfacesAttribute(): NetworkInterfacesAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readNetworkInterfacesAttribute(): NetworkInterfacesAttribute {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}") - } + 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) { "Networkinterfaces attribute not found in response" } + } + + requireNotNull(attributeData) { + "Networkinterfaces 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(GeneralDiagnosticsClusterNetworkInterface.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(GeneralDiagnosticsClusterNetworkInterface.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + return NetworkInterfacesAttribute(decodedValue) } suspend fun subscribeNetworkInterfacesAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - NetworkInterfacesAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(NetworkInterfacesAttributeSubscriptionState.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) { - "Networkinterfaces attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Networkinterfaces 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(GeneralDiagnosticsClusterNetworkInterface.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(GeneralDiagnosticsClusterNetworkInterface.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(NetworkInterfacesAttributeSubscriptionState.Success(decodedValue)) } @@ -367,76 +423,81 @@ class GeneralDiagnosticsCluster( emit(NetworkInterfacesAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readRebootCountAttribute(): UShort { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readRebootCountAttribute(): UShort {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}") - } + 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) { "Rebootcount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rebootcount 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 subscribeRebootCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Rebootcount attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rebootcount attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -448,667 +509,698 @@ class GeneralDiagnosticsCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readUpTimeAttribute(): ULong? { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readUpTimeAttribute(): ULong? {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}") - } + 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) { "Uptime attribute not found in response" } + } + + requireNotNull(attributeData) { + "Uptime attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ULong? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getULong(AnonymousTag) - } else { - null - } + val decodedValue: ULong? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeUpTimeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ULongSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ULongSubscriptionState.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) { "Uptime attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Uptime 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.isNextTag(AnonymousTag)) { - tlvReader.getULong(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(ULongSubscriptionState.Success(it)) } + val decodedValue: ULong? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(ULongSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ULongSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readTotalOperationalHoursAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readTotalOperationalHoursAttribute(): UInt? {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}") - } + 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) { "Totaloperationalhours attribute not found in response" } + } + + requireNotNull(attributeData) { + "Totaloperationalhours attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeTotalOperationalHoursAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Totaloperationalhours attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Totaloperationalhours attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readBootReasonAttribute(): 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)) - +suspend fun readBootReasonAttribute(): 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}") - } + 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) { "Bootreason attribute not found in response" } + } + + requireNotNull(attributeData) { + "Bootreason 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeBootReasonAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Bootreason attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Bootreason 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)) } + 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 readActiveHardwareFaultsAttribute(): ActiveHardwareFaultsAttribute { - val ATTRIBUTE_ID: UInt = 5u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readActiveHardwareFaultsAttribute(): ActiveHardwareFaultsAttribute {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}") - } + 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) { "Activehardwarefaults attribute not found in response" } + } + + requireNotNull(attributeData) { + "Activehardwarefaults attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) } + tlvReader.exitContainer() + } + } else { + null + } + return ActiveHardwareFaultsAttribute(decodedValue) } suspend fun subscribeActiveHardwareFaultsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ActiveHardwareFaultsAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ActiveHardwareFaultsAttributeSubscriptionState.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) { - "Activehardwarefaults attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Activehardwarefaults attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { emit(ActiveHardwareFaultsAttributeSubscriptionState.Success(it)) } + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { + emit(ActiveHardwareFaultsAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ActiveHardwareFaultsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readActiveRadioFaultsAttribute(): ActiveRadioFaultsAttribute { - val ATTRIBUTE_ID: UInt = 6u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readActiveRadioFaultsAttribute(): ActiveRadioFaultsAttribute {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}") - } + 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) { "Activeradiofaults attribute not found in response" } + } + + requireNotNull(attributeData) { + "Activeradiofaults attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) } + tlvReader.exitContainer() + } + } else { + null + } + return ActiveRadioFaultsAttribute(decodedValue) } suspend fun subscribeActiveRadioFaultsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ActiveRadioFaultsAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ActiveRadioFaultsAttributeSubscriptionState.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) { - "Activeradiofaults attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Activeradiofaults attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { emit(ActiveRadioFaultsAttributeSubscriptionState.Success(it)) } + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { + emit(ActiveRadioFaultsAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ActiveRadioFaultsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readActiveNetworkFaultsAttribute(): ActiveNetworkFaultsAttribute { - val ATTRIBUTE_ID: UInt = 7u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readActiveNetworkFaultsAttribute(): ActiveNetworkFaultsAttribute {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}") - } + 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) { "Activenetworkfaults attribute not found in response" } + } + + requireNotNull(attributeData) { + "Activenetworkfaults attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) } + tlvReader.exitContainer() + } + } else { + null + } + return ActiveNetworkFaultsAttribute(decodedValue) } suspend fun subscribeActiveNetworkFaultsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ActiveNetworkFaultsAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ActiveNetworkFaultsAttributeSubscriptionState.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) { - "Activenetworkfaults attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Activenetworkfaults attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { emit(ActiveNetworkFaultsAttributeSubscriptionState.Success(it)) } + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { + emit(ActiveNetworkFaultsAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ActiveNetworkFaultsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readTestEventTriggersEnabledAttribute(): Boolean { - val ATTRIBUTE_ID: UInt = 8u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readTestEventTriggersEnabledAttribute(): Boolean {val ATTRIBUTE_ID: UInt = 8u + + 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}") - } + 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) { "Testeventtriggersenabled attribute not found in response" } + } + + requireNotNull(attributeData) { + "Testeventtriggersenabled attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Boolean = tlvReader.getBoolean(AnonymousTag) + return decodedValue } suspend fun subscribeTestEventTriggersEnabledAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Testeventtriggersenabled attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Testeventtriggersenabled attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -1121,96 +1213,97 @@ class GeneralDiagnosticsCluster( emit(BooleanSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1218,96 +1311,97 @@ class GeneralDiagnosticsCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1315,94 +1409,97 @@ class GeneralDiagnosticsCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1410,94 +1507,97 @@ class GeneralDiagnosticsCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1505,76 +1605,81 @@ class GeneralDiagnosticsCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1586,77 +1691,80 @@ class GeneralDiagnosticsCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1669,7 +1777,7 @@ class GeneralDiagnosticsCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/GroupKeyManagementCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/GroupKeyManagementCluster.kt index a693149fedc58e..b571528b945460 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/GroupKeyManagementCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/GroupKeyManagementCluster.kt @@ -17,143 +17,173 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.UIntSubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState +import matter.controller.UByteSubscriptionState import matter.controller.UShortSubscriptionState +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.cluster.structs.* +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class GroupKeyManagementCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class KeySetReadResponse(val groupKeySet: GroupKeyManagementClusterGroupKeySetStruct) - - class KeySetReadAllIndicesResponse(val groupKeySetIDs: List) +class GroupKeyManagementCluster(private val controller: MatterController, private val endpointId: UShort) { + class KeySetReadResponse( + val groupKeySet: GroupKeyManagementClusterGroupKeySetStruct + ) - class GroupKeyMapAttribute(val value: List) + class KeySetReadAllIndicesResponse( + val groupKeySetIDs: List + ) +class GroupKeyMapAttribute( + val value: List + ) sealed class GroupKeyMapAttributeSubscriptionState { - data class Success(val value: List) : - GroupKeyMapAttributeSubscriptionState() - + data class Success( + val value: List + ) : GroupKeyMapAttributeSubscriptionState() + data class Error(val exception: Exception) : GroupKeyMapAttributeSubscriptionState() - object SubscriptionEstablished : GroupKeyMapAttributeSubscriptionState() - } - - class GroupTableAttribute(val value: List) + object SubscriptionEstablished : GroupKeyMapAttributeSubscriptionState() + } +class GroupTableAttribute( + val value: List + ) sealed class GroupTableAttributeSubscriptionState { - data class Success(val value: List) : - GroupTableAttributeSubscriptionState() - + data class Success( + val value: List + ) : GroupTableAttributeSubscriptionState() + data class Error(val exception: Exception) : GroupTableAttributeSubscriptionState() - object SubscriptionEstablished : GroupTableAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : GroupTableAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun keySetWrite( - groupKeySet: GroupKeyManagementClusterGroupKeySetStruct, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun keySetWrite(groupKeySet: GroupKeyManagementClusterGroupKeySetStruct + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_GROUP_KEY_SET_REQ: Int = 0 - groupKeySet.toTlv(ContextSpecificTag(TAG_GROUP_KEY_SET_REQ), tlvWriter) + groupKeySet.toTlv(ContextSpecificTag(TAG_GROUP_KEY_SET_REQ), tlvWriter) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun keySetRead( - groupKeySetID: UShort, - timedInvokeTimeout: Duration? = null, - ): KeySetReadResponse { + suspend fun keySetRead(groupKeySetID: UShort + ,timedInvokeTimeout: Duration? = null): KeySetReadResponse { val commandId: UInt = 1u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_GROUP_KEY_SET_ID_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_GROUP_KEY_SET_ID_REQ), groupKeySetID) + tlvWriter.put(ContextSpecificTag(TAG_GROUP_KEY_SET_ID_REQ), groupKeySetID) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -163,61 +193,68 @@ class GroupKeyManagementCluster( tlvReader.enterStructure(AnonymousTag) val TAG_GROUP_KEY_SET: Int = 0 var groupKeySet_decoded: GroupKeyManagementClusterGroupKeySetStruct? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_GROUP_KEY_SET)) { - groupKeySet_decoded = GroupKeyManagementClusterGroupKeySetStruct.fromTlv(tag, tlvReader) - } else { + + if (tag == ContextSpecificTag(TAG_GROUP_KEY_SET)) {groupKeySet_decoded = GroupKeyManagementClusterGroupKeySetStruct.fromTlv(tag, tlvReader)} + + + else { tlvReader.skipElement() } } + + if (groupKeySet_decoded == null) { - throw IllegalStateException("groupKeySet not found in TLV") + throw IllegalStateException("groupKeySet not found in TLV") } + tlvReader.exitContainer() - return KeySetReadResponse(groupKeySet_decoded) + return KeySetReadResponse( + groupKeySet_decoded + ) } - suspend fun keySetRemove(groupKeySetID: UShort, timedInvokeTimeout: Duration? = null) { + suspend fun keySetRemove(groupKeySetID: UShort + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 3u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_GROUP_KEY_SET_ID_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_GROUP_KEY_SET_ID_REQ), groupKeySetID) + tlvWriter.put(ContextSpecificTag(TAG_GROUP_KEY_SET_ID_REQ), groupKeySetID) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun keySetReadAllIndices( - timedInvokeTimeout: Duration? = null - ): KeySetReadAllIndicesResponse { + suspend fun keySetReadAllIndices(timedInvokeTimeout: Duration? = null): KeySetReadAllIndicesResponse { val commandId: UInt = 4u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -227,95 +264,109 @@ class GroupKeyManagementCluster( tlvReader.enterStructure(AnonymousTag) val TAG_GROUP_KEY_SET_I_DS: Int = 0 var groupKeySetIDs_decoded: List? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_GROUP_KEY_SET_I_DS)) { - groupKeySetIDs_decoded = - buildList { - tlvReader.enterArray(tag) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getUShort(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { + + if (tag == ContextSpecificTag(TAG_GROUP_KEY_SET_I_DS)) {groupKeySetIDs_decoded = buildList { + tlvReader.enterArray(tag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUShort(AnonymousTag)) + } + tlvReader.exitContainer() + }} + + + else { tlvReader.skipElement() } } + + if (groupKeySetIDs_decoded == null) { - throw IllegalStateException("groupKeySetIDs not found in TLV") + throw IllegalStateException("groupKeySetIDs not found in TLV") } + tlvReader.exitContainer() - return KeySetReadAllIndicesResponse(groupKeySetIDs_decoded) + return KeySetReadAllIndicesResponse( + groupKeySetIDs_decoded + ) } - - suspend fun readGroupKeyMapAttribute(): GroupKeyMapAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readGroupKeyMapAttribute(): GroupKeyMapAttribute {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}") - } + 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) { "Groupkeymap attribute not found in response" } + } + + requireNotNull(attributeData) { + "Groupkeymap 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(GroupKeyManagementClusterGroupKeyMapStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(GroupKeyManagementClusterGroupKeyMapStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + return GroupKeyMapAttribute(decodedValue) } suspend fun writeGroupKeyMapAttribute( value: List, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startArray(AnonymousTag) - for (item in value.iterator()) { - item.toTlv(AnonymousTag, tlvWriter) - } - tlvWriter.endArray() + for (item in value.iterator()) { + item.toTlv(AnonymousTag, tlvWriter) + } + tlvWriter.endArray() val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -336,56 +387,53 @@ class GroupKeyManagementCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeGroupKeyMapAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - GroupKeyMapAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(GroupKeyMapAttributeSubscriptionState.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) { "Groupkeymap attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Groupkeymap 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(GroupKeyManagementClusterGroupKeyMapStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(GroupKeyManagementClusterGroupKeyMapStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(GroupKeyMapAttributeSubscriptionState.Success(decodedValue)) } @@ -393,94 +441,97 @@ class GroupKeyManagementCluster( emit(GroupKeyMapAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readGroupTableAttribute(): GroupTableAttribute { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readGroupTableAttribute(): GroupTableAttribute {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}") - } + 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) { "Grouptable attribute not found in response" } + } + + requireNotNull(attributeData) { + "Grouptable 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(GroupKeyManagementClusterGroupInfoMapStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(GroupKeyManagementClusterGroupInfoMapStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + return GroupTableAttribute(decodedValue) } suspend fun subscribeGroupTableAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - GroupTableAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(GroupTableAttributeSubscriptionState.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) { "Grouptable attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Grouptable 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(GroupKeyManagementClusterGroupInfoMapStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(GroupKeyManagementClusterGroupInfoMapStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(GroupTableAttributeSubscriptionState.Success(decodedValue)) } @@ -488,77 +539,80 @@ class GroupKeyManagementCluster( emit(GroupTableAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readMaxGroupsPerFabricAttribute(): 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)) - +suspend fun readMaxGroupsPerFabricAttribute(): 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}") - } + 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) { "Maxgroupsperfabric attribute not found in response" } + } + + requireNotNull(attributeData) { + "Maxgroupsperfabric 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 subscribeMaxGroupsPerFabricAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Maxgroupsperfabric attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Maxgroupsperfabric attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -571,77 +625,80 @@ class GroupKeyManagementCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readMaxGroupKeysPerFabricAttribute(): UShort { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMaxGroupKeysPerFabricAttribute(): UShort {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}") - } + 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) { "Maxgroupkeysperfabric attribute not found in response" } + } + + requireNotNull(attributeData) { + "Maxgroupkeysperfabric 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 subscribeMaxGroupKeysPerFabricAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Maxgroupkeysperfabric attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Maxgroupkeysperfabric attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -654,96 +711,97 @@ class GroupKeyManagementCluster( emit(UShortSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -751,96 +809,97 @@ class GroupKeyManagementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -848,94 +907,97 @@ class GroupKeyManagementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -943,94 +1005,97 @@ class GroupKeyManagementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1038,76 +1103,81 @@ class GroupKeyManagementCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1119,77 +1189,80 @@ class GroupKeyManagementCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1202,7 +1275,7 @@ class GroupKeyManagementCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/GroupsCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/GroupsCluster.kt index 6af48037daf4f7..3c4c4edab256b0 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/GroupsCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/GroupsCluster.kt @@ -17,83 +17,125 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter class GroupsCluster(private val controller: MatterController, private val endpointId: UShort) { - class AddGroupResponse(val status: UByte, val groupID: UShort) - - class ViewGroupResponse(val status: UByte, val groupID: UShort, val groupName: String) - - class GetGroupMembershipResponse(val capacity: UByte?, val groupList: List) - - class RemoveGroupResponse(val status: UByte, val groupID: UShort) - - class GeneratedCommandListAttribute(val value: List) + class AddGroupResponse( + val status: UByte, + val groupID: UShort + ) + + class ViewGroupResponse( + val status: UByte, + val groupID: UShort, + val groupName: String + ) + + class GetGroupMembershipResponse( + val capacity: UByte?, + val groupList: List + ) + + class RemoveGroupResponse( + val status: UByte, + val groupID: UShort + ) +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun addGroup( - groupID: UShort, - groupName: String, - timedInvokeTimeout: Duration? = null, - ): AddGroupResponse { + suspend fun addGroup(groupID: UShort + ,groupName: String + ,timedInvokeTimeout: Duration? = null): AddGroupResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() @@ -103,14 +145,14 @@ class GroupsCluster(private val controller: MatterController, private val endpoi tlvWriter.put(ContextSpecificTag(TAG_GROUP_ID_REQ), groupID) val TAG_GROUP_NAME_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_GROUP_NAME_REQ), groupName) + tlvWriter.put(ContextSpecificTag(TAG_GROUP_NAME_REQ), groupName) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -120,52 +162,61 @@ class GroupsCluster(private val controller: MatterController, private val endpoi tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_GROUP_ID: 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_STATUS)) {status_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_GROUP_ID)) {groupID_decoded = tlvReader.getUShort(tag)} + - if (tag == ContextSpecificTag(TAG_GROUP_ID)) { - groupID_decoded = tlvReader.getUShort(tag) - } else { + else { tlvReader.skipElement() } } + + if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - + + if (groupID_decoded == null) { - throw IllegalStateException("groupID not found in TLV") + throw IllegalStateException("groupID not found in TLV") } + tlvReader.exitContainer() - return AddGroupResponse(status_decoded, groupID_decoded) + return AddGroupResponse( + status_decoded, + groupID_decoded + ) } - suspend fun viewGroup(groupID: UShort, timedInvokeTimeout: Duration? = null): ViewGroupResponse { + suspend fun viewGroup(groupID: UShort + ,timedInvokeTimeout: Duration? = null): ViewGroupResponse { val commandId: UInt = 1u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_GROUP_ID_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_GROUP_ID_REQ), groupID) + tlvWriter.put(ContextSpecificTag(TAG_GROUP_ID_REQ), groupID) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -175,52 +226,58 @@ class GroupsCluster(private val controller: MatterController, private val endpoi tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_GROUP_ID: Int = 1 var groupID_decoded: UShort? = null - + val TAG_GROUP_NAME: Int = 2 var groupName_decoded: String? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_STATUS)) { - status_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_GROUP_ID)) { - groupID_decoded = tlvReader.getUShort(tag) - } + + if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_GROUP_ID)) {groupID_decoded = tlvReader.getUShort(tag)} + + if (tag == ContextSpecificTag(TAG_GROUP_NAME)) {groupName_decoded = tlvReader.getString(tag)} + - if (tag == ContextSpecificTag(TAG_GROUP_NAME)) { - groupName_decoded = tlvReader.getString(tag) - } else { + else { tlvReader.skipElement() } } + + if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - + + if (groupID_decoded == null) { - throw IllegalStateException("groupID not found in TLV") + throw IllegalStateException("groupID not found in TLV") } - + + if (groupName_decoded == null) { - throw IllegalStateException("groupName not found in TLV") + throw IllegalStateException("groupName not found in TLV") } + tlvReader.exitContainer() - return ViewGroupResponse(status_decoded, groupID_decoded, groupName_decoded) + return ViewGroupResponse( + status_decoded, + groupID_decoded, + groupName_decoded + ) } - suspend fun getGroupMembership( - groupList: List, - timedInvokeTimeout: Duration? = null, - ): GetGroupMembershipResponse { + suspend fun getGroupMembership(groupList: List + ,timedInvokeTimeout: Duration? = null): GetGroupMembershipResponse { val commandId: UInt = 2u val tlvWriter = TlvWriter() @@ -228,17 +285,17 @@ class GroupsCluster(private val controller: MatterController, private val endpoi val TAG_GROUP_LIST_REQ: Int = 0 tlvWriter.startArray(ContextSpecificTag(TAG_GROUP_LIST_REQ)) - for (item in groupList.iterator()) { - tlvWriter.put(AnonymousTag, item) - } - tlvWriter.endArray() + for (item in groupList.iterator()) { + tlvWriter.put(AnonymousTag, item) + } + tlvWriter.endArray() tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -248,69 +305,75 @@ class GroupsCluster(private val controller: MatterController, private val endpoi tlvReader.enterStructure(AnonymousTag) val TAG_CAPACITY: Int = 0 var capacity_decoded: UByte? = null - + val TAG_GROUP_LIST: Int = 1 var groupList_decoded: List? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_CAPACITY)) { - capacity_decoded = + + 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 - } - } + tlvReader.getUByte(tag) + } else { + tlvReader.getNull(tag) + null + } + }} + + if (tag == ContextSpecificTag(TAG_GROUP_LIST)) {groupList_decoded = buildList { + tlvReader.enterArray(tag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUShort(AnonymousTag)) } + tlvReader.exitContainer() + }} + - if (tag == ContextSpecificTag(TAG_GROUP_LIST)) { - groupList_decoded = - buildList { - tlvReader.enterArray(tag) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getUShort(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { + else { tlvReader.skipElement() } } + + + + if (groupList_decoded == null) { - throw IllegalStateException("groupList not found in TLV") + throw IllegalStateException("groupList not found in TLV") } + tlvReader.exitContainer() - return GetGroupMembershipResponse(capacity_decoded, groupList_decoded) + return GetGroupMembershipResponse( + capacity_decoded, + groupList_decoded + ) } - suspend fun removeGroup( - groupID: UShort, - timedInvokeTimeout: Duration? = null, - ): RemoveGroupResponse { + suspend fun removeGroup(groupID: UShort + ,timedInvokeTimeout: Duration? = null): RemoveGroupResponse { val commandId: UInt = 3u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_GROUP_ID_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_GROUP_ID_REQ), groupID) + tlvWriter.put(ContextSpecificTag(TAG_GROUP_ID_REQ), groupID) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -320,60 +383,66 @@ class GroupsCluster(private val controller: MatterController, private val endpoi tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_GROUP_ID: 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_STATUS)) {status_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_GROUP_ID)) {groupID_decoded = tlvReader.getUShort(tag)} + - if (tag == ContextSpecificTag(TAG_GROUP_ID)) { - groupID_decoded = tlvReader.getUShort(tag) - } else { + else { tlvReader.skipElement() } } + + if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - + + if (groupID_decoded == null) { - throw IllegalStateException("groupID not found in TLV") + throw IllegalStateException("groupID not found in TLV") } + tlvReader.exitContainer() - return RemoveGroupResponse(status_decoded, groupID_decoded) + return RemoveGroupResponse( + status_decoded, + groupID_decoded + ) } suspend fun removeAllGroups(timedInvokeTimeout: Duration? = null) { val commandId: UInt = 4u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun addGroupIfIdentifying( - groupID: UShort, - groupName: String, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun addGroupIfIdentifying(groupID: UShort + ,groupName: String + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 5u val tlvWriter = TlvWriter() @@ -383,87 +452,92 @@ class GroupsCluster(private val controller: MatterController, private val endpoi tlvWriter.put(ContextSpecificTag(TAG_GROUP_ID_REQ), groupID) val TAG_GROUP_NAME_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_GROUP_NAME_REQ), groupName) + tlvWriter.put(ContextSpecificTag(TAG_GROUP_NAME_REQ), groupName) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - - suspend fun readNameSupportAttribute(): 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)) - +suspend fun readNameSupportAttribute(): 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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -475,96 +549,97 @@ class GroupsCluster(private val controller: MatterController, private val endpoi emit(UByteSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -572,96 +647,97 @@ class GroupsCluster(private val controller: MatterController, private val endpoi 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -669,94 +745,97 @@ class GroupsCluster(private val controller: MatterController, private val endpoi 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -764,94 +843,97 @@ class GroupsCluster(private val controller: MatterController, private val endpoi 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -859,76 +941,81 @@ class GroupsCluster(private val controller: MatterController, private val endpoi 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -940,77 +1027,80 @@ class GroupsCluster(private val controller: MatterController, private val endpoi 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1023,7 +1113,7 @@ class GroupsCluster(private val controller: MatterController, private val endpoi emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/HepaFilterMonitoringCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/HepaFilterMonitoringCluster.kt index f6337f9fac983f..8ca45695cd230c 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/HepaFilterMonitoringCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/HepaFilterMonitoringCluster.kt @@ -17,369 +17,410 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration 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.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.cluster.structs.* +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class HepaFilterMonitoringCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class LastChangedTimeAttribute(val value: UInt?) +class HepaFilterMonitoringCluster(private val controller: MatterController, private val endpointId: UShort) {class LastChangedTimeAttribute( + val value: UInt? + ) sealed class LastChangedTimeAttributeSubscriptionState { - data class Success(val value: UInt?) : LastChangedTimeAttributeSubscriptionState() - + data class Success( + val value: UInt? + ) : LastChangedTimeAttributeSubscriptionState() + data class Error(val exception: Exception) : LastChangedTimeAttributeSubscriptionState() - object SubscriptionEstablished : LastChangedTimeAttributeSubscriptionState() - } - - class ReplacementProductListAttribute( + object SubscriptionEstablished : LastChangedTimeAttributeSubscriptionState() + } +class ReplacementProductListAttribute( val value: List? ) sealed class ReplacementProductListAttributeSubscriptionState { - data class Success(val value: List?) : - ReplacementProductListAttributeSubscriptionState() - + data class Success( + val value: List? + ) : ReplacementProductListAttributeSubscriptionState() + data class Error(val exception: Exception) : ReplacementProductListAttributeSubscriptionState() - object SubscriptionEstablished : ReplacementProductListAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : ReplacementProductListAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } suspend fun resetCondition(timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - - suspend fun readConditionAttribute(): 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)) - +suspend fun readConditionAttribute(): 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}") - } + 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) { "Condition attribute not found in response" } + } + + requireNotNull(attributeData) { + "Condition 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeConditionAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Condition attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Condition 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)) } + 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 readDegradationDirectionAttribute(): 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)) - +suspend fun readDegradationDirectionAttribute(): 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}") - } + 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) { "Degradationdirection attribute not found in response" } + } + + requireNotNull(attributeData) { + "Degradationdirection 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeDegradationDirectionAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Degradationdirection attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Degradationdirection 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)) } + 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 readChangeIndicationAttribute(): UByte { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readChangeIndicationAttribute(): UByte {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}") - } + 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) { "Changeindication attribute not found in response" } + } + + requireNotNull(attributeData) { + "Changeindication 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 subscribeChangeIndicationAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Changeindication attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Changeindication attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -392,160 +433,174 @@ class HepaFilterMonitoringCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readInPlaceIndicatorAttribute(): 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)) - +suspend fun readInPlaceIndicatorAttribute(): 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}") - } + 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) { "Inplaceindicator attribute not found in response" } + } + + requireNotNull(attributeData) { + "Inplaceindicator 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 - } + val decodedValue: Boolean? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeInPlaceIndicatorAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Inplaceindicator attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Inplaceindicator 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)) } + 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 readLastChangedTimeAttribute(): LastChangedTimeAttribute { - val ATTRIBUTE_ID: UInt = 4u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readLastChangedTimeAttribute(): LastChangedTimeAttribute {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}") - } + 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) { "Lastchangedtime attribute not found in response" } + } + + requireNotNull(attributeData) { + "Lastchangedtime attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return LastChangedTimeAttribute(decodedValue) } - suspend fun writeLastChangedTimeAttribute(value: UInt, timedWriteTimeout: Duration? = null) { + suspend fun writeLastChangedTimeAttribute( + value: UInt, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 4u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -566,270 +621,266 @@ class HepaFilterMonitoringCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeLastChangedTimeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - LastChangedTimeAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(LastChangedTimeAttributeSubscriptionState.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) { - "Lastchangedtime attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Lastchangedtime attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(LastChangedTimeAttributeSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(LastChangedTimeAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(LastChangedTimeAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readReplacementProductListAttribute(): ReplacementProductListAttribute { - val ATTRIBUTE_ID: UInt = 5u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readReplacementProductListAttribute(): ReplacementProductListAttribute {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}") - } + 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) { "Replacementproductlist attribute not found in response" } + } + + requireNotNull(attributeData) { + "Replacementproductlist attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add( - HepaFilterMonitoringClusterReplacementProductStruct.fromTlv(AnonymousTag, tlvReader) - ) - } - tlvReader.exitContainer() - } - } else { - null + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(HepaFilterMonitoringClusterReplacementProductStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + } else { + null + } + return ReplacementProductListAttribute(decodedValue) } suspend fun subscribeReplacementProductListAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ReplacementProductListAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ReplacementProductListAttributeSubscriptionState.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) { - "Replacementproductlist attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Replacementproductlist attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add( - HepaFilterMonitoringClusterReplacementProductStruct.fromTlv( - AnonymousTag, - tlvReader, - ) - ) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { emit(ReplacementProductListAttributeSubscriptionState.Success(it)) } + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(HepaFilterMonitoringClusterReplacementProductStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { + emit(ReplacementProductListAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ReplacementProductListAttributeSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -837,96 +888,97 @@ class HepaFilterMonitoringCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -934,94 +986,97 @@ class HepaFilterMonitoringCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1029,94 +1084,97 @@ class HepaFilterMonitoringCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1124,76 +1182,81 @@ class HepaFilterMonitoringCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1205,77 +1268,80 @@ class HepaFilterMonitoringCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1288,7 +1354,7 @@ class HepaFilterMonitoringCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/IcdManagementCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/IcdManagementCluster.kt index 414e38d360a803..6eb93060a63d9d 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/IcdManagementCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/IcdManagementCluster.kt @@ -17,99 +17,128 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest -import matter.controller.StringSubscriptionState +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class IcdManagementCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class RegisterClientResponse(val ICDCounter: UInt) - - class StayActiveResponse(val promisedActiveDuration: UInt) +class IcdManagementCluster(private val controller: MatterController, private val endpointId: UShort) { + class RegisterClientResponse( + val ICDCounter: UInt + ) - class RegisteredClientsAttribute( + class StayActiveResponse( + val promisedActiveDuration: UInt + ) +class RegisteredClientsAttribute( val value: List? ) sealed class RegisteredClientsAttributeSubscriptionState { - data class Success(val value: List?) : - RegisteredClientsAttributeSubscriptionState() - + data class Success( + val value: List? + ) : RegisteredClientsAttributeSubscriptionState() + data class Error(val exception: Exception) : RegisteredClientsAttributeSubscriptionState() - object SubscriptionEstablished : RegisteredClientsAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : RegisteredClientsAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun registerClient( - checkInNodeID: ULong, - monitoredSubject: ULong, - key: ByteArray, - verificationKey: ByteArray?, - clientType: UByte, - timedInvokeTimeout: Duration? = null, - ): RegisterClientResponse { + suspend fun registerClient(checkInNodeID: ULong + ,monitoredSubject: ULong + ,key: ByteArray + ,verificationKey: ByteArray? + ,clientType: UByte + ,timedInvokeTimeout: Duration? = null): RegisterClientResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() @@ -130,14 +159,14 @@ class IcdManagementCluster( } val TAG_CLIENT_TYPE_REQ: Int = 4 - tlvWriter.put(ContextSpecificTag(TAG_CLIENT_TYPE_REQ), clientType) + tlvWriter.put(ContextSpecificTag(TAG_CLIENT_TYPE_REQ), clientType) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -147,31 +176,37 @@ class IcdManagementCluster( tlvReader.enterStructure(AnonymousTag) val TAG_ICD_COUNTER: Int = 0 var ICDCounter_decoded: UInt? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_ICD_COUNTER)) { - ICDCounter_decoded = tlvReader.getUInt(tag) - } else { + + if (tag == ContextSpecificTag(TAG_ICD_COUNTER)) {ICDCounter_decoded = tlvReader.getUInt(tag)} + + + else { tlvReader.skipElement() } } + + if (ICDCounter_decoded == null) { - throw IllegalStateException("ICDCounter not found in TLV") + throw IllegalStateException("ICDCounter not found in TLV") } + tlvReader.exitContainer() - return RegisterClientResponse(ICDCounter_decoded) + return RegisterClientResponse( + ICDCounter_decoded + ) } - suspend fun unregisterClient( - checkInNodeID: ULong, - verificationKey: ByteArray?, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun unregisterClient(checkInNodeID: ULong + ,verificationKey: ByteArray? + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 2u val tlvWriter = TlvWriter() @@ -183,38 +218,36 @@ class IcdManagementCluster( val TAG_VERIFICATION_KEY_REQ: Int = 1 verificationKey?.let { tlvWriter.put(ContextSpecificTag(TAG_VERIFICATION_KEY_REQ), verificationKey) - } + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun stayActiveRequest( - stayActiveDuration: UInt, - timedInvokeTimeout: Duration? = null, - ): StayActiveResponse { + suspend fun stayActiveRequest(stayActiveDuration: UInt + ,timedInvokeTimeout: Duration? = null): StayActiveResponse { val commandId: UInt = 3u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_STAY_ACTIVE_DURATION_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_STAY_ACTIVE_DURATION_REQ), stayActiveDuration) + tlvWriter.put(ContextSpecificTag(TAG_STAY_ACTIVE_DURATION_REQ), stayActiveDuration) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -224,94 +257,105 @@ class IcdManagementCluster( tlvReader.enterStructure(AnonymousTag) val TAG_PROMISED_ACTIVE_DURATION: Int = 0 var promisedActiveDuration_decoded: UInt? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_PROMISED_ACTIVE_DURATION)) { - promisedActiveDuration_decoded = tlvReader.getUInt(tag) - } else { + + if (tag == ContextSpecificTag(TAG_PROMISED_ACTIVE_DURATION)) {promisedActiveDuration_decoded = tlvReader.getUInt(tag)} + + + else { tlvReader.skipElement() } } + + if (promisedActiveDuration_decoded == null) { - throw IllegalStateException("promisedActiveDuration not found in TLV") + throw IllegalStateException("promisedActiveDuration not found in TLV") } + tlvReader.exitContainer() - return StayActiveResponse(promisedActiveDuration_decoded) + return StayActiveResponse( + promisedActiveDuration_decoded + ) } - - suspend fun readIdleModeDurationAttribute(): UInt { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readIdleModeDurationAttribute(): UInt {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}") - } + 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) { "Idlemodeduration attribute not found in response" } + } + + requireNotNull(attributeData) { + "Idlemodeduration 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 subscribeIdleModeDurationAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Idlemodeduration attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Idlemodeduration attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -324,77 +368,80 @@ class IcdManagementCluster( emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readActiveModeDurationAttribute(): UInt { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readActiveModeDurationAttribute(): UInt {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}") - } + 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) { "Activemodeduration attribute not found in response" } + } + + requireNotNull(attributeData) { + "Activemodeduration 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 subscribeActiveModeDurationAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Activemodeduration attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Activemodeduration attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -407,77 +454,80 @@ class IcdManagementCluster( emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readActiveModeThresholdAttribute(): 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)) - +suspend fun readActiveModeThresholdAttribute(): 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}") - } + 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) { "Activemodethreshold attribute not found in response" } + } + + requireNotNull(attributeData) { + "Activemodethreshold 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 subscribeActiveModeThresholdAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Activemodethreshold attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Activemodethreshold attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -490,762 +540,788 @@ class IcdManagementCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readRegisteredClientsAttribute(): RegisteredClientsAttribute { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readRegisteredClientsAttribute(): RegisteredClientsAttribute {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}") - } + 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) { "Registeredclients attribute not found in response" } + } + + requireNotNull(attributeData) { + "Registeredclients attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(IcdManagementClusterMonitoringRegistrationStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(IcdManagementClusterMonitoringRegistrationStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + } else { + null + } + return RegisteredClientsAttribute(decodedValue) } suspend fun subscribeRegisteredClientsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - RegisteredClientsAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(RegisteredClientsAttributeSubscriptionState.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) { - "Registeredclients attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Registeredclients attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add( - IcdManagementClusterMonitoringRegistrationStruct.fromTlv( - AnonymousTag, - tlvReader, - ) - ) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { emit(RegisteredClientsAttributeSubscriptionState.Success(it)) } + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(IcdManagementClusterMonitoringRegistrationStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { + emit(RegisteredClientsAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(RegisteredClientsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readICDCounterAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 4u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readICDCounterAttribute(): UInt? {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}") - } + 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) { "Icdcounter attribute not found in response" } + } + + requireNotNull(attributeData) { + "Icdcounter attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeICDCounterAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Icdcounter attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Icdcounter attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readClientsSupportedPerFabricAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 5u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readClientsSupportedPerFabricAttribute(): UShort? {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}") - } + 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) { "Clientssupportedperfabric attribute not found in response" } + } + + requireNotNull(attributeData) { + "Clientssupportedperfabric 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeClientsSupportedPerFabricAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Clientssupportedperfabric attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Clientssupportedperfabric 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)) } + 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 readUserActiveModeTriggerHintAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 6u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readUserActiveModeTriggerHintAttribute(): UInt? {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}") - } + 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) { "Useractivemodetriggerhint attribute not found in response" } + } + + requireNotNull(attributeData) { + "Useractivemodetriggerhint attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeUserActiveModeTriggerHintAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Useractivemodetriggerhint attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Useractivemodetriggerhint attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readUserActiveModeTriggerInstructionAttribute(): String? { - val ATTRIBUTE_ID: UInt = 7u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readUserActiveModeTriggerInstructionAttribute(): String? {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}") - } + 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) { - "Useractivemodetriggerinstruction attribute not found in response" + } + + requireNotNull(attributeData) { + "Useractivemodetriggerinstruction attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeUserActiveModeTriggerInstructionAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StringSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StringSubscriptionState.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) { - "Useractivemodetriggerinstruction attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Useractivemodetriggerinstruction attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(StringSubscriptionState.Success(it)) } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(StringSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readOperatingModeAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 8u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readOperatingModeAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 8u + + 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}") - } + 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) { "Operatingmode attribute not found in response" } + } + + requireNotNull(attributeData) { + "Operatingmode 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeOperatingModeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Operatingmode attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Operatingmode 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)) } + 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 readMaximumCheckInBackOffAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 9u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMaximumCheckInBackOffAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 9u + + 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}") - } + 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) { "Maximumcheckinbackoff attribute not found in response" } + } + + requireNotNull(attributeData) { + "Maximumcheckinbackoff attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeMaximumCheckInBackOffAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Maximumcheckinbackoff attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Maximumcheckinbackoff attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1253,96 +1329,97 @@ class IcdManagementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1350,94 +1427,97 @@ class IcdManagementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1445,94 +1525,97 @@ class IcdManagementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1540,76 +1623,81 @@ class IcdManagementCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1621,77 +1709,80 @@ class IcdManagementCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1704,7 +1795,7 @@ class IcdManagementCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/IdentifyCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/IdentifyCluster.kt index b120e941cac02b..cdf0dd8d361438 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/IdentifyCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/IdentifyCluster.kt @@ -17,99 +17,126 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.cluster.structs.* +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class IdentifyCluster(private val controller: MatterController, private val endpointId: UShort) { - class GeneratedCommandListAttribute(val value: List) +class IdentifyCluster(private val controller: MatterController, private val endpointId: UShort) {class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun identify(identifyTime: UShort, timedInvokeTimeout: Duration? = null) { + suspend fun identify(identifyTime: UShort + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_IDENTIFY_TIME_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_IDENTIFY_TIME_REQ), identifyTime) + tlvWriter.put(ContextSpecificTag(TAG_IDENTIFY_TIME_REQ), identifyTime) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun triggerEffect( - effectIdentifier: UByte, - effectVariant: UByte, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun triggerEffect(effectIdentifier: UByte + ,effectVariant: UByte + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 64u val tlvWriter = TlvWriter() @@ -119,68 +146,79 @@ class IdentifyCluster(private val controller: MatterController, private val endp tlvWriter.put(ContextSpecificTag(TAG_EFFECT_IDENTIFIER_REQ), effectIdentifier) val TAG_EFFECT_VARIANT_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_EFFECT_VARIANT_REQ), effectVariant) + tlvWriter.put(ContextSpecificTag(TAG_EFFECT_VARIANT_REQ), effectVariant) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - - suspend fun readIdentifyTimeAttribute(): UShort { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readIdentifyTimeAttribute(): UShort {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}") - } + 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) { "Identifytime attribute not found in response" } + } + + requireNotNull(attributeData) { + "Identifytime 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 writeIdentifyTimeAttribute(value: UShort, timedWriteTimeout: Duration? = null) { + suspend fun writeIdentifyTimeAttribute( + value: UShort, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -201,45 +239,43 @@ class IdentifyCluster(private val controller: MatterController, private val endp throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeIdentifyTimeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Identifytime attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Identifytime attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -251,76 +287,81 @@ class IdentifyCluster(private val controller: MatterController, private val endp emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readIdentifyTypeAttribute(): 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)) - +suspend fun readIdentifyTypeAttribute(): 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}") - } + 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) { "Identifytype attribute not found in response" } + } + + requireNotNull(attributeData) { + "Identifytype 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 subscribeIdentifyTypeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Identifytype attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Identifytype attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -332,96 +373,97 @@ class IdentifyCluster(private val controller: MatterController, private val endp emit(UByteSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -429,96 +471,97 @@ class IdentifyCluster(private val controller: MatterController, private val endp 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -526,94 +569,97 @@ class IdentifyCluster(private val controller: MatterController, private val endp 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -621,94 +667,97 @@ class IdentifyCluster(private val controller: MatterController, private val endp 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -716,76 +765,81 @@ class IdentifyCluster(private val controller: MatterController, private val endp 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -797,77 +851,80 @@ class IdentifyCluster(private val controller: MatterController, private val endp 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -880,7 +937,7 @@ class IdentifyCluster(private val controller: MatterController, private val endp emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/IlluminanceMeasurementCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/IlluminanceMeasurementCluster.kt index b5af4230e86c34..cbfb9f08ed8a40 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/IlluminanceMeasurementCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/IlluminanceMeasurementCluster.kt @@ -17,671 +17,742 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.UIntSubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState +import matter.controller.UByteSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath +import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader +import matter.tlv.TlvWriter -class IlluminanceMeasurementCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class MeasuredValueAttribute(val value: UShort?) +class IlluminanceMeasurementCluster(private val controller: MatterController, private val endpointId: UShort) {class MeasuredValueAttribute( + val value: UShort? + ) sealed class MeasuredValueAttributeSubscriptionState { - data class Success(val value: UShort?) : MeasuredValueAttributeSubscriptionState() - + data class Success( + val value: UShort? + ) : MeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() - } - - class MinMeasuredValueAttribute(val value: UShort?) + object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() + } +class MinMeasuredValueAttribute( + val value: UShort? + ) sealed class MinMeasuredValueAttributeSubscriptionState { - data class Success(val value: UShort?) : MinMeasuredValueAttributeSubscriptionState() - + data class Success( + val value: UShort? + ) : MinMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MinMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() - } - - class MaxMeasuredValueAttribute(val value: UShort?) + object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() + } +class MaxMeasuredValueAttribute( + val value: UShort? + ) sealed class MaxMeasuredValueAttributeSubscriptionState { - data class Success(val value: UShort?) : MaxMeasuredValueAttributeSubscriptionState() - + data class Success( + val value: UShort? + ) : MaxMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MaxMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() - } - - class LightSensorTypeAttribute(val value: UByte?) + object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() + } +class LightSensorTypeAttribute( + val value: UByte? + ) sealed class LightSensorTypeAttributeSubscriptionState { - data class Success(val value: UByte?) : LightSensorTypeAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : LightSensorTypeAttributeSubscriptionState() + data class Error(val exception: Exception) : LightSensorTypeAttributeSubscriptionState() - object SubscriptionEstablished : LightSensorTypeAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : LightSensorTypeAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } - - suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } +suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute {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}") - } + 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) { "Measuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Measuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = - if (!tlvReader.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MeasuredValueAttribute(decodedValue) } suspend fun subscribeMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MeasuredValueAttributeSubscriptionState.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) { "Measuredvalue attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Measuredvalue 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.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute {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}") - } + 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) { "Minmeasuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Minmeasuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = - if (!tlvReader.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MinMeasuredValueAttribute(decodedValue) } suspend fun subscribeMinMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MinMeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MinMeasuredValueAttributeSubscriptionState.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) { - "Minmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Minmeasuredvalue 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.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MinMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute {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}") - } + 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) { "Maxmeasuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Maxmeasuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = - if (!tlvReader.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MaxMeasuredValueAttribute(decodedValue) } suspend fun subscribeMaxMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MaxMeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MaxMeasuredValueAttributeSubscriptionState.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) { - "Maxmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Maxmeasuredvalue 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.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MaxMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readToleranceAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readToleranceAttribute(): UShort? {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}") - } + 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) { "Tolerance attribute not found in response" } + } + + requireNotNull(attributeData) { + "Tolerance 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeToleranceAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Tolerance attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Tolerance 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)) } + 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 readLightSensorTypeAttribute(): LightSensorTypeAttribute { - val ATTRIBUTE_ID: UInt = 4u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readLightSensorTypeAttribute(): LightSensorTypeAttribute {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}") - } + 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) { "Lightsensortype attribute not found in response" } + } + + requireNotNull(attributeData) { + "Lightsensortype attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return LightSensorTypeAttribute(decodedValue) } suspend fun subscribeLightSensorTypeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - LightSensorTypeAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(LightSensorTypeAttributeSubscriptionState.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) { - "Lightsensortype attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Lightsensortype 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(LightSensorTypeAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(LightSensorTypeAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(LightSensorTypeAttributeSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -689,96 +760,97 @@ class IlluminanceMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -786,94 +858,97 @@ class IlluminanceMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -881,94 +956,97 @@ class IlluminanceMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -976,76 +1054,81 @@ class IlluminanceMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1057,77 +1140,80 @@ class IlluminanceMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1140,7 +1226,7 @@ class IlluminanceMeasurementCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/KeypadInputCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/KeypadInputCluster.kt index eb59229ab1a415..168b0718b0ff16 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/KeypadInputCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/KeypadInputCluster.kt @@ -17,86 +17,121 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.UIntSubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState +import matter.controller.UByteSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter class KeypadInputCluster(private val controller: MatterController, private val endpointId: UShort) { - class SendKeyResponse(val status: UByte) - - class GeneratedCommandListAttribute(val value: List) + class SendKeyResponse( + val status: UByte + ) +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun sendKey(keyCode: UByte, timedInvokeTimeout: Duration? = null): SendKeyResponse { + suspend fun sendKey(keyCode: UByte + ,timedInvokeTimeout: Duration? = null): SendKeyResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_KEY_CODE_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_KEY_CODE_REQ), keyCode) + tlvWriter.put(ContextSpecificTag(TAG_KEY_CODE_REQ), keyCode) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -106,113 +141,122 @@ class KeypadInputCluster(private val controller: MatterController, private val e tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_STATUS)) { - status_decoded = tlvReader.getUByte(tag) - } else { + + if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} + + + else { tlvReader.skipElement() } } + + if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } + tlvReader.exitContainer() - return SendKeyResponse(status_decoded) + return SendKeyResponse( + status_decoded + ) } - - 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -220,96 +264,97 @@ class KeypadInputCluster(private val controller: MatterController, private val e 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -317,94 +362,97 @@ class KeypadInputCluster(private val controller: MatterController, private val e 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -412,94 +460,97 @@ class KeypadInputCluster(private val controller: MatterController, private val e 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -507,76 +558,81 @@ class KeypadInputCluster(private val controller: MatterController, private val e 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -588,77 +644,80 @@ class KeypadInputCluster(private val controller: MatterController, private val e 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -671,7 +730,7 @@ class KeypadInputCluster(private val controller: MatterController, private val e emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/LaundryDryerControlsCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/LaundryDryerControlsCluster.kt index 9bd0fdf90b4b2a..c4800abe53cffd 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/LaundryDryerControlsCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/LaundryDryerControlsCluster.kt @@ -17,178 +17,215 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.UIntSubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState +import matter.controller.UByteSubscriptionState import matter.controller.UShortSubscriptionState +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.cluster.structs.* +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath +import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class LaundryDryerControlsCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class SupportedDrynessLevelsAttribute(val value: List) +class LaundryDryerControlsCluster(private val controller: MatterController, private val endpointId: UShort) {class SupportedDrynessLevelsAttribute( + val value: List + ) sealed class SupportedDrynessLevelsAttributeSubscriptionState { - data class Success(val value: List) : SupportedDrynessLevelsAttributeSubscriptionState() - + data class Success( + val value: List + ) : SupportedDrynessLevelsAttributeSubscriptionState() + data class Error(val exception: Exception) : SupportedDrynessLevelsAttributeSubscriptionState() - object SubscriptionEstablished : SupportedDrynessLevelsAttributeSubscriptionState() - } - - class SelectedDrynessLevelAttribute(val value: UByte?) + object SubscriptionEstablished : SupportedDrynessLevelsAttributeSubscriptionState() + } +class SelectedDrynessLevelAttribute( + val value: UByte? + ) sealed class SelectedDrynessLevelAttributeSubscriptionState { - data class Success(val value: UByte?) : SelectedDrynessLevelAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : SelectedDrynessLevelAttributeSubscriptionState() + data class Error(val exception: Exception) : SelectedDrynessLevelAttributeSubscriptionState() - object SubscriptionEstablished : SelectedDrynessLevelAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : SelectedDrynessLevelAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } - - suspend fun readSupportedDrynessLevelsAttribute(): SupportedDrynessLevelsAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } +suspend fun readSupportedDrynessLevelsAttribute(): SupportedDrynessLevelsAttribute {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}") - } + 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) { "Supporteddrynesslevels attribute not found in response" } + } + + requireNotNull(attributeData) { + "Supporteddrynesslevels 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.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) } + tlvReader.exitContainer() + } + return SupportedDrynessLevelsAttribute(decodedValue) } suspend fun subscribeSupportedDrynessLevelsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - SupportedDrynessLevelsAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(SupportedDrynessLevelsAttributeSubscriptionState.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) { - "Supporteddrynesslevels attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Supporteddrynesslevels 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.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(SupportedDrynessLevelsAttributeSubscriptionState.Success(decodedValue)) } @@ -196,66 +233,73 @@ class LaundryDryerControlsCluster( emit(SupportedDrynessLevelsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readSelectedDrynessLevelAttribute(): SelectedDrynessLevelAttribute { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readSelectedDrynessLevelAttribute(): SelectedDrynessLevelAttribute {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}") - } + 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) { "Selecteddrynesslevel attribute not found in response" } + } + + requireNotNull(attributeData) { + "Selecteddrynesslevel attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return SelectedDrynessLevelAttribute(decodedValue) } suspend fun writeSelectedDrynessLevelAttribute( value: UByte, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 1u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -276,154 +320,153 @@ class LaundryDryerControlsCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeSelectedDrynessLevelAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - SelectedDrynessLevelAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(SelectedDrynessLevelAttributeSubscriptionState.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) { - "Selecteddrynesslevel attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Selecteddrynesslevel 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.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(SelectedDrynessLevelAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(SelectedDrynessLevelAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(SelectedDrynessLevelAttributeSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -431,96 +474,97 @@ class LaundryDryerControlsCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -528,94 +572,97 @@ class LaundryDryerControlsCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -623,94 +670,97 @@ class LaundryDryerControlsCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -718,76 +768,81 @@ class LaundryDryerControlsCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -799,77 +854,80 @@ class LaundryDryerControlsCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -882,7 +940,7 @@ class LaundryDryerControlsCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/LaundryWasherControlsCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/LaundryWasherControlsCluster.kt index 0fb11d882daa52..2e547ec206a574 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/LaundryWasherControlsCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/LaundryWasherControlsCluster.kt @@ -17,263 +17,317 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.cluster.structs.* +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath +import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class LaundryWasherControlsCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class SpinSpeedsAttribute(val value: List?) +class LaundryWasherControlsCluster(private val controller: MatterController, private val endpointId: UShort) {class SpinSpeedsAttribute( + val value: List? + ) sealed class SpinSpeedsAttributeSubscriptionState { - data class Success(val value: List?) : SpinSpeedsAttributeSubscriptionState() - + data class Success( + val value: List? + ) : SpinSpeedsAttributeSubscriptionState() + data class Error(val exception: Exception) : SpinSpeedsAttributeSubscriptionState() - object SubscriptionEstablished : SpinSpeedsAttributeSubscriptionState() - } - - class SpinSpeedCurrentAttribute(val value: UByte?) + object SubscriptionEstablished : SpinSpeedsAttributeSubscriptionState() + } +class SpinSpeedCurrentAttribute( + val value: UByte? + ) sealed class SpinSpeedCurrentAttributeSubscriptionState { - data class Success(val value: UByte?) : SpinSpeedCurrentAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : SpinSpeedCurrentAttributeSubscriptionState() + data class Error(val exception: Exception) : SpinSpeedCurrentAttributeSubscriptionState() - object SubscriptionEstablished : SpinSpeedCurrentAttributeSubscriptionState() - } - - class SupportedRinsesAttribute(val value: List?) + object SubscriptionEstablished : SpinSpeedCurrentAttributeSubscriptionState() + } +class SupportedRinsesAttribute( + val value: List? + ) sealed class SupportedRinsesAttributeSubscriptionState { - data class Success(val value: List?) : SupportedRinsesAttributeSubscriptionState() - + data class Success( + val value: List? + ) : SupportedRinsesAttributeSubscriptionState() + data class Error(val exception: Exception) : SupportedRinsesAttributeSubscriptionState() - object SubscriptionEstablished : SupportedRinsesAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : SupportedRinsesAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } - - suspend fun readSpinSpeedsAttribute(): SpinSpeedsAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } +suspend fun readSpinSpeedsAttribute(): SpinSpeedsAttribute {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}") - } + 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) { "Spinspeeds attribute not found in response" } + } + + requireNotNull(attributeData) { + "Spinspeeds attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getString(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getString(AnonymousTag)) } + tlvReader.exitContainer() + } + } else { + null + } + return SpinSpeedsAttribute(decodedValue) } suspend fun subscribeSpinSpeedsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - SpinSpeedsAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(SpinSpeedsAttributeSubscriptionState.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) { "Spinspeeds attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Spinspeeds attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getString(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { emit(SpinSpeedsAttributeSubscriptionState.Success(it)) } + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getString(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { + emit(SpinSpeedsAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(SpinSpeedsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readSpinSpeedCurrentAttribute(): SpinSpeedCurrentAttribute { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readSpinSpeedCurrentAttribute(): SpinSpeedCurrentAttribute {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}") - } + 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) { "Spinspeedcurrent attribute not found in response" } + } + + requireNotNull(attributeData) { + "Spinspeedcurrent attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return SpinSpeedCurrentAttribute(decodedValue) } - suspend fun writeSpinSpeedCurrentAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeSpinSpeedCurrentAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 1u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -294,124 +348,132 @@ class LaundryWasherControlsCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeSpinSpeedCurrentAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - SpinSpeedCurrentAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(SpinSpeedCurrentAttributeSubscriptionState.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) { - "Spinspeedcurrent attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Spinspeedcurrent 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(SpinSpeedCurrentAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(SpinSpeedCurrentAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(SpinSpeedCurrentAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readNumberOfRinsesAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readNumberOfRinsesAttribute(): UByte? {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}") - } + 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) { "Numberofrinses attribute not found in response" } + } + + requireNotNull(attributeData) { + "Numberofrinses 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } - suspend fun writeNumberOfRinsesAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeNumberOfRinsesAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 2u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -432,258 +494,261 @@ class LaundryWasherControlsCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNumberOfRinsesAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Numberofrinses attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Numberofrinses 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)) } + 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 readSupportedRinsesAttribute(): SupportedRinsesAttribute { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readSupportedRinsesAttribute(): SupportedRinsesAttribute {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}") - } + 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) { "Supportedrinses attribute not found in response" } + } + + requireNotNull(attributeData) { + "Supportedrinses attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) } + tlvReader.exitContainer() + } + } else { + null + } + return SupportedRinsesAttribute(decodedValue) } suspend fun subscribeSupportedRinsesAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - SupportedRinsesAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(SupportedRinsesAttributeSubscriptionState.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) { - "Supportedrinses attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Supportedrinses attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { emit(SupportedRinsesAttributeSubscriptionState.Success(it)) } + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { + emit(SupportedRinsesAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(SupportedRinsesAttributeSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -691,96 +756,97 @@ class LaundryWasherControlsCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -788,94 +854,97 @@ class LaundryWasherControlsCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -883,94 +952,97 @@ class LaundryWasherControlsCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -978,76 +1050,81 @@ class LaundryWasherControlsCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1059,77 +1136,80 @@ class LaundryWasherControlsCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1142,7 +1222,7 @@ class LaundryWasherControlsCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/LaundryWasherModeCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/LaundryWasherModeCluster.kt index 45f9e469f1d91d..3094ee32e0a394 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/LaundryWasherModeCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/LaundryWasherModeCluster.kt @@ -17,127 +17,161 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.cluster.structs.* +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class LaundryWasherModeCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class ChangeToModeResponse(val status: UByte, val statusText: String?) - - class SupportedModesAttribute(val value: List) +class LaundryWasherModeCluster(private val controller: MatterController, private val endpointId: UShort) { + class ChangeToModeResponse( + val status: UByte, + val statusText: String? + ) +class SupportedModesAttribute( + val value: List + ) sealed class SupportedModesAttributeSubscriptionState { - data class Success(val value: List) : - SupportedModesAttributeSubscriptionState() - + data class Success( + val value: List + ) : SupportedModesAttributeSubscriptionState() + data class Error(val exception: Exception) : SupportedModesAttributeSubscriptionState() - object SubscriptionEstablished : SupportedModesAttributeSubscriptionState() - } - - class StartUpModeAttribute(val value: UByte?) + object SubscriptionEstablished : SupportedModesAttributeSubscriptionState() + } +class StartUpModeAttribute( + val value: UByte? + ) sealed class StartUpModeAttributeSubscriptionState { - data class Success(val value: UByte?) : StartUpModeAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : StartUpModeAttributeSubscriptionState() + data class Error(val exception: Exception) : StartUpModeAttributeSubscriptionState() - object SubscriptionEstablished : StartUpModeAttributeSubscriptionState() - } - - class OnModeAttribute(val value: UByte?) + object SubscriptionEstablished : StartUpModeAttributeSubscriptionState() + } +class OnModeAttribute( + val value: UByte? + ) sealed class OnModeAttributeSubscriptionState { - data class Success(val value: UByte?) : OnModeAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : OnModeAttributeSubscriptionState() + data class Error(val exception: Exception) : OnModeAttributeSubscriptionState() - object SubscriptionEstablished : OnModeAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : OnModeAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun changeToMode( - newMode: UByte, - timedInvokeTimeout: Duration? = null, - ): ChangeToModeResponse { + suspend fun changeToMode(newMode: UByte + ,timedInvokeTimeout: Duration? = null): ChangeToModeResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_NEW_MODE_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_NEW_MODE_REQ), newMode) + tlvWriter.put(ContextSpecificTag(TAG_NEW_MODE_REQ), newMode) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -147,130 +181,140 @@ class LaundryWasherModeCluster( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_STATUS_TEXT: Int = 1 var statusText_decoded: String? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_STATUS)) { - status_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_STATUS_TEXT)) { - statusText_decoded = + + if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_STATUS_TEXT)) {statusText_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - } - } else { + tlvReader.getString(tag) + } else { + null + } + }} + + + else { tlvReader.skipElement() } } + + if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } + + + tlvReader.exitContainer() - return ChangeToModeResponse(status_decoded, statusText_decoded) + return ChangeToModeResponse( + status_decoded, + statusText_decoded + ) } - - suspend fun readSupportedModesAttribute(): SupportedModesAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readSupportedModesAttribute(): SupportedModesAttribute {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}") - } + 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) { "Supportedmodes attribute not found in response" } + } + + requireNotNull(attributeData) { + "Supportedmodes 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(LaundryWasherModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(LaundryWasherModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + return SupportedModesAttribute(decodedValue) } suspend fun subscribeSupportedModesAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - SupportedModesAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(SupportedModesAttributeSubscriptionState.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) { - "Supportedmodes attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Supportedmodes 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(LaundryWasherModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(LaundryWasherModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(SupportedModesAttributeSubscriptionState.Success(decodedValue)) } @@ -278,76 +322,81 @@ class LaundryWasherModeCluster( emit(SupportedModesAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readCurrentModeAttribute(): 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)) - +suspend fun readCurrentModeAttribute(): 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}") - } + 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) { "Currentmode attribute not found in response" } + } + + requireNotNull(attributeData) { + "Currentmode 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 subscribeCurrentModeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Currentmode attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Currentmode attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -359,67 +408,77 @@ class LaundryWasherModeCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readStartUpModeAttribute(): StartUpModeAttribute { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readStartUpModeAttribute(): StartUpModeAttribute {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}") - } + 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) { "Startupmode attribute not found in response" } + } + + requireNotNull(attributeData) { + "Startupmode attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return StartUpModeAttribute(decodedValue) } - suspend fun writeStartUpModeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeStartUpModeAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 2u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -440,127 +499,137 @@ class LaundryWasherModeCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeStartUpModeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StartUpModeAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StartUpModeAttributeSubscriptionState.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) { "Startupmode attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Startupmode 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(StartUpModeAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(StartUpModeAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(StartUpModeAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readOnModeAttribute(): OnModeAttribute { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readOnModeAttribute(): OnModeAttribute {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}") - } + 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) { "Onmode attribute not found in response" } + } + + requireNotNull(attributeData) { + "Onmode attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return OnModeAttribute(decodedValue) } - suspend fun writeOnModeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeOnModeAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 3u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -581,156 +650,157 @@ class LaundryWasherModeCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeOnModeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - OnModeAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(OnModeAttributeSubscriptionState.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) { "Onmode attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Onmode 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(OnModeAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(OnModeAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(OnModeAttributeSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -738,96 +808,97 @@ class LaundryWasherModeCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -835,94 +906,97 @@ class LaundryWasherModeCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -930,94 +1004,97 @@ class LaundryWasherModeCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1025,76 +1102,81 @@ class LaundryWasherModeCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1106,77 +1188,80 @@ class LaundryWasherModeCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1189,7 +1274,7 @@ class LaundryWasherModeCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/LevelControlCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/LevelControlCluster.kt index e77e463d61ce2b..293ad3ccf28462 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/LevelControlCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/LevelControlCluster.kt @@ -17,143 +17,184 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.cluster.structs.* +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class LevelControlCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class CurrentLevelAttribute(val value: UByte?) +class LevelControlCluster(private val controller: MatterController, private val endpointId: UShort) {class CurrentLevelAttribute( + val value: UByte? + ) sealed class CurrentLevelAttributeSubscriptionState { - data class Success(val value: UByte?) : CurrentLevelAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : CurrentLevelAttributeSubscriptionState() + data class Error(val exception: Exception) : CurrentLevelAttributeSubscriptionState() - object SubscriptionEstablished : CurrentLevelAttributeSubscriptionState() - } - - class OnLevelAttribute(val value: UByte?) + object SubscriptionEstablished : CurrentLevelAttributeSubscriptionState() + } +class OnLevelAttribute( + val value: UByte? + ) sealed class OnLevelAttributeSubscriptionState { - data class Success(val value: UByte?) : OnLevelAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : OnLevelAttributeSubscriptionState() + data class Error(val exception: Exception) : OnLevelAttributeSubscriptionState() - object SubscriptionEstablished : OnLevelAttributeSubscriptionState() - } - - class OnTransitionTimeAttribute(val value: UShort?) + object SubscriptionEstablished : OnLevelAttributeSubscriptionState() + } +class OnTransitionTimeAttribute( + val value: UShort? + ) sealed class OnTransitionTimeAttributeSubscriptionState { - data class Success(val value: UShort?) : OnTransitionTimeAttributeSubscriptionState() - + data class Success( + val value: UShort? + ) : OnTransitionTimeAttributeSubscriptionState() + data class Error(val exception: Exception) : OnTransitionTimeAttributeSubscriptionState() - object SubscriptionEstablished : OnTransitionTimeAttributeSubscriptionState() - } - - class OffTransitionTimeAttribute(val value: UShort?) + object SubscriptionEstablished : OnTransitionTimeAttributeSubscriptionState() + } +class OffTransitionTimeAttribute( + val value: UShort? + ) sealed class OffTransitionTimeAttributeSubscriptionState { - data class Success(val value: UShort?) : OffTransitionTimeAttributeSubscriptionState() - + data class Success( + val value: UShort? + ) : OffTransitionTimeAttributeSubscriptionState() + data class Error(val exception: Exception) : OffTransitionTimeAttributeSubscriptionState() - object SubscriptionEstablished : OffTransitionTimeAttributeSubscriptionState() - } - - class DefaultMoveRateAttribute(val value: UByte?) + object SubscriptionEstablished : OffTransitionTimeAttributeSubscriptionState() + } +class DefaultMoveRateAttribute( + val value: UByte? + ) sealed class DefaultMoveRateAttributeSubscriptionState { - data class Success(val value: UByte?) : DefaultMoveRateAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : DefaultMoveRateAttributeSubscriptionState() + data class Error(val exception: Exception) : DefaultMoveRateAttributeSubscriptionState() - object SubscriptionEstablished : DefaultMoveRateAttributeSubscriptionState() - } - - class StartUpCurrentLevelAttribute(val value: UByte?) + object SubscriptionEstablished : DefaultMoveRateAttributeSubscriptionState() + } +class StartUpCurrentLevelAttribute( + val value: UByte? + ) sealed class StartUpCurrentLevelAttributeSubscriptionState { - data class Success(val value: UByte?) : StartUpCurrentLevelAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : StartUpCurrentLevelAttributeSubscriptionState() + data class Error(val exception: Exception) : StartUpCurrentLevelAttributeSubscriptionState() - object SubscriptionEstablished : StartUpCurrentLevelAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : StartUpCurrentLevelAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun moveToLevel( - level: UByte, - transitionTime: UShort?, - optionsMask: UByte, - optionsOverride: UByte, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun moveToLevel(level: UByte + ,transitionTime: UShort? + ,optionsMask: UByte + ,optionsOverride: UByte + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() @@ -171,27 +212,25 @@ class LevelControlCluster( tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 3 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun move( - moveMode: UByte, - rate: UByte?, - optionsMask: UByte, - optionsOverride: UByte, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun move(moveMode: UByte + ,rate: UByte? + ,optionsMask: UByte + ,optionsOverride: UByte + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 1u val tlvWriter = TlvWriter() @@ -201,34 +240,34 @@ class LevelControlCluster( tlvWriter.put(ContextSpecificTag(TAG_MOVE_MODE_REQ), moveMode) val TAG_RATE_REQ: Int = 1 - rate?.let { tlvWriter.put(ContextSpecificTag(TAG_RATE_REQ), rate) } + rate?.let { + tlvWriter.put(ContextSpecificTag(TAG_RATE_REQ), rate) + } val TAG_OPTIONS_MASK_REQ: Int = 2 tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 3 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun step( - stepMode: UByte, - stepSize: UByte, - transitionTime: UShort?, - optionsMask: UByte, - optionsOverride: UByte, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun step(stepMode: UByte + ,stepSize: UByte + ,transitionTime: UShort? + ,optionsMask: UByte + ,optionsOverride: UByte + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 2u val tlvWriter = TlvWriter() @@ -249,25 +288,23 @@ class LevelControlCluster( tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 4 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun stop( - optionsMask: UByte, - optionsOverride: UByte, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun stop(optionsMask: UByte + ,optionsOverride: UByte + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 3u val tlvWriter = TlvWriter() @@ -277,27 +314,25 @@ class LevelControlCluster( tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun moveToLevelWithOnOff( - level: UByte, - transitionTime: UShort?, - optionsMask: UByte, - optionsOverride: UByte, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun moveToLevelWithOnOff(level: UByte + ,transitionTime: UShort? + ,optionsMask: UByte + ,optionsOverride: UByte + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 4u val tlvWriter = TlvWriter() @@ -315,27 +350,25 @@ class LevelControlCluster( tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 3 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun moveWithOnOff( - moveMode: UByte, - rate: UByte?, - optionsMask: UByte, - optionsOverride: UByte, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun moveWithOnOff(moveMode: UByte + ,rate: UByte? + ,optionsMask: UByte + ,optionsOverride: UByte + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 5u val tlvWriter = TlvWriter() @@ -345,34 +378,34 @@ class LevelControlCluster( tlvWriter.put(ContextSpecificTag(TAG_MOVE_MODE_REQ), moveMode) val TAG_RATE_REQ: Int = 1 - rate?.let { tlvWriter.put(ContextSpecificTag(TAG_RATE_REQ), rate) } + rate?.let { + tlvWriter.put(ContextSpecificTag(TAG_RATE_REQ), rate) + } val TAG_OPTIONS_MASK_REQ: Int = 2 tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 3 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun stepWithOnOff( - stepMode: UByte, - stepSize: UByte, - transitionTime: UShort?, - optionsMask: UByte, - optionsOverride: UByte, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun stepWithOnOff(stepMode: UByte + ,stepSize: UByte + ,transitionTime: UShort? + ,optionsMask: UByte + ,optionsOverride: UByte + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 6u val tlvWriter = TlvWriter() @@ -393,25 +426,23 @@ class LevelControlCluster( tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 4 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun stopWithOnOff( - optionsMask: UByte, - optionsOverride: UByte, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun stopWithOnOff(optionsMask: UByte + ,optionsOverride: UByte + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 7u val tlvWriter = TlvWriter() @@ -421,730 +452,782 @@ class LevelControlCluster( tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun moveToClosestFrequency(frequency: UShort, timedInvokeTimeout: Duration? = null) { + suspend fun moveToClosestFrequency(frequency: UShort + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 8u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_FREQUENCY_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_FREQUENCY_REQ), frequency) + tlvWriter.put(ContextSpecificTag(TAG_FREQUENCY_REQ), frequency) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } +suspend fun readCurrentLevelAttribute(): CurrentLevelAttribute {val ATTRIBUTE_ID: UInt = 0u - suspend fun readCurrentLevelAttribute(): CurrentLevelAttribute { - 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 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}") - } + 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) { "Currentlevel attribute not found in response" } + } + + requireNotNull(attributeData) { + "Currentlevel attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return CurrentLevelAttribute(decodedValue) } suspend fun subscribeCurrentLevelAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - CurrentLevelAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(CurrentLevelAttributeSubscriptionState.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) { "Currentlevel attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Currentlevel 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.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(CurrentLevelAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(CurrentLevelAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(CurrentLevelAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRemainingTimeAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 1u - suspend fun readRemainingTimeAttribute(): UShort? { - 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 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}") - } + 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) { "Remainingtime attribute not found in response" } + } + + requireNotNull(attributeData) { + "Remainingtime 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeRemainingTimeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Remainingtime attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Remainingtime 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readMinLevelAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 2u - suspend fun readMinLevelAttribute(): UByte? { - 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 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}") - } + 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) { "Minlevel attribute not found in response" } + } + + requireNotNull(attributeData) { + "Minlevel 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeMinLevelAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Minlevel attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Minlevel 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readMaxLevelAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 3u - suspend fun readMaxLevelAttribute(): UByte? { - 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 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}") - } + 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) { "Maxlevel attribute not found in response" } + } + + requireNotNull(attributeData) { + "Maxlevel 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeMaxLevelAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Maxlevel attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Maxlevel 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readCurrentFrequencyAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 4u - suspend fun readCurrentFrequencyAttribute(): UShort? { - 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 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}") - } + 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) { "Currentfrequency attribute not found in response" } + } + + requireNotNull(attributeData) { + "Currentfrequency 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeCurrentFrequencyAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Currentfrequency attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Currentfrequency 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readMinFrequencyAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 5u - suspend fun readMinFrequencyAttribute(): UShort? { - 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 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}") - } + 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) { "Minfrequency attribute not found in response" } + } + + requireNotNull(attributeData) { + "Minfrequency 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeMinFrequencyAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Minfrequency attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Minfrequency 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readMaxFrequencyAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 6u - suspend fun readMaxFrequencyAttribute(): 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 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}") - } + 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) { "Maxfrequency attribute not found in response" } + } + + requireNotNull(attributeData) { + "Maxfrequency 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeMaxFrequencyAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Maxfrequency attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Maxfrequency 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readOptionsAttribute(): UByte {val ATTRIBUTE_ID: UInt = 15u - suspend fun readOptionsAttribute(): UByte { - val ATTRIBUTE_ID: UInt = 15u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Options attribute not found in response" } + } + + requireNotNull(attributeData) { + "Options 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 writeOptionsAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeOptionsAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 15u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -1165,45 +1248,43 @@ class LevelControlCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeOptionsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 15u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Options attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Options attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -1215,65 +1296,72 @@ class LevelControlCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readOnOffTransitionTimeAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 16u - suspend fun readOnOffTransitionTimeAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 16u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Onofftransitiontime attribute not found in response" } + } + + requireNotNull(attributeData) { + "Onofftransitiontime 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun writeOnOffTransitionTimeAttribute( value: UShort, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -1294,120 +1382,128 @@ class LevelControlCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeOnOffTransitionTimeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Onofftransitiontime attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Onofftransitiontime 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readOnLevelAttribute(): OnLevelAttribute {val ATTRIBUTE_ID: UInt = 17u - suspend fun readOnLevelAttribute(): OnLevelAttribute { - val ATTRIBUTE_ID: UInt = 17u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Onlevel attribute not found in response" } + } + + requireNotNull(attributeData) { + "Onlevel attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return OnLevelAttribute(decodedValue) } - suspend fun writeOnLevelAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeOnLevelAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 17u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -1428,123 +1524,133 @@ class LevelControlCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeOnLevelAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 17u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - OnLevelAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(OnLevelAttributeSubscriptionState.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) { "Onlevel attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Onlevel 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.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(OnLevelAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(OnLevelAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(OnLevelAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readOnTransitionTimeAttribute(): OnTransitionTimeAttribute {val ATTRIBUTE_ID: UInt = 18u - suspend fun readOnTransitionTimeAttribute(): OnTransitionTimeAttribute { - val ATTRIBUTE_ID: UInt = 18u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Ontransitiontime attribute not found in response" } + } + + requireNotNull(attributeData) { + "Ontransitiontime attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return OnTransitionTimeAttribute(decodedValue) } - suspend fun writeOnTransitionTimeAttribute(value: UShort, timedWriteTimeout: Duration? = null) { + suspend fun writeOnTransitionTimeAttribute( + value: UShort, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 18u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -1565,129 +1671,137 @@ class LevelControlCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeOnTransitionTimeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 18u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - OnTransitionTimeAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(OnTransitionTimeAttributeSubscriptionState.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) { - "Ontransitiontime attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Ontransitiontime 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(OnTransitionTimeAttributeSubscriptionState.Success(it)) } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(OnTransitionTimeAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(OnTransitionTimeAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readOffTransitionTimeAttribute(): OffTransitionTimeAttribute {val ATTRIBUTE_ID: UInt = 19u - suspend fun readOffTransitionTimeAttribute(): OffTransitionTimeAttribute { - val ATTRIBUTE_ID: UInt = 19u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Offtransitiontime attribute not found in response" } + } + + requireNotNull(attributeData) { + "Offtransitiontime attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return OffTransitionTimeAttribute(decodedValue) } - suspend fun writeOffTransitionTimeAttribute(value: UShort, timedWriteTimeout: Duration? = null) { + suspend fun writeOffTransitionTimeAttribute( + value: UShort, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 19u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -1708,129 +1822,137 @@ class LevelControlCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeOffTransitionTimeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 19u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - OffTransitionTimeAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(OffTransitionTimeAttributeSubscriptionState.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) { - "Offtransitiontime attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Offtransitiontime 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(OffTransitionTimeAttributeSubscriptionState.Success(it)) } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(OffTransitionTimeAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(OffTransitionTimeAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readDefaultMoveRateAttribute(): DefaultMoveRateAttribute {val ATTRIBUTE_ID: UInt = 20u - suspend fun readDefaultMoveRateAttribute(): DefaultMoveRateAttribute { - val ATTRIBUTE_ID: UInt = 20u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Defaultmoverate attribute not found in response" } + } + + requireNotNull(attributeData) { + "Defaultmoverate attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return DefaultMoveRateAttribute(decodedValue) } - suspend fun writeDefaultMoveRateAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeDefaultMoveRateAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 20u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -1851,129 +1973,137 @@ class LevelControlCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeDefaultMoveRateAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 20u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - DefaultMoveRateAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(DefaultMoveRateAttributeSubscriptionState.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) { - "Defaultmoverate attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Defaultmoverate 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(DefaultMoveRateAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(DefaultMoveRateAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(DefaultMoveRateAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readStartUpCurrentLevelAttribute(): StartUpCurrentLevelAttribute {val ATTRIBUTE_ID: UInt = 16384u - suspend fun readStartUpCurrentLevelAttribute(): StartUpCurrentLevelAttribute { - val ATTRIBUTE_ID: UInt = 16384u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Startupcurrentlevel attribute not found in response" } + } + + requireNotNull(attributeData) { + "Startupcurrentlevel attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return StartUpCurrentLevelAttribute(decodedValue) } - suspend fun writeStartUpCurrentLevelAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeStartUpCurrentLevelAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16384u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -1994,158 +2124,157 @@ class LevelControlCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeStartUpCurrentLevelAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16384u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StartUpCurrentLevelAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StartUpCurrentLevelAttributeSubscriptionState.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) { - "Startupcurrentlevel attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Startupcurrentlevel 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(StartUpCurrentLevelAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(StartUpCurrentLevelAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(StartUpCurrentLevelAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65528u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -2153,96 +2282,97 @@ class LevelControlCluster( emit(GeneratedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65529u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -2250,94 +2380,97 @@ class LevelControlCluster( emit(AcceptedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt = 65530u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -2345,94 +2478,97 @@ class LevelControlCluster( emit(EventListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ID: UInt = 65531u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -2440,76 +2576,81 @@ class LevelControlCluster( emit(AttributeListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u - 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 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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -2521,77 +2662,80 @@ class LevelControlCluster( emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 65533u - 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 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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -2604,7 +2748,7 @@ class LevelControlCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/LocalizationConfigurationCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/LocalizationConfigurationCluster.kt index e652658edb19d2..d2c92eb1b5c1f9 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/LocalizationConfigurationCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/LocalizationConfigurationCluster.kt @@ -17,130 +17,173 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest -import matter.controller.StringSubscriptionState +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.UIntSubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState +import matter.controller.UByteSubscriptionState import matter.controller.UShortSubscriptionState +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.cluster.structs.* +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath +import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class LocalizationConfigurationCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class SupportedLocalesAttribute(val value: List) +class LocalizationConfigurationCluster(private val controller: MatterController, private val endpointId: UShort) {class SupportedLocalesAttribute( + val value: List + ) sealed class SupportedLocalesAttributeSubscriptionState { - data class Success(val value: List) : SupportedLocalesAttributeSubscriptionState() - + data class Success( + val value: List + ) : SupportedLocalesAttributeSubscriptionState() + data class Error(val exception: Exception) : SupportedLocalesAttributeSubscriptionState() - object SubscriptionEstablished : SupportedLocalesAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : SupportedLocalesAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } - - suspend fun readActiveLocaleAttribute(): String { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } +suspend fun readActiveLocaleAttribute(): String {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}") - } + 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) { "Activelocale attribute not found in response" } + } + + requireNotNull(attributeData) { + "Activelocale attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: String = tlvReader.getString(AnonymousTag) + return decodedValue } - suspend fun writeActiveLocaleAttribute(value: String, timedWriteTimeout: Duration? = null) { + suspend fun writeActiveLocaleAttribute( + value: String, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -161,45 +204,43 @@ class LocalizationConfigurationCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeActiveLocaleAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StringSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StringSubscriptionState.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) { "Activelocale attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Activelocale attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -211,96 +252,97 @@ class LocalizationConfigurationCluster( emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readSupportedLocalesAttribute(): SupportedLocalesAttribute { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readSupportedLocalesAttribute(): SupportedLocalesAttribute {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}") - } + 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) { "Supportedlocales attribute not found in response" } + } + + requireNotNull(attributeData) { + "Supportedlocales 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.getString(AnonymousTag)) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getString(AnonymousTag)) } + tlvReader.exitContainer() + } + return SupportedLocalesAttribute(decodedValue) } suspend fun subscribeSupportedLocalesAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - SupportedLocalesAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(SupportedLocalesAttributeSubscriptionState.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) { - "Supportedlocales attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Supportedlocales 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.getString(AnonymousTag)) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getString(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(SupportedLocalesAttributeSubscriptionState.Success(decodedValue)) } @@ -308,96 +350,97 @@ class LocalizationConfigurationCluster( emit(SupportedLocalesAttributeSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -405,96 +448,97 @@ class LocalizationConfigurationCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -502,94 +546,97 @@ class LocalizationConfigurationCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -597,94 +644,97 @@ class LocalizationConfigurationCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -692,76 +742,81 @@ class LocalizationConfigurationCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -773,77 +828,80 @@ class LocalizationConfigurationCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -856,7 +914,7 @@ class LocalizationConfigurationCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/LowPowerCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/LowPowerCluster.kt index 126f9b33301e05..93f537837ccd34 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/LowPowerCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/LowPowerCluster.kt @@ -17,173 +17,207 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.UIntSubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState +import matter.controller.UByteSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class LowPowerCluster(private val controller: MatterController, private val endpointId: UShort) { - class GeneratedCommandListAttribute(val value: List) +class LowPowerCluster(private val controller: MatterController, private val endpointId: UShort) {class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } suspend fun sleep(timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - - 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -191,96 +225,97 @@ class LowPowerCluster(private val controller: MatterController, private val endp 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -288,94 +323,97 @@ class LowPowerCluster(private val controller: MatterController, private val endp 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -383,94 +421,97 @@ class LowPowerCluster(private val controller: MatterController, private val endp 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -478,76 +519,81 @@ class LowPowerCluster(private val controller: MatterController, private val endp 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -559,77 +605,80 @@ class LowPowerCluster(private val controller: MatterController, private val endp 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -642,7 +691,7 @@ class LowPowerCluster(private val controller: MatterController, private val endp emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/MediaInputCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/MediaInputCluster.kt index ed65c99541c8e4..d26de7c78f7c10 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/MediaInputCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/MediaInputCluster.kt @@ -17,96 +17,130 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class MediaInputCluster(private val controller: MatterController, private val endpointId: UShort) { - class InputListAttribute(val value: List) +class MediaInputCluster(private val controller: MatterController, private val endpointId: UShort) {class InputListAttribute( + val value: List + ) sealed class InputListAttributeSubscriptionState { - data class Success(val value: List) : - InputListAttributeSubscriptionState() - + data class Success( + val value: List + ) : InputListAttributeSubscriptionState() + data class Error(val exception: Exception) : InputListAttributeSubscriptionState() - object SubscriptionEstablished : InputListAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : InputListAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun selectInput(index: UByte, timedInvokeTimeout: Duration? = null) { + suspend fun selectInput(index: UByte + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_INDEX_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_INDEX_REQ), index) + tlvWriter.put(ContextSpecificTag(TAG_INDEX_REQ), index) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -117,14 +151,14 @@ class MediaInputCluster(private val controller: MatterController, private val en val commandId: UInt = 1u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -135,21 +169,23 @@ class MediaInputCluster(private val controller: MatterController, private val en val commandId: UInt = 2u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun renameInput(index: UByte, name: String, timedInvokeTimeout: Duration? = null) { + suspend fun renameInput(index: UByte + ,name: String + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 3u val tlvWriter = TlvWriter() @@ -159,105 +195,108 @@ class MediaInputCluster(private val controller: MatterController, private val en tlvWriter.put(ContextSpecificTag(TAG_INDEX_REQ), index) val TAG_NAME_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_NAME_REQ), name) + tlvWriter.put(ContextSpecificTag(TAG_NAME_REQ), name) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - - suspend fun readInputListAttribute(): InputListAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readInputListAttribute(): InputListAttribute {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}") - } + 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) { "Inputlist attribute not found in response" } + } + + requireNotNull(attributeData) { + "Inputlist 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(MediaInputClusterInputInfoStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(MediaInputClusterInputInfoStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + return InputListAttribute(decodedValue) } suspend fun subscribeInputListAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - InputListAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(InputListAttributeSubscriptionState.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) { "Inputlist attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Inputlist 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(MediaInputClusterInputInfoStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(MediaInputClusterInputInfoStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(InputListAttributeSubscriptionState.Success(decodedValue)) } @@ -265,76 +304,81 @@ class MediaInputCluster(private val controller: MatterController, private val en emit(InputListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readCurrentInputAttribute(): 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)) - +suspend fun readCurrentInputAttribute(): 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}") - } + 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) { "Currentinput attribute not found in response" } + } + + requireNotNull(attributeData) { + "Currentinput 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 subscribeCurrentInputAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Currentinput attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Currentinput attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -346,96 +390,97 @@ class MediaInputCluster(private val controller: MatterController, private val en emit(UByteSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -443,96 +488,97 @@ class MediaInputCluster(private val controller: MatterController, private val en 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -540,94 +586,97 @@ class MediaInputCluster(private val controller: MatterController, private val en 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -635,94 +684,97 @@ class MediaInputCluster(private val controller: MatterController, private val en 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -730,76 +782,81 @@ class MediaInputCluster(private val controller: MatterController, private val en 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -811,77 +868,80 @@ class MediaInputCluster(private val controller: MatterController, private val en 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -894,7 +954,7 @@ class MediaInputCluster(private val controller: MatterController, private val en emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/MediaPlaybackCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/MediaPlaybackCluster.kt index 53a4847c134590..ad3efe69a871ca 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/MediaPlaybackCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/MediaPlaybackCluster.kt @@ -17,183 +17,235 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.FloatSubscriptionState -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class MediaPlaybackCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class PlaybackResponse(val status: UByte, val data: String?) - - class StartTimeAttribute(val value: ULong?) +class MediaPlaybackCluster(private val controller: MatterController, private val endpointId: UShort) { + class PlaybackResponse( + val status: UByte, + val data: String? + ) +class StartTimeAttribute( + val value: ULong? + ) sealed class StartTimeAttributeSubscriptionState { - data class Success(val value: ULong?) : StartTimeAttributeSubscriptionState() - + data class Success( + val value: ULong? + ) : StartTimeAttributeSubscriptionState() + data class Error(val exception: Exception) : StartTimeAttributeSubscriptionState() - object SubscriptionEstablished : StartTimeAttributeSubscriptionState() - } - - class DurationAttribute(val value: ULong?) + object SubscriptionEstablished : StartTimeAttributeSubscriptionState() + } +class DurationAttribute( + val value: ULong? + ) sealed class DurationAttributeSubscriptionState { - data class Success(val value: ULong?) : DurationAttributeSubscriptionState() - + data class Success( + val value: ULong? + ) : DurationAttributeSubscriptionState() + data class Error(val exception: Exception) : DurationAttributeSubscriptionState() - object SubscriptionEstablished : DurationAttributeSubscriptionState() - } - - class SampledPositionAttribute(val value: MediaPlaybackClusterPlaybackPositionStruct?) + object SubscriptionEstablished : DurationAttributeSubscriptionState() + } +class SampledPositionAttribute( + val value: MediaPlaybackClusterPlaybackPositionStruct? + ) sealed class SampledPositionAttributeSubscriptionState { - data class Success(val value: MediaPlaybackClusterPlaybackPositionStruct?) : - SampledPositionAttributeSubscriptionState() - + data class Success( + val value: MediaPlaybackClusterPlaybackPositionStruct? + ) : SampledPositionAttributeSubscriptionState() + data class Error(val exception: Exception) : SampledPositionAttributeSubscriptionState() - object SubscriptionEstablished : SampledPositionAttributeSubscriptionState() - } - - class SeekRangeEndAttribute(val value: ULong?) + object SubscriptionEstablished : SampledPositionAttributeSubscriptionState() + } +class SeekRangeEndAttribute( + val value: ULong? + ) sealed class SeekRangeEndAttributeSubscriptionState { - data class Success(val value: ULong?) : SeekRangeEndAttributeSubscriptionState() - + data class Success( + val value: ULong? + ) : SeekRangeEndAttributeSubscriptionState() + data class Error(val exception: Exception) : SeekRangeEndAttributeSubscriptionState() - object SubscriptionEstablished : SeekRangeEndAttributeSubscriptionState() - } - - class SeekRangeStartAttribute(val value: ULong?) + object SubscriptionEstablished : SeekRangeEndAttributeSubscriptionState() + } +class SeekRangeStartAttribute( + val value: ULong? + ) sealed class SeekRangeStartAttributeSubscriptionState { - data class Success(val value: ULong?) : SeekRangeStartAttributeSubscriptionState() - + data class Success( + val value: ULong? + ) : SeekRangeStartAttributeSubscriptionState() + data class Error(val exception: Exception) : SeekRangeStartAttributeSubscriptionState() - object SubscriptionEstablished : SeekRangeStartAttributeSubscriptionState() - } - - class ActiveAudioTrackAttribute(val value: MediaPlaybackClusterTrackStruct?) + object SubscriptionEstablished : SeekRangeStartAttributeSubscriptionState() + } +class ActiveAudioTrackAttribute( + val value: MediaPlaybackClusterTrackStruct? + ) sealed class ActiveAudioTrackAttributeSubscriptionState { - data class Success(val value: MediaPlaybackClusterTrackStruct?) : - ActiveAudioTrackAttributeSubscriptionState() - + data class Success( + val value: MediaPlaybackClusterTrackStruct? + ) : ActiveAudioTrackAttributeSubscriptionState() + data class Error(val exception: Exception) : ActiveAudioTrackAttributeSubscriptionState() - object SubscriptionEstablished : ActiveAudioTrackAttributeSubscriptionState() - } - - class AvailableAudioTracksAttribute(val value: List?) + object SubscriptionEstablished : ActiveAudioTrackAttributeSubscriptionState() + } +class AvailableAudioTracksAttribute( + val value: List? + ) sealed class AvailableAudioTracksAttributeSubscriptionState { - data class Success(val value: List?) : - AvailableAudioTracksAttributeSubscriptionState() - + data class Success( + val value: List? + ) : AvailableAudioTracksAttributeSubscriptionState() + data class Error(val exception: Exception) : AvailableAudioTracksAttributeSubscriptionState() - object SubscriptionEstablished : AvailableAudioTracksAttributeSubscriptionState() - } - - class ActiveTextTrackAttribute(val value: MediaPlaybackClusterTrackStruct?) + object SubscriptionEstablished : AvailableAudioTracksAttributeSubscriptionState() + } +class ActiveTextTrackAttribute( + val value: MediaPlaybackClusterTrackStruct? + ) sealed class ActiveTextTrackAttributeSubscriptionState { - data class Success(val value: MediaPlaybackClusterTrackStruct?) : - ActiveTextTrackAttributeSubscriptionState() - + data class Success( + val value: MediaPlaybackClusterTrackStruct? + ) : ActiveTextTrackAttributeSubscriptionState() + data class Error(val exception: Exception) : ActiveTextTrackAttributeSubscriptionState() - object SubscriptionEstablished : ActiveTextTrackAttributeSubscriptionState() - } - - class AvailableTextTracksAttribute(val value: List?) + object SubscriptionEstablished : ActiveTextTrackAttributeSubscriptionState() + } +class AvailableTextTracksAttribute( + val value: List? + ) sealed class AvailableTextTracksAttributeSubscriptionState { - data class Success(val value: List?) : - AvailableTextTracksAttributeSubscriptionState() - + data class Success( + val value: List? + ) : AvailableTextTracksAttributeSubscriptionState() + data class Error(val exception: Exception) : AvailableTextTracksAttributeSubscriptionState() - object SubscriptionEstablished : AvailableTextTracksAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : AvailableTextTracksAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } suspend fun play(timedInvokeTimeout: Duration? = null): PlaybackResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -203,55 +255,64 @@ class MediaPlaybackCluster( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_DATA: Int = 1 var data_decoded: String? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_STATUS)) { - status_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_DATA)) { - data_decoded = + + if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_DATA)) {data_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - } - } else { + tlvReader.getString(tag) + } else { + null + } + }} + + + else { tlvReader.skipElement() } } + + if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } + + + tlvReader.exitContainer() - return PlaybackResponse(status_decoded, data_decoded) + return PlaybackResponse( + status_decoded, + data_decoded + ) } suspend fun pause(timedInvokeTimeout: Duration? = null): PlaybackResponse { val commandId: UInt = 1u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -261,55 +322,64 @@ class MediaPlaybackCluster( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_DATA: Int = 1 var data_decoded: String? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_STATUS)) { - status_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_DATA)) { - data_decoded = + + if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_DATA)) {data_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - } - } else { + tlvReader.getString(tag) + } else { + null + } + }} + + + else { tlvReader.skipElement() } } + + if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } + + + tlvReader.exitContainer() - return PlaybackResponse(status_decoded, data_decoded) + return PlaybackResponse( + status_decoded, + data_decoded + ) } suspend fun stop(timedInvokeTimeout: Duration? = null): PlaybackResponse { val commandId: UInt = 2u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -319,55 +389,64 @@ class MediaPlaybackCluster( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_DATA: Int = 1 var data_decoded: String? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_STATUS)) { - status_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_DATA)) { - data_decoded = + + if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_DATA)) {data_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - } - } else { + tlvReader.getString(tag) + } else { + null + } + }} + + + else { tlvReader.skipElement() } } + + if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } + + + tlvReader.exitContainer() - return PlaybackResponse(status_decoded, data_decoded) + return PlaybackResponse( + status_decoded, + data_decoded + ) } suspend fun startOver(timedInvokeTimeout: Duration? = null): PlaybackResponse { val commandId: UInt = 3u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -377,55 +456,64 @@ class MediaPlaybackCluster( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_DATA: Int = 1 var data_decoded: String? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_STATUS)) { - status_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_DATA)) { - data_decoded = + + if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_DATA)) {data_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - } - } else { + tlvReader.getString(tag) + } else { + null + } + }} + + + else { tlvReader.skipElement() } } + + if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } + + + tlvReader.exitContainer() - return PlaybackResponse(status_decoded, data_decoded) + return PlaybackResponse( + status_decoded, + data_decoded + ) } suspend fun previous(timedInvokeTimeout: Duration? = null): PlaybackResponse { val commandId: UInt = 4u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -435,55 +523,64 @@ class MediaPlaybackCluster( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_DATA: Int = 1 var data_decoded: String? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_STATUS)) { - status_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_DATA)) { - data_decoded = + + if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_DATA)) {data_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - } - } else { + tlvReader.getString(tag) + } else { + null + } + }} + + + else { tlvReader.skipElement() } } + + if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } + + + tlvReader.exitContainer() - return PlaybackResponse(status_decoded, data_decoded) + return PlaybackResponse( + status_decoded, + data_decoded + ) } suspend fun next(timedInvokeTimeout: Duration? = null): PlaybackResponse { val commandId: UInt = 5u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -493,47 +590,54 @@ class MediaPlaybackCluster( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_DATA: Int = 1 var data_decoded: String? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_STATUS)) { - status_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_DATA)) { - data_decoded = + + if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_DATA)) {data_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - } - } else { + tlvReader.getString(tag) + } else { + null + } + }} + + + else { tlvReader.skipElement() } } + + if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } + + + tlvReader.exitContainer() - return PlaybackResponse(status_decoded, data_decoded) + return PlaybackResponse( + status_decoded, + data_decoded + ) } - suspend fun rewind( - audioAdvanceUnmuted: Boolean?, - timedInvokeTimeout: Duration? = null, - ): PlaybackResponse { + suspend fun rewind(audioAdvanceUnmuted: Boolean? + ,timedInvokeTimeout: Duration? = null): PlaybackResponse { val commandId: UInt = 6u val tlvWriter = TlvWriter() @@ -542,14 +646,14 @@ class MediaPlaybackCluster( val TAG_AUDIO_ADVANCE_UNMUTED_REQ: Int = 0 audioAdvanceUnmuted?.let { tlvWriter.put(ContextSpecificTag(TAG_AUDIO_ADVANCE_UNMUTED_REQ), audioAdvanceUnmuted) - } + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -559,47 +663,54 @@ class MediaPlaybackCluster( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_DATA: Int = 1 var data_decoded: String? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_STATUS)) { - status_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_DATA)) { - data_decoded = + + if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_DATA)) {data_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - } - } else { + tlvReader.getString(tag) + } else { + null + } + }} + + + else { tlvReader.skipElement() } } + + if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } + + + tlvReader.exitContainer() - return PlaybackResponse(status_decoded, data_decoded) + return PlaybackResponse( + status_decoded, + data_decoded + ) } - suspend fun fastForward( - audioAdvanceUnmuted: Boolean?, - timedInvokeTimeout: Duration? = null, - ): PlaybackResponse { + suspend fun fastForward(audioAdvanceUnmuted: Boolean? + ,timedInvokeTimeout: Duration? = null): PlaybackResponse { val commandId: UInt = 7u val tlvWriter = TlvWriter() @@ -608,14 +719,14 @@ class MediaPlaybackCluster( val TAG_AUDIO_ADVANCE_UNMUTED_REQ: Int = 0 audioAdvanceUnmuted?.let { tlvWriter.put(ContextSpecificTag(TAG_AUDIO_ADVANCE_UNMUTED_REQ), audioAdvanceUnmuted) - } + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -625,64 +736,68 @@ class MediaPlaybackCluster( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_DATA: Int = 1 var data_decoded: String? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_STATUS)) { - status_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_DATA)) { - data_decoded = + + if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_DATA)) {data_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - } - } else { + tlvReader.getString(tag) + } else { + null + } + }} + + + else { tlvReader.skipElement() } } + + if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } + + + tlvReader.exitContainer() - return PlaybackResponse(status_decoded, data_decoded) + return PlaybackResponse( + status_decoded, + data_decoded + ) } - suspend fun skipForward( - deltaPositionMilliseconds: ULong, - timedInvokeTimeout: Duration? = null, - ): PlaybackResponse { + suspend fun skipForward(deltaPositionMilliseconds: ULong + ,timedInvokeTimeout: Duration? = null): PlaybackResponse { val commandId: UInt = 8u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_DELTA_POSITION_MILLISECONDS_REQ: Int = 0 - tlvWriter.put( - ContextSpecificTag(TAG_DELTA_POSITION_MILLISECONDS_REQ), - deltaPositionMilliseconds, - ) + tlvWriter.put(ContextSpecificTag(TAG_DELTA_POSITION_MILLISECONDS_REQ), deltaPositionMilliseconds) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -692,64 +807,68 @@ class MediaPlaybackCluster( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_DATA: Int = 1 var data_decoded: String? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_STATUS)) { - status_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_DATA)) { - data_decoded = + + if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_DATA)) {data_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - } - } else { + tlvReader.getString(tag) + } else { + null + } + }} + + + else { tlvReader.skipElement() } } + + if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } + + + tlvReader.exitContainer() - return PlaybackResponse(status_decoded, data_decoded) + return PlaybackResponse( + status_decoded, + data_decoded + ) } - suspend fun skipBackward( - deltaPositionMilliseconds: ULong, - timedInvokeTimeout: Duration? = null, - ): PlaybackResponse { + suspend fun skipBackward(deltaPositionMilliseconds: ULong + ,timedInvokeTimeout: Duration? = null): PlaybackResponse { val commandId: UInt = 9u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_DELTA_POSITION_MILLISECONDS_REQ: Int = 0 - tlvWriter.put( - ContextSpecificTag(TAG_DELTA_POSITION_MILLISECONDS_REQ), - deltaPositionMilliseconds, - ) + tlvWriter.put(ContextSpecificTag(TAG_DELTA_POSITION_MILLISECONDS_REQ), deltaPositionMilliseconds) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -759,58 +878,68 @@ class MediaPlaybackCluster( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_DATA: Int = 1 var data_decoded: String? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_STATUS)) { - status_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_DATA)) { - data_decoded = + + if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_DATA)) {data_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - } - } else { + tlvReader.getString(tag) + } else { + null + } + }} + + + else { tlvReader.skipElement() } } + + if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } + + + tlvReader.exitContainer() - return PlaybackResponse(status_decoded, data_decoded) + return PlaybackResponse( + status_decoded, + data_decoded + ) } - suspend fun seek(position: ULong, timedInvokeTimeout: Duration? = null): PlaybackResponse { + suspend fun seek(position: ULong + ,timedInvokeTimeout: Duration? = null): PlaybackResponse { val commandId: UInt = 11u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_POSITION_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_POSITION_REQ), position) + tlvWriter.put(ContextSpecificTag(TAG_POSITION_REQ), position) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -820,48 +949,55 @@ class MediaPlaybackCluster( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_DATA: Int = 1 var data_decoded: String? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_STATUS)) { - status_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_DATA)) { - data_decoded = + + if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_DATA)) {data_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - } - } else { + tlvReader.getString(tag) + } else { + null + } + }} + + + else { tlvReader.skipElement() } } + + if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } + + + tlvReader.exitContainer() - return PlaybackResponse(status_decoded, data_decoded) + return PlaybackResponse( + status_decoded, + data_decoded + ) } - suspend fun activateAudioTrack( - trackID: String, - audioOutputIndex: UByte, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun activateAudioTrack(trackID: String + ,audioOutputIndex: UByte + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 12u val tlvWriter = TlvWriter() @@ -871,35 +1007,36 @@ class MediaPlaybackCluster( tlvWriter.put(ContextSpecificTag(TAG_TRACK_ID_REQ), trackID) val TAG_AUDIO_OUTPUT_INDEX_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_AUDIO_OUTPUT_INDEX_REQ), audioOutputIndex) + tlvWriter.put(ContextSpecificTag(TAG_AUDIO_OUTPUT_INDEX_REQ), audioOutputIndex) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun activateTextTrack(trackID: String, timedInvokeTimeout: Duration? = null) { + suspend fun activateTextTrack(trackID: String + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 13u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_TRACK_ID_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_TRACK_ID_REQ), trackID) + tlvWriter.put(ContextSpecificTag(TAG_TRACK_ID_REQ), trackID) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -910,87 +1047,92 @@ class MediaPlaybackCluster( val commandId: UInt = 14u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } +suspend fun readCurrentStateAttribute(): UByte {val ATTRIBUTE_ID: UInt = 0u - suspend fun readCurrentStateAttribute(): 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 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}") - } + 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) { "Currentstate attribute not found in response" } + } + + requireNotNull(attributeData) { + "Currentstate 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 subscribeCurrentStateAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Currentstate attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Currentstate attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -1002,1132 +1144,1181 @@ class MediaPlaybackCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readStartTimeAttribute(): StartTimeAttribute {val ATTRIBUTE_ID: UInt = 1u - suspend fun readStartTimeAttribute(): StartTimeAttribute { - 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 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}") - } + 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) { "Starttime attribute not found in response" } + } + + requireNotNull(attributeData) { + "Starttime 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 - } + val decodedValue: ULong? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return StartTimeAttribute(decodedValue) } suspend fun subscribeStartTimeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StartTimeAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StartTimeAttributeSubscriptionState.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) { "Starttime attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Starttime 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(StartTimeAttributeSubscriptionState.Success(it)) } + val decodedValue: ULong? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(StartTimeAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(StartTimeAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readDurationAttribute(): DurationAttribute {val ATTRIBUTE_ID: UInt = 2u - suspend fun readDurationAttribute(): DurationAttribute { - 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 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}") - } + 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) { "Duration attribute not found in response" } + } + + requireNotNull(attributeData) { + "Duration 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 - } + val decodedValue: ULong? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return DurationAttribute(decodedValue) } suspend fun subscribeDurationAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - DurationAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(DurationAttributeSubscriptionState.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) { "Duration attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Duration 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(DurationAttributeSubscriptionState.Success(it)) } + val decodedValue: ULong? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(DurationAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(DurationAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readSampledPositionAttribute(): SampledPositionAttribute {val ATTRIBUTE_ID: UInt = 3u - suspend fun readSampledPositionAttribute(): SampledPositionAttribute { - 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 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}") - } + 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) { "Sampledposition attribute not found in response" } + } + + requireNotNull(attributeData) { + "Sampledposition attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: MediaPlaybackClusterPlaybackPositionStruct? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - MediaPlaybackClusterPlaybackPositionStruct.fromTlv(AnonymousTag, tlvReader) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: MediaPlaybackClusterPlaybackPositionStruct? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + MediaPlaybackClusterPlaybackPositionStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return SampledPositionAttribute(decodedValue) } suspend fun subscribeSampledPositionAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - SampledPositionAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(SampledPositionAttributeSubscriptionState.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) { - "Sampledposition attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Sampledposition attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: MediaPlaybackClusterPlaybackPositionStruct? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - MediaPlaybackClusterPlaybackPositionStruct.fromTlv(AnonymousTag, tlvReader) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(SampledPositionAttributeSubscriptionState.Success(it)) } + val decodedValue: MediaPlaybackClusterPlaybackPositionStruct? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + MediaPlaybackClusterPlaybackPositionStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(SampledPositionAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(SampledPositionAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readPlaybackSpeedAttribute(): Float? {val ATTRIBUTE_ID: UInt = 4u - suspend fun readPlaybackSpeedAttribute(): Float? { - 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 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}") - } + 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) { "Playbackspeed attribute not found in response" } + } + + requireNotNull(attributeData) { + "Playbackspeed attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } + val decodedValue: Float? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribePlaybackSpeedAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - FloatSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(FloatSubscriptionState.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) { "Playbackspeed attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Playbackspeed attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(FloatSubscriptionState.Success(it)) } + val decodedValue: Float? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(FloatSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(FloatSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readSeekRangeEndAttribute(): SeekRangeEndAttribute {val ATTRIBUTE_ID: UInt = 5u - suspend fun readSeekRangeEndAttribute(): SeekRangeEndAttribute { - 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 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}") - } + 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) { "Seekrangeend attribute not found in response" } + } + + requireNotNull(attributeData) { + "Seekrangeend 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 - } + val decodedValue: ULong? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return SeekRangeEndAttribute(decodedValue) } suspend fun subscribeSeekRangeEndAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - SeekRangeEndAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(SeekRangeEndAttributeSubscriptionState.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) { "Seekrangeend attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Seekrangeend 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(SeekRangeEndAttributeSubscriptionState.Success(it)) } + val decodedValue: ULong? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(SeekRangeEndAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(SeekRangeEndAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readSeekRangeStartAttribute(): SeekRangeStartAttribute {val ATTRIBUTE_ID: UInt = 6u - suspend fun readSeekRangeStartAttribute(): SeekRangeStartAttribute { - 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 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}") - } + 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) { "Seekrangestart attribute not found in response" } + } + + requireNotNull(attributeData) { + "Seekrangestart 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 - } + val decodedValue: ULong? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return SeekRangeStartAttribute(decodedValue) } suspend fun subscribeSeekRangeStartAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - SeekRangeStartAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(SeekRangeStartAttributeSubscriptionState.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) { - "Seekrangestart attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Seekrangestart 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(SeekRangeStartAttributeSubscriptionState.Success(it)) } + val decodedValue: ULong? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(SeekRangeStartAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(SeekRangeStartAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readActiveAudioTrackAttribute(): ActiveAudioTrackAttribute {val ATTRIBUTE_ID: UInt = 7u - suspend fun readActiveAudioTrackAttribute(): ActiveAudioTrackAttribute { - 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 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}") - } + 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) { "Activeaudiotrack attribute not found in response" } + } + + requireNotNull(attributeData) { + "Activeaudiotrack attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: MediaPlaybackClusterTrackStruct? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - MediaPlaybackClusterTrackStruct.fromTlv(AnonymousTag, tlvReader) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: MediaPlaybackClusterTrackStruct? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + MediaPlaybackClusterTrackStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return ActiveAudioTrackAttribute(decodedValue) } suspend fun subscribeActiveAudioTrackAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ActiveAudioTrackAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ActiveAudioTrackAttributeSubscriptionState.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) { - "Activeaudiotrack attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Activeaudiotrack attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: MediaPlaybackClusterTrackStruct? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - MediaPlaybackClusterTrackStruct.fromTlv(AnonymousTag, tlvReader) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(ActiveAudioTrackAttributeSubscriptionState.Success(it)) } + val decodedValue: MediaPlaybackClusterTrackStruct? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + MediaPlaybackClusterTrackStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(ActiveAudioTrackAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ActiveAudioTrackAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAvailableAudioTracksAttribute(): AvailableAudioTracksAttribute {val ATTRIBUTE_ID: UInt = 8u - suspend fun readAvailableAudioTracksAttribute(): AvailableAudioTracksAttribute { - val ATTRIBUTE_ID: UInt = 8u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Availableaudiotracks attribute not found in response" } + } + + requireNotNull(attributeData) { + "Availableaudiotracks attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(MediaPlaybackClusterTrackStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null + val decodedValue: List? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(MediaPlaybackClusterTrackStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return AvailableAudioTracksAttribute(decodedValue) } suspend fun subscribeAvailableAudioTracksAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - AvailableAudioTracksAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(AvailableAudioTracksAttributeSubscriptionState.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) { - "Availableaudiotracks attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Availableaudiotracks attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(MediaPlaybackClusterTrackStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(AvailableAudioTracksAttributeSubscriptionState.Success(it)) } + val decodedValue: List? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(MediaPlaybackClusterTrackStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(AvailableAudioTracksAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(AvailableAudioTracksAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readActiveTextTrackAttribute(): ActiveTextTrackAttribute {val ATTRIBUTE_ID: UInt = 9u - suspend fun readActiveTextTrackAttribute(): ActiveTextTrackAttribute { - val ATTRIBUTE_ID: UInt = 9u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Activetexttrack attribute not found in response" } + } + + requireNotNull(attributeData) { + "Activetexttrack attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: MediaPlaybackClusterTrackStruct? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - MediaPlaybackClusterTrackStruct.fromTlv(AnonymousTag, tlvReader) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: MediaPlaybackClusterTrackStruct? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + MediaPlaybackClusterTrackStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return ActiveTextTrackAttribute(decodedValue) } suspend fun subscribeActiveTextTrackAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ActiveTextTrackAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ActiveTextTrackAttributeSubscriptionState.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) { - "Activetexttrack attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Activetexttrack attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: MediaPlaybackClusterTrackStruct? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - MediaPlaybackClusterTrackStruct.fromTlv(AnonymousTag, tlvReader) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(ActiveTextTrackAttributeSubscriptionState.Success(it)) } + val decodedValue: MediaPlaybackClusterTrackStruct? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + MediaPlaybackClusterTrackStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(ActiveTextTrackAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ActiveTextTrackAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAvailableTextTracksAttribute(): AvailableTextTracksAttribute {val ATTRIBUTE_ID: UInt = 10u - suspend fun readAvailableTextTracksAttribute(): AvailableTextTracksAttribute { - val ATTRIBUTE_ID: UInt = 10u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Availabletexttracks attribute not found in response" } + } + + requireNotNull(attributeData) { + "Availabletexttracks attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(MediaPlaybackClusterTrackStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null + val decodedValue: List? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(MediaPlaybackClusterTrackStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return AvailableTextTracksAttribute(decodedValue) } suspend fun subscribeAvailableTextTracksAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - AvailableTextTracksAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(AvailableTextTracksAttributeSubscriptionState.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) { - "Availabletexttracks attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Availabletexttracks attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(MediaPlaybackClusterTrackStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(AvailableTextTracksAttributeSubscriptionState.Success(it)) } + val decodedValue: List? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(MediaPlaybackClusterTrackStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(AvailableTextTracksAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(AvailableTextTracksAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65528u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -2135,96 +2326,97 @@ class MediaPlaybackCluster( emit(GeneratedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65529u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -2232,94 +2424,97 @@ class MediaPlaybackCluster( emit(AcceptedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt = 65530u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -2327,94 +2522,97 @@ class MediaPlaybackCluster( emit(EventListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ID: UInt = 65531u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -2422,76 +2620,81 @@ class MediaPlaybackCluster( emit(AttributeListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u - 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 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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -2503,77 +2706,80 @@ class MediaPlaybackCluster( emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 65533u - 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 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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -2586,7 +2792,7 @@ class MediaPlaybackCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/MessagesCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/MessagesCluster.kt index e832c5cefe49b3..effa24084cd5ab 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/MessagesCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/MessagesCluster.kt @@ -17,100 +17,135 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.UIntSubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState +import matter.controller.UByteSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class MessagesCluster(private val controller: MatterController, private val endpointId: UShort) { - class MessagesAttribute(val value: List) +class MessagesCluster(private val controller: MatterController, private val endpointId: UShort) {class MessagesAttribute( + val value: List + ) sealed class MessagesAttributeSubscriptionState { - data class Success(val value: List) : - MessagesAttributeSubscriptionState() - + data class Success( + val value: List + ) : MessagesAttributeSubscriptionState() + data class Error(val exception: Exception) : MessagesAttributeSubscriptionState() - object SubscriptionEstablished : MessagesAttributeSubscriptionState() - } - - class ActiveMessageIDsAttribute(val value: List) + object SubscriptionEstablished : MessagesAttributeSubscriptionState() + } +class ActiveMessageIDsAttribute( + val value: List + ) sealed class ActiveMessageIDsAttributeSubscriptionState { - data class Success(val value: List) : ActiveMessageIDsAttributeSubscriptionState() - + data class Success( + val value: List + ) : ActiveMessageIDsAttributeSubscriptionState() + data class Error(val exception: Exception) : ActiveMessageIDsAttributeSubscriptionState() - object SubscriptionEstablished : ActiveMessageIDsAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : ActiveMessageIDsAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } - - suspend fun presentMessagesRequest( - messageID: ByteArray, - priority: UByte, - messageControl: UByte, - startTime: UInt?, - duration: ULong?, - messageText: String, - responses: List?, - timedInvokeTimeout: Duration? = null, - ) { + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } + + suspend fun presentMessagesRequest(messageID: ByteArray + ,priority: UByte + ,messageControl: UByte + ,startTime: UInt? + ,duration: ULong? + ,messageText: String + ,responses: List? + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() @@ -126,10 +161,14 @@ class MessagesCluster(private val controller: MatterController, private val endp tlvWriter.put(ContextSpecificTag(TAG_MESSAGE_CONTROL_REQ), messageControl) val TAG_START_TIME_REQ: Int = 3 - startTime?.let { tlvWriter.put(ContextSpecificTag(TAG_START_TIME_REQ), startTime) } + startTime?.let { + tlvWriter.put(ContextSpecificTag(TAG_START_TIME_REQ), startTime) + } val TAG_DURATION_REQ: Int = 4 - duration?.let { tlvWriter.put(ContextSpecificTag(TAG_DURATION_REQ), duration) } + duration?.let { + tlvWriter.put(ContextSpecificTag(TAG_DURATION_REQ), duration) + } val TAG_MESSAGE_TEXT_REQ: Int = 5 tlvWriter.put(ContextSpecificTag(TAG_MESSAGE_TEXT_REQ), messageText) @@ -141,24 +180,22 @@ class MessagesCluster(private val controller: MatterController, private val endp item.toTlv(AnonymousTag, tlvWriter) } tlvWriter.endArray() - } + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun cancelMessagesRequest( - messageIDs: List, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun cancelMessagesRequest(messageIDs: List + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 1u val tlvWriter = TlvWriter() @@ -166,108 +203,111 @@ class MessagesCluster(private val controller: MatterController, private val endp val TAG_MESSAGE_I_DS_REQ: Int = 0 tlvWriter.startArray(ContextSpecificTag(TAG_MESSAGE_I_DS_REQ)) - for (item in messageIDs.iterator()) { - tlvWriter.put(AnonymousTag, item) - } - tlvWriter.endArray() + for (item in messageIDs.iterator()) { + tlvWriter.put(AnonymousTag, item) + } + tlvWriter.endArray() tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - - suspend fun readMessagesAttribute(): MessagesAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMessagesAttribute(): MessagesAttribute {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}") - } + 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) { "Messages attribute not found in response" } + } + + requireNotNull(attributeData) { + "Messages 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(MessagesClusterMessageStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(MessagesClusterMessageStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + return MessagesAttribute(decodedValue) } suspend fun subscribeMessagesAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MessagesAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MessagesAttributeSubscriptionState.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) { "Messages attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Messages 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(MessagesClusterMessageStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(MessagesClusterMessageStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(MessagesAttributeSubscriptionState.Success(decodedValue)) } @@ -275,96 +315,97 @@ class MessagesCluster(private val controller: MatterController, private val endp emit(MessagesAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readActiveMessageIDsAttribute(): ActiveMessageIDsAttribute { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readActiveMessageIDsAttribute(): ActiveMessageIDsAttribute {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}") - } + 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) { "Activemessageids attribute not found in response" } + } + + requireNotNull(attributeData) { + "Activemessageids 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.getByteArray(AnonymousTag)) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getByteArray(AnonymousTag)) } + tlvReader.exitContainer() + } + return ActiveMessageIDsAttribute(decodedValue) } suspend fun subscribeActiveMessageIDsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ActiveMessageIDsAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ActiveMessageIDsAttributeSubscriptionState.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) { - "Activemessageids attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Activemessageids 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.getByteArray(AnonymousTag)) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getByteArray(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(ActiveMessageIDsAttributeSubscriptionState.Success(decodedValue)) } @@ -372,96 +413,97 @@ class MessagesCluster(private val controller: MatterController, private val endp emit(ActiveMessageIDsAttributeSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -469,96 +511,97 @@ class MessagesCluster(private val controller: MatterController, private val endp 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -566,94 +609,97 @@ class MessagesCluster(private val controller: MatterController, private val endp 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -661,94 +707,97 @@ class MessagesCluster(private val controller: MatterController, private val endp 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -756,76 +805,81 @@ class MessagesCluster(private val controller: MatterController, private val endp 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -837,77 +891,80 @@ class MessagesCluster(private val controller: MatterController, private val endp 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -920,7 +977,7 @@ class MessagesCluster(private val controller: MatterController, private val endp emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/MicrowaveOvenControlCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/MicrowaveOvenControlCluster.kt index 55beb250c74862..08a1b816898255 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/MicrowaveOvenControlCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/MicrowaveOvenControlCluster.kt @@ -17,104 +17,139 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class MicrowaveOvenControlCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class SupportedWattsAttribute(val value: List?) +class MicrowaveOvenControlCluster(private val controller: MatterController, private val endpointId: UShort) {class SupportedWattsAttribute( + val value: List? + ) sealed class SupportedWattsAttributeSubscriptionState { - data class Success(val value: List?) : SupportedWattsAttributeSubscriptionState() - + data class Success( + val value: List? + ) : SupportedWattsAttributeSubscriptionState() + data class Error(val exception: Exception) : SupportedWattsAttributeSubscriptionState() - object SubscriptionEstablished : SupportedWattsAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : SupportedWattsAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun setCookingParameters( - cookMode: UByte?, - cookTime: UInt?, - powerSetting: UByte?, - wattSettingIndex: UByte?, - startAfterSetting: Boolean?, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun setCookingParameters(cookMode: UByte? + ,cookTime: UInt? + ,powerSetting: UByte? + ,wattSettingIndex: UByte? + ,startAfterSetting: Boolean? + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_COOK_MODE_REQ: Int = 0 - cookMode?.let { tlvWriter.put(ContextSpecificTag(TAG_COOK_MODE_REQ), cookMode) } + cookMode?.let { + tlvWriter.put(ContextSpecificTag(TAG_COOK_MODE_REQ), cookMode) + } val TAG_COOK_TIME_REQ: Int = 1 - cookTime?.let { tlvWriter.put(ContextSpecificTag(TAG_COOK_TIME_REQ), cookTime) } + cookTime?.let { + tlvWriter.put(ContextSpecificTag(TAG_COOK_TIME_REQ), cookTime) + } val TAG_POWER_SETTING_REQ: Int = 2 - powerSetting?.let { tlvWriter.put(ContextSpecificTag(TAG_POWER_SETTING_REQ), powerSetting) } + powerSetting?.let { + tlvWriter.put(ContextSpecificTag(TAG_POWER_SETTING_REQ), powerSetting) + } val TAG_WATT_SETTING_INDEX_REQ: Int = 3 wattSettingIndex?.let { @@ -124,108 +159,114 @@ class MicrowaveOvenControlCluster( val TAG_START_AFTER_SETTING_REQ: Int = 4 startAfterSetting?.let { tlvWriter.put(ContextSpecificTag(TAG_START_AFTER_SETTING_REQ), startAfterSetting) - } + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun addMoreTime(timeToAdd: UInt, timedInvokeTimeout: Duration? = null) { + suspend fun addMoreTime(timeToAdd: UInt + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 1u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_TIME_TO_ADD_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_TIME_TO_ADD_REQ), timeToAdd) + tlvWriter.put(ContextSpecificTag(TAG_TIME_TO_ADD_REQ), timeToAdd) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - - suspend fun readCookTimeAttribute(): UInt { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readCookTimeAttribute(): UInt {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}") - } + 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) { "Cooktime attribute not found in response" } + } + + requireNotNull(attributeData) { + "Cooktime 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 subscribeCookTimeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Cooktime attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Cooktime attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -237,76 +278,81 @@ class MicrowaveOvenControlCluster( emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readMaxCookTimeAttribute(): UInt { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMaxCookTimeAttribute(): UInt {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}") - } + 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) { "Maxcooktime attribute not found in response" } + } + + requireNotNull(attributeData) { + "Maxcooktime 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 subscribeMaxCookTimeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Maxcooktime attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Maxcooktime attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -318,749 +364,788 @@ class MicrowaveOvenControlCluster( emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readPowerSettingAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readPowerSettingAttribute(): UByte? {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}") - } + 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) { "Powersetting attribute not found in response" } + } + + requireNotNull(attributeData) { + "Powersetting 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribePowerSettingAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Powersetting attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Powersetting 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)) } + 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 readMinPowerAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMinPowerAttribute(): UByte? {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}") - } + 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) { "Minpower attribute not found in response" } + } + + requireNotNull(attributeData) { + "Minpower 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeMinPowerAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Minpower attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Minpower 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)) } + 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 readMaxPowerAttribute(): 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)) - +suspend fun readMaxPowerAttribute(): 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}") - } + 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) { "Maxpower attribute not found in response" } + } + + requireNotNull(attributeData) { + "Maxpower 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeMaxPowerAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Maxpower attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Maxpower 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)) } + 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 readPowerStepAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 5u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readPowerStepAttribute(): UByte? {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}") - } + 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) { "Powerstep attribute not found in response" } + } + + requireNotNull(attributeData) { + "Powerstep 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribePowerStepAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Powerstep attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Powerstep 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)) } + 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 readSupportedWattsAttribute(): SupportedWattsAttribute { - val ATTRIBUTE_ID: UInt = 6u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readSupportedWattsAttribute(): SupportedWattsAttribute {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}") - } + 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) { "Supportedwatts attribute not found in response" } + } + + requireNotNull(attributeData) { + "Supportedwatts attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getUShort(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUShort(AnonymousTag)) } + tlvReader.exitContainer() + } + } else { + null + } + return SupportedWattsAttribute(decodedValue) } suspend fun subscribeSupportedWattsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - SupportedWattsAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(SupportedWattsAttributeSubscriptionState.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) { - "Supportedwatts attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Supportedwatts attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getUShort(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { emit(SupportedWattsAttributeSubscriptionState.Success(it)) } + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUShort(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { + emit(SupportedWattsAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(SupportedWattsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readSelectedWattIndexAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 7u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readSelectedWattIndexAttribute(): UByte? {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}") - } + 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) { "Selectedwattindex attribute not found in response" } + } + + requireNotNull(attributeData) { + "Selectedwattindex 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeSelectedWattIndexAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Selectedwattindex attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Selectedwattindex 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)) } + 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 readWattRatingAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 8u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readWattRatingAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 8u + + 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}") - } + 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) { "Wattrating attribute not found in response" } + } + + requireNotNull(attributeData) { + "Wattrating 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeWattRatingAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Wattrating attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Wattrating 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)) } + 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 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1068,96 +1153,97 @@ class MicrowaveOvenControlCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1165,94 +1251,97 @@ class MicrowaveOvenControlCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1260,94 +1349,97 @@ class MicrowaveOvenControlCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1355,76 +1447,81 @@ class MicrowaveOvenControlCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1436,77 +1533,80 @@ class MicrowaveOvenControlCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1519,7 +1619,7 @@ class MicrowaveOvenControlCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/MicrowaveOvenModeCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/MicrowaveOvenModeCluster.kt index ae3df9b21f5b98..70c0c2f0b02c69 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/MicrowaveOvenModeCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/MicrowaveOvenModeCluster.kt @@ -17,166 +17,202 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath +import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader +import matter.tlv.TlvWriter -class MicrowaveOvenModeCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class SupportedModesAttribute(val value: List) +class MicrowaveOvenModeCluster(private val controller: MatterController, private val endpointId: UShort) {class SupportedModesAttribute( + val value: List + ) sealed class SupportedModesAttributeSubscriptionState { - data class Success(val value: List) : - SupportedModesAttributeSubscriptionState() - + data class Success( + val value: List + ) : SupportedModesAttributeSubscriptionState() + data class Error(val exception: Exception) : SupportedModesAttributeSubscriptionState() - object SubscriptionEstablished : SupportedModesAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : SupportedModesAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } - - suspend fun readSupportedModesAttribute(): SupportedModesAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } +suspend fun readSupportedModesAttribute(): SupportedModesAttribute {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}") - } + 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) { "Supportedmodes attribute not found in response" } + } + + requireNotNull(attributeData) { + "Supportedmodes 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(MicrowaveOvenModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(MicrowaveOvenModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + return SupportedModesAttribute(decodedValue) } suspend fun subscribeSupportedModesAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - SupportedModesAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(SupportedModesAttributeSubscriptionState.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) { - "Supportedmodes attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Supportedmodes 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(MicrowaveOvenModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(MicrowaveOvenModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(SupportedModesAttributeSubscriptionState.Success(decodedValue)) } @@ -184,76 +220,81 @@ class MicrowaveOvenModeCluster( emit(SupportedModesAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readCurrentModeAttribute(): 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)) - +suspend fun readCurrentModeAttribute(): 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}") - } + 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) { "Currentmode attribute not found in response" } + } + + requireNotNull(attributeData) { + "Currentmode 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 subscribeCurrentModeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Currentmode attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Currentmode attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -265,96 +306,97 @@ class MicrowaveOvenModeCluster( emit(UByteSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -362,96 +404,97 @@ class MicrowaveOvenModeCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -459,94 +502,97 @@ class MicrowaveOvenModeCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -554,94 +600,97 @@ class MicrowaveOvenModeCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -649,76 +698,81 @@ class MicrowaveOvenModeCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -730,77 +784,80 @@ class MicrowaveOvenModeCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -813,7 +870,7 @@ class MicrowaveOvenModeCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/ModeSelectCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/ModeSelectCluster.kt index 3b93695d9ce56c..e07ee80f76b046 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/ModeSelectCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/ModeSelectCluster.kt @@ -17,203 +17,247 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest -import matter.controller.StringSubscriptionState +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.cluster.structs.* +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class ModeSelectCluster(private val controller: MatterController, private val endpointId: UShort) { - class StandardNamespaceAttribute(val value: UShort?) +class ModeSelectCluster(private val controller: MatterController, private val endpointId: UShort) {class StandardNamespaceAttribute( + val value: UShort? + ) sealed class StandardNamespaceAttributeSubscriptionState { - data class Success(val value: UShort?) : StandardNamespaceAttributeSubscriptionState() - + data class Success( + val value: UShort? + ) : StandardNamespaceAttributeSubscriptionState() + data class Error(val exception: Exception) : StandardNamespaceAttributeSubscriptionState() - object SubscriptionEstablished : StandardNamespaceAttributeSubscriptionState() - } - - class SupportedModesAttribute(val value: List) + object SubscriptionEstablished : StandardNamespaceAttributeSubscriptionState() + } +class SupportedModesAttribute( + val value: List + ) sealed class SupportedModesAttributeSubscriptionState { - data class Success(val value: List) : - SupportedModesAttributeSubscriptionState() - + data class Success( + val value: List + ) : SupportedModesAttributeSubscriptionState() + data class Error(val exception: Exception) : SupportedModesAttributeSubscriptionState() - object SubscriptionEstablished : SupportedModesAttributeSubscriptionState() - } - - class StartUpModeAttribute(val value: UByte?) + object SubscriptionEstablished : SupportedModesAttributeSubscriptionState() + } +class StartUpModeAttribute( + val value: UByte? + ) sealed class StartUpModeAttributeSubscriptionState { - data class Success(val value: UByte?) : StartUpModeAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : StartUpModeAttributeSubscriptionState() + data class Error(val exception: Exception) : StartUpModeAttributeSubscriptionState() - object SubscriptionEstablished : StartUpModeAttributeSubscriptionState() - } - - class OnModeAttribute(val value: UByte?) + object SubscriptionEstablished : StartUpModeAttributeSubscriptionState() + } +class OnModeAttribute( + val value: UByte? + ) sealed class OnModeAttributeSubscriptionState { - data class Success(val value: UByte?) : OnModeAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : OnModeAttributeSubscriptionState() + data class Error(val exception: Exception) : OnModeAttributeSubscriptionState() - object SubscriptionEstablished : OnModeAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : OnModeAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun changeToMode(newMode: UByte, timedInvokeTimeout: Duration? = null) { + suspend fun changeToMode(newMode: UByte + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_NEW_MODE_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_NEW_MODE_REQ), newMode) + tlvWriter.put(ContextSpecificTag(TAG_NEW_MODE_REQ), newMode) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - - suspend fun readDescriptionAttribute(): String { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readDescriptionAttribute(): String {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}") - } + 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) { "Description attribute not found in response" } + } + + requireNotNull(attributeData) { + "Description attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: String = tlvReader.getString(AnonymousTag) + return decodedValue } suspend fun subscribeDescriptionAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StringSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StringSubscriptionState.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) { "Description attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Description attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -225,191 +269,196 @@ class ModeSelectCluster(private val controller: MatterController, private val en emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readStandardNamespaceAttribute(): StandardNamespaceAttribute { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readStandardNamespaceAttribute(): StandardNamespaceAttribute {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}") - } + 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) { "Standardnamespace attribute not found in response" } + } + + requireNotNull(attributeData) { + "Standardnamespace attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = - if (!tlvReader.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return StandardNamespaceAttribute(decodedValue) } suspend fun subscribeStandardNamespaceAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StandardNamespaceAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StandardNamespaceAttributeSubscriptionState.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) { - "Standardnamespace attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Standardnamespace 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.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(StandardNamespaceAttributeSubscriptionState.Success(it)) } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(StandardNamespaceAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(StandardNamespaceAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readSupportedModesAttribute(): SupportedModesAttribute { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readSupportedModesAttribute(): SupportedModesAttribute {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}") - } + 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) { "Supportedmodes attribute not found in response" } + } + + requireNotNull(attributeData) { + "Supportedmodes 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(ModeSelectClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(ModeSelectClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + return SupportedModesAttribute(decodedValue) } suspend fun subscribeSupportedModesAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - SupportedModesAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(SupportedModesAttributeSubscriptionState.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) { - "Supportedmodes attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Supportedmodes 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(ModeSelectClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(ModeSelectClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(SupportedModesAttributeSubscriptionState.Success(decodedValue)) } @@ -417,76 +466,81 @@ class ModeSelectCluster(private val controller: MatterController, private val en emit(SupportedModesAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readCurrentModeAttribute(): UByte { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readCurrentModeAttribute(): UByte {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}") - } + 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) { "Currentmode attribute not found in response" } + } + + requireNotNull(attributeData) { + "Currentmode 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 subscribeCurrentModeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Currentmode attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Currentmode attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -498,67 +552,77 @@ class ModeSelectCluster(private val controller: MatterController, private val en emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readStartUpModeAttribute(): StartUpModeAttribute { - val ATTRIBUTE_ID: UInt = 4u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readStartUpModeAttribute(): StartUpModeAttribute {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}") - } + 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) { "Startupmode attribute not found in response" } + } + + requireNotNull(attributeData) { + "Startupmode attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return StartUpModeAttribute(decodedValue) } - suspend fun writeStartUpModeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeStartUpModeAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 4u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -579,127 +643,137 @@ class ModeSelectCluster(private val controller: MatterController, private val en throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeStartUpModeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StartUpModeAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StartUpModeAttributeSubscriptionState.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) { "Startupmode attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Startupmode 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(StartUpModeAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(StartUpModeAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(StartUpModeAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readOnModeAttribute(): OnModeAttribute { - val ATTRIBUTE_ID: UInt = 5u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readOnModeAttribute(): OnModeAttribute {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}") - } + 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) { "Onmode attribute not found in response" } + } + + requireNotNull(attributeData) { + "Onmode attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return OnModeAttribute(decodedValue) } - suspend fun writeOnModeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeOnModeAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 5u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -720,156 +794,157 @@ class ModeSelectCluster(private val controller: MatterController, private val en throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeOnModeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - OnModeAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(OnModeAttributeSubscriptionState.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) { "Onmode attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Onmode 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(OnModeAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(OnModeAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(OnModeAttributeSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -877,96 +952,97 @@ class ModeSelectCluster(private val controller: MatterController, private val en 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -974,94 +1050,97 @@ class ModeSelectCluster(private val controller: MatterController, private val en 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1069,94 +1148,97 @@ class ModeSelectCluster(private val controller: MatterController, private val en 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1164,76 +1246,81 @@ class ModeSelectCluster(private val controller: MatterController, private val en 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1245,77 +1332,80 @@ class ModeSelectCluster(private val controller: MatterController, private val en 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1328,7 +1418,7 @@ class ModeSelectCluster(private val controller: MatterController, private val en emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/NetworkCommissioningCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/NetworkCommissioningCluster.kt index 2a144baed4f8fd..5a6e43bcee3cb3 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/NetworkCommissioningCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/NetworkCommissioningCluster.kt @@ -17,173 +17,216 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration 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.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.cluster.structs.* +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class NetworkCommissioningCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { +class NetworkCommissioningCluster(private val controller: MatterController, private val endpointId: UShort) { class ScanNetworksResponse( - val networkingStatus: UByte, - val debugText: String?, - val wiFiScanResults: List?, - val threadScanResults: List?, + val networkingStatus: UByte, + val debugText: String?, + val wiFiScanResults: List?, + val threadScanResults: List? ) class NetworkConfigResponse( - val networkingStatus: UByte, - val debugText: String?, - val networkIndex: UByte?, - val clientIdentity: ByteArray?, - val possessionSignature: ByteArray?, + val networkingStatus: UByte, + val debugText: String?, + val networkIndex: UByte?, + val clientIdentity: ByteArray?, + val possessionSignature: ByteArray? ) class ConnectNetworkResponse( - val networkingStatus: UByte, - val debugText: String?, - val errorValue: Int?, + val networkingStatus: UByte, + val debugText: String?, + val errorValue: Int? ) - class QueryIdentityResponse(val identity: ByteArray, val possessionSignature: ByteArray?) - - class NetworksAttribute(val value: List) + class QueryIdentityResponse( + val identity: ByteArray, + val possessionSignature: ByteArray? + ) +class NetworksAttribute( + val value: List + ) sealed class NetworksAttributeSubscriptionState { - data class Success(val value: List) : - NetworksAttributeSubscriptionState() - + data class Success( + val value: List + ) : NetworksAttributeSubscriptionState() + data class Error(val exception: Exception) : NetworksAttributeSubscriptionState() - object SubscriptionEstablished : NetworksAttributeSubscriptionState() - } - - class LastNetworkingStatusAttribute(val value: UByte?) + object SubscriptionEstablished : NetworksAttributeSubscriptionState() + } +class LastNetworkingStatusAttribute( + val value: UByte? + ) sealed class LastNetworkingStatusAttributeSubscriptionState { - data class Success(val value: UByte?) : LastNetworkingStatusAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : LastNetworkingStatusAttributeSubscriptionState() + data class Error(val exception: Exception) : LastNetworkingStatusAttributeSubscriptionState() - object SubscriptionEstablished : LastNetworkingStatusAttributeSubscriptionState() - } - - class LastNetworkIDAttribute(val value: ByteArray?) + object SubscriptionEstablished : LastNetworkingStatusAttributeSubscriptionState() + } +class LastNetworkIDAttribute( + val value: ByteArray? + ) sealed class LastNetworkIDAttributeSubscriptionState { - data class Success(val value: ByteArray?) : LastNetworkIDAttributeSubscriptionState() - + data class Success( + val value: ByteArray? + ) : LastNetworkIDAttributeSubscriptionState() + data class Error(val exception: Exception) : LastNetworkIDAttributeSubscriptionState() - object SubscriptionEstablished : LastNetworkIDAttributeSubscriptionState() - } - - class LastConnectErrorValueAttribute(val value: Int?) + object SubscriptionEstablished : LastNetworkIDAttributeSubscriptionState() + } +class LastConnectErrorValueAttribute( + val value: Int? + ) sealed class LastConnectErrorValueAttributeSubscriptionState { - data class Success(val value: Int?) : LastConnectErrorValueAttributeSubscriptionState() - + data class Success( + val value: Int? + ) : LastConnectErrorValueAttributeSubscriptionState() + data class Error(val exception: Exception) : LastConnectErrorValueAttributeSubscriptionState() - object SubscriptionEstablished : LastConnectErrorValueAttributeSubscriptionState() - } - - class SupportedWiFiBandsAttribute(val value: List?) + object SubscriptionEstablished : LastConnectErrorValueAttributeSubscriptionState() + } +class SupportedWiFiBandsAttribute( + val value: List? + ) sealed class SupportedWiFiBandsAttributeSubscriptionState { - data class Success(val value: List?) : SupportedWiFiBandsAttributeSubscriptionState() - + data class Success( + val value: List? + ) : SupportedWiFiBandsAttributeSubscriptionState() + data class Error(val exception: Exception) : SupportedWiFiBandsAttributeSubscriptionState() - object SubscriptionEstablished : SupportedWiFiBandsAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : SupportedWiFiBandsAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun scanNetworks( - ssid: ByteArray?, - breadcrumb: ULong?, - timedInvokeTimeout: Duration? = null, - ): ScanNetworksResponse { + suspend fun scanNetworks(ssid: ByteArray? + ,breadcrumb: ULong? + ,timedInvokeTimeout: Duration? = null): ScanNetworksResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_SSID_REQ: Int = 0 - ssid?.let { tlvWriter.put(ContextSpecificTag(TAG_SSID_REQ), ssid) } + ssid?.let { + tlvWriter.put(ContextSpecificTag(TAG_SSID_REQ), ssid) + } val TAG_BREADCRUMB_REQ: Int = 1 - breadcrumb?.let { tlvWriter.put(ContextSpecificTag(TAG_BREADCRUMB_REQ), breadcrumb) } + breadcrumb?.let { + tlvWriter.put(ContextSpecificTag(TAG_BREADCRUMB_REQ), breadcrumb) + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -193,96 +236,89 @@ class NetworkCommissioningCluster( tlvReader.enterStructure(AnonymousTag) val TAG_NETWORKING_STATUS: Int = 0 var networkingStatus_decoded: UByte? = null - + val TAG_DEBUG_TEXT: Int = 1 var debugText_decoded: String? = null - + val TAG_WI_FI_SCAN_RESULTS: Int = 2 - var wiFiScanResults_decoded: List? = - null - + var wiFiScanResults_decoded: List? = null + val TAG_THREAD_SCAN_RESULTS: Int = 3 - var threadScanResults_decoded: - List? = - null + var threadScanResults_decoded: List? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_NETWORKING_STATUS)) { - networkingStatus_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_DEBUG_TEXT)) { - debugText_decoded = + + if (tag == ContextSpecificTag(TAG_NETWORKING_STATUS)) {networkingStatus_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_DEBUG_TEXT)) {debugText_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - } - } - - if (tag == ContextSpecificTag(TAG_WI_FI_SCAN_RESULTS)) { - wiFiScanResults_decoded = + tlvReader.getString(tag) + } else { + null + } + }} + + if (tag == ContextSpecificTag(TAG_WI_FI_SCAN_RESULTS)) {wiFiScanResults_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - buildList { - tlvReader.enterArray(tag) - while (!tlvReader.isEndOfContainer()) { - add( - NetworkCommissioningClusterWiFiInterfaceScanResultStruct.fromTlv( - AnonymousTag, - tlvReader, - ) - ) - } - tlvReader.exitContainer() - } - } else { - null - } - } + buildList { + tlvReader.enterArray(tag) + while(!tlvReader.isEndOfContainer()) { + add(NetworkCommissioningClusterWiFiInterfaceScanResultStruct.fromTlv(AnonymousTag, tlvReader)) } - - if (tag == ContextSpecificTag(TAG_THREAD_SCAN_RESULTS)) { - threadScanResults_decoded = + tlvReader.exitContainer() + } + } else { + null + } + }} + + if (tag == ContextSpecificTag(TAG_THREAD_SCAN_RESULTS)) {threadScanResults_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - buildList { - tlvReader.enterArray(tag) - while (!tlvReader.isEndOfContainer()) { - add( - NetworkCommissioningClusterThreadInterfaceScanResultStruct.fromTlv( - AnonymousTag, - tlvReader, - ) - ) - } - tlvReader.exitContainer() - } - } else { - null - } - } - } else { + buildList { + tlvReader.enterArray(tag) + while(!tlvReader.isEndOfContainer()) { + add(NetworkCommissioningClusterThreadInterfaceScanResultStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null + } + }} + + + else { tlvReader.skipElement() } } + + if (networkingStatus_decoded == null) { - throw IllegalStateException("networkingStatus not found in TLV") + throw IllegalStateException("networkingStatus not found in TLV") } + + + + + + + tlvReader.exitContainer() @@ -290,19 +326,17 @@ class NetworkCommissioningCluster( networkingStatus_decoded, debugText_decoded, wiFiScanResults_decoded, - threadScanResults_decoded, + threadScanResults_decoded ) } - suspend fun addOrUpdateWiFiNetwork( - ssid: ByteArray, - credentials: ByteArray, - breadcrumb: ULong?, - networkIdentity: ByteArray?, - clientIdentifier: ByteArray?, - possessionNonce: ByteArray?, - timedInvokeTimeout: Duration? = null, - ): NetworkConfigResponse { + suspend fun addOrUpdateWiFiNetwork(ssid: ByteArray + ,credentials: ByteArray + ,breadcrumb: ULong? + ,networkIdentity: ByteArray? + ,clientIdentifier: ByteArray? + ,possessionNonce: ByteArray? + ,timedInvokeTimeout: Duration? = null): NetworkConfigResponse { val commandId: UInt = 2u val tlvWriter = TlvWriter() @@ -315,7 +349,9 @@ class NetworkCommissioningCluster( tlvWriter.put(ContextSpecificTag(TAG_CREDENTIALS_REQ), credentials) val TAG_BREADCRUMB_REQ: Int = 2 - breadcrumb?.let { tlvWriter.put(ContextSpecificTag(TAG_BREADCRUMB_REQ), breadcrumb) } + breadcrumb?.let { + tlvWriter.put(ContextSpecificTag(TAG_BREADCRUMB_REQ), breadcrumb) + } val TAG_NETWORK_IDENTITY_REQ: Int = 3 networkIdentity?.let { @@ -330,14 +366,14 @@ class NetworkCommissioningCluster( val TAG_POSSESSION_NONCE_REQ: Int = 5 possessionNonce?.let { tlvWriter.put(ContextSpecificTag(TAG_POSSESSION_NONCE_REQ), possessionNonce) - } + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -347,88 +383,94 @@ class NetworkCommissioningCluster( tlvReader.enterStructure(AnonymousTag) val TAG_NETWORKING_STATUS: Int = 0 var networkingStatus_decoded: UByte? = null - + val TAG_DEBUG_TEXT: Int = 1 var debugText_decoded: String? = null - + val TAG_NETWORK_INDEX: Int = 2 var networkIndex_decoded: UByte? = null - + val TAG_CLIENT_IDENTITY: Int = 3 var clientIdentity_decoded: ByteArray? = null - + val TAG_POSSESSION_SIGNATURE: Int = 4 var possessionSignature_decoded: ByteArray? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_NETWORKING_STATUS)) { - networkingStatus_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_DEBUG_TEXT)) { - debugText_decoded = + + if (tag == ContextSpecificTag(TAG_NETWORKING_STATUS)) {networkingStatus_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_DEBUG_TEXT)) {debugText_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - } - } - - if (tag == ContextSpecificTag(TAG_NETWORK_INDEX)) { - networkIndex_decoded = + tlvReader.getString(tag) + } else { + null + } + }} + + if (tag == ContextSpecificTag(TAG_NETWORK_INDEX)) {networkIndex_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getUByte(tag) - } else { - null - } - } - } - - if (tag == ContextSpecificTag(TAG_CLIENT_IDENTITY)) { - clientIdentity_decoded = + tlvReader.getUByte(tag) + } else { + null + } + }} + + if (tag == ContextSpecificTag(TAG_CLIENT_IDENTITY)) {clientIdentity_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getByteArray(tag) - } else { - null - } - } - } - - if (tag == ContextSpecificTag(TAG_POSSESSION_SIGNATURE)) { - possessionSignature_decoded = + tlvReader.getByteArray(tag) + } else { + null + } + }} + + if (tag == ContextSpecificTag(TAG_POSSESSION_SIGNATURE)) {possessionSignature_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getByteArray(tag) - } else { - null - } - } - } else { + tlvReader.getByteArray(tag) + } else { + null + } + }} + + + else { tlvReader.skipElement() } } + + if (networkingStatus_decoded == null) { - throw IllegalStateException("networkingStatus not found in TLV") + throw IllegalStateException("networkingStatus not found in TLV") } + + + + + + + + + tlvReader.exitContainer() @@ -437,15 +479,13 @@ class NetworkCommissioningCluster( debugText_decoded, networkIndex_decoded, clientIdentity_decoded, - possessionSignature_decoded, + possessionSignature_decoded ) } - suspend fun addOrUpdateThreadNetwork( - operationalDataset: ByteArray, - breadcrumb: ULong?, - timedInvokeTimeout: Duration? = null, - ): NetworkConfigResponse { + suspend fun addOrUpdateThreadNetwork(operationalDataset: ByteArray + ,breadcrumb: ULong? + ,timedInvokeTimeout: Duration? = null): NetworkConfigResponse { val commandId: UInt = 3u val tlvWriter = TlvWriter() @@ -455,14 +495,16 @@ class NetworkCommissioningCluster( tlvWriter.put(ContextSpecificTag(TAG_OPERATIONAL_DATASET_REQ), operationalDataset) val TAG_BREADCRUMB_REQ: Int = 1 - breadcrumb?.let { tlvWriter.put(ContextSpecificTag(TAG_BREADCRUMB_REQ), breadcrumb) } + breadcrumb?.let { + tlvWriter.put(ContextSpecificTag(TAG_BREADCRUMB_REQ), breadcrumb) + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -472,88 +514,94 @@ class NetworkCommissioningCluster( tlvReader.enterStructure(AnonymousTag) val TAG_NETWORKING_STATUS: Int = 0 var networkingStatus_decoded: UByte? = null - + val TAG_DEBUG_TEXT: Int = 1 var debugText_decoded: String? = null - + val TAG_NETWORK_INDEX: Int = 2 var networkIndex_decoded: UByte? = null - + val TAG_CLIENT_IDENTITY: Int = 3 var clientIdentity_decoded: ByteArray? = null - + val TAG_POSSESSION_SIGNATURE: Int = 4 var possessionSignature_decoded: ByteArray? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_NETWORKING_STATUS)) { - networkingStatus_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_DEBUG_TEXT)) { - debugText_decoded = + + if (tag == ContextSpecificTag(TAG_NETWORKING_STATUS)) {networkingStatus_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_DEBUG_TEXT)) {debugText_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - } - } - - if (tag == ContextSpecificTag(TAG_NETWORK_INDEX)) { - networkIndex_decoded = + tlvReader.getString(tag) + } else { + null + } + }} + + if (tag == ContextSpecificTag(TAG_NETWORK_INDEX)) {networkIndex_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getUByte(tag) - } else { - null - } - } - } - - if (tag == ContextSpecificTag(TAG_CLIENT_IDENTITY)) { - clientIdentity_decoded = + tlvReader.getUByte(tag) + } else { + null + } + }} + + if (tag == ContextSpecificTag(TAG_CLIENT_IDENTITY)) {clientIdentity_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getByteArray(tag) - } else { - null - } - } - } - - if (tag == ContextSpecificTag(TAG_POSSESSION_SIGNATURE)) { - possessionSignature_decoded = + tlvReader.getByteArray(tag) + } else { + null + } + }} + + if (tag == ContextSpecificTag(TAG_POSSESSION_SIGNATURE)) {possessionSignature_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getByteArray(tag) - } else { - null - } - } - } else { + tlvReader.getByteArray(tag) + } else { + null + } + }} + + + else { tlvReader.skipElement() } } + + if (networkingStatus_decoded == null) { - throw IllegalStateException("networkingStatus not found in TLV") + throw IllegalStateException("networkingStatus not found in TLV") } + + + + + + + + + tlvReader.exitContainer() @@ -562,15 +610,13 @@ class NetworkCommissioningCluster( debugText_decoded, networkIndex_decoded, clientIdentity_decoded, - possessionSignature_decoded, + possessionSignature_decoded ) } - suspend fun removeNetwork( - networkID: ByteArray, - breadcrumb: ULong?, - timedInvokeTimeout: Duration? = null, - ): NetworkConfigResponse { + suspend fun removeNetwork(networkID: ByteArray + ,breadcrumb: ULong? + ,timedInvokeTimeout: Duration? = null): NetworkConfigResponse { val commandId: UInt = 4u val tlvWriter = TlvWriter() @@ -580,14 +626,16 @@ class NetworkCommissioningCluster( tlvWriter.put(ContextSpecificTag(TAG_NETWORK_ID_REQ), networkID) val TAG_BREADCRUMB_REQ: Int = 1 - breadcrumb?.let { tlvWriter.put(ContextSpecificTag(TAG_BREADCRUMB_REQ), breadcrumb) } + breadcrumb?.let { + tlvWriter.put(ContextSpecificTag(TAG_BREADCRUMB_REQ), breadcrumb) + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -597,88 +645,94 @@ class NetworkCommissioningCluster( tlvReader.enterStructure(AnonymousTag) val TAG_NETWORKING_STATUS: Int = 0 var networkingStatus_decoded: UByte? = null - + val TAG_DEBUG_TEXT: Int = 1 var debugText_decoded: String? = null - + val TAG_NETWORK_INDEX: Int = 2 var networkIndex_decoded: UByte? = null - + val TAG_CLIENT_IDENTITY: Int = 3 var clientIdentity_decoded: ByteArray? = null - + val TAG_POSSESSION_SIGNATURE: Int = 4 var possessionSignature_decoded: ByteArray? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_NETWORKING_STATUS)) { - networkingStatus_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_DEBUG_TEXT)) { - debugText_decoded = + + if (tag == ContextSpecificTag(TAG_NETWORKING_STATUS)) {networkingStatus_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_DEBUG_TEXT)) {debugText_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - } - } - - if (tag == ContextSpecificTag(TAG_NETWORK_INDEX)) { - networkIndex_decoded = + tlvReader.getString(tag) + } else { + null + } + }} + + if (tag == ContextSpecificTag(TAG_NETWORK_INDEX)) {networkIndex_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getUByte(tag) - } else { - null - } - } - } - - if (tag == ContextSpecificTag(TAG_CLIENT_IDENTITY)) { - clientIdentity_decoded = + tlvReader.getUByte(tag) + } else { + null + } + }} + + if (tag == ContextSpecificTag(TAG_CLIENT_IDENTITY)) {clientIdentity_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getByteArray(tag) - } else { - null - } - } - } - - if (tag == ContextSpecificTag(TAG_POSSESSION_SIGNATURE)) { - possessionSignature_decoded = + tlvReader.getByteArray(tag) + } else { + null + } + }} + + if (tag == ContextSpecificTag(TAG_POSSESSION_SIGNATURE)) {possessionSignature_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getByteArray(tag) - } else { - null - } - } - } else { + tlvReader.getByteArray(tag) + } else { + null + } + }} + + + else { tlvReader.skipElement() } } + + if (networkingStatus_decoded == null) { - throw IllegalStateException("networkingStatus not found in TLV") + throw IllegalStateException("networkingStatus not found in TLV") } + + + + + + + + + tlvReader.exitContainer() @@ -687,15 +741,13 @@ class NetworkCommissioningCluster( debugText_decoded, networkIndex_decoded, clientIdentity_decoded, - possessionSignature_decoded, + possessionSignature_decoded ) } - suspend fun connectNetwork( - networkID: ByteArray, - breadcrumb: ULong?, - timedInvokeTimeout: Duration? = null, - ): ConnectNetworkResponse { + suspend fun connectNetwork(networkID: ByteArray + ,breadcrumb: ULong? + ,timedInvokeTimeout: Duration? = null): ConnectNetworkResponse { val commandId: UInt = 6u val tlvWriter = TlvWriter() @@ -705,14 +757,16 @@ class NetworkCommissioningCluster( tlvWriter.put(ContextSpecificTag(TAG_NETWORK_ID_REQ), networkID) val TAG_BREADCRUMB_REQ: Int = 1 - breadcrumb?.let { tlvWriter.put(ContextSpecificTag(TAG_BREADCRUMB_REQ), breadcrumb) } + breadcrumb?.let { + tlvWriter.put(ContextSpecificTag(TAG_BREADCRUMB_REQ), breadcrumb) + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -722,67 +776,75 @@ class NetworkCommissioningCluster( tlvReader.enterStructure(AnonymousTag) val TAG_NETWORKING_STATUS: Int = 0 var networkingStatus_decoded: UByte? = null - + val TAG_DEBUG_TEXT: Int = 1 var debugText_decoded: String? = null - + val TAG_ERROR_VALUE: Int = 2 var errorValue_decoded: Int? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_NETWORKING_STATUS)) { - networkingStatus_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_DEBUG_TEXT)) { - debugText_decoded = + + if (tag == ContextSpecificTag(TAG_NETWORKING_STATUS)) {networkingStatus_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_DEBUG_TEXT)) {debugText_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - } - } - - if (tag == ContextSpecificTag(TAG_ERROR_VALUE)) { - errorValue_decoded = + tlvReader.getString(tag) + } else { + null + } + }} + + if (tag == ContextSpecificTag(TAG_ERROR_VALUE)) {errorValue_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (!tlvReader.isNull()) { - tlvReader.getInt(tag) - } else { - tlvReader.getNull(tag) - null - } - } - } else { + tlvReader.getInt(tag) + } else { + tlvReader.getNull(tag) + null + } + }} + + + else { tlvReader.skipElement() } } + + if (networkingStatus_decoded == null) { - throw IllegalStateException("networkingStatus not found in TLV") + throw IllegalStateException("networkingStatus not found in TLV") } + + + + + tlvReader.exitContainer() - return ConnectNetworkResponse(networkingStatus_decoded, debugText_decoded, errorValue_decoded) + return ConnectNetworkResponse( + networkingStatus_decoded, + debugText_decoded, + errorValue_decoded + ) } - suspend fun reorderNetwork( - networkID: ByteArray, - networkIndex: UByte, - breadcrumb: ULong?, - timedInvokeTimeout: Duration? = null, - ): NetworkConfigResponse { + suspend fun reorderNetwork(networkID: ByteArray + ,networkIndex: UByte + ,breadcrumb: ULong? + ,timedInvokeTimeout: Duration? = null): NetworkConfigResponse { val commandId: UInt = 8u val tlvWriter = TlvWriter() @@ -795,14 +857,16 @@ class NetworkCommissioningCluster( tlvWriter.put(ContextSpecificTag(TAG_NETWORK_INDEX_REQ), networkIndex) val TAG_BREADCRUMB_REQ: Int = 2 - breadcrumb?.let { tlvWriter.put(ContextSpecificTag(TAG_BREADCRUMB_REQ), breadcrumb) } + breadcrumb?.let { + tlvWriter.put(ContextSpecificTag(TAG_BREADCRUMB_REQ), breadcrumb) + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -812,88 +876,94 @@ class NetworkCommissioningCluster( tlvReader.enterStructure(AnonymousTag) val TAG_NETWORKING_STATUS: Int = 0 var networkingStatus_decoded: UByte? = null - + val TAG_DEBUG_TEXT: Int = 1 var debugText_decoded: String? = null - + val TAG_NETWORK_INDEX: Int = 2 var networkIndex_decoded: UByte? = null - + val TAG_CLIENT_IDENTITY: Int = 3 var clientIdentity_decoded: ByteArray? = null - + val TAG_POSSESSION_SIGNATURE: Int = 4 var possessionSignature_decoded: ByteArray? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_NETWORKING_STATUS)) { - networkingStatus_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_DEBUG_TEXT)) { - debugText_decoded = + + if (tag == ContextSpecificTag(TAG_NETWORKING_STATUS)) {networkingStatus_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_DEBUG_TEXT)) {debugText_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - } - } - - if (tag == ContextSpecificTag(TAG_NETWORK_INDEX)) { - networkIndex_decoded = + tlvReader.getString(tag) + } else { + null + } + }} + + if (tag == ContextSpecificTag(TAG_NETWORK_INDEX)) {networkIndex_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getUByte(tag) - } else { - null - } - } - } - - if (tag == ContextSpecificTag(TAG_CLIENT_IDENTITY)) { - clientIdentity_decoded = + tlvReader.getUByte(tag) + } else { + null + } + }} + + if (tag == ContextSpecificTag(TAG_CLIENT_IDENTITY)) {clientIdentity_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getByteArray(tag) - } else { - null - } - } - } - - if (tag == ContextSpecificTag(TAG_POSSESSION_SIGNATURE)) { - possessionSignature_decoded = + tlvReader.getByteArray(tag) + } else { + null + } + }} + + if (tag == ContextSpecificTag(TAG_POSSESSION_SIGNATURE)) {possessionSignature_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getByteArray(tag) - } else { - null - } - } - } else { + tlvReader.getByteArray(tag) + } else { + null + } + }} + + + else { tlvReader.skipElement() } } + + if (networkingStatus_decoded == null) { - throw IllegalStateException("networkingStatus not found in TLV") + throw IllegalStateException("networkingStatus not found in TLV") } + + + + + + + + + tlvReader.exitContainer() @@ -902,15 +972,13 @@ class NetworkCommissioningCluster( debugText_decoded, networkIndex_decoded, clientIdentity_decoded, - possessionSignature_decoded, + possessionSignature_decoded ) } - suspend fun queryIdentity( - keyIdentifier: ByteArray, - possessionNonce: ByteArray?, - timedInvokeTimeout: Duration? = null, - ): QueryIdentityResponse { + suspend fun queryIdentity(keyIdentifier: ByteArray + ,possessionNonce: ByteArray? + ,timedInvokeTimeout: Duration? = null): QueryIdentityResponse { val commandId: UInt = 9u val tlvWriter = TlvWriter() @@ -922,14 +990,14 @@ class NetworkCommissioningCluster( val TAG_POSSESSION_NONCE_REQ: Int = 1 possessionNonce?.let { tlvWriter.put(ContextSpecificTag(TAG_POSSESSION_NONCE_REQ), possessionNonce) - } + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -939,110 +1007,124 @@ class NetworkCommissioningCluster( tlvReader.enterStructure(AnonymousTag) val TAG_IDENTITY: Int = 0 var identity_decoded: ByteArray? = null - + val TAG_POSSESSION_SIGNATURE: Int = 1 var possessionSignature_decoded: ByteArray? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_IDENTITY)) { - identity_decoded = tlvReader.getByteArray(tag) - } - - if (tag == ContextSpecificTag(TAG_POSSESSION_SIGNATURE)) { - possessionSignature_decoded = + + if (tag == ContextSpecificTag(TAG_IDENTITY)) {identity_decoded = tlvReader.getByteArray(tag)} + + if (tag == ContextSpecificTag(TAG_POSSESSION_SIGNATURE)) {possessionSignature_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getByteArray(tag) - } else { - null - } - } - } else { + tlvReader.getByteArray(tag) + } else { + null + } + }} + + + else { tlvReader.skipElement() } } + + if (identity_decoded == null) { - throw IllegalStateException("identity not found in TLV") + throw IllegalStateException("identity not found in TLV") } + + + tlvReader.exitContainer() - return QueryIdentityResponse(identity_decoded, possessionSignature_decoded) + return QueryIdentityResponse( + identity_decoded, + possessionSignature_decoded + ) } +suspend fun readMaxNetworksAttribute(): UByte {val ATTRIBUTE_ID: UInt = 0u - suspend fun readMaxNetworksAttribute(): 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 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}") - } + 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) { "Maxnetworks attribute not found in response" } + } + + requireNotNull(attributeData) { + "Maxnetworks 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 subscribeMaxNetworksAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Maxnetworks attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Maxnetworks attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -1054,94 +1136,97 @@ class NetworkCommissioningCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNetworksAttribute(): NetworksAttribute {val ATTRIBUTE_ID: UInt = 1u - suspend fun readNetworksAttribute(): NetworksAttribute { - 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 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}") - } + 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) { "Networks attribute not found in response" } + } + + requireNotNull(attributeData) { + "Networks 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(NetworkCommissioningClusterNetworkInfoStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(NetworkCommissioningClusterNetworkInfoStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + return NetworksAttribute(decodedValue) } suspend fun subscribeNetworksAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - NetworksAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(NetworksAttributeSubscriptionState.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) { "Networks attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Networks 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(NetworkCommissioningClusterNetworkInfoStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(NetworkCommissioningClusterNetworkInfoStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(NetworksAttributeSubscriptionState.Success(decodedValue)) } @@ -1149,243 +1234,262 @@ class NetworkCommissioningCluster( emit(NetworksAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readScanMaxTimeSecondsAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 2u - suspend fun readScanMaxTimeSecondsAttribute(): UByte? { - 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 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}") - } + 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) { "Scanmaxtimeseconds attribute not found in response" } + } + + requireNotNull(attributeData) { + "Scanmaxtimeseconds 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeScanMaxTimeSecondsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Scanmaxtimeseconds attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Scanmaxtimeseconds 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)) } + 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 readConnectMaxTimeSecondsAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 3u - suspend fun readConnectMaxTimeSecondsAttribute(): UByte? { - 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 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}") - } + 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) { "Connectmaxtimeseconds attribute not found in response" } + } + + requireNotNull(attributeData) { + "Connectmaxtimeseconds 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeConnectMaxTimeSecondsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Connectmaxtimeseconds attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Connectmaxtimeseconds 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)) } + 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 readInterfaceEnabledAttribute(): Boolean {val ATTRIBUTE_ID: UInt = 4u - suspend fun readInterfaceEnabledAttribute(): Boolean { - 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 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}") - } + 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) { "Interfaceenabled attribute not found in response" } + } + + requireNotNull(attributeData) { + "Interfaceenabled attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Boolean = tlvReader.getBoolean(AnonymousTag) + return decodedValue } - suspend fun writeInterfaceEnabledAttribute(value: Boolean, timedWriteTimeout: Duration? = null) { + suspend fun writeInterfaceEnabledAttribute( + value: Boolean, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 4u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -1406,46 +1510,42 @@ class NetworkCommissioningCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeInterfaceEnabledAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Interfaceenabled attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Interfaceenabled attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -1458,668 +1558,697 @@ class NetworkCommissioningCluster( emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readLastNetworkingStatusAttribute(): LastNetworkingStatusAttribute {val ATTRIBUTE_ID: UInt = 5u - suspend fun readLastNetworkingStatusAttribute(): LastNetworkingStatusAttribute { - 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 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}") - } + 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) { "Lastnetworkingstatus attribute not found in response" } + } + + requireNotNull(attributeData) { + "Lastnetworkingstatus attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return LastNetworkingStatusAttribute(decodedValue) } suspend fun subscribeLastNetworkingStatusAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - LastNetworkingStatusAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(LastNetworkingStatusAttributeSubscriptionState.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) { - "Lastnetworkingstatus attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Lastnetworkingstatus 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.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(LastNetworkingStatusAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(LastNetworkingStatusAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(LastNetworkingStatusAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readLastNetworkIDAttribute(): LastNetworkIDAttribute {val ATTRIBUTE_ID: UInt = 6u - suspend fun readLastNetworkIDAttribute(): LastNetworkIDAttribute { - 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 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}") - } + 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) { "Lastnetworkid attribute not found in response" } + } + + requireNotNull(attributeData) { + "Lastnetworkid attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = - if (!tlvReader.isNull()) { - tlvReader.getByteArray(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ByteArray? = if (!tlvReader.isNull()) { + tlvReader.getByteArray(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return LastNetworkIDAttribute(decodedValue) } suspend fun subscribeLastNetworkIDAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - LastNetworkIDAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(LastNetworkIDAttributeSubscriptionState.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) { "Lastnetworkid attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Lastnetworkid attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = - if (!tlvReader.isNull()) { - tlvReader.getByteArray(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ByteArray? = if (!tlvReader.isNull()) { + tlvReader.getByteArray(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(LastNetworkIDAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(LastNetworkIDAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(LastNetworkIDAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readLastConnectErrorValueAttribute(): LastConnectErrorValueAttribute {val ATTRIBUTE_ID: UInt = 7u - suspend fun readLastConnectErrorValueAttribute(): LastConnectErrorValueAttribute { - 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 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}") - } + 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) { "Lastconnecterrorvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Lastconnecterrorvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Int? = - if (!tlvReader.isNull()) { - tlvReader.getInt(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Int? = if (!tlvReader.isNull()) { + tlvReader.getInt(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return LastConnectErrorValueAttribute(decodedValue) } suspend fun subscribeLastConnectErrorValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - LastConnectErrorValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(LastConnectErrorValueAttributeSubscriptionState.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) { - "Lastconnecterrorvalue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Lastconnecterrorvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Int? = - if (!tlvReader.isNull()) { - tlvReader.getInt(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Int? = if (!tlvReader.isNull()) { + tlvReader.getInt(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(LastConnectErrorValueAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(LastConnectErrorValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(LastConnectErrorValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readSupportedWiFiBandsAttribute(): SupportedWiFiBandsAttribute {val ATTRIBUTE_ID: UInt = 8u - suspend fun readSupportedWiFiBandsAttribute(): SupportedWiFiBandsAttribute { - val ATTRIBUTE_ID: UInt = 8u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Supportedwifibands attribute not found in response" } + } + + requireNotNull(attributeData) { + "Supportedwifibands attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) } + tlvReader.exitContainer() + } + } else { + null + } + return SupportedWiFiBandsAttribute(decodedValue) } suspend fun subscribeSupportedWiFiBandsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - SupportedWiFiBandsAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(SupportedWiFiBandsAttributeSubscriptionState.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) { - "Supportedwifibands attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Supportedwifibands attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { emit(SupportedWiFiBandsAttributeSubscriptionState.Success(it)) } + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { + emit(SupportedWiFiBandsAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(SupportedWiFiBandsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readSupportedThreadFeaturesAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 9u - suspend fun readSupportedThreadFeaturesAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 9u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Supportedthreadfeatures attribute not found in response" } + } + + requireNotNull(attributeData) { + "Supportedthreadfeatures 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeSupportedThreadFeaturesAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Supportedthreadfeatures attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Supportedthreadfeatures 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)) } + 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 readThreadVersionAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 10u - suspend fun readThreadVersionAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 10u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Threadversion attribute not found in response" } + } + + requireNotNull(attributeData) { + "Threadversion 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeThreadVersionAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Threadversion attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Threadversion 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)) } + 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 readGeneratedCommandListAttribute(): GeneratedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65528u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -2127,96 +2256,97 @@ class NetworkCommissioningCluster( emit(GeneratedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65529u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -2224,94 +2354,97 @@ class NetworkCommissioningCluster( emit(AcceptedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt = 65530u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -2319,94 +2452,97 @@ class NetworkCommissioningCluster( emit(EventListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ID: UInt = 65531u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -2414,76 +2550,81 @@ class NetworkCommissioningCluster( emit(AttributeListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u - 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 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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -2495,77 +2636,80 @@ class NetworkCommissioningCluster( emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 65533u - 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 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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -2578,7 +2722,7 @@ class NetworkCommissioningCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/NitrogenDioxideConcentrationMeasurementCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/NitrogenDioxideConcentrationMeasurementCluster.kt index 5f4aa378c771d6..d34170fb14b72c 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/NitrogenDioxideConcentrationMeasurementCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/NitrogenDioxideConcentrationMeasurementCluster.kt @@ -17,1273 +17,1371 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.FloatSubscriptionState import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath +import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader +import matter.tlv.TlvWriter -class NitrogenDioxideConcentrationMeasurementCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class MeasuredValueAttribute(val value: Float?) +class NitrogenDioxideConcentrationMeasurementCluster(private val controller: MatterController, private val endpointId: UShort) {class MeasuredValueAttribute( + val value: Float? + ) sealed class MeasuredValueAttributeSubscriptionState { - data class Success(val value: Float?) : MeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Float? + ) : MeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() - } - - class MinMeasuredValueAttribute(val value: Float?) + object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() + } +class MinMeasuredValueAttribute( + val value: Float? + ) sealed class MinMeasuredValueAttributeSubscriptionState { - data class Success(val value: Float?) : MinMeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Float? + ) : MinMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MinMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() - } - - class MaxMeasuredValueAttribute(val value: Float?) + object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() + } +class MaxMeasuredValueAttribute( + val value: Float? + ) sealed class MaxMeasuredValueAttributeSubscriptionState { - data class Success(val value: Float?) : MaxMeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Float? + ) : MaxMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MaxMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() - } - - class PeakMeasuredValueAttribute(val value: Float?) + object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() + } +class PeakMeasuredValueAttribute( + val value: Float? + ) sealed class PeakMeasuredValueAttributeSubscriptionState { - data class Success(val value: Float?) : PeakMeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Float? + ) : PeakMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : PeakMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : PeakMeasuredValueAttributeSubscriptionState() - } - - class AverageMeasuredValueAttribute(val value: Float?) + object SubscriptionEstablished : PeakMeasuredValueAttributeSubscriptionState() + } +class AverageMeasuredValueAttribute( + val value: Float? + ) sealed class AverageMeasuredValueAttributeSubscriptionState { - data class Success(val value: Float?) : AverageMeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Float? + ) : AverageMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : AverageMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : AverageMeasuredValueAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : AverageMeasuredValueAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } - - suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } +suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute {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}") - } + 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) { "Measuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Measuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MeasuredValueAttribute(decodedValue) } suspend fun subscribeMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MeasuredValueAttributeSubscriptionState.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) { "Measuredvalue attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Measuredvalue attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute {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}") - } + 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) { "Minmeasuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Minmeasuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MinMeasuredValueAttribute(decodedValue) } suspend fun subscribeMinMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MinMeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MinMeasuredValueAttributeSubscriptionState.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) { - "Minmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Minmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MinMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute {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}") - } + 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) { "Maxmeasuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Maxmeasuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MaxMeasuredValueAttribute(decodedValue) } suspend fun subscribeMaxMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MaxMeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MaxMeasuredValueAttributeSubscriptionState.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) { - "Maxmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Maxmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MaxMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readPeakMeasuredValueAttribute(): PeakMeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readPeakMeasuredValueAttribute(): PeakMeasuredValueAttribute {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}") - } + 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) { "Peakmeasuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Peakmeasuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return PeakMeasuredValueAttribute(decodedValue) } suspend fun subscribePeakMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - PeakMeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(PeakMeasuredValueAttributeSubscriptionState.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) { - "Peakmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Peakmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(PeakMeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(PeakMeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(PeakMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readPeakMeasuredValueWindowAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 4u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readPeakMeasuredValueWindowAttribute(): UInt? {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}") - } + 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) { "Peakmeasuredvaluewindow attribute not found in response" } + } + + requireNotNull(attributeData) { + "Peakmeasuredvaluewindow attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribePeakMeasuredValueWindowAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Peakmeasuredvaluewindow attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Peakmeasuredvaluewindow attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readAverageMeasuredValueAttribute(): AverageMeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 5u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readAverageMeasuredValueAttribute(): AverageMeasuredValueAttribute {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}") - } + 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) { "Averagemeasuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Averagemeasuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return AverageMeasuredValueAttribute(decodedValue) } suspend fun subscribeAverageMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - AverageMeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(AverageMeasuredValueAttributeSubscriptionState.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) { - "Averagemeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Averagemeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(AverageMeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(AverageMeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(AverageMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readAverageMeasuredValueWindowAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 6u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readAverageMeasuredValueWindowAttribute(): UInt? {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}") - } + 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) { "Averagemeasuredvaluewindow attribute not found in response" } + } + + requireNotNull(attributeData) { + "Averagemeasuredvaluewindow attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeAverageMeasuredValueWindowAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Averagemeasuredvaluewindow attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Averagemeasuredvaluewindow attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readUncertaintyAttribute(): Float? { - val ATTRIBUTE_ID: UInt = 7u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readUncertaintyAttribute(): Float? {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}") - } + 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) { "Uncertainty attribute not found in response" } + } + + requireNotNull(attributeData) { + "Uncertainty attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } + val decodedValue: Float? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeUncertaintyAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - FloatSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(FloatSubscriptionState.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) { "Uncertainty attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Uncertainty attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(FloatSubscriptionState.Success(it)) } + val decodedValue: Float? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(FloatSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(FloatSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readMeasurementUnitAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 8u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMeasurementUnitAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 8u + + 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}") - } + 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) { "Measurementunit attribute not found in response" } + } + + requireNotNull(attributeData) { + "Measurementunit 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeMeasurementUnitAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Measurementunit attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Measurementunit 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)) } + 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 readMeasurementMediumAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 9u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMeasurementMediumAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 9u + + 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}") - } + 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) { "Measurementmedium attribute not found in response" } + } + + requireNotNull(attributeData) { + "Measurementmedium 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeMeasurementMediumAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Measurementmedium attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Measurementmedium 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)) } + 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 readLevelValueAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 10u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readLevelValueAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 10u + + 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}") - } + 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) { "Levelvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Levelvalue 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeLevelValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Levelvalue attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Levelvalue 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)) } + 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 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1291,96 +1389,97 @@ class NitrogenDioxideConcentrationMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1388,94 +1487,97 @@ class NitrogenDioxideConcentrationMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1483,94 +1585,97 @@ class NitrogenDioxideConcentrationMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1578,76 +1683,81 @@ class NitrogenDioxideConcentrationMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1659,77 +1769,80 @@ class NitrogenDioxideConcentrationMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1742,12 +1855,11 @@ class NitrogenDioxideConcentrationMeasurementCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { - private val logger = - Logger.getLogger(NitrogenDioxideConcentrationMeasurementCluster::class.java.name) + private val logger = Logger.getLogger(NitrogenDioxideConcentrationMeasurementCluster::class.java.name) const val CLUSTER_ID: UInt = 1043u } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/OccupancySensingCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/OccupancySensingCluster.kt index bb54163f860ad0..5b8960133111fa 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/OccupancySensingCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/OccupancySensingCluster.kt @@ -17,150 +17,186 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.cluster.structs.* +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath +import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class OccupancySensingCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class HoldTimeLimitsAttribute(val value: OccupancySensingClusterHoldTimeLimitsStruct?) +class OccupancySensingCluster(private val controller: MatterController, private val endpointId: UShort) {class HoldTimeLimitsAttribute( + val value: OccupancySensingClusterHoldTimeLimitsStruct? + ) sealed class HoldTimeLimitsAttributeSubscriptionState { - data class Success(val value: OccupancySensingClusterHoldTimeLimitsStruct?) : - HoldTimeLimitsAttributeSubscriptionState() - + data class Success( + val value: OccupancySensingClusterHoldTimeLimitsStruct? + ) : HoldTimeLimitsAttributeSubscriptionState() + data class Error(val exception: Exception) : HoldTimeLimitsAttributeSubscriptionState() - object SubscriptionEstablished : HoldTimeLimitsAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : HoldTimeLimitsAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } - - suspend fun readOccupancyAttribute(): 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)) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } +suspend fun readOccupancyAttribute(): 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}") - } + 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) { "Occupancy attribute not found in response" } + } + + requireNotNull(attributeData) { + "Occupancy 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 subscribeOccupancyAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Occupancy attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Occupancy attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -172,77 +208,80 @@ class OccupancySensingCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readOccupancySensorTypeAttribute(): 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)) - +suspend fun readOccupancySensorTypeAttribute(): 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}") - } + 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) { "Occupancysensortype attribute not found in response" } + } + + requireNotNull(attributeData) { + "Occupancysensortype 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 subscribeOccupancySensorTypeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Occupancysensortype attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Occupancysensortype attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -255,77 +294,80 @@ class OccupancySensingCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readOccupancySensorTypeBitmapAttribute(): UByte { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readOccupancySensorTypeBitmapAttribute(): UByte {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}") - } + 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) { "Occupancysensortypebitmap attribute not found in response" } + } + + requireNotNull(attributeData) { + "Occupancysensortypebitmap 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 subscribeOccupancySensorTypeBitmapAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Occupancysensortypebitmap attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Occupancysensortypebitmap attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -338,62 +380,72 @@ class OccupancySensingCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readHoldTimeAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readHoldTimeAttribute(): UShort? {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}") - } + 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) { "Holdtime attribute not found in response" } + } + + requireNotNull(attributeData) { + "Holdtime 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } - suspend fun writeHoldTimeAttribute(value: UShort, timedWriteTimeout: Duration? = null) { + suspend fun writeHoldTimeAttribute( + value: UShort, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 3u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -414,213 +466,224 @@ class OccupancySensingCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeHoldTimeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Holdtime attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Holdtime 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readHoldTimeLimitsAttribute(): HoldTimeLimitsAttribute { - val ATTRIBUTE_ID: UInt = 4u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readHoldTimeLimitsAttribute(): HoldTimeLimitsAttribute {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}") - } + 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) { "Holdtimelimits attribute not found in response" } + } + + requireNotNull(attributeData) { + "Holdtimelimits attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: OccupancySensingClusterHoldTimeLimitsStruct? = - if (tlvReader.isNextTag(AnonymousTag)) { - OccupancySensingClusterHoldTimeLimitsStruct.fromTlv(AnonymousTag, tlvReader) - } else { - null - } + val decodedValue: OccupancySensingClusterHoldTimeLimitsStruct? = if (tlvReader.isNextTag(AnonymousTag)) { + OccupancySensingClusterHoldTimeLimitsStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } + return HoldTimeLimitsAttribute(decodedValue) } suspend fun subscribeHoldTimeLimitsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - HoldTimeLimitsAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(HoldTimeLimitsAttributeSubscriptionState.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) { - "Holdtimelimits attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Holdtimelimits attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: OccupancySensingClusterHoldTimeLimitsStruct? = - if (tlvReader.isNextTag(AnonymousTag)) { - OccupancySensingClusterHoldTimeLimitsStruct.fromTlv(AnonymousTag, tlvReader) - } else { - null - } + val decodedValue: OccupancySensingClusterHoldTimeLimitsStruct? = if (tlvReader.isNextTag(AnonymousTag)) { + OccupancySensingClusterHoldTimeLimitsStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } - decodedValue?.let { emit(HoldTimeLimitsAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(HoldTimeLimitsAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(HoldTimeLimitsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readPIROccupiedToUnoccupiedDelayAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 16u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readPIROccupiedToUnoccupiedDelayAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 16u + + 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}") - } + 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) { "Piroccupiedtounoccupieddelay attribute not found in response" } + } + + requireNotNull(attributeData) { + "Piroccupiedtounoccupieddelay 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun writePIROccupiedToUnoccupiedDelayAttribute( value: UShort, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -641,122 +704,127 @@ class OccupancySensingCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribePIROccupiedToUnoccupiedDelayAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Piroccupiedtounoccupieddelay attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Piroccupiedtounoccupieddelay 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readPIRUnoccupiedToOccupiedDelayAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 17u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readPIRUnoccupiedToOccupiedDelayAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 17u + + 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}") - } + 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) { "Pirunoccupiedtooccupieddelay attribute not found in response" } + } + + requireNotNull(attributeData) { + "Pirunoccupiedtooccupieddelay 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun writePIRUnoccupiedToOccupiedDelayAttribute( value: UShort, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 17u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -777,124 +845,127 @@ class OccupancySensingCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribePIRUnoccupiedToOccupiedDelayAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 17u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Pirunoccupiedtooccupieddelay attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Pirunoccupiedtooccupieddelay 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readPIRUnoccupiedToOccupiedThresholdAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 18u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readPIRUnoccupiedToOccupiedThresholdAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 18u + + 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}") - } + 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) { - "Pirunoccupiedtooccupiedthreshold attribute not found in response" + } + + requireNotNull(attributeData) { + "Pirunoccupiedtooccupiedthreshold 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun writePIRUnoccupiedToOccupiedThresholdAttribute( value: UByte, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 18u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -915,124 +986,127 @@ class OccupancySensingCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribePIRUnoccupiedToOccupiedThresholdAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 18u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Pirunoccupiedtooccupiedthreshold attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Pirunoccupiedtooccupiedthreshold 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readUltrasonicOccupiedToUnoccupiedDelayAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 32u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readUltrasonicOccupiedToUnoccupiedDelayAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 32u + + 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}") - } + 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) { - "Ultrasonicoccupiedtounoccupieddelay attribute not found in response" + } + + requireNotNull(attributeData) { + "Ultrasonicoccupiedtounoccupieddelay 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun writeUltrasonicOccupiedToUnoccupiedDelayAttribute( value: UShort, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 32u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -1053,124 +1127,127 @@ class OccupancySensingCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeUltrasonicOccupiedToUnoccupiedDelayAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 32u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Ultrasonicoccupiedtounoccupieddelay attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Ultrasonicoccupiedtounoccupieddelay 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readUltrasonicUnoccupiedToOccupiedDelayAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 33u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readUltrasonicUnoccupiedToOccupiedDelayAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 33u + + 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}") - } + 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) { - "Ultrasonicunoccupiedtooccupieddelay attribute not found in response" + } + + requireNotNull(attributeData) { + "Ultrasonicunoccupiedtooccupieddelay 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun writeUltrasonicUnoccupiedToOccupiedDelayAttribute( value: UShort, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 33u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -1191,124 +1268,127 @@ class OccupancySensingCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeUltrasonicUnoccupiedToOccupiedDelayAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 33u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Ultrasonicunoccupiedtooccupieddelay attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Ultrasonicunoccupiedtooccupieddelay 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readUltrasonicUnoccupiedToOccupiedThresholdAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 34u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readUltrasonicUnoccupiedToOccupiedThresholdAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 34u + + 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}") - } + 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) { - "Ultrasonicunoccupiedtooccupiedthreshold attribute not found in response" + } + + requireNotNull(attributeData) { + "Ultrasonicunoccupiedtooccupiedthreshold 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun writeUltrasonicUnoccupiedToOccupiedThresholdAttribute( value: UByte, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 34u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -1329,124 +1409,127 @@ class OccupancySensingCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeUltrasonicUnoccupiedToOccupiedThresholdAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 34u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Ultrasonicunoccupiedtooccupiedthreshold attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Ultrasonicunoccupiedtooccupiedthreshold 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readPhysicalContactOccupiedToUnoccupiedDelayAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 48u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readPhysicalContactOccupiedToUnoccupiedDelayAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 48u + + 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}") - } + 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) { - "Physicalcontactoccupiedtounoccupieddelay attribute not found in response" + } + + requireNotNull(attributeData) { + "Physicalcontactoccupiedtounoccupieddelay 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun writePhysicalContactOccupiedToUnoccupiedDelayAttribute( value: UShort, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 48u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -1467,124 +1550,127 @@ class OccupancySensingCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribePhysicalContactOccupiedToUnoccupiedDelayAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 48u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Physicalcontactoccupiedtounoccupieddelay attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Physicalcontactoccupiedtounoccupieddelay 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readPhysicalContactUnoccupiedToOccupiedDelayAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 49u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readPhysicalContactUnoccupiedToOccupiedDelayAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 49u + + 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}") - } + 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) { - "Physicalcontactunoccupiedtooccupieddelay attribute not found in response" + } + + requireNotNull(attributeData) { + "Physicalcontactunoccupiedtooccupieddelay 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun writePhysicalContactUnoccupiedToOccupiedDelayAttribute( value: UShort, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 49u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -1605,124 +1691,127 @@ class OccupancySensingCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribePhysicalContactUnoccupiedToOccupiedDelayAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 49u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Physicalcontactunoccupiedtooccupieddelay attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Physicalcontactunoccupiedtooccupieddelay 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readPhysicalContactUnoccupiedToOccupiedThresholdAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 50u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readPhysicalContactUnoccupiedToOccupiedThresholdAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 50u + + 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}") - } + 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) { - "Physicalcontactunoccupiedtooccupiedthreshold attribute not found in response" + } + + requireNotNull(attributeData) { + "Physicalcontactunoccupiedtooccupiedthreshold 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun writePhysicalContactUnoccupiedToOccupiedThresholdAttribute( value: UByte, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 50u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -1743,153 +1832,152 @@ class OccupancySensingCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribePhysicalContactUnoccupiedToOccupiedThresholdAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 50u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Physicalcontactunoccupiedtooccupiedthreshold attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Physicalcontactunoccupiedtooccupiedthreshold 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1897,96 +1985,97 @@ class OccupancySensingCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1994,94 +2083,97 @@ class OccupancySensingCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -2089,94 +2181,97 @@ class OccupancySensingCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -2184,76 +2279,81 @@ class OccupancySensingCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -2265,77 +2365,80 @@ class OccupancySensingCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -2348,7 +2451,7 @@ class OccupancySensingCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/OnOffCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/OnOffCluster.kt index 1701c1dafa527f..8897b4bd04a433 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/OnOffCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/OnOffCluster.kt @@ -17,95 +17,126 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration 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.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.UIntSubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState +import matter.controller.UByteSubscriptionState import matter.controller.UShortSubscriptionState +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.cluster.structs.* +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class OnOffCluster(private val controller: MatterController, private val endpointId: UShort) { - class StartUpOnOffAttribute(val value: UByte?) +class OnOffCluster(private val controller: MatterController, private val endpointId: UShort) {class StartUpOnOffAttribute( + val value: UByte? + ) sealed class StartUpOnOffAttributeSubscriptionState { - data class Success(val value: UByte?) : StartUpOnOffAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : StartUpOnOffAttributeSubscriptionState() + data class Error(val exception: Exception) : StartUpOnOffAttributeSubscriptionState() - object SubscriptionEstablished : StartUpOnOffAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : StartUpOnOffAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } suspend fun off(timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -116,14 +147,14 @@ class OnOffCluster(private val controller: MatterController, private val endpoin val commandId: UInt = 1u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -134,25 +165,23 @@ class OnOffCluster(private val controller: MatterController, private val endpoin val commandId: UInt = 2u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun offWithEffect( - effectIdentifier: UByte, - effectVariant: UByte, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun offWithEffect(effectIdentifier: UByte + ,effectVariant: UByte + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 64u val tlvWriter = TlvWriter() @@ -162,14 +191,14 @@ class OnOffCluster(private val controller: MatterController, private val endpoin tlvWriter.put(ContextSpecificTag(TAG_EFFECT_IDENTIFIER_REQ), effectIdentifier) val TAG_EFFECT_VARIANT_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_EFFECT_VARIANT_REQ), effectVariant) + tlvWriter.put(ContextSpecificTag(TAG_EFFECT_VARIANT_REQ), effectVariant) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -180,26 +209,24 @@ class OnOffCluster(private val controller: MatterController, private val endpoin val commandId: UInt = 65u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun onWithTimedOff( - onOffControl: UByte, - onTime: UShort, - offWaitTime: UShort, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun onWithTimedOff(onOffControl: UByte + ,onTime: UShort + ,offWaitTime: UShort + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 66u val tlvWriter = TlvWriter() @@ -212,87 +239,92 @@ class OnOffCluster(private val controller: MatterController, private val endpoin tlvWriter.put(ContextSpecificTag(TAG_ON_TIME_REQ), onTime) val TAG_OFF_WAIT_TIME_REQ: Int = 2 - tlvWriter.put(ContextSpecificTag(TAG_OFF_WAIT_TIME_REQ), offWaitTime) + tlvWriter.put(ContextSpecificTag(TAG_OFF_WAIT_TIME_REQ), offWaitTime) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - - suspend fun readOnOffAttribute(): Boolean { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readOnOffAttribute(): Boolean {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}") - } + 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) { "Onoff attribute not found in response" } + } + + requireNotNull(attributeData) { + "Onoff attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Boolean = tlvReader.getBoolean(AnonymousTag) + return decodedValue } suspend fun subscribeOnOffAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Onoff attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Onoff attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -304,155 +336,169 @@ class OnOffCluster(private val controller: MatterController, private val endpoin emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readGlobalSceneControlAttribute(): Boolean? { - val ATTRIBUTE_ID: UInt = 16384u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readGlobalSceneControlAttribute(): Boolean? {val ATTRIBUTE_ID: UInt = 16384u + + 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}") - } + 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) { "Globalscenecontrol attribute not found in response" } + } + + requireNotNull(attributeData) { + "Globalscenecontrol 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 - } + val decodedValue: Boolean? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeGlobalSceneControlAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16384u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Globalscenecontrol attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Globalscenecontrol 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)) } + 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 readOnTimeAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 16385u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readOnTimeAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 16385u + + 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}") - } + 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) { "Ontime attribute not found in response" } + } + + requireNotNull(attributeData) { + "Ontime 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } - suspend fun writeOnTimeAttribute(value: UShort, timedWriteTimeout: Duration? = null) { + suspend fun writeOnTimeAttribute( + value: UShort, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16385u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -473,117 +519,127 @@ class OnOffCluster(private val controller: MatterController, private val endpoin throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeOnTimeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16385u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Ontime attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Ontime 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)) } + 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 readOffWaitTimeAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 16386u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readOffWaitTimeAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 16386u + + 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}") - } + 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) { "Offwaittime attribute not found in response" } + } + + requireNotNull(attributeData) { + "Offwaittime 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } - suspend fun writeOffWaitTimeAttribute(value: UShort, timedWriteTimeout: Duration? = null) { + suspend fun writeOffWaitTimeAttribute( + value: UShort, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16386u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -604,122 +660,132 @@ class OnOffCluster(private val controller: MatterController, private val endpoin throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeOffWaitTimeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16386u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Offwaittime attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Offwaittime 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)) } + 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 readStartUpOnOffAttribute(): StartUpOnOffAttribute { - val ATTRIBUTE_ID: UInt = 16387u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readStartUpOnOffAttribute(): StartUpOnOffAttribute {val ATTRIBUTE_ID: UInt = 16387u + + 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}") - } + 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) { "Startuponoff attribute not found in response" } + } + + requireNotNull(attributeData) { + "Startuponoff attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return StartUpOnOffAttribute(decodedValue) } - suspend fun writeStartUpOnOffAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeStartUpOnOffAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16387u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -740,156 +806,157 @@ class OnOffCluster(private val controller: MatterController, private val endpoin throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeStartUpOnOffAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16387u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StartUpOnOffAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StartUpOnOffAttributeSubscriptionState.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) { "Startuponoff attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Startuponoff 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(StartUpOnOffAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(StartUpOnOffAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(StartUpOnOffAttributeSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -897,96 +964,97 @@ class OnOffCluster(private val controller: MatterController, private val endpoin 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -994,94 +1062,97 @@ class OnOffCluster(private val controller: MatterController, private val endpoin 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1089,94 +1160,97 @@ class OnOffCluster(private val controller: MatterController, private val endpoin 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1184,76 +1258,81 @@ class OnOffCluster(private val controller: MatterController, private val endpoin 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1265,77 +1344,80 @@ class OnOffCluster(private val controller: MatterController, private val endpoin 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1348,7 +1430,7 @@ class OnOffCluster(private val controller: MatterController, private val endpoin emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/OnOffSwitchConfigurationCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/OnOffSwitchConfigurationCluster.kt index 88a03128e9f596..d30268d4c2280c 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/OnOffSwitchConfigurationCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/OnOffSwitchConfigurationCluster.kt @@ -17,139 +17,173 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.cluster.structs.* +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath +import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class OnOffSwitchConfigurationCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class GeneratedCommandListAttribute(val value: List) +class OnOffSwitchConfigurationCluster(private val controller: MatterController, private val endpointId: UShort) {class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } - - suspend fun readSwitchTypeAttribute(): 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)) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } +suspend fun readSwitchTypeAttribute(): 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}") - } + 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) { "Switchtype attribute not found in response" } + } + + requireNotNull(attributeData) { + "Switchtype 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 subscribeSwitchTypeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Switchtype attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Switchtype attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -161,57 +195,68 @@ class OnOffSwitchConfigurationCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readSwitchActionsAttribute(): UByte { - val ATTRIBUTE_ID: UInt = 16u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readSwitchActionsAttribute(): UByte {val ATTRIBUTE_ID: UInt = 16u + + 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}") - } + 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) { "Switchactions attribute not found in response" } + } + + requireNotNull(attributeData) { + "Switchactions 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 writeSwitchActionsAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeSwitchActionsAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -232,45 +277,43 @@ class OnOffSwitchConfigurationCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeSwitchActionsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Switchactions attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Switchactions attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -282,96 +325,97 @@ class OnOffSwitchConfigurationCluster( emit(UByteSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -379,96 +423,97 @@ class OnOffSwitchConfigurationCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -476,94 +521,97 @@ class OnOffSwitchConfigurationCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -571,94 +619,97 @@ class OnOffSwitchConfigurationCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -666,76 +717,81 @@ class OnOffSwitchConfigurationCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -747,77 +803,80 @@ class OnOffSwitchConfigurationCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -830,7 +889,7 @@ class OnOffSwitchConfigurationCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/OperationalCredentialsCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/OperationalCredentialsCluster.kt index d96efd654fe092..07eb5e0061faf5 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/OperationalCredentialsCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/OperationalCredentialsCluster.kt @@ -17,136 +17,176 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class OperationalCredentialsCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { +class OperationalCredentialsCluster(private val controller: MatterController, private val endpointId: UShort) { class AttestationResponse( - val attestationElements: ByteArray, - val attestationSignature: ByteArray, + val attestationElements: ByteArray, + val attestationSignature: ByteArray ) - class CertificateChainResponse(val certificate: ByteArray) - - class CSRResponse(val NOCSRElements: ByteArray, val attestationSignature: ByteArray) + class CertificateChainResponse( + val certificate: ByteArray + ) - class NOCResponse(val statusCode: UByte, val fabricIndex: UByte?, val debugText: String?) + class CSRResponse( + val NOCSRElements: ByteArray, + val attestationSignature: ByteArray + ) - class NOCsAttribute(val value: List) + class NOCResponse( + val statusCode: UByte, + val fabricIndex: UByte?, + val debugText: String? + ) +class NOCsAttribute( + val value: List + ) sealed class NOCsAttributeSubscriptionState { - data class Success(val value: List) : - NOCsAttributeSubscriptionState() - + data class Success( + val value: List + ) : NOCsAttributeSubscriptionState() + data class Error(val exception: Exception) : NOCsAttributeSubscriptionState() - object SubscriptionEstablished : NOCsAttributeSubscriptionState() - } - - class FabricsAttribute(val value: List) + object SubscriptionEstablished : NOCsAttributeSubscriptionState() + } +class FabricsAttribute( + val value: List + ) sealed class FabricsAttributeSubscriptionState { - data class Success(val value: List) : - FabricsAttributeSubscriptionState() - + data class Success( + val value: List + ) : FabricsAttributeSubscriptionState() + data class Error(val exception: Exception) : FabricsAttributeSubscriptionState() - object SubscriptionEstablished : FabricsAttributeSubscriptionState() - } - - class TrustedRootCertificatesAttribute(val value: List) + object SubscriptionEstablished : FabricsAttributeSubscriptionState() + } +class TrustedRootCertificatesAttribute( + val value: List + ) sealed class TrustedRootCertificatesAttributeSubscriptionState { - data class Success(val value: List) : - TrustedRootCertificatesAttributeSubscriptionState() - - data class Error(val exception: Exception) : - TrustedRootCertificatesAttributeSubscriptionState() - - object SubscriptionEstablished : TrustedRootCertificatesAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + data class Success( + val value: List + ) : TrustedRootCertificatesAttributeSubscriptionState() + + data class Error(val exception: Exception) : TrustedRootCertificatesAttributeSubscriptionState() + + object SubscriptionEstablished : TrustedRootCertificatesAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun attestationRequest( - attestationNonce: ByteArray, - timedInvokeTimeout: Duration? = null, - ): AttestationResponse { + suspend fun attestationRequest(attestationNonce: ByteArray + ,timedInvokeTimeout: Duration? = null): AttestationResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_ATTESTATION_NONCE_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_ATTESTATION_NONCE_REQ), attestationNonce) + tlvWriter.put(ContextSpecificTag(TAG_ATTESTATION_NONCE_REQ), attestationNonce) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -156,55 +196,61 @@ class OperationalCredentialsCluster( tlvReader.enterStructure(AnonymousTag) val TAG_ATTESTATION_ELEMENTS: Int = 0 var attestationElements_decoded: ByteArray? = null - + val TAG_ATTESTATION_SIGNATURE: Int = 1 var attestationSignature_decoded: ByteArray? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_ATTESTATION_ELEMENTS)) { - attestationElements_decoded = tlvReader.getByteArray(tag) - } + + if (tag == ContextSpecificTag(TAG_ATTESTATION_ELEMENTS)) {attestationElements_decoded = tlvReader.getByteArray(tag)} + + if (tag == ContextSpecificTag(TAG_ATTESTATION_SIGNATURE)) {attestationSignature_decoded = tlvReader.getByteArray(tag)} + - if (tag == ContextSpecificTag(TAG_ATTESTATION_SIGNATURE)) { - attestationSignature_decoded = tlvReader.getByteArray(tag) - } else { + else { tlvReader.skipElement() } } + + if (attestationElements_decoded == null) { - throw IllegalStateException("attestationElements not found in TLV") + throw IllegalStateException("attestationElements not found in TLV") } - + + if (attestationSignature_decoded == null) { - throw IllegalStateException("attestationSignature not found in TLV") + throw IllegalStateException("attestationSignature not found in TLV") } + tlvReader.exitContainer() - return AttestationResponse(attestationElements_decoded, attestationSignature_decoded) + return AttestationResponse( + attestationElements_decoded, + attestationSignature_decoded + ) } - suspend fun certificateChainRequest( - certificateType: UByte, - timedInvokeTimeout: Duration? = null, - ): CertificateChainResponse { + suspend fun certificateChainRequest(certificateType: UByte + ,timedInvokeTimeout: Duration? = null): CertificateChainResponse { val commandId: UInt = 2u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_CERTIFICATE_TYPE_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_CERTIFICATE_TYPE_REQ), certificateType) + tlvWriter.put(ContextSpecificTag(TAG_CERTIFICATE_TYPE_REQ), certificateType) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -214,31 +260,37 @@ class OperationalCredentialsCluster( tlvReader.enterStructure(AnonymousTag) val TAG_CERTIFICATE: Int = 0 var certificate_decoded: ByteArray? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_CERTIFICATE)) { - certificate_decoded = tlvReader.getByteArray(tag) - } else { + + if (tag == ContextSpecificTag(TAG_CERTIFICATE)) {certificate_decoded = tlvReader.getByteArray(tag)} + + + else { tlvReader.skipElement() } } + + if (certificate_decoded == null) { - throw IllegalStateException("certificate not found in TLV") + throw IllegalStateException("certificate not found in TLV") } + tlvReader.exitContainer() - return CertificateChainResponse(certificate_decoded) + return CertificateChainResponse( + certificate_decoded + ) } - suspend fun CSRRequest( - CSRNonce: ByteArray, - isForUpdateNOC: Boolean?, - timedInvokeTimeout: Duration? = null, - ): CSRResponse { + suspend fun CSRRequest(CSRNonce: ByteArray + ,isForUpdateNOC: Boolean? + ,timedInvokeTimeout: Duration? = null): CSRResponse { val commandId: UInt = 4u val tlvWriter = TlvWriter() @@ -250,14 +302,14 @@ class OperationalCredentialsCluster( val TAG_IS_FOR_UPDATE_NOC_REQ: Int = 1 isForUpdateNOC?.let { tlvWriter.put(ContextSpecificTag(TAG_IS_FOR_UPDATE_NOC_REQ), isForUpdateNOC) - } + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -267,45 +319,51 @@ class OperationalCredentialsCluster( tlvReader.enterStructure(AnonymousTag) val TAG_NOCSR_ELEMENTS: Int = 0 var NOCSRElements_decoded: ByteArray? = null - + val TAG_ATTESTATION_SIGNATURE: Int = 1 var attestationSignature_decoded: ByteArray? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_NOCSR_ELEMENTS)) { - NOCSRElements_decoded = tlvReader.getByteArray(tag) - } + + if (tag == ContextSpecificTag(TAG_NOCSR_ELEMENTS)) {NOCSRElements_decoded = tlvReader.getByteArray(tag)} + + if (tag == ContextSpecificTag(TAG_ATTESTATION_SIGNATURE)) {attestationSignature_decoded = tlvReader.getByteArray(tag)} + - if (tag == ContextSpecificTag(TAG_ATTESTATION_SIGNATURE)) { - attestationSignature_decoded = tlvReader.getByteArray(tag) - } else { + else { tlvReader.skipElement() } } + + if (NOCSRElements_decoded == null) { - throw IllegalStateException("NOCSRElements not found in TLV") + throw IllegalStateException("NOCSRElements not found in TLV") } - + + if (attestationSignature_decoded == null) { - throw IllegalStateException("attestationSignature not found in TLV") + throw IllegalStateException("attestationSignature not found in TLV") } + tlvReader.exitContainer() - return CSRResponse(NOCSRElements_decoded, attestationSignature_decoded) + return CSRResponse( + NOCSRElements_decoded, + attestationSignature_decoded + ) } - suspend fun addNOC( - NOCValue: ByteArray, - ICACValue: ByteArray?, - IPKValue: ByteArray, - caseAdminSubject: ULong, - adminVendorId: UShort, - timedInvokeTimeout: Duration? = null, - ): NOCResponse { + suspend fun addNOC(NOCValue: ByteArray + ,ICACValue: ByteArray? + ,IPKValue: ByteArray + ,caseAdminSubject: ULong + ,adminVendorId: UShort + ,timedInvokeTimeout: Duration? = null): NOCResponse { val commandId: UInt = 6u val tlvWriter = TlvWriter() @@ -315,7 +373,9 @@ class OperationalCredentialsCluster( tlvWriter.put(ContextSpecificTag(TAG_NOC_VALUE_REQ), NOCValue) val TAG_ICAC_VALUE_REQ: Int = 1 - ICACValue?.let { tlvWriter.put(ContextSpecificTag(TAG_ICAC_VALUE_REQ), ICACValue) } + ICACValue?.let { + tlvWriter.put(ContextSpecificTag(TAG_ICAC_VALUE_REQ), ICACValue) + } val TAG_IPK_VALUE_REQ: Int = 2 tlvWriter.put(ContextSpecificTag(TAG_IPK_VALUE_REQ), IPKValue) @@ -324,14 +384,14 @@ class OperationalCredentialsCluster( tlvWriter.put(ContextSpecificTag(TAG_CASE_ADMIN_SUBJECT_REQ), caseAdminSubject) val TAG_ADMIN_VENDOR_ID_REQ: Int = 4 - tlvWriter.put(ContextSpecificTag(TAG_ADMIN_VENDOR_ID_REQ), adminVendorId) + tlvWriter.put(ContextSpecificTag(TAG_ADMIN_VENDOR_ID_REQ), adminVendorId) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -341,65 +401,73 @@ class OperationalCredentialsCluster( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS_CODE: Int = 0 var statusCode_decoded: UByte? = null - + val TAG_FABRIC_INDEX: Int = 1 var fabricIndex_decoded: UByte? = null - + val TAG_DEBUG_TEXT: Int = 2 var debugText_decoded: String? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_STATUS_CODE)) { - statusCode_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_FABRIC_INDEX)) { - fabricIndex_decoded = + + if (tag == ContextSpecificTag(TAG_STATUS_CODE)) {statusCode_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_FABRIC_INDEX)) {fabricIndex_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getUByte(tag) - } else { - null - } - } - } - - if (tag == ContextSpecificTag(TAG_DEBUG_TEXT)) { - debugText_decoded = + tlvReader.getUByte(tag) + } else { + null + } + }} + + if (tag == ContextSpecificTag(TAG_DEBUG_TEXT)) {debugText_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - } - } else { + tlvReader.getString(tag) + } else { + null + } + }} + + + else { tlvReader.skipElement() } } + + if (statusCode_decoded == null) { - throw IllegalStateException("statusCode not found in TLV") + throw IllegalStateException("statusCode not found in TLV") } + + + + + tlvReader.exitContainer() - return NOCResponse(statusCode_decoded, fabricIndex_decoded, debugText_decoded) + return NOCResponse( + statusCode_decoded, + fabricIndex_decoded, + debugText_decoded + ) } - suspend fun updateNOC( - NOCValue: ByteArray, - ICACValue: ByteArray?, - timedInvokeTimeout: Duration? = null, - ): NOCResponse { + suspend fun updateNOC(NOCValue: ByteArray + ,ICACValue: ByteArray? + ,timedInvokeTimeout: Duration? = null): NOCResponse { val commandId: UInt = 7u val tlvWriter = TlvWriter() @@ -409,14 +477,16 @@ class OperationalCredentialsCluster( tlvWriter.put(ContextSpecificTag(TAG_NOC_VALUE_REQ), NOCValue) val TAG_ICAC_VALUE_REQ: Int = 1 - ICACValue?.let { tlvWriter.put(ContextSpecificTag(TAG_ICAC_VALUE_REQ), ICACValue) } + ICACValue?.let { + tlvWriter.put(ContextSpecificTag(TAG_ICAC_VALUE_REQ), ICACValue) + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -426,75 +496,86 @@ class OperationalCredentialsCluster( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS_CODE: Int = 0 var statusCode_decoded: UByte? = null - + val TAG_FABRIC_INDEX: Int = 1 var fabricIndex_decoded: UByte? = null - + val TAG_DEBUG_TEXT: Int = 2 var debugText_decoded: String? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_STATUS_CODE)) { - statusCode_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_FABRIC_INDEX)) { - fabricIndex_decoded = + + if (tag == ContextSpecificTag(TAG_STATUS_CODE)) {statusCode_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_FABRIC_INDEX)) {fabricIndex_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getUByte(tag) - } else { - null - } - } - } - - if (tag == ContextSpecificTag(TAG_DEBUG_TEXT)) { - debugText_decoded = + tlvReader.getUByte(tag) + } else { + null + } + }} + + if (tag == ContextSpecificTag(TAG_DEBUG_TEXT)) {debugText_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - } - } else { + tlvReader.getString(tag) + } else { + null + } + }} + + + else { tlvReader.skipElement() } } + + if (statusCode_decoded == null) { - throw IllegalStateException("statusCode not found in TLV") + throw IllegalStateException("statusCode not found in TLV") } + + + + + tlvReader.exitContainer() - return NOCResponse(statusCode_decoded, fabricIndex_decoded, debugText_decoded) + return NOCResponse( + statusCode_decoded, + fabricIndex_decoded, + debugText_decoded + ) } - suspend fun updateFabricLabel(label: String, timedInvokeTimeout: Duration? = null): NOCResponse { + suspend fun updateFabricLabel(label: String + ,timedInvokeTimeout: Duration? = null): NOCResponse { val commandId: UInt = 9u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_LABEL_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_LABEL_REQ), label) + tlvWriter.put(ContextSpecificTag(TAG_LABEL_REQ), label) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -504,75 +585,86 @@ class OperationalCredentialsCluster( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS_CODE: Int = 0 var statusCode_decoded: UByte? = null - + val TAG_FABRIC_INDEX: Int = 1 var fabricIndex_decoded: UByte? = null - + val TAG_DEBUG_TEXT: Int = 2 var debugText_decoded: String? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_STATUS_CODE)) { - statusCode_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_FABRIC_INDEX)) { - fabricIndex_decoded = + + if (tag == ContextSpecificTag(TAG_STATUS_CODE)) {statusCode_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_FABRIC_INDEX)) {fabricIndex_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getUByte(tag) - } else { - null - } - } - } - - if (tag == ContextSpecificTag(TAG_DEBUG_TEXT)) { - debugText_decoded = + tlvReader.getUByte(tag) + } else { + null + } + }} + + if (tag == ContextSpecificTag(TAG_DEBUG_TEXT)) {debugText_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - } - } else { + tlvReader.getString(tag) + } else { + null + } + }} + + + else { tlvReader.skipElement() } } + + if (statusCode_decoded == null) { - throw IllegalStateException("statusCode not found in TLV") + throw IllegalStateException("statusCode not found in TLV") } + + + + + tlvReader.exitContainer() - return NOCResponse(statusCode_decoded, fabricIndex_decoded, debugText_decoded) + return NOCResponse( + statusCode_decoded, + fabricIndex_decoded, + debugText_decoded + ) } - suspend fun removeFabric(fabricIndex: UByte, timedInvokeTimeout: Duration? = null): NOCResponse { + suspend fun removeFabric(fabricIndex: UByte + ,timedInvokeTimeout: Duration? = null): NOCResponse { val commandId: UInt = 10u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_FABRIC_INDEX_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_FABRIC_INDEX_REQ), fabricIndex) + tlvWriter.put(ContextSpecificTag(TAG_FABRIC_INDEX_REQ), fabricIndex) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -582,169 +674,180 @@ class OperationalCredentialsCluster( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS_CODE: Int = 0 var statusCode_decoded: UByte? = null - + val TAG_FABRIC_INDEX: Int = 1 var fabricIndex_decoded: UByte? = null - + val TAG_DEBUG_TEXT: Int = 2 var debugText_decoded: String? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_STATUS_CODE)) { - statusCode_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_FABRIC_INDEX)) { - fabricIndex_decoded = + + if (tag == ContextSpecificTag(TAG_STATUS_CODE)) {statusCode_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_FABRIC_INDEX)) {fabricIndex_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getUByte(tag) - } else { - null - } - } - } - - if (tag == ContextSpecificTag(TAG_DEBUG_TEXT)) { - debugText_decoded = + tlvReader.getUByte(tag) + } else { + null + } + }} + + if (tag == ContextSpecificTag(TAG_DEBUG_TEXT)) {debugText_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - } - } else { + tlvReader.getString(tag) + } else { + null + } + }} + + + else { tlvReader.skipElement() } } + + if (statusCode_decoded == null) { - throw IllegalStateException("statusCode not found in TLV") + throw IllegalStateException("statusCode not found in TLV") } + + + + + tlvReader.exitContainer() - return NOCResponse(statusCode_decoded, fabricIndex_decoded, debugText_decoded) + return NOCResponse( + statusCode_decoded, + fabricIndex_decoded, + debugText_decoded + ) } - suspend fun addTrustedRootCertificate( - rootCACertificate: ByteArray, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun addTrustedRootCertificate(rootCACertificate: ByteArray + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 11u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_ROOT_CA_CERTIFICATE_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_ROOT_CA_CERTIFICATE_REQ), rootCACertificate) + tlvWriter.put(ContextSpecificTag(TAG_ROOT_CA_CERTIFICATE_REQ), rootCACertificate) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - - suspend fun readNOCsAttribute(): NOCsAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readNOCsAttribute(): NOCsAttribute {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}") - } + 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) { "Nocs attribute not found in response" } + } + + requireNotNull(attributeData) { + "Nocs 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(OperationalCredentialsClusterNOCStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(OperationalCredentialsClusterNOCStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + return NOCsAttribute(decodedValue) } suspend fun subscribeNOCsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - NOCsAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(NOCsAttributeSubscriptionState.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) { "Nocs attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Nocs 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(OperationalCredentialsClusterNOCStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(OperationalCredentialsClusterNOCStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(NOCsAttributeSubscriptionState.Success(decodedValue)) } @@ -752,99 +855,97 @@ class OperationalCredentialsCluster( emit(NOCsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readFabricsAttribute(): FabricsAttribute { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readFabricsAttribute(): FabricsAttribute {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}") - } + 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) { "Fabrics attribute not found in response" } + } + + requireNotNull(attributeData) { + "Fabrics 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(OperationalCredentialsClusterFabricDescriptorStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(OperationalCredentialsClusterFabricDescriptorStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + return FabricsAttribute(decodedValue) } suspend fun subscribeFabricsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - FabricsAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(FabricsAttributeSubscriptionState.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) { "Fabrics attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Fabrics 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( - OperationalCredentialsClusterFabricDescriptorStruct.fromTlv( - AnonymousTag, - tlvReader, - ) - ) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(OperationalCredentialsClusterFabricDescriptorStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(FabricsAttributeSubscriptionState.Success(decodedValue)) } @@ -852,77 +953,80 @@ class OperationalCredentialsCluster( emit(FabricsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readSupportedFabricsAttribute(): UByte { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readSupportedFabricsAttribute(): UByte {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}") - } + 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) { "Supportedfabrics attribute not found in response" } + } + + requireNotNull(attributeData) { + "Supportedfabrics 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 subscribeSupportedFabricsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Supportedfabrics attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Supportedfabrics attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -935,77 +1039,80 @@ class OperationalCredentialsCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readCommissionedFabricsAttribute(): UByte { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readCommissionedFabricsAttribute(): UByte {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}") - } + 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) { "Commissionedfabrics attribute not found in response" } + } + + requireNotNull(attributeData) { + "Commissionedfabrics 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 subscribeCommissionedFabricsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Commissionedfabrics attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Commissionedfabrics attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -1018,96 +1125,97 @@ class OperationalCredentialsCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readTrustedRootCertificatesAttribute(): TrustedRootCertificatesAttribute { - val ATTRIBUTE_ID: UInt = 4u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readTrustedRootCertificatesAttribute(): TrustedRootCertificatesAttribute {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}") - } + 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) { "Trustedrootcertificates attribute not found in response" } + } + + requireNotNull(attributeData) { + "Trustedrootcertificates 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.getByteArray(AnonymousTag)) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getByteArray(AnonymousTag)) } + tlvReader.exitContainer() + } + return TrustedRootCertificatesAttribute(decodedValue) } suspend fun subscribeTrustedRootCertificatesAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - TrustedRootCertificatesAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(TrustedRootCertificatesAttributeSubscriptionState.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) { - "Trustedrootcertificates attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Trustedrootcertificates 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.getByteArray(AnonymousTag)) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getByteArray(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(TrustedRootCertificatesAttributeSubscriptionState.Success(decodedValue)) } @@ -1115,77 +1223,80 @@ class OperationalCredentialsCluster( emit(TrustedRootCertificatesAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readCurrentFabricIndexAttribute(): UByte { - val ATTRIBUTE_ID: UInt = 5u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readCurrentFabricIndexAttribute(): UByte {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}") - } + 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) { "Currentfabricindex attribute not found in response" } + } + + requireNotNull(attributeData) { + "Currentfabricindex 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 subscribeCurrentFabricIndexAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Currentfabricindex attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Currentfabricindex attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -1198,96 +1309,97 @@ class OperationalCredentialsCluster( emit(UByteSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1295,96 +1407,97 @@ class OperationalCredentialsCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1392,94 +1505,97 @@ class OperationalCredentialsCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1487,94 +1603,97 @@ class OperationalCredentialsCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1582,76 +1701,81 @@ class OperationalCredentialsCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1663,77 +1787,80 @@ class OperationalCredentialsCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1746,7 +1873,7 @@ class OperationalCredentialsCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/OperationalStateCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/OperationalStateCluster.kt index cef150821f7b44..e9f4f326e1fdbe 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/OperationalStateCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/OperationalStateCluster.kt @@ -17,143 +17,182 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class OperationalStateCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { +class OperationalStateCluster(private val controller: MatterController, private val endpointId: UShort) { class OperationalCommandResponse( val commandResponseState: OperationalStateClusterErrorStateStruct ) - - class PhaseListAttribute(val value: List?) +class PhaseListAttribute( + val value: List? + ) sealed class PhaseListAttributeSubscriptionState { - data class Success(val value: List?) : PhaseListAttributeSubscriptionState() - + data class Success( + val value: List? + ) : PhaseListAttributeSubscriptionState() + data class Error(val exception: Exception) : PhaseListAttributeSubscriptionState() - object SubscriptionEstablished : PhaseListAttributeSubscriptionState() - } - - class CurrentPhaseAttribute(val value: UByte?) + object SubscriptionEstablished : PhaseListAttributeSubscriptionState() + } +class CurrentPhaseAttribute( + val value: UByte? + ) sealed class CurrentPhaseAttributeSubscriptionState { - data class Success(val value: UByte?) : CurrentPhaseAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : CurrentPhaseAttributeSubscriptionState() + data class Error(val exception: Exception) : CurrentPhaseAttributeSubscriptionState() - object SubscriptionEstablished : CurrentPhaseAttributeSubscriptionState() - } - - class CountdownTimeAttribute(val value: UInt?) + object SubscriptionEstablished : CurrentPhaseAttributeSubscriptionState() + } +class CountdownTimeAttribute( + val value: UInt? + ) sealed class CountdownTimeAttributeSubscriptionState { - data class Success(val value: UInt?) : CountdownTimeAttributeSubscriptionState() - + data class Success( + val value: UInt? + ) : CountdownTimeAttributeSubscriptionState() + data class Error(val exception: Exception) : CountdownTimeAttributeSubscriptionState() - object SubscriptionEstablished : CountdownTimeAttributeSubscriptionState() - } - - class OperationalStateListAttribute( + object SubscriptionEstablished : CountdownTimeAttributeSubscriptionState() + } +class OperationalStateListAttribute( val value: List ) sealed class OperationalStateListAttributeSubscriptionState { - data class Success(val value: List) : - OperationalStateListAttributeSubscriptionState() - + data class Success( + val value: List + ) : OperationalStateListAttributeSubscriptionState() + data class Error(val exception: Exception) : OperationalStateListAttributeSubscriptionState() - object SubscriptionEstablished : OperationalStateListAttributeSubscriptionState() - } - - class OperationalErrorAttribute(val value: OperationalStateClusterErrorStateStruct) + object SubscriptionEstablished : OperationalStateListAttributeSubscriptionState() + } +class OperationalErrorAttribute( + val value: OperationalStateClusterErrorStateStruct + ) sealed class OperationalErrorAttributeSubscriptionState { - data class Success(val value: OperationalStateClusterErrorStateStruct) : - OperationalErrorAttributeSubscriptionState() - + data class Success( + val value: OperationalStateClusterErrorStateStruct + ) : OperationalErrorAttributeSubscriptionState() + data class Error(val exception: Exception) : OperationalErrorAttributeSubscriptionState() - object SubscriptionEstablished : OperationalErrorAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : OperationalErrorAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } suspend fun pause(timedInvokeTimeout: Duration? = null): OperationalCommandResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -163,39 +202,46 @@ class OperationalStateCluster( tlvReader.enterStructure(AnonymousTag) val TAG_COMMAND_RESPONSE_STATE: Int = 0 var commandResponseState_decoded: OperationalStateClusterErrorStateStruct? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_COMMAND_RESPONSE_STATE)) { - commandResponseState_decoded = - OperationalStateClusterErrorStateStruct.fromTlv(tag, tlvReader) - } else { + + if (tag == ContextSpecificTag(TAG_COMMAND_RESPONSE_STATE)) {commandResponseState_decoded = OperationalStateClusterErrorStateStruct.fromTlv(tag, tlvReader)} + + + else { tlvReader.skipElement() } } + + if (commandResponseState_decoded == null) { - throw IllegalStateException("commandResponseState not found in TLV") + throw IllegalStateException("commandResponseState not found in TLV") } + tlvReader.exitContainer() - return OperationalCommandResponse(commandResponseState_decoded) + return OperationalCommandResponse( + commandResponseState_decoded + ) } suspend fun stop(timedInvokeTimeout: Duration? = null): OperationalCommandResponse { val commandId: UInt = 1u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -205,39 +251,46 @@ class OperationalStateCluster( tlvReader.enterStructure(AnonymousTag) val TAG_COMMAND_RESPONSE_STATE: Int = 0 var commandResponseState_decoded: OperationalStateClusterErrorStateStruct? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_COMMAND_RESPONSE_STATE)) { - commandResponseState_decoded = - OperationalStateClusterErrorStateStruct.fromTlv(tag, tlvReader) - } else { + + if (tag == ContextSpecificTag(TAG_COMMAND_RESPONSE_STATE)) {commandResponseState_decoded = OperationalStateClusterErrorStateStruct.fromTlv(tag, tlvReader)} + + + else { tlvReader.skipElement() } } + + if (commandResponseState_decoded == null) { - throw IllegalStateException("commandResponseState not found in TLV") + throw IllegalStateException("commandResponseState not found in TLV") } + tlvReader.exitContainer() - return OperationalCommandResponse(commandResponseState_decoded) + return OperationalCommandResponse( + commandResponseState_decoded + ) } suspend fun start(timedInvokeTimeout: Duration? = null): OperationalCommandResponse { val commandId: UInt = 2u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -247,39 +300,46 @@ class OperationalStateCluster( tlvReader.enterStructure(AnonymousTag) val TAG_COMMAND_RESPONSE_STATE: Int = 0 var commandResponseState_decoded: OperationalStateClusterErrorStateStruct? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_COMMAND_RESPONSE_STATE)) { - commandResponseState_decoded = - OperationalStateClusterErrorStateStruct.fromTlv(tag, tlvReader) - } else { + + if (tag == ContextSpecificTag(TAG_COMMAND_RESPONSE_STATE)) {commandResponseState_decoded = OperationalStateClusterErrorStateStruct.fromTlv(tag, tlvReader)} + + + else { tlvReader.skipElement() } } + + if (commandResponseState_decoded == null) { - throw IllegalStateException("commandResponseState not found in TLV") + throw IllegalStateException("commandResponseState not found in TLV") } + tlvReader.exitContainer() - return OperationalCommandResponse(commandResponseState_decoded) + return OperationalCommandResponse( + commandResponseState_decoded + ) } suspend fun resume(timedInvokeTimeout: Duration? = null): OperationalCommandResponse { val commandId: UInt = 3u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -289,413 +349,439 @@ class OperationalStateCluster( tlvReader.enterStructure(AnonymousTag) val TAG_COMMAND_RESPONSE_STATE: Int = 0 var commandResponseState_decoded: OperationalStateClusterErrorStateStruct? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_COMMAND_RESPONSE_STATE)) { - commandResponseState_decoded = - OperationalStateClusterErrorStateStruct.fromTlv(tag, tlvReader) - } else { + + if (tag == ContextSpecificTag(TAG_COMMAND_RESPONSE_STATE)) {commandResponseState_decoded = OperationalStateClusterErrorStateStruct.fromTlv(tag, tlvReader)} + + + else { tlvReader.skipElement() } } + + if (commandResponseState_decoded == null) { - throw IllegalStateException("commandResponseState not found in TLV") + throw IllegalStateException("commandResponseState not found in TLV") } + tlvReader.exitContainer() - return OperationalCommandResponse(commandResponseState_decoded) + return OperationalCommandResponse( + commandResponseState_decoded + ) } - - suspend fun readPhaseListAttribute(): PhaseListAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readPhaseListAttribute(): PhaseListAttribute {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}") - } + 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) { "Phaselist attribute not found in response" } + } + + requireNotNull(attributeData) { + "Phaselist attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (!tlvReader.isNull()) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getString(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - tlvReader.getNull(AnonymousTag) - null + val decodedValue: List? = if (!tlvReader.isNull()) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getString(AnonymousTag)) } + tlvReader.exitContainer() + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return PhaseListAttribute(decodedValue) } suspend fun subscribePhaseListAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - PhaseListAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(PhaseListAttributeSubscriptionState.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) { "Phaselist attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Phaselist attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (!tlvReader.isNull()) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getString(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(PhaseListAttributeSubscriptionState.Success(it)) } + val decodedValue: List? = if (!tlvReader.isNull()) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getString(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(PhaseListAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(PhaseListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readCurrentPhaseAttribute(): CurrentPhaseAttribute { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readCurrentPhaseAttribute(): CurrentPhaseAttribute {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}") - } + 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) { "Currentphase attribute not found in response" } + } + + requireNotNull(attributeData) { + "Currentphase attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return CurrentPhaseAttribute(decodedValue) } suspend fun subscribeCurrentPhaseAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - CurrentPhaseAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(CurrentPhaseAttributeSubscriptionState.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) { "Currentphase attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Currentphase 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.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(CurrentPhaseAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(CurrentPhaseAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(CurrentPhaseAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readCountdownTimeAttribute(): CountdownTimeAttribute { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readCountdownTimeAttribute(): CountdownTimeAttribute {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}") - } + 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) { "Countdowntime attribute not found in response" } + } + + requireNotNull(attributeData) { + "Countdowntime attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return CountdownTimeAttribute(decodedValue) } suspend fun subscribeCountdownTimeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - CountdownTimeAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(CountdownTimeAttributeSubscriptionState.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) { "Countdowntime attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Countdowntime attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(CountdownTimeAttributeSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(CountdownTimeAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(CountdownTimeAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readOperationalStateListAttribute(): OperationalStateListAttribute { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readOperationalStateListAttribute(): OperationalStateListAttribute {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}") - } + 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) { "Operationalstatelist attribute not found in response" } + } + + requireNotNull(attributeData) { + "Operationalstatelist 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(OperationalStateClusterOperationalStateStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(OperationalStateClusterOperationalStateStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + return OperationalStateListAttribute(decodedValue) } suspend fun subscribeOperationalStateListAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - OperationalStateListAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(OperationalStateListAttributeSubscriptionState.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) { - "Operationalstatelist attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Operationalstatelist 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(OperationalStateClusterOperationalStateStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(OperationalStateClusterOperationalStateStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(OperationalStateListAttributeSubscriptionState.Success(decodedValue)) } @@ -703,77 +789,80 @@ class OperationalStateCluster( emit(OperationalStateListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readOperationalStateAttribute(): 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)) - +suspend fun readOperationalStateAttribute(): 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}") - } + 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) { "Operationalstate attribute not found in response" } + } + + requireNotNull(attributeData) { + "Operationalstate 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 subscribeOperationalStateAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Operationalstate attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Operationalstate attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -786,84 +875,85 @@ class OperationalStateCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readOperationalErrorAttribute(): OperationalErrorAttribute { - val ATTRIBUTE_ID: UInt = 5u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readOperationalErrorAttribute(): OperationalErrorAttribute {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}") - } + 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) { "Operationalerror attribute not found in response" } + } + + requireNotNull(attributeData) { + "Operationalerror attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: OperationalStateClusterErrorStateStruct = - OperationalStateClusterErrorStateStruct.fromTlv(AnonymousTag, tlvReader) + val decodedValue: OperationalStateClusterErrorStateStruct = OperationalStateClusterErrorStateStruct.fromTlv(AnonymousTag, tlvReader) + return OperationalErrorAttribute(decodedValue) } suspend fun subscribeOperationalErrorAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - OperationalErrorAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(OperationalErrorAttributeSubscriptionState.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) { - "Operationalerror attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Operationalerror attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: OperationalStateClusterErrorStateStruct = - OperationalStateClusterErrorStateStruct.fromTlv(AnonymousTag, tlvReader) + val decodedValue: OperationalStateClusterErrorStateStruct = OperationalStateClusterErrorStateStruct.fromTlv(AnonymousTag, tlvReader) emit(OperationalErrorAttributeSubscriptionState.Success(decodedValue)) } @@ -871,96 +961,97 @@ class OperationalStateCluster( emit(OperationalErrorAttributeSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -968,96 +1059,97 @@ class OperationalStateCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1065,94 +1157,97 @@ class OperationalStateCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1160,94 +1255,97 @@ class OperationalStateCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1255,76 +1353,81 @@ class OperationalStateCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1336,77 +1439,80 @@ class OperationalStateCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1419,7 +1525,7 @@ class OperationalStateCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/OtaSoftwareUpdateProviderCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/OtaSoftwareUpdateProviderCluster.kt index cf8525ed7f2ad7..182bdf0e2712c9 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/OtaSoftwareUpdateProviderCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/OtaSoftwareUpdateProviderCluster.kt @@ -17,96 +17,126 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.UIntSubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState +import matter.controller.UByteSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class OtaSoftwareUpdateProviderCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { +class OtaSoftwareUpdateProviderCluster(private val controller: MatterController, private val endpointId: UShort) { class QueryImageResponse( - val status: UByte, - val delayedActionTime: UInt?, - val imageURI: String?, - val softwareVersion: UInt?, - val softwareVersionString: String?, - val updateToken: ByteArray?, - val userConsentNeeded: Boolean?, - val metadataForRequestor: ByteArray?, + val status: UByte, + val delayedActionTime: UInt?, + val imageURI: String?, + val softwareVersion: UInt?, + val softwareVersionString: String?, + val updateToken: ByteArray?, + val userConsentNeeded: Boolean?, + val metadataForRequestor: ByteArray? ) - class ApplyUpdateResponse(val action: UByte, val delayedActionTime: UInt) - - class GeneratedCommandListAttribute(val value: List) + class ApplyUpdateResponse( + val action: UByte, + val delayedActionTime: UInt + ) +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } - - suspend fun queryImage( - vendorID: UShort, - productID: UShort, - softwareVersion: UInt, - protocolsSupported: List, - hardwareVersion: UShort?, - location: String?, - requestorCanConsent: Boolean?, - metadataForProvider: ByteArray?, - timedInvokeTimeout: Duration? = null, - ): QueryImageResponse { + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } + + suspend fun queryImage(vendorID: UShort + ,productID: UShort + ,softwareVersion: UInt + ,protocolsSupported: List + ,hardwareVersion: UShort? + ,location: String? + ,requestorCanConsent: Boolean? + ,metadataForProvider: ByteArray? + ,timedInvokeTimeout: Duration? = null): QueryImageResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() @@ -123,10 +153,10 @@ class OtaSoftwareUpdateProviderCluster( val TAG_PROTOCOLS_SUPPORTED_REQ: Int = 3 tlvWriter.startArray(ContextSpecificTag(TAG_PROTOCOLS_SUPPORTED_REQ)) - for (item in protocolsSupported.iterator()) { - tlvWriter.put(AnonymousTag, item) - } - tlvWriter.endArray() + for (item in protocolsSupported.iterator()) { + tlvWriter.put(AnonymousTag, item) + } + tlvWriter.endArray() val TAG_HARDWARE_VERSION_REQ: Int = 4 hardwareVersion?.let { @@ -134,7 +164,9 @@ class OtaSoftwareUpdateProviderCluster( } val TAG_LOCATION_REQ: Int = 5 - location?.let { tlvWriter.put(ContextSpecificTag(TAG_LOCATION_REQ), location) } + location?.let { + tlvWriter.put(ContextSpecificTag(TAG_LOCATION_REQ), location) + } val TAG_REQUESTOR_CAN_CONSENT_REQ: Int = 6 requestorCanConsent?.let { @@ -144,14 +176,14 @@ class OtaSoftwareUpdateProviderCluster( val TAG_METADATA_FOR_PROVIDER_REQ: Int = 7 metadataForProvider?.let { tlvWriter.put(ContextSpecificTag(TAG_METADATA_FOR_PROVIDER_REQ), metadataForProvider) - } + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -161,139 +193,145 @@ class OtaSoftwareUpdateProviderCluster( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_DELAYED_ACTION_TIME: Int = 1 var delayedActionTime_decoded: UInt? = null - + val TAG_IMAGE_URI: Int = 2 var imageURI_decoded: String? = null - + val TAG_SOFTWARE_VERSION: Int = 3 var softwareVersion_decoded: UInt? = null - + val TAG_SOFTWARE_VERSION_STRING: Int = 4 var softwareVersionString_decoded: String? = null - + val TAG_UPDATE_TOKEN: Int = 5 var updateToken_decoded: ByteArray? = null - + val TAG_USER_CONSENT_NEEDED: Int = 6 var userConsentNeeded_decoded: Boolean? = null - + val TAG_METADATA_FOR_REQUESTOR: Int = 7 var metadataForRequestor_decoded: ByteArray? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_STATUS)) { - status_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_DELAYED_ACTION_TIME)) { - delayedActionTime_decoded = + + if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_DELAYED_ACTION_TIME)) {delayedActionTime_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getUInt(tag) - } else { - null - } - } - } - - if (tag == ContextSpecificTag(TAG_IMAGE_URI)) { - imageURI_decoded = + tlvReader.getUInt(tag) + } else { + null + } + }} + + if (tag == ContextSpecificTag(TAG_IMAGE_URI)) {imageURI_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - } - } - - if (tag == ContextSpecificTag(TAG_SOFTWARE_VERSION)) { - softwareVersion_decoded = + tlvReader.getString(tag) + } else { + null + } + }} + + if (tag == ContextSpecificTag(TAG_SOFTWARE_VERSION)) {softwareVersion_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getUInt(tag) - } else { - null - } - } - } - - if (tag == ContextSpecificTag(TAG_SOFTWARE_VERSION_STRING)) { - softwareVersionString_decoded = + tlvReader.getUInt(tag) + } else { + null + } + }} + + if (tag == ContextSpecificTag(TAG_SOFTWARE_VERSION_STRING)) {softwareVersionString_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - } - } - - if (tag == ContextSpecificTag(TAG_UPDATE_TOKEN)) { - updateToken_decoded = + tlvReader.getString(tag) + } else { + null + } + }} + + if (tag == ContextSpecificTag(TAG_UPDATE_TOKEN)) {updateToken_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getByteArray(tag) - } else { - null - } - } - } - - if (tag == ContextSpecificTag(TAG_USER_CONSENT_NEEDED)) { - userConsentNeeded_decoded = + tlvReader.getByteArray(tag) + } else { + null + } + }} + + if (tag == ContextSpecificTag(TAG_USER_CONSENT_NEEDED)) {userConsentNeeded_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getBoolean(tag) - } else { - null - } - } - } - - if (tag == ContextSpecificTag(TAG_METADATA_FOR_REQUESTOR)) { - metadataForRequestor_decoded = + tlvReader.getBoolean(tag) + } else { + null + } + }} + + if (tag == ContextSpecificTag(TAG_METADATA_FOR_REQUESTOR)) {metadataForRequestor_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getByteArray(tag) - } else { - null - } - } - } else { + tlvReader.getByteArray(tag) + } else { + null + } + }} + + + else { tlvReader.skipElement() } } + + if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } + + + + + + + + + + + + + + + tlvReader.exitContainer() @@ -305,15 +343,13 @@ class OtaSoftwareUpdateProviderCluster( softwareVersionString_decoded, updateToken_decoded, userConsentNeeded_decoded, - metadataForRequestor_decoded, + metadataForRequestor_decoded ) } - suspend fun applyUpdateRequest( - updateToken: ByteArray, - newVersion: UInt, - timedInvokeTimeout: Duration? = null, - ): ApplyUpdateResponse { + suspend fun applyUpdateRequest(updateToken: ByteArray + ,newVersion: UInt + ,timedInvokeTimeout: Duration? = null): ApplyUpdateResponse { val commandId: UInt = 2u val tlvWriter = TlvWriter() @@ -323,14 +359,14 @@ class OtaSoftwareUpdateProviderCluster( tlvWriter.put(ContextSpecificTag(TAG_UPDATE_TOKEN_REQ), updateToken) val TAG_NEW_VERSION_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_NEW_VERSION_REQ), newVersion) + tlvWriter.put(ContextSpecificTag(TAG_NEW_VERSION_REQ), newVersion) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -340,42 +376,48 @@ class OtaSoftwareUpdateProviderCluster( tlvReader.enterStructure(AnonymousTag) val TAG_ACTION: Int = 0 var action_decoded: UByte? = null - + val TAG_DELAYED_ACTION_TIME: Int = 1 var delayedActionTime_decoded: UInt? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_ACTION)) { - action_decoded = tlvReader.getUByte(tag) - } + + if (tag == ContextSpecificTag(TAG_ACTION)) {action_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_DELAYED_ACTION_TIME)) {delayedActionTime_decoded = tlvReader.getUInt(tag)} + - if (tag == ContextSpecificTag(TAG_DELAYED_ACTION_TIME)) { - delayedActionTime_decoded = tlvReader.getUInt(tag) - } else { + else { tlvReader.skipElement() } } + + if (action_decoded == null) { - throw IllegalStateException("action not found in TLV") + throw IllegalStateException("action not found in TLV") } - + + if (delayedActionTime_decoded == null) { - throw IllegalStateException("delayedActionTime not found in TLV") + throw IllegalStateException("delayedActionTime not found in TLV") } + tlvReader.exitContainer() - return ApplyUpdateResponse(action_decoded, delayedActionTime_decoded) + return ApplyUpdateResponse( + action_decoded, + delayedActionTime_decoded + ) } - suspend fun notifyUpdateApplied( - updateToken: ByteArray, - softwareVersion: UInt, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun notifyUpdateApplied(updateToken: ByteArray + ,softwareVersion: UInt + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 4u val tlvWriter = TlvWriter() @@ -385,107 +427,108 @@ class OtaSoftwareUpdateProviderCluster( tlvWriter.put(ContextSpecificTag(TAG_UPDATE_TOKEN_REQ), updateToken) val TAG_SOFTWARE_VERSION_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_SOFTWARE_VERSION_REQ), softwareVersion) + tlvWriter.put(ContextSpecificTag(TAG_SOFTWARE_VERSION_REQ), softwareVersion) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } +suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65528u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -493,96 +536,97 @@ class OtaSoftwareUpdateProviderCluster( emit(GeneratedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65529u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -590,94 +634,97 @@ class OtaSoftwareUpdateProviderCluster( emit(AcceptedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt = 65530u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -685,94 +732,97 @@ class OtaSoftwareUpdateProviderCluster( emit(EventListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ID: UInt = 65531u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -780,76 +830,81 @@ class OtaSoftwareUpdateProviderCluster( emit(AttributeListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u - 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 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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -861,77 +916,80 @@ class OtaSoftwareUpdateProviderCluster( emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 65533u - 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 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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -944,7 +1002,7 @@ class OtaSoftwareUpdateProviderCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/OtaSoftwareUpdateRequestorCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/OtaSoftwareUpdateRequestorCluster.kt index 21ca7bd092ed56..cff6f3e8817cd9 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/OtaSoftwareUpdateRequestorCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/OtaSoftwareUpdateRequestorCluster.kt @@ -17,108 +17,133 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration 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.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.cluster.structs.* +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class OtaSoftwareUpdateRequestorCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class DefaultOTAProvidersAttribute( +class OtaSoftwareUpdateRequestorCluster(private val controller: MatterController, private val endpointId: UShort) {class DefaultOTAProvidersAttribute( val value: List ) sealed class DefaultOTAProvidersAttributeSubscriptionState { - data class Success(val value: List) : - DefaultOTAProvidersAttributeSubscriptionState() - + data class Success( + val value: List + ) : DefaultOTAProvidersAttributeSubscriptionState() + data class Error(val exception: Exception) : DefaultOTAProvidersAttributeSubscriptionState() - object SubscriptionEstablished : DefaultOTAProvidersAttributeSubscriptionState() - } - - class UpdateStateProgressAttribute(val value: UByte?) + object SubscriptionEstablished : DefaultOTAProvidersAttributeSubscriptionState() + } +class UpdateStateProgressAttribute( + val value: UByte? + ) sealed class UpdateStateProgressAttributeSubscriptionState { - data class Success(val value: UByte?) : UpdateStateProgressAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : UpdateStateProgressAttributeSubscriptionState() + data class Error(val exception: Exception) : UpdateStateProgressAttributeSubscriptionState() - object SubscriptionEstablished : UpdateStateProgressAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : UpdateStateProgressAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun announceOTAProvider( - providerNodeID: ULong, - vendorID: UShort, - announcementReason: UByte, - metadataForNode: ByteArray?, - endpoint: UShort, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun announceOTAProvider(providerNodeID: ULong + ,vendorID: UShort + ,announcementReason: UByte + ,metadataForNode: ByteArray? + ,endpoint: UShort + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() @@ -139,82 +164,89 @@ class OtaSoftwareUpdateRequestorCluster( } val TAG_ENDPOINT_REQ: Int = 4 - tlvWriter.put(ContextSpecificTag(TAG_ENDPOINT_REQ), endpoint) + tlvWriter.put(ContextSpecificTag(TAG_ENDPOINT_REQ), endpoint) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - - suspend fun readDefaultOTAProvidersAttribute(): DefaultOTAProvidersAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readDefaultOTAProvidersAttribute(): DefaultOTAProvidersAttribute {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}") - } + 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) { "Defaultotaproviders attribute not found in response" } + } + + requireNotNull(attributeData) { + "Defaultotaproviders 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(OtaSoftwareUpdateRequestorClusterProviderLocation.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(OtaSoftwareUpdateRequestorClusterProviderLocation.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + return DefaultOTAProvidersAttribute(decodedValue) } suspend fun writeDefaultOTAProvidersAttribute( value: List, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startArray(AnonymousTag) - for (item in value.iterator()) { - item.toTlv(AnonymousTag, tlvWriter) - } - tlvWriter.endArray() + for (item in value.iterator()) { + item.toTlv(AnonymousTag, tlvWriter) + } + tlvWriter.endArray() val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -235,60 +267,53 @@ class OtaSoftwareUpdateRequestorCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeDefaultOTAProvidersAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - DefaultOTAProvidersAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(DefaultOTAProvidersAttributeSubscriptionState.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) { - "Defaultotaproviders attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Defaultotaproviders 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( - OtaSoftwareUpdateRequestorClusterProviderLocation.fromTlv(AnonymousTag, tlvReader) - ) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(OtaSoftwareUpdateRequestorClusterProviderLocation.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(DefaultOTAProvidersAttributeSubscriptionState.Success(decodedValue)) } @@ -296,77 +321,80 @@ class OtaSoftwareUpdateRequestorCluster( emit(DefaultOTAProvidersAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readUpdatePossibleAttribute(): Boolean { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readUpdatePossibleAttribute(): Boolean {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}") - } + 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) { "Updatepossible attribute not found in response" } + } + + requireNotNull(attributeData) { + "Updatepossible attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Boolean = tlvReader.getBoolean(AnonymousTag) + return decodedValue } suspend fun subscribeUpdatePossibleAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Updatepossible attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Updatepossible attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -379,76 +407,81 @@ class OtaSoftwareUpdateRequestorCluster( emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readUpdateStateAttribute(): UByte { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readUpdateStateAttribute(): UByte {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}") - } + 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) { "Updatestate attribute not found in response" } + } + + requireNotNull(attributeData) { + "Updatestate 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 subscribeUpdateStateAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Updatestate attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Updatestate attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -460,191 +493,196 @@ class OtaSoftwareUpdateRequestorCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readUpdateStateProgressAttribute(): UpdateStateProgressAttribute { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readUpdateStateProgressAttribute(): UpdateStateProgressAttribute {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}") - } + 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) { "Updatestateprogress attribute not found in response" } + } + + requireNotNull(attributeData) { + "Updatestateprogress attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return UpdateStateProgressAttribute(decodedValue) } suspend fun subscribeUpdateStateProgressAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - UpdateStateProgressAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(UpdateStateProgressAttributeSubscriptionState.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) { - "Updatestateprogress attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Updatestateprogress 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.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(UpdateStateProgressAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(UpdateStateProgressAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UpdateStateProgressAttributeSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -652,96 +690,97 @@ class OtaSoftwareUpdateRequestorCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -749,94 +788,97 @@ class OtaSoftwareUpdateRequestorCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -844,94 +886,97 @@ class OtaSoftwareUpdateRequestorCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -939,76 +984,81 @@ class OtaSoftwareUpdateRequestorCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1020,77 +1070,80 @@ class OtaSoftwareUpdateRequestorCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1103,7 +1156,7 @@ class OtaSoftwareUpdateRequestorCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/OvenCavityOperationalStateCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/OvenCavityOperationalStateCluster.kt index 545b2c620a0237..4ca4bd4f9307c1 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/OvenCavityOperationalStateCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/OvenCavityOperationalStateCluster.kt @@ -17,143 +17,182 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class OvenCavityOperationalStateCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { +class OvenCavityOperationalStateCluster(private val controller: MatterController, private val endpointId: UShort) { class OperationalCommandResponse( val commandResponseState: OvenCavityOperationalStateClusterErrorStateStruct ) - - class PhaseListAttribute(val value: List?) +class PhaseListAttribute( + val value: List? + ) sealed class PhaseListAttributeSubscriptionState { - data class Success(val value: List?) : PhaseListAttributeSubscriptionState() - + data class Success( + val value: List? + ) : PhaseListAttributeSubscriptionState() + data class Error(val exception: Exception) : PhaseListAttributeSubscriptionState() - object SubscriptionEstablished : PhaseListAttributeSubscriptionState() - } - - class CurrentPhaseAttribute(val value: UByte?) + object SubscriptionEstablished : PhaseListAttributeSubscriptionState() + } +class CurrentPhaseAttribute( + val value: UByte? + ) sealed class CurrentPhaseAttributeSubscriptionState { - data class Success(val value: UByte?) : CurrentPhaseAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : CurrentPhaseAttributeSubscriptionState() + data class Error(val exception: Exception) : CurrentPhaseAttributeSubscriptionState() - object SubscriptionEstablished : CurrentPhaseAttributeSubscriptionState() - } - - class CountdownTimeAttribute(val value: UInt?) + object SubscriptionEstablished : CurrentPhaseAttributeSubscriptionState() + } +class CountdownTimeAttribute( + val value: UInt? + ) sealed class CountdownTimeAttributeSubscriptionState { - data class Success(val value: UInt?) : CountdownTimeAttributeSubscriptionState() - + data class Success( + val value: UInt? + ) : CountdownTimeAttributeSubscriptionState() + data class Error(val exception: Exception) : CountdownTimeAttributeSubscriptionState() - object SubscriptionEstablished : CountdownTimeAttributeSubscriptionState() - } - - class OperationalStateListAttribute( + object SubscriptionEstablished : CountdownTimeAttributeSubscriptionState() + } +class OperationalStateListAttribute( val value: List ) sealed class OperationalStateListAttributeSubscriptionState { - data class Success(val value: List) : - OperationalStateListAttributeSubscriptionState() - + data class Success( + val value: List + ) : OperationalStateListAttributeSubscriptionState() + data class Error(val exception: Exception) : OperationalStateListAttributeSubscriptionState() - object SubscriptionEstablished : OperationalStateListAttributeSubscriptionState() - } - - class OperationalErrorAttribute(val value: OvenCavityOperationalStateClusterErrorStateStruct) + object SubscriptionEstablished : OperationalStateListAttributeSubscriptionState() + } +class OperationalErrorAttribute( + val value: OvenCavityOperationalStateClusterErrorStateStruct + ) sealed class OperationalErrorAttributeSubscriptionState { - data class Success(val value: OvenCavityOperationalStateClusterErrorStateStruct) : - OperationalErrorAttributeSubscriptionState() - + data class Success( + val value: OvenCavityOperationalStateClusterErrorStateStruct + ) : OperationalErrorAttributeSubscriptionState() + data class Error(val exception: Exception) : OperationalErrorAttributeSubscriptionState() - object SubscriptionEstablished : OperationalErrorAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : OperationalErrorAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } suspend fun pause(timedInvokeTimeout: Duration? = null): OperationalCommandResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -163,39 +202,46 @@ class OvenCavityOperationalStateCluster( tlvReader.enterStructure(AnonymousTag) val TAG_COMMAND_RESPONSE_STATE: Int = 0 var commandResponseState_decoded: OvenCavityOperationalStateClusterErrorStateStruct? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_COMMAND_RESPONSE_STATE)) { - commandResponseState_decoded = - OvenCavityOperationalStateClusterErrorStateStruct.fromTlv(tag, tlvReader) - } else { + + if (tag == ContextSpecificTag(TAG_COMMAND_RESPONSE_STATE)) {commandResponseState_decoded = OvenCavityOperationalStateClusterErrorStateStruct.fromTlv(tag, tlvReader)} + + + else { tlvReader.skipElement() } } + + if (commandResponseState_decoded == null) { - throw IllegalStateException("commandResponseState not found in TLV") + throw IllegalStateException("commandResponseState not found in TLV") } + tlvReader.exitContainer() - return OperationalCommandResponse(commandResponseState_decoded) + return OperationalCommandResponse( + commandResponseState_decoded + ) } suspend fun stop(timedInvokeTimeout: Duration? = null): OperationalCommandResponse { val commandId: UInt = 1u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -205,39 +251,46 @@ class OvenCavityOperationalStateCluster( tlvReader.enterStructure(AnonymousTag) val TAG_COMMAND_RESPONSE_STATE: Int = 0 var commandResponseState_decoded: OvenCavityOperationalStateClusterErrorStateStruct? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_COMMAND_RESPONSE_STATE)) { - commandResponseState_decoded = - OvenCavityOperationalStateClusterErrorStateStruct.fromTlv(tag, tlvReader) - } else { + + if (tag == ContextSpecificTag(TAG_COMMAND_RESPONSE_STATE)) {commandResponseState_decoded = OvenCavityOperationalStateClusterErrorStateStruct.fromTlv(tag, tlvReader)} + + + else { tlvReader.skipElement() } } + + if (commandResponseState_decoded == null) { - throw IllegalStateException("commandResponseState not found in TLV") + throw IllegalStateException("commandResponseState not found in TLV") } + tlvReader.exitContainer() - return OperationalCommandResponse(commandResponseState_decoded) + return OperationalCommandResponse( + commandResponseState_decoded + ) } suspend fun start(timedInvokeTimeout: Duration? = null): OperationalCommandResponse { val commandId: UInt = 2u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -247,39 +300,46 @@ class OvenCavityOperationalStateCluster( tlvReader.enterStructure(AnonymousTag) val TAG_COMMAND_RESPONSE_STATE: Int = 0 var commandResponseState_decoded: OvenCavityOperationalStateClusterErrorStateStruct? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_COMMAND_RESPONSE_STATE)) { - commandResponseState_decoded = - OvenCavityOperationalStateClusterErrorStateStruct.fromTlv(tag, tlvReader) - } else { + + if (tag == ContextSpecificTag(TAG_COMMAND_RESPONSE_STATE)) {commandResponseState_decoded = OvenCavityOperationalStateClusterErrorStateStruct.fromTlv(tag, tlvReader)} + + + else { tlvReader.skipElement() } } + + if (commandResponseState_decoded == null) { - throw IllegalStateException("commandResponseState not found in TLV") + throw IllegalStateException("commandResponseState not found in TLV") } + tlvReader.exitContainer() - return OperationalCommandResponse(commandResponseState_decoded) + return OperationalCommandResponse( + commandResponseState_decoded + ) } suspend fun resume(timedInvokeTimeout: Duration? = null): OperationalCommandResponse { val commandId: UInt = 3u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -289,420 +349,439 @@ class OvenCavityOperationalStateCluster( tlvReader.enterStructure(AnonymousTag) val TAG_COMMAND_RESPONSE_STATE: Int = 0 var commandResponseState_decoded: OvenCavityOperationalStateClusterErrorStateStruct? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_COMMAND_RESPONSE_STATE)) { - commandResponseState_decoded = - OvenCavityOperationalStateClusterErrorStateStruct.fromTlv(tag, tlvReader) - } else { + + if (tag == ContextSpecificTag(TAG_COMMAND_RESPONSE_STATE)) {commandResponseState_decoded = OvenCavityOperationalStateClusterErrorStateStruct.fromTlv(tag, tlvReader)} + + + else { tlvReader.skipElement() } } + + if (commandResponseState_decoded == null) { - throw IllegalStateException("commandResponseState not found in TLV") + throw IllegalStateException("commandResponseState not found in TLV") } + tlvReader.exitContainer() - return OperationalCommandResponse(commandResponseState_decoded) + return OperationalCommandResponse( + commandResponseState_decoded + ) } - - suspend fun readPhaseListAttribute(): PhaseListAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readPhaseListAttribute(): PhaseListAttribute {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}") - } + 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) { "Phaselist attribute not found in response" } + } + + requireNotNull(attributeData) { + "Phaselist attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (!tlvReader.isNull()) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getString(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - tlvReader.getNull(AnonymousTag) - null + val decodedValue: List? = if (!tlvReader.isNull()) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getString(AnonymousTag)) } + tlvReader.exitContainer() + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return PhaseListAttribute(decodedValue) } suspend fun subscribePhaseListAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - PhaseListAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(PhaseListAttributeSubscriptionState.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) { "Phaselist attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Phaselist attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (!tlvReader.isNull()) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getString(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(PhaseListAttributeSubscriptionState.Success(it)) } + val decodedValue: List? = if (!tlvReader.isNull()) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getString(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(PhaseListAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(PhaseListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readCurrentPhaseAttribute(): CurrentPhaseAttribute { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readCurrentPhaseAttribute(): CurrentPhaseAttribute {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}") - } + 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) { "Currentphase attribute not found in response" } + } + + requireNotNull(attributeData) { + "Currentphase attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return CurrentPhaseAttribute(decodedValue) } suspend fun subscribeCurrentPhaseAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - CurrentPhaseAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(CurrentPhaseAttributeSubscriptionState.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) { "Currentphase attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Currentphase 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.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(CurrentPhaseAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(CurrentPhaseAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(CurrentPhaseAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readCountdownTimeAttribute(): CountdownTimeAttribute { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readCountdownTimeAttribute(): CountdownTimeAttribute {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}") - } + 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) { "Countdowntime attribute not found in response" } + } + + requireNotNull(attributeData) { + "Countdowntime attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return CountdownTimeAttribute(decodedValue) } suspend fun subscribeCountdownTimeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - CountdownTimeAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(CountdownTimeAttributeSubscriptionState.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) { "Countdowntime attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Countdowntime attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(CountdownTimeAttributeSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(CountdownTimeAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(CountdownTimeAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readOperationalStateListAttribute(): OperationalStateListAttribute { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readOperationalStateListAttribute(): OperationalStateListAttribute {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}") - } + 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) { "Operationalstatelist attribute not found in response" } + } + + requireNotNull(attributeData) { + "Operationalstatelist 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( - OvenCavityOperationalStateClusterOperationalStateStruct.fromTlv(AnonymousTag, tlvReader) - ) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(OvenCavityOperationalStateClusterOperationalStateStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + return OperationalStateListAttribute(decodedValue) } suspend fun subscribeOperationalStateListAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - OperationalStateListAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(OperationalStateListAttributeSubscriptionState.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) { - "Operationalstatelist attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Operationalstatelist 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( - OvenCavityOperationalStateClusterOperationalStateStruct.fromTlv( - AnonymousTag, - tlvReader, - ) - ) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(OvenCavityOperationalStateClusterOperationalStateStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(OperationalStateListAttributeSubscriptionState.Success(decodedValue)) } @@ -710,77 +789,80 @@ class OvenCavityOperationalStateCluster( emit(OperationalStateListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readOperationalStateAttribute(): 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)) - +suspend fun readOperationalStateAttribute(): 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}") - } + 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) { "Operationalstate attribute not found in response" } + } + + requireNotNull(attributeData) { + "Operationalstate 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 subscribeOperationalStateAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Operationalstate attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Operationalstate attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -793,84 +875,85 @@ class OvenCavityOperationalStateCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readOperationalErrorAttribute(): OperationalErrorAttribute { - val ATTRIBUTE_ID: UInt = 5u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readOperationalErrorAttribute(): OperationalErrorAttribute {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}") - } + 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) { "Operationalerror attribute not found in response" } + } + + requireNotNull(attributeData) { + "Operationalerror attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: OvenCavityOperationalStateClusterErrorStateStruct = - OvenCavityOperationalStateClusterErrorStateStruct.fromTlv(AnonymousTag, tlvReader) + val decodedValue: OvenCavityOperationalStateClusterErrorStateStruct = OvenCavityOperationalStateClusterErrorStateStruct.fromTlv(AnonymousTag, tlvReader) + return OperationalErrorAttribute(decodedValue) } suspend fun subscribeOperationalErrorAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - OperationalErrorAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(OperationalErrorAttributeSubscriptionState.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) { - "Operationalerror attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Operationalerror attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: OvenCavityOperationalStateClusterErrorStateStruct = - OvenCavityOperationalStateClusterErrorStateStruct.fromTlv(AnonymousTag, tlvReader) + val decodedValue: OvenCavityOperationalStateClusterErrorStateStruct = OvenCavityOperationalStateClusterErrorStateStruct.fromTlv(AnonymousTag, tlvReader) emit(OperationalErrorAttributeSubscriptionState.Success(decodedValue)) } @@ -878,96 +961,97 @@ class OvenCavityOperationalStateCluster( emit(OperationalErrorAttributeSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -975,96 +1059,97 @@ class OvenCavityOperationalStateCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1072,94 +1157,97 @@ class OvenCavityOperationalStateCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1167,94 +1255,97 @@ class OvenCavityOperationalStateCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1262,76 +1353,81 @@ class OvenCavityOperationalStateCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1343,77 +1439,80 @@ class OvenCavityOperationalStateCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1426,7 +1525,7 @@ class OvenCavityOperationalStateCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/OvenModeCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/OvenModeCluster.kt index 3bf17486833050..072808ed1b0f75 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/OvenModeCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/OvenModeCluster.kt @@ -17,124 +17,161 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.cluster.structs.* +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter class OvenModeCluster(private val controller: MatterController, private val endpointId: UShort) { - class ChangeToModeResponse(val status: UByte, val statusText: String?) - - class SupportedModesAttribute(val value: List) + class ChangeToModeResponse( + val status: UByte, + val statusText: String? + ) +class SupportedModesAttribute( + val value: List + ) sealed class SupportedModesAttributeSubscriptionState { - data class Success(val value: List) : - SupportedModesAttributeSubscriptionState() - + data class Success( + val value: List + ) : SupportedModesAttributeSubscriptionState() + data class Error(val exception: Exception) : SupportedModesAttributeSubscriptionState() - object SubscriptionEstablished : SupportedModesAttributeSubscriptionState() - } - - class StartUpModeAttribute(val value: UByte?) + object SubscriptionEstablished : SupportedModesAttributeSubscriptionState() + } +class StartUpModeAttribute( + val value: UByte? + ) sealed class StartUpModeAttributeSubscriptionState { - data class Success(val value: UByte?) : StartUpModeAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : StartUpModeAttributeSubscriptionState() + data class Error(val exception: Exception) : StartUpModeAttributeSubscriptionState() - object SubscriptionEstablished : StartUpModeAttributeSubscriptionState() - } - - class OnModeAttribute(val value: UByte?) + object SubscriptionEstablished : StartUpModeAttributeSubscriptionState() + } +class OnModeAttribute( + val value: UByte? + ) sealed class OnModeAttributeSubscriptionState { - data class Success(val value: UByte?) : OnModeAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : OnModeAttributeSubscriptionState() + data class Error(val exception: Exception) : OnModeAttributeSubscriptionState() - object SubscriptionEstablished : OnModeAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : OnModeAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun changeToMode( - newMode: UByte, - timedInvokeTimeout: Duration? = null, - ): ChangeToModeResponse { + suspend fun changeToMode(newMode: UByte + ,timedInvokeTimeout: Duration? = null): ChangeToModeResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_NEW_MODE_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_NEW_MODE_REQ), newMode) + tlvWriter.put(ContextSpecificTag(TAG_NEW_MODE_REQ), newMode) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -144,130 +181,140 @@ class OvenModeCluster(private val controller: MatterController, private val endp tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_STATUS_TEXT: Int = 1 var statusText_decoded: String? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_STATUS)) { - status_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_STATUS_TEXT)) { - statusText_decoded = + + if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_STATUS_TEXT)) {statusText_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - } - } else { + tlvReader.getString(tag) + } else { + null + } + }} + + + else { tlvReader.skipElement() } } + + if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } + + + tlvReader.exitContainer() - return ChangeToModeResponse(status_decoded, statusText_decoded) + return ChangeToModeResponse( + status_decoded, + statusText_decoded + ) } - - suspend fun readSupportedModesAttribute(): SupportedModesAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readSupportedModesAttribute(): SupportedModesAttribute {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}") - } + 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) { "Supportedmodes attribute not found in response" } + } + + requireNotNull(attributeData) { + "Supportedmodes 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(OvenModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(OvenModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + return SupportedModesAttribute(decodedValue) } suspend fun subscribeSupportedModesAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - SupportedModesAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(SupportedModesAttributeSubscriptionState.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) { - "Supportedmodes attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Supportedmodes 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(OvenModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(OvenModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(SupportedModesAttributeSubscriptionState.Success(decodedValue)) } @@ -275,76 +322,81 @@ class OvenModeCluster(private val controller: MatterController, private val endp emit(SupportedModesAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readCurrentModeAttribute(): 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)) - +suspend fun readCurrentModeAttribute(): 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}") - } + 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) { "Currentmode attribute not found in response" } + } + + requireNotNull(attributeData) { + "Currentmode 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 subscribeCurrentModeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Currentmode attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Currentmode attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -356,67 +408,77 @@ class OvenModeCluster(private val controller: MatterController, private val endp emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readStartUpModeAttribute(): StartUpModeAttribute { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readStartUpModeAttribute(): StartUpModeAttribute {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}") - } + 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) { "Startupmode attribute not found in response" } + } + + requireNotNull(attributeData) { + "Startupmode attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return StartUpModeAttribute(decodedValue) } - suspend fun writeStartUpModeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeStartUpModeAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 2u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -437,127 +499,137 @@ class OvenModeCluster(private val controller: MatterController, private val endp throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeStartUpModeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StartUpModeAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StartUpModeAttributeSubscriptionState.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) { "Startupmode attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Startupmode 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(StartUpModeAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(StartUpModeAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(StartUpModeAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readOnModeAttribute(): OnModeAttribute { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readOnModeAttribute(): OnModeAttribute {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}") - } + 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) { "Onmode attribute not found in response" } + } + + requireNotNull(attributeData) { + "Onmode attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return OnModeAttribute(decodedValue) } - suspend fun writeOnModeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeOnModeAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 3u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -578,156 +650,157 @@ class OvenModeCluster(private val controller: MatterController, private val endp throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeOnModeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - OnModeAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(OnModeAttributeSubscriptionState.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) { "Onmode attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Onmode 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(OnModeAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(OnModeAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(OnModeAttributeSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -735,96 +808,97 @@ class OvenModeCluster(private val controller: MatterController, private val endp 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -832,94 +906,97 @@ class OvenModeCluster(private val controller: MatterController, private val endp 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -927,94 +1004,97 @@ class OvenModeCluster(private val controller: MatterController, private val endp 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1022,76 +1102,81 @@ class OvenModeCluster(private val controller: MatterController, private val endp 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1103,77 +1188,80 @@ class OvenModeCluster(private val controller: MatterController, private val endp 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1186,7 +1274,7 @@ class OvenModeCluster(private val controller: MatterController, private val endp emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/OzoneConcentrationMeasurementCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/OzoneConcentrationMeasurementCluster.kt index a8285931c68e63..427cf896b35373 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/OzoneConcentrationMeasurementCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/OzoneConcentrationMeasurementCluster.kt @@ -17,1273 +17,1371 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.FloatSubscriptionState import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath +import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader +import matter.tlv.TlvWriter -class OzoneConcentrationMeasurementCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class MeasuredValueAttribute(val value: Float?) +class OzoneConcentrationMeasurementCluster(private val controller: MatterController, private val endpointId: UShort) {class MeasuredValueAttribute( + val value: Float? + ) sealed class MeasuredValueAttributeSubscriptionState { - data class Success(val value: Float?) : MeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Float? + ) : MeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() - } - - class MinMeasuredValueAttribute(val value: Float?) + object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() + } +class MinMeasuredValueAttribute( + val value: Float? + ) sealed class MinMeasuredValueAttributeSubscriptionState { - data class Success(val value: Float?) : MinMeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Float? + ) : MinMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MinMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() - } - - class MaxMeasuredValueAttribute(val value: Float?) + object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() + } +class MaxMeasuredValueAttribute( + val value: Float? + ) sealed class MaxMeasuredValueAttributeSubscriptionState { - data class Success(val value: Float?) : MaxMeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Float? + ) : MaxMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MaxMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() - } - - class PeakMeasuredValueAttribute(val value: Float?) + object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() + } +class PeakMeasuredValueAttribute( + val value: Float? + ) sealed class PeakMeasuredValueAttributeSubscriptionState { - data class Success(val value: Float?) : PeakMeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Float? + ) : PeakMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : PeakMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : PeakMeasuredValueAttributeSubscriptionState() - } - - class AverageMeasuredValueAttribute(val value: Float?) + object SubscriptionEstablished : PeakMeasuredValueAttributeSubscriptionState() + } +class AverageMeasuredValueAttribute( + val value: Float? + ) sealed class AverageMeasuredValueAttributeSubscriptionState { - data class Success(val value: Float?) : AverageMeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Float? + ) : AverageMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : AverageMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : AverageMeasuredValueAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : AverageMeasuredValueAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } - - suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } +suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute {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}") - } + 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) { "Measuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Measuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MeasuredValueAttribute(decodedValue) } suspend fun subscribeMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MeasuredValueAttributeSubscriptionState.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) { "Measuredvalue attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Measuredvalue attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute {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}") - } + 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) { "Minmeasuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Minmeasuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MinMeasuredValueAttribute(decodedValue) } suspend fun subscribeMinMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MinMeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MinMeasuredValueAttributeSubscriptionState.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) { - "Minmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Minmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MinMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute {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}") - } + 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) { "Maxmeasuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Maxmeasuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MaxMeasuredValueAttribute(decodedValue) } suspend fun subscribeMaxMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MaxMeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MaxMeasuredValueAttributeSubscriptionState.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) { - "Maxmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Maxmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MaxMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readPeakMeasuredValueAttribute(): PeakMeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readPeakMeasuredValueAttribute(): PeakMeasuredValueAttribute {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}") - } + 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) { "Peakmeasuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Peakmeasuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return PeakMeasuredValueAttribute(decodedValue) } suspend fun subscribePeakMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - PeakMeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(PeakMeasuredValueAttributeSubscriptionState.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) { - "Peakmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Peakmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(PeakMeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(PeakMeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(PeakMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readPeakMeasuredValueWindowAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 4u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readPeakMeasuredValueWindowAttribute(): UInt? {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}") - } + 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) { "Peakmeasuredvaluewindow attribute not found in response" } + } + + requireNotNull(attributeData) { + "Peakmeasuredvaluewindow attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribePeakMeasuredValueWindowAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Peakmeasuredvaluewindow attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Peakmeasuredvaluewindow attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readAverageMeasuredValueAttribute(): AverageMeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 5u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readAverageMeasuredValueAttribute(): AverageMeasuredValueAttribute {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}") - } + 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) { "Averagemeasuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Averagemeasuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return AverageMeasuredValueAttribute(decodedValue) } suspend fun subscribeAverageMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - AverageMeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(AverageMeasuredValueAttributeSubscriptionState.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) { - "Averagemeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Averagemeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(AverageMeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(AverageMeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(AverageMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readAverageMeasuredValueWindowAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 6u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readAverageMeasuredValueWindowAttribute(): UInt? {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}") - } + 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) { "Averagemeasuredvaluewindow attribute not found in response" } + } + + requireNotNull(attributeData) { + "Averagemeasuredvaluewindow attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeAverageMeasuredValueWindowAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Averagemeasuredvaluewindow attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Averagemeasuredvaluewindow attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readUncertaintyAttribute(): Float? { - val ATTRIBUTE_ID: UInt = 7u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readUncertaintyAttribute(): Float? {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}") - } + 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) { "Uncertainty attribute not found in response" } + } + + requireNotNull(attributeData) { + "Uncertainty attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } + val decodedValue: Float? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeUncertaintyAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - FloatSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(FloatSubscriptionState.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) { "Uncertainty attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Uncertainty attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(FloatSubscriptionState.Success(it)) } + val decodedValue: Float? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(FloatSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(FloatSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readMeasurementUnitAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 8u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMeasurementUnitAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 8u + + 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}") - } + 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) { "Measurementunit attribute not found in response" } + } + + requireNotNull(attributeData) { + "Measurementunit 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeMeasurementUnitAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Measurementunit attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Measurementunit 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)) } + 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 readMeasurementMediumAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 9u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMeasurementMediumAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 9u + + 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}") - } + 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) { "Measurementmedium attribute not found in response" } + } + + requireNotNull(attributeData) { + "Measurementmedium 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeMeasurementMediumAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Measurementmedium attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Measurementmedium 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)) } + 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 readLevelValueAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 10u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readLevelValueAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 10u + + 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}") - } + 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) { "Levelvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Levelvalue 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeLevelValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Levelvalue attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Levelvalue 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)) } + 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 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1291,96 +1389,97 @@ class OzoneConcentrationMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1388,94 +1487,97 @@ class OzoneConcentrationMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1483,94 +1585,97 @@ class OzoneConcentrationMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1578,76 +1683,81 @@ class OzoneConcentrationMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1659,77 +1769,80 @@ class OzoneConcentrationMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1742,7 +1855,7 @@ class OzoneConcentrationMeasurementCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/Pm10ConcentrationMeasurementCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/Pm10ConcentrationMeasurementCluster.kt index e77f7bab254198..0105d1d2a3b075 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/Pm10ConcentrationMeasurementCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/Pm10ConcentrationMeasurementCluster.kt @@ -17,1273 +17,1371 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.FloatSubscriptionState import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath +import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader +import matter.tlv.TlvWriter -class Pm10ConcentrationMeasurementCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class MeasuredValueAttribute(val value: Float?) +class Pm10ConcentrationMeasurementCluster(private val controller: MatterController, private val endpointId: UShort) {class MeasuredValueAttribute( + val value: Float? + ) sealed class MeasuredValueAttributeSubscriptionState { - data class Success(val value: Float?) : MeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Float? + ) : MeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() - } - - class MinMeasuredValueAttribute(val value: Float?) + object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() + } +class MinMeasuredValueAttribute( + val value: Float? + ) sealed class MinMeasuredValueAttributeSubscriptionState { - data class Success(val value: Float?) : MinMeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Float? + ) : MinMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MinMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() - } - - class MaxMeasuredValueAttribute(val value: Float?) + object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() + } +class MaxMeasuredValueAttribute( + val value: Float? + ) sealed class MaxMeasuredValueAttributeSubscriptionState { - data class Success(val value: Float?) : MaxMeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Float? + ) : MaxMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MaxMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() - } - - class PeakMeasuredValueAttribute(val value: Float?) + object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() + } +class PeakMeasuredValueAttribute( + val value: Float? + ) sealed class PeakMeasuredValueAttributeSubscriptionState { - data class Success(val value: Float?) : PeakMeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Float? + ) : PeakMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : PeakMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : PeakMeasuredValueAttributeSubscriptionState() - } - - class AverageMeasuredValueAttribute(val value: Float?) + object SubscriptionEstablished : PeakMeasuredValueAttributeSubscriptionState() + } +class AverageMeasuredValueAttribute( + val value: Float? + ) sealed class AverageMeasuredValueAttributeSubscriptionState { - data class Success(val value: Float?) : AverageMeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Float? + ) : AverageMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : AverageMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : AverageMeasuredValueAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : AverageMeasuredValueAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } - - suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } +suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute {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}") - } + 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) { "Measuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Measuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MeasuredValueAttribute(decodedValue) } suspend fun subscribeMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MeasuredValueAttributeSubscriptionState.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) { "Measuredvalue attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Measuredvalue attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute {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}") - } + 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) { "Minmeasuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Minmeasuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MinMeasuredValueAttribute(decodedValue) } suspend fun subscribeMinMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MinMeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MinMeasuredValueAttributeSubscriptionState.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) { - "Minmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Minmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MinMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute {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}") - } + 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) { "Maxmeasuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Maxmeasuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MaxMeasuredValueAttribute(decodedValue) } suspend fun subscribeMaxMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MaxMeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MaxMeasuredValueAttributeSubscriptionState.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) { - "Maxmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Maxmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MaxMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readPeakMeasuredValueAttribute(): PeakMeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readPeakMeasuredValueAttribute(): PeakMeasuredValueAttribute {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}") - } + 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) { "Peakmeasuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Peakmeasuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return PeakMeasuredValueAttribute(decodedValue) } suspend fun subscribePeakMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - PeakMeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(PeakMeasuredValueAttributeSubscriptionState.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) { - "Peakmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Peakmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(PeakMeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(PeakMeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(PeakMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readPeakMeasuredValueWindowAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 4u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readPeakMeasuredValueWindowAttribute(): UInt? {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}") - } + 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) { "Peakmeasuredvaluewindow attribute not found in response" } + } + + requireNotNull(attributeData) { + "Peakmeasuredvaluewindow attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribePeakMeasuredValueWindowAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Peakmeasuredvaluewindow attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Peakmeasuredvaluewindow attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readAverageMeasuredValueAttribute(): AverageMeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 5u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readAverageMeasuredValueAttribute(): AverageMeasuredValueAttribute {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}") - } + 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) { "Averagemeasuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Averagemeasuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return AverageMeasuredValueAttribute(decodedValue) } suspend fun subscribeAverageMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - AverageMeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(AverageMeasuredValueAttributeSubscriptionState.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) { - "Averagemeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Averagemeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(AverageMeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(AverageMeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(AverageMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readAverageMeasuredValueWindowAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 6u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readAverageMeasuredValueWindowAttribute(): UInt? {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}") - } + 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) { "Averagemeasuredvaluewindow attribute not found in response" } + } + + requireNotNull(attributeData) { + "Averagemeasuredvaluewindow attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeAverageMeasuredValueWindowAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Averagemeasuredvaluewindow attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Averagemeasuredvaluewindow attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readUncertaintyAttribute(): Float? { - val ATTRIBUTE_ID: UInt = 7u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readUncertaintyAttribute(): Float? {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}") - } + 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) { "Uncertainty attribute not found in response" } + } + + requireNotNull(attributeData) { + "Uncertainty attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } + val decodedValue: Float? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeUncertaintyAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - FloatSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(FloatSubscriptionState.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) { "Uncertainty attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Uncertainty attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(FloatSubscriptionState.Success(it)) } + val decodedValue: Float? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(FloatSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(FloatSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readMeasurementUnitAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 8u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMeasurementUnitAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 8u + + 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}") - } + 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) { "Measurementunit attribute not found in response" } + } + + requireNotNull(attributeData) { + "Measurementunit 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeMeasurementUnitAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Measurementunit attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Measurementunit 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)) } + 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 readMeasurementMediumAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 9u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMeasurementMediumAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 9u + + 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}") - } + 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) { "Measurementmedium attribute not found in response" } + } + + requireNotNull(attributeData) { + "Measurementmedium 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeMeasurementMediumAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Measurementmedium attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Measurementmedium 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)) } + 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 readLevelValueAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 10u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readLevelValueAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 10u + + 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}") - } + 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) { "Levelvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Levelvalue 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeLevelValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Levelvalue attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Levelvalue 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)) } + 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 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1291,96 +1389,97 @@ class Pm10ConcentrationMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1388,94 +1487,97 @@ class Pm10ConcentrationMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1483,94 +1585,97 @@ class Pm10ConcentrationMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1578,76 +1683,81 @@ class Pm10ConcentrationMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1659,77 +1769,80 @@ class Pm10ConcentrationMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1742,7 +1855,7 @@ class Pm10ConcentrationMeasurementCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/Pm1ConcentrationMeasurementCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/Pm1ConcentrationMeasurementCluster.kt index 81986a50338d73..56a19df1bc928d 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/Pm1ConcentrationMeasurementCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/Pm1ConcentrationMeasurementCluster.kt @@ -17,1273 +17,1371 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.FloatSubscriptionState import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath +import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader +import matter.tlv.TlvWriter -class Pm1ConcentrationMeasurementCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class MeasuredValueAttribute(val value: Float?) +class Pm1ConcentrationMeasurementCluster(private val controller: MatterController, private val endpointId: UShort) {class MeasuredValueAttribute( + val value: Float? + ) sealed class MeasuredValueAttributeSubscriptionState { - data class Success(val value: Float?) : MeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Float? + ) : MeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() - } - - class MinMeasuredValueAttribute(val value: Float?) + object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() + } +class MinMeasuredValueAttribute( + val value: Float? + ) sealed class MinMeasuredValueAttributeSubscriptionState { - data class Success(val value: Float?) : MinMeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Float? + ) : MinMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MinMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() - } - - class MaxMeasuredValueAttribute(val value: Float?) + object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() + } +class MaxMeasuredValueAttribute( + val value: Float? + ) sealed class MaxMeasuredValueAttributeSubscriptionState { - data class Success(val value: Float?) : MaxMeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Float? + ) : MaxMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MaxMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() - } - - class PeakMeasuredValueAttribute(val value: Float?) + object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() + } +class PeakMeasuredValueAttribute( + val value: Float? + ) sealed class PeakMeasuredValueAttributeSubscriptionState { - data class Success(val value: Float?) : PeakMeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Float? + ) : PeakMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : PeakMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : PeakMeasuredValueAttributeSubscriptionState() - } - - class AverageMeasuredValueAttribute(val value: Float?) + object SubscriptionEstablished : PeakMeasuredValueAttributeSubscriptionState() + } +class AverageMeasuredValueAttribute( + val value: Float? + ) sealed class AverageMeasuredValueAttributeSubscriptionState { - data class Success(val value: Float?) : AverageMeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Float? + ) : AverageMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : AverageMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : AverageMeasuredValueAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : AverageMeasuredValueAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } - - suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } +suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute {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}") - } + 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) { "Measuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Measuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MeasuredValueAttribute(decodedValue) } suspend fun subscribeMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MeasuredValueAttributeSubscriptionState.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) { "Measuredvalue attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Measuredvalue attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute {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}") - } + 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) { "Minmeasuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Minmeasuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MinMeasuredValueAttribute(decodedValue) } suspend fun subscribeMinMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MinMeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MinMeasuredValueAttributeSubscriptionState.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) { - "Minmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Minmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MinMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute {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}") - } + 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) { "Maxmeasuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Maxmeasuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MaxMeasuredValueAttribute(decodedValue) } suspend fun subscribeMaxMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MaxMeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MaxMeasuredValueAttributeSubscriptionState.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) { - "Maxmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Maxmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MaxMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readPeakMeasuredValueAttribute(): PeakMeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readPeakMeasuredValueAttribute(): PeakMeasuredValueAttribute {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}") - } + 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) { "Peakmeasuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Peakmeasuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return PeakMeasuredValueAttribute(decodedValue) } suspend fun subscribePeakMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - PeakMeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(PeakMeasuredValueAttributeSubscriptionState.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) { - "Peakmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Peakmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(PeakMeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(PeakMeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(PeakMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readPeakMeasuredValueWindowAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 4u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readPeakMeasuredValueWindowAttribute(): UInt? {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}") - } + 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) { "Peakmeasuredvaluewindow attribute not found in response" } + } + + requireNotNull(attributeData) { + "Peakmeasuredvaluewindow attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribePeakMeasuredValueWindowAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Peakmeasuredvaluewindow attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Peakmeasuredvaluewindow attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readAverageMeasuredValueAttribute(): AverageMeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 5u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readAverageMeasuredValueAttribute(): AverageMeasuredValueAttribute {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}") - } + 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) { "Averagemeasuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Averagemeasuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return AverageMeasuredValueAttribute(decodedValue) } suspend fun subscribeAverageMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - AverageMeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(AverageMeasuredValueAttributeSubscriptionState.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) { - "Averagemeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Averagemeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(AverageMeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(AverageMeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(AverageMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readAverageMeasuredValueWindowAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 6u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readAverageMeasuredValueWindowAttribute(): UInt? {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}") - } + 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) { "Averagemeasuredvaluewindow attribute not found in response" } + } + + requireNotNull(attributeData) { + "Averagemeasuredvaluewindow attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeAverageMeasuredValueWindowAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Averagemeasuredvaluewindow attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Averagemeasuredvaluewindow attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readUncertaintyAttribute(): Float? { - val ATTRIBUTE_ID: UInt = 7u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readUncertaintyAttribute(): Float? {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}") - } + 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) { "Uncertainty attribute not found in response" } + } + + requireNotNull(attributeData) { + "Uncertainty attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } + val decodedValue: Float? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeUncertaintyAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - FloatSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(FloatSubscriptionState.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) { "Uncertainty attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Uncertainty attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(FloatSubscriptionState.Success(it)) } + val decodedValue: Float? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(FloatSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(FloatSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readMeasurementUnitAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 8u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMeasurementUnitAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 8u + + 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}") - } + 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) { "Measurementunit attribute not found in response" } + } + + requireNotNull(attributeData) { + "Measurementunit 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeMeasurementUnitAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Measurementunit attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Measurementunit 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)) } + 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 readMeasurementMediumAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 9u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMeasurementMediumAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 9u + + 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}") - } + 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) { "Measurementmedium attribute not found in response" } + } + + requireNotNull(attributeData) { + "Measurementmedium 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeMeasurementMediumAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Measurementmedium attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Measurementmedium 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)) } + 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 readLevelValueAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 10u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readLevelValueAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 10u + + 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}") - } + 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) { "Levelvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Levelvalue 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeLevelValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Levelvalue attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Levelvalue 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)) } + 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 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1291,96 +1389,97 @@ class Pm1ConcentrationMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1388,94 +1487,97 @@ class Pm1ConcentrationMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1483,94 +1585,97 @@ class Pm1ConcentrationMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1578,76 +1683,81 @@ class Pm1ConcentrationMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1659,77 +1769,80 @@ class Pm1ConcentrationMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1742,7 +1855,7 @@ class Pm1ConcentrationMeasurementCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/Pm25ConcentrationMeasurementCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/Pm25ConcentrationMeasurementCluster.kt index 4c236f2255d213..090d17ca0c1584 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/Pm25ConcentrationMeasurementCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/Pm25ConcentrationMeasurementCluster.kt @@ -17,1273 +17,1371 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.FloatSubscriptionState import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath +import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader +import matter.tlv.TlvWriter -class Pm25ConcentrationMeasurementCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class MeasuredValueAttribute(val value: Float?) +class Pm25ConcentrationMeasurementCluster(private val controller: MatterController, private val endpointId: UShort) {class MeasuredValueAttribute( + val value: Float? + ) sealed class MeasuredValueAttributeSubscriptionState { - data class Success(val value: Float?) : MeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Float? + ) : MeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() - } - - class MinMeasuredValueAttribute(val value: Float?) + object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() + } +class MinMeasuredValueAttribute( + val value: Float? + ) sealed class MinMeasuredValueAttributeSubscriptionState { - data class Success(val value: Float?) : MinMeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Float? + ) : MinMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MinMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() - } - - class MaxMeasuredValueAttribute(val value: Float?) + object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() + } +class MaxMeasuredValueAttribute( + val value: Float? + ) sealed class MaxMeasuredValueAttributeSubscriptionState { - data class Success(val value: Float?) : MaxMeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Float? + ) : MaxMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MaxMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() - } - - class PeakMeasuredValueAttribute(val value: Float?) + object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() + } +class PeakMeasuredValueAttribute( + val value: Float? + ) sealed class PeakMeasuredValueAttributeSubscriptionState { - data class Success(val value: Float?) : PeakMeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Float? + ) : PeakMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : PeakMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : PeakMeasuredValueAttributeSubscriptionState() - } - - class AverageMeasuredValueAttribute(val value: Float?) + object SubscriptionEstablished : PeakMeasuredValueAttributeSubscriptionState() + } +class AverageMeasuredValueAttribute( + val value: Float? + ) sealed class AverageMeasuredValueAttributeSubscriptionState { - data class Success(val value: Float?) : AverageMeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Float? + ) : AverageMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : AverageMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : AverageMeasuredValueAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : AverageMeasuredValueAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } - - suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } +suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute {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}") - } + 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) { "Measuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Measuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MeasuredValueAttribute(decodedValue) } suspend fun subscribeMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MeasuredValueAttributeSubscriptionState.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) { "Measuredvalue attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Measuredvalue attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute {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}") - } + 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) { "Minmeasuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Minmeasuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MinMeasuredValueAttribute(decodedValue) } suspend fun subscribeMinMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MinMeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MinMeasuredValueAttributeSubscriptionState.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) { - "Minmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Minmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MinMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute {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}") - } + 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) { "Maxmeasuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Maxmeasuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MaxMeasuredValueAttribute(decodedValue) } suspend fun subscribeMaxMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MaxMeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MaxMeasuredValueAttributeSubscriptionState.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) { - "Maxmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Maxmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MaxMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readPeakMeasuredValueAttribute(): PeakMeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readPeakMeasuredValueAttribute(): PeakMeasuredValueAttribute {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}") - } + 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) { "Peakmeasuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Peakmeasuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return PeakMeasuredValueAttribute(decodedValue) } suspend fun subscribePeakMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - PeakMeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(PeakMeasuredValueAttributeSubscriptionState.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) { - "Peakmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Peakmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(PeakMeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(PeakMeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(PeakMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readPeakMeasuredValueWindowAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 4u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readPeakMeasuredValueWindowAttribute(): UInt? {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}") - } + 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) { "Peakmeasuredvaluewindow attribute not found in response" } + } + + requireNotNull(attributeData) { + "Peakmeasuredvaluewindow attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribePeakMeasuredValueWindowAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Peakmeasuredvaluewindow attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Peakmeasuredvaluewindow attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readAverageMeasuredValueAttribute(): AverageMeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 5u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readAverageMeasuredValueAttribute(): AverageMeasuredValueAttribute {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}") - } + 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) { "Averagemeasuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Averagemeasuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return AverageMeasuredValueAttribute(decodedValue) } suspend fun subscribeAverageMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - AverageMeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(AverageMeasuredValueAttributeSubscriptionState.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) { - "Averagemeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Averagemeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(AverageMeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(AverageMeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(AverageMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readAverageMeasuredValueWindowAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 6u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readAverageMeasuredValueWindowAttribute(): UInt? {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}") - } + 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) { "Averagemeasuredvaluewindow attribute not found in response" } + } + + requireNotNull(attributeData) { + "Averagemeasuredvaluewindow attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeAverageMeasuredValueWindowAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Averagemeasuredvaluewindow attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Averagemeasuredvaluewindow attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readUncertaintyAttribute(): Float? { - val ATTRIBUTE_ID: UInt = 7u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readUncertaintyAttribute(): Float? {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}") - } + 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) { "Uncertainty attribute not found in response" } + } + + requireNotNull(attributeData) { + "Uncertainty attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } + val decodedValue: Float? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeUncertaintyAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - FloatSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(FloatSubscriptionState.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) { "Uncertainty attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Uncertainty attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(FloatSubscriptionState.Success(it)) } + val decodedValue: Float? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(FloatSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(FloatSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readMeasurementUnitAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 8u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMeasurementUnitAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 8u + + 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}") - } + 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) { "Measurementunit attribute not found in response" } + } + + requireNotNull(attributeData) { + "Measurementunit 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeMeasurementUnitAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Measurementunit attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Measurementunit 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)) } + 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 readMeasurementMediumAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 9u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMeasurementMediumAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 9u + + 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}") - } + 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) { "Measurementmedium attribute not found in response" } + } + + requireNotNull(attributeData) { + "Measurementmedium 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeMeasurementMediumAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Measurementmedium attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Measurementmedium 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)) } + 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 readLevelValueAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 10u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readLevelValueAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 10u + + 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}") - } + 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) { "Levelvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Levelvalue 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeLevelValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Levelvalue attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Levelvalue 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)) } + 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 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1291,96 +1389,97 @@ class Pm25ConcentrationMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1388,94 +1487,97 @@ class Pm25ConcentrationMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1483,94 +1585,97 @@ class Pm25ConcentrationMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1578,76 +1683,81 @@ class Pm25ConcentrationMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1659,77 +1769,80 @@ class Pm25ConcentrationMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1742,7 +1855,7 @@ class Pm25ConcentrationMeasurementCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/PowerSourceCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/PowerSourceCluster.kt index fa4dd69d99fdd1..835ea746f9a7d8 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/PowerSourceCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/PowerSourceCluster.kt @@ -17,257 +17,329 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.BooleanSubscriptionState import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest -import matter.controller.StringSubscriptionState +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath +import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader +import matter.tlv.TlvWriter -class PowerSourceCluster(private val controller: MatterController, private val endpointId: UShort) { - class WiredAssessedInputVoltageAttribute(val value: UInt?) +class PowerSourceCluster(private val controller: MatterController, private val endpointId: UShort) {class WiredAssessedInputVoltageAttribute( + val value: UInt? + ) sealed class WiredAssessedInputVoltageAttributeSubscriptionState { - data class Success(val value: UInt?) : WiredAssessedInputVoltageAttributeSubscriptionState() - - data class Error(val exception: Exception) : - WiredAssessedInputVoltageAttributeSubscriptionState() - - object SubscriptionEstablished : WiredAssessedInputVoltageAttributeSubscriptionState() - } - - class WiredAssessedInputFrequencyAttribute(val value: UShort?) + data class Success( + val value: UInt? + ) : WiredAssessedInputVoltageAttributeSubscriptionState() + + data class Error(val exception: Exception) : WiredAssessedInputVoltageAttributeSubscriptionState() + + object SubscriptionEstablished : WiredAssessedInputVoltageAttributeSubscriptionState() + } +class WiredAssessedInputFrequencyAttribute( + val value: UShort? + ) sealed class WiredAssessedInputFrequencyAttributeSubscriptionState { - data class Success(val value: UShort?) : - WiredAssessedInputFrequencyAttributeSubscriptionState() - - data class Error(val exception: Exception) : - WiredAssessedInputFrequencyAttributeSubscriptionState() - - object SubscriptionEstablished : WiredAssessedInputFrequencyAttributeSubscriptionState() - } - - class WiredAssessedCurrentAttribute(val value: UInt?) + data class Success( + val value: UShort? + ) : WiredAssessedInputFrequencyAttributeSubscriptionState() + + data class Error(val exception: Exception) : WiredAssessedInputFrequencyAttributeSubscriptionState() + + object SubscriptionEstablished : WiredAssessedInputFrequencyAttributeSubscriptionState() + } +class WiredAssessedCurrentAttribute( + val value: UInt? + ) sealed class WiredAssessedCurrentAttributeSubscriptionState { - data class Success(val value: UInt?) : WiredAssessedCurrentAttributeSubscriptionState() - + data class Success( + val value: UInt? + ) : WiredAssessedCurrentAttributeSubscriptionState() + data class Error(val exception: Exception) : WiredAssessedCurrentAttributeSubscriptionState() - object SubscriptionEstablished : WiredAssessedCurrentAttributeSubscriptionState() - } - - class ActiveWiredFaultsAttribute(val value: List?) + object SubscriptionEstablished : WiredAssessedCurrentAttributeSubscriptionState() + } +class ActiveWiredFaultsAttribute( + val value: List? + ) sealed class ActiveWiredFaultsAttributeSubscriptionState { - data class Success(val value: List?) : ActiveWiredFaultsAttributeSubscriptionState() - + data class Success( + val value: List? + ) : ActiveWiredFaultsAttributeSubscriptionState() + data class Error(val exception: Exception) : ActiveWiredFaultsAttributeSubscriptionState() - object SubscriptionEstablished : ActiveWiredFaultsAttributeSubscriptionState() - } - - class BatVoltageAttribute(val value: UInt?) + object SubscriptionEstablished : ActiveWiredFaultsAttributeSubscriptionState() + } +class BatVoltageAttribute( + val value: UInt? + ) sealed class BatVoltageAttributeSubscriptionState { - data class Success(val value: UInt?) : BatVoltageAttributeSubscriptionState() - + data class Success( + val value: UInt? + ) : BatVoltageAttributeSubscriptionState() + data class Error(val exception: Exception) : BatVoltageAttributeSubscriptionState() - object SubscriptionEstablished : BatVoltageAttributeSubscriptionState() - } - - class BatPercentRemainingAttribute(val value: UByte?) + object SubscriptionEstablished : BatVoltageAttributeSubscriptionState() + } +class BatPercentRemainingAttribute( + val value: UByte? + ) sealed class BatPercentRemainingAttributeSubscriptionState { - data class Success(val value: UByte?) : BatPercentRemainingAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : BatPercentRemainingAttributeSubscriptionState() + data class Error(val exception: Exception) : BatPercentRemainingAttributeSubscriptionState() - object SubscriptionEstablished : BatPercentRemainingAttributeSubscriptionState() - } - - class BatTimeRemainingAttribute(val value: UInt?) + object SubscriptionEstablished : BatPercentRemainingAttributeSubscriptionState() + } +class BatTimeRemainingAttribute( + val value: UInt? + ) sealed class BatTimeRemainingAttributeSubscriptionState { - data class Success(val value: UInt?) : BatTimeRemainingAttributeSubscriptionState() - + data class Success( + val value: UInt? + ) : BatTimeRemainingAttributeSubscriptionState() + data class Error(val exception: Exception) : BatTimeRemainingAttributeSubscriptionState() - object SubscriptionEstablished : BatTimeRemainingAttributeSubscriptionState() - } - - class ActiveBatFaultsAttribute(val value: List?) + object SubscriptionEstablished : BatTimeRemainingAttributeSubscriptionState() + } +class ActiveBatFaultsAttribute( + val value: List? + ) sealed class ActiveBatFaultsAttributeSubscriptionState { - data class Success(val value: List?) : ActiveBatFaultsAttributeSubscriptionState() - + data class Success( + val value: List? + ) : ActiveBatFaultsAttributeSubscriptionState() + data class Error(val exception: Exception) : ActiveBatFaultsAttributeSubscriptionState() - object SubscriptionEstablished : ActiveBatFaultsAttributeSubscriptionState() - } - - class BatTimeToFullChargeAttribute(val value: UInt?) + object SubscriptionEstablished : ActiveBatFaultsAttributeSubscriptionState() + } +class BatTimeToFullChargeAttribute( + val value: UInt? + ) sealed class BatTimeToFullChargeAttributeSubscriptionState { - data class Success(val value: UInt?) : BatTimeToFullChargeAttributeSubscriptionState() - + data class Success( + val value: UInt? + ) : BatTimeToFullChargeAttributeSubscriptionState() + data class Error(val exception: Exception) : BatTimeToFullChargeAttributeSubscriptionState() - object SubscriptionEstablished : BatTimeToFullChargeAttributeSubscriptionState() - } - - class BatChargingCurrentAttribute(val value: UInt?) + object SubscriptionEstablished : BatTimeToFullChargeAttributeSubscriptionState() + } +class BatChargingCurrentAttribute( + val value: UInt? + ) sealed class BatChargingCurrentAttributeSubscriptionState { - data class Success(val value: UInt?) : BatChargingCurrentAttributeSubscriptionState() - + data class Success( + val value: UInt? + ) : BatChargingCurrentAttributeSubscriptionState() + data class Error(val exception: Exception) : BatChargingCurrentAttributeSubscriptionState() - object SubscriptionEstablished : BatChargingCurrentAttributeSubscriptionState() - } - - class ActiveBatChargeFaultsAttribute(val value: List?) + object SubscriptionEstablished : BatChargingCurrentAttributeSubscriptionState() + } +class ActiveBatChargeFaultsAttribute( + val value: List? + ) sealed class ActiveBatChargeFaultsAttributeSubscriptionState { - data class Success(val value: List?) : ActiveBatChargeFaultsAttributeSubscriptionState() - + data class Success( + val value: List? + ) : ActiveBatChargeFaultsAttributeSubscriptionState() + data class Error(val exception: Exception) : ActiveBatChargeFaultsAttributeSubscriptionState() - object SubscriptionEstablished : ActiveBatChargeFaultsAttributeSubscriptionState() - } - - class EndpointListAttribute(val value: List) + object SubscriptionEstablished : ActiveBatChargeFaultsAttributeSubscriptionState() + } +class EndpointListAttribute( + val value: List + ) sealed class EndpointListAttributeSubscriptionState { - data class Success(val value: List) : EndpointListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EndpointListAttributeSubscriptionState() + data class Error(val exception: Exception) : EndpointListAttributeSubscriptionState() - object SubscriptionEstablished : EndpointListAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : EndpointListAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } - - suspend fun readStatusAttribute(): 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)) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } +suspend fun readStatusAttribute(): 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}") - } + 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) { "Status attribute not found in response" } + } + + requireNotNull(attributeData) { + "Status 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 subscribeStatusAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Status attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Status attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -279,76 +351,81 @@ class PowerSourceCluster(private val controller: MatterController, private val e emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readOrderAttribute(): UByte {val ATTRIBUTE_ID: UInt = 1u - suspend fun readOrderAttribute(): 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 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}") - } + 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) { "Order attribute not found in response" } + } + + requireNotNull(attributeData) { + "Order 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 subscribeOrderAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Order attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Order attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -360,76 +437,81 @@ class PowerSourceCluster(private val controller: MatterController, private val e emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readDescriptionAttribute(): String {val ATTRIBUTE_ID: UInt = 2u - suspend fun readDescriptionAttribute(): String { - 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 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}") - } + 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) { "Description attribute not found in response" } + } + + requireNotNull(attributeData) { + "Description attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: String = tlvReader.getString(AnonymousTag) + return decodedValue } suspend fun subscribeDescriptionAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StringSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StringSubscriptionState.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) { "Description attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Description attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -441,2808 +523,2929 @@ class PowerSourceCluster(private val controller: MatterController, private val e emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readWiredAssessedInputVoltageAttribute(): WiredAssessedInputVoltageAttribute {val ATTRIBUTE_ID: UInt = 3u - suspend fun readWiredAssessedInputVoltageAttribute(): WiredAssessedInputVoltageAttribute { - 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 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}") - } + 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) { "Wiredassessedinputvoltage attribute not found in response" } + } + + requireNotNull(attributeData) { + "Wiredassessedinputvoltage attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return WiredAssessedInputVoltageAttribute(decodedValue) } suspend fun subscribeWiredAssessedInputVoltageAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - WiredAssessedInputVoltageAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(WiredAssessedInputVoltageAttributeSubscriptionState.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) { - "Wiredassessedinputvoltage attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Wiredassessedinputvoltage attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } decodedValue?.let { emit(WiredAssessedInputVoltageAttributeSubscriptionState.Success(it)) } + } SubscriptionState.SubscriptionEstablished -> { emit(WiredAssessedInputVoltageAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readWiredAssessedInputFrequencyAttribute(): WiredAssessedInputFrequencyAttribute {val ATTRIBUTE_ID: UInt = 4u - suspend fun readWiredAssessedInputFrequencyAttribute(): WiredAssessedInputFrequencyAttribute { - 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 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}") - } + 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) { "Wiredassessedinputfrequency attribute not found in response" } + } + + requireNotNull(attributeData) { + "Wiredassessedinputfrequency attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return WiredAssessedInputFrequencyAttribute(decodedValue) } suspend fun subscribeWiredAssessedInputFrequencyAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - WiredAssessedInputFrequencyAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(WiredAssessedInputFrequencyAttributeSubscriptionState.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) { - "Wiredassessedinputfrequency attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Wiredassessedinputfrequency 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } decodedValue?.let { emit(WiredAssessedInputFrequencyAttributeSubscriptionState.Success(it)) } + } SubscriptionState.SubscriptionEstablished -> { emit(WiredAssessedInputFrequencyAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readWiredCurrentTypeAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 5u - suspend fun readWiredCurrentTypeAttribute(): UByte? { - 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 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}") - } + 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) { "Wiredcurrenttype attribute not found in response" } + } + + requireNotNull(attributeData) { + "Wiredcurrenttype 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeWiredCurrentTypeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Wiredcurrenttype attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Wiredcurrenttype 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readWiredAssessedCurrentAttribute(): WiredAssessedCurrentAttribute {val ATTRIBUTE_ID: UInt = 6u - suspend fun readWiredAssessedCurrentAttribute(): WiredAssessedCurrentAttribute { - 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 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}") - } + 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) { "Wiredassessedcurrent attribute not found in response" } + } + + requireNotNull(attributeData) { + "Wiredassessedcurrent attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return WiredAssessedCurrentAttribute(decodedValue) } suspend fun subscribeWiredAssessedCurrentAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - WiredAssessedCurrentAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(WiredAssessedCurrentAttributeSubscriptionState.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) { - "Wiredassessedcurrent attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Wiredassessedcurrent attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(WiredAssessedCurrentAttributeSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(WiredAssessedCurrentAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(WiredAssessedCurrentAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readWiredNominalVoltageAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 7u - suspend fun readWiredNominalVoltageAttribute(): UInt? { - 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 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}") - } + 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) { "Wirednominalvoltage attribute not found in response" } + } + + requireNotNull(attributeData) { + "Wirednominalvoltage attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeWiredNominalVoltageAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Wirednominalvoltage attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Wirednominalvoltage attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readWiredMaximumCurrentAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 8u - suspend fun readWiredMaximumCurrentAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 8u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Wiredmaximumcurrent attribute not found in response" } + } + + requireNotNull(attributeData) { + "Wiredmaximumcurrent attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeWiredMaximumCurrentAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Wiredmaximumcurrent attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Wiredmaximumcurrent attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readWiredPresentAttribute(): Boolean? {val ATTRIBUTE_ID: UInt = 9u - suspend fun readWiredPresentAttribute(): Boolean? { - val ATTRIBUTE_ID: UInt = 9u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Wiredpresent attribute not found in response" } + } + + requireNotNull(attributeData) { + "Wiredpresent 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 - } + val decodedValue: Boolean? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeWiredPresentAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Wiredpresent attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Wiredpresent 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 - } + val decodedValue: Boolean? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(BooleanSubscriptionState.Success(it)) } + decodedValue?.let { + emit(BooleanSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readActiveWiredFaultsAttribute(): ActiveWiredFaultsAttribute {val ATTRIBUTE_ID: UInt = 10u - suspend fun readActiveWiredFaultsAttribute(): ActiveWiredFaultsAttribute { - val ATTRIBUTE_ID: UInt = 10u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Activewiredfaults attribute not found in response" } + } + + requireNotNull(attributeData) { + "Activewiredfaults attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) } + tlvReader.exitContainer() + } + } else { + null + } + return ActiveWiredFaultsAttribute(decodedValue) } suspend fun subscribeActiveWiredFaultsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ActiveWiredFaultsAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ActiveWiredFaultsAttributeSubscriptionState.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) { - "Activewiredfaults attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Activewiredfaults attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { emit(ActiveWiredFaultsAttributeSubscriptionState.Success(it)) } + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { + emit(ActiveWiredFaultsAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ActiveWiredFaultsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readBatVoltageAttribute(): BatVoltageAttribute {val ATTRIBUTE_ID: UInt = 11u - suspend fun readBatVoltageAttribute(): BatVoltageAttribute { - val ATTRIBUTE_ID: UInt = 11u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Batvoltage attribute not found in response" } + } + + requireNotNull(attributeData) { + "Batvoltage attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return BatVoltageAttribute(decodedValue) } suspend fun subscribeBatVoltageAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 11u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - BatVoltageAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(BatVoltageAttributeSubscriptionState.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) { "Batvoltage attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Batvoltage attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(BatVoltageAttributeSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(BatVoltageAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(BatVoltageAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readBatPercentRemainingAttribute(): BatPercentRemainingAttribute {val ATTRIBUTE_ID: UInt = 12u - suspend fun readBatPercentRemainingAttribute(): BatPercentRemainingAttribute { - val ATTRIBUTE_ID: UInt = 12u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Batpercentremaining attribute not found in response" } + } + + requireNotNull(attributeData) { + "Batpercentremaining attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return BatPercentRemainingAttribute(decodedValue) } suspend fun subscribeBatPercentRemainingAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 12u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - BatPercentRemainingAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(BatPercentRemainingAttributeSubscriptionState.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) { - "Batpercentremaining attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Batpercentremaining 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(BatPercentRemainingAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(BatPercentRemainingAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(BatPercentRemainingAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readBatTimeRemainingAttribute(): BatTimeRemainingAttribute {val ATTRIBUTE_ID: UInt = 13u - suspend fun readBatTimeRemainingAttribute(): BatTimeRemainingAttribute { - val ATTRIBUTE_ID: UInt = 13u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Battimeremaining attribute not found in response" } + } + + requireNotNull(attributeData) { + "Battimeremaining attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return BatTimeRemainingAttribute(decodedValue) } suspend fun subscribeBatTimeRemainingAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 13u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - BatTimeRemainingAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(BatTimeRemainingAttributeSubscriptionState.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) { - "Battimeremaining attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Battimeremaining attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(BatTimeRemainingAttributeSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(BatTimeRemainingAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(BatTimeRemainingAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readBatChargeLevelAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 14u - suspend fun readBatChargeLevelAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 14u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Batchargelevel attribute not found in response" } + } + + requireNotNull(attributeData) { + "Batchargelevel 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeBatChargeLevelAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 14u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Batchargelevel attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Batchargelevel 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readBatReplacementNeededAttribute(): Boolean? {val ATTRIBUTE_ID: UInt = 15u - suspend fun readBatReplacementNeededAttribute(): Boolean? { - val ATTRIBUTE_ID: UInt = 15u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Batreplacementneeded attribute not found in response" } + } + + requireNotNull(attributeData) { + "Batreplacementneeded 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 - } + val decodedValue: Boolean? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeBatReplacementNeededAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 15u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Batreplacementneeded attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Batreplacementneeded 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 - } + val decodedValue: Boolean? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(BooleanSubscriptionState.Success(it)) } + decodedValue?.let { + emit(BooleanSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readBatReplaceabilityAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 16u - suspend fun readBatReplaceabilityAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 16u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Batreplaceability attribute not found in response" } + } + + requireNotNull(attributeData) { + "Batreplaceability 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeBatReplaceabilityAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Batreplaceability attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Batreplaceability 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readBatPresentAttribute(): Boolean? {val ATTRIBUTE_ID: UInt = 17u - suspend fun readBatPresentAttribute(): Boolean? { - val ATTRIBUTE_ID: UInt = 17u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Batpresent attribute not found in response" } + } + + requireNotNull(attributeData) { + "Batpresent 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 - } + val decodedValue: Boolean? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeBatPresentAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 17u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Batpresent attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Batpresent 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 - } + val decodedValue: Boolean? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(BooleanSubscriptionState.Success(it)) } + decodedValue?.let { + emit(BooleanSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readActiveBatFaultsAttribute(): ActiveBatFaultsAttribute {val ATTRIBUTE_ID: UInt = 18u - suspend fun readActiveBatFaultsAttribute(): ActiveBatFaultsAttribute { - val ATTRIBUTE_ID: UInt = 18u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Activebatfaults attribute not found in response" } + } + + requireNotNull(attributeData) { + "Activebatfaults attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) } + tlvReader.exitContainer() + } + } else { + null + } + return ActiveBatFaultsAttribute(decodedValue) } suspend fun subscribeActiveBatFaultsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 18u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ActiveBatFaultsAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ActiveBatFaultsAttributeSubscriptionState.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) { - "Activebatfaults attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Activebatfaults attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { emit(ActiveBatFaultsAttributeSubscriptionState.Success(it)) } + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { + emit(ActiveBatFaultsAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ActiveBatFaultsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readBatReplacementDescriptionAttribute(): String? {val ATTRIBUTE_ID: UInt = 19u - suspend fun readBatReplacementDescriptionAttribute(): String? { - val ATTRIBUTE_ID: UInt = 19u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Batreplacementdescription attribute not found in response" } + } + + requireNotNull(attributeData) { + "Batreplacementdescription attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeBatReplacementDescriptionAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 19u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StringSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StringSubscriptionState.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) { - "Batreplacementdescription attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Batreplacementdescription attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(StringSubscriptionState.Success(it)) } + decodedValue?.let { + emit(StringSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readBatCommonDesignationAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 20u - suspend fun readBatCommonDesignationAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 20u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Batcommondesignation attribute not found in response" } + } + + requireNotNull(attributeData) { + "Batcommondesignation 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeBatCommonDesignationAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 20u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Batcommondesignation attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Batcommondesignation 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readBatANSIDesignationAttribute(): String? {val ATTRIBUTE_ID: UInt = 21u - suspend fun readBatANSIDesignationAttribute(): String? { - val ATTRIBUTE_ID: UInt = 21u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Batansidesignation attribute not found in response" } + } + + requireNotNull(attributeData) { + "Batansidesignation attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeBatANSIDesignationAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 21u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StringSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StringSubscriptionState.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) { - "Batansidesignation attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Batansidesignation attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(StringSubscriptionState.Success(it)) } + decodedValue?.let { + emit(StringSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readBatIECDesignationAttribute(): String? {val ATTRIBUTE_ID: UInt = 22u - suspend fun readBatIECDesignationAttribute(): String? { - val ATTRIBUTE_ID: UInt = 22u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Batiecdesignation attribute not found in response" } + } + + requireNotNull(attributeData) { + "Batiecdesignation attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeBatIECDesignationAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 22u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StringSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StringSubscriptionState.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) { - "Batiecdesignation attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Batiecdesignation attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(StringSubscriptionState.Success(it)) } + decodedValue?.let { + emit(StringSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readBatApprovedChemistryAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 23u - suspend fun readBatApprovedChemistryAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 23u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Batapprovedchemistry attribute not found in response" } + } + + requireNotNull(attributeData) { + "Batapprovedchemistry 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeBatApprovedChemistryAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 23u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Batapprovedchemistry attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Batapprovedchemistry 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readBatCapacityAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 24u - suspend fun readBatCapacityAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 24u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Batcapacity attribute not found in response" } + } + + requireNotNull(attributeData) { + "Batcapacity attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeBatCapacityAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 24u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Batcapacity attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Batcapacity attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readBatQuantityAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 25u - suspend fun readBatQuantityAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 25u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Batquantity attribute not found in response" } + } + + requireNotNull(attributeData) { + "Batquantity 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeBatQuantityAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 25u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Batquantity attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Batquantity 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readBatChargeStateAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 26u - suspend fun readBatChargeStateAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 26u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Batchargestate attribute not found in response" } + } + + requireNotNull(attributeData) { + "Batchargestate 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeBatChargeStateAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 26u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Batchargestate attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Batchargestate 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readBatTimeToFullChargeAttribute(): BatTimeToFullChargeAttribute {val ATTRIBUTE_ID: UInt = 27u - suspend fun readBatTimeToFullChargeAttribute(): BatTimeToFullChargeAttribute { - val ATTRIBUTE_ID: UInt = 27u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Battimetofullcharge attribute not found in response" } + } + + requireNotNull(attributeData) { + "Battimetofullcharge attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return BatTimeToFullChargeAttribute(decodedValue) } suspend fun subscribeBatTimeToFullChargeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 27u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - BatTimeToFullChargeAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(BatTimeToFullChargeAttributeSubscriptionState.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) { - "Battimetofullcharge attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Battimetofullcharge attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(BatTimeToFullChargeAttributeSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(BatTimeToFullChargeAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(BatTimeToFullChargeAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readBatFunctionalWhileChargingAttribute(): Boolean? {val ATTRIBUTE_ID: UInt = 28u - suspend fun readBatFunctionalWhileChargingAttribute(): Boolean? { - val ATTRIBUTE_ID: UInt = 28u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Batfunctionalwhilecharging attribute not found in response" } + } + + requireNotNull(attributeData) { + "Batfunctionalwhilecharging 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 - } + val decodedValue: Boolean? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeBatFunctionalWhileChargingAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 28u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Batfunctionalwhilecharging attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Batfunctionalwhilecharging 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 - } + val decodedValue: Boolean? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(BooleanSubscriptionState.Success(it)) } + decodedValue?.let { + emit(BooleanSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readBatChargingCurrentAttribute(): BatChargingCurrentAttribute {val ATTRIBUTE_ID: UInt = 29u - suspend fun readBatChargingCurrentAttribute(): BatChargingCurrentAttribute { - val ATTRIBUTE_ID: UInt = 29u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Batchargingcurrent attribute not found in response" } + } + + requireNotNull(attributeData) { + "Batchargingcurrent attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return BatChargingCurrentAttribute(decodedValue) } suspend fun subscribeBatChargingCurrentAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 29u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - BatChargingCurrentAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(BatChargingCurrentAttributeSubscriptionState.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) { - "Batchargingcurrent attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Batchargingcurrent attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(BatChargingCurrentAttributeSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(BatChargingCurrentAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(BatChargingCurrentAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readActiveBatChargeFaultsAttribute(): ActiveBatChargeFaultsAttribute {val ATTRIBUTE_ID: UInt = 30u - suspend fun readActiveBatChargeFaultsAttribute(): ActiveBatChargeFaultsAttribute { - val ATTRIBUTE_ID: UInt = 30u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Activebatchargefaults attribute not found in response" } + } + + requireNotNull(attributeData) { + "Activebatchargefaults attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) } + tlvReader.exitContainer() + } + } else { + null + } + return ActiveBatChargeFaultsAttribute(decodedValue) } suspend fun subscribeActiveBatChargeFaultsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 30u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ActiveBatChargeFaultsAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ActiveBatChargeFaultsAttributeSubscriptionState.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) { - "Activebatchargefaults attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Activebatchargefaults attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { emit(ActiveBatChargeFaultsAttributeSubscriptionState.Success(it)) } + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { + emit(ActiveBatChargeFaultsAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ActiveBatChargeFaultsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readEndpointListAttribute(): EndpointListAttribute {val ATTRIBUTE_ID: UInt = 31u - suspend fun readEndpointListAttribute(): EndpointListAttribute { - val ATTRIBUTE_ID: UInt = 31u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Endpointlist attribute not found in response" } + } + + requireNotNull(attributeData) { + "Endpointlist 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.getUShort(AnonymousTag)) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUShort(AnonymousTag)) } + tlvReader.exitContainer() + } + return EndpointListAttribute(decodedValue) } suspend fun subscribeEndpointListAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 31u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - EndpointListAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(EndpointListAttributeSubscriptionState.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) { "Endpointlist attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Endpointlist 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.getUShort(AnonymousTag)) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUShort(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EndpointListAttributeSubscriptionState.Success(decodedValue)) } @@ -3250,96 +3453,97 @@ class PowerSourceCluster(private val controller: MatterController, private val e emit(EndpointListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65528u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -3347,96 +3551,97 @@ class PowerSourceCluster(private val controller: MatterController, private val e emit(GeneratedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65529u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -3444,94 +3649,97 @@ class PowerSourceCluster(private val controller: MatterController, private val e emit(AcceptedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt = 65530u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -3539,94 +3747,97 @@ class PowerSourceCluster(private val controller: MatterController, private val e emit(EventListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ID: UInt = 65531u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -3634,76 +3845,81 @@ class PowerSourceCluster(private val controller: MatterController, private val e emit(AttributeListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u - 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 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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -3715,77 +3931,80 @@ class PowerSourceCluster(private val controller: MatterController, private val e emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 65533u - 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 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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -3798,7 +4017,7 @@ class PowerSourceCluster(private val controller: MatterController, private val e emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/PowerSourceConfigurationCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/PowerSourceConfigurationCluster.kt index edf0fe59a8a295..59bfeff63ee455 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/PowerSourceConfigurationCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/PowerSourceConfigurationCluster.kt @@ -17,162 +17,202 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.UIntSubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState +import matter.controller.UByteSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath +import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader +import matter.tlv.TlvWriter -class PowerSourceConfigurationCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class SourcesAttribute(val value: List) +class PowerSourceConfigurationCluster(private val controller: MatterController, private val endpointId: UShort) {class SourcesAttribute( + val value: List + ) sealed class SourcesAttributeSubscriptionState { - data class Success(val value: List) : SourcesAttributeSubscriptionState() - + data class Success( + val value: List + ) : SourcesAttributeSubscriptionState() + data class Error(val exception: Exception) : SourcesAttributeSubscriptionState() - object SubscriptionEstablished : SourcesAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : SourcesAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } - - suspend fun readSourcesAttribute(): SourcesAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } +suspend fun readSourcesAttribute(): SourcesAttribute {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}") - } + 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) { "Sources attribute not found in response" } + } + + requireNotNull(attributeData) { + "Sources 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.getUShort(AnonymousTag)) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUShort(AnonymousTag)) } + tlvReader.exitContainer() + } + return SourcesAttribute(decodedValue) } suspend fun subscribeSourcesAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - SourcesAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(SourcesAttributeSubscriptionState.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) { "Sources attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Sources 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.getUShort(AnonymousTag)) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUShort(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(SourcesAttributeSubscriptionState.Success(decodedValue)) } @@ -180,96 +220,97 @@ class PowerSourceConfigurationCluster( emit(SourcesAttributeSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -277,96 +318,97 @@ class PowerSourceConfigurationCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -374,94 +416,97 @@ class PowerSourceConfigurationCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -469,94 +514,97 @@ class PowerSourceConfigurationCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -564,76 +612,81 @@ class PowerSourceConfigurationCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -645,77 +698,80 @@ class PowerSourceConfigurationCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -728,7 +784,7 @@ class PowerSourceConfigurationCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/PowerTopologyCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/PowerTopologyCluster.kt index 276501e391d049..2555983a6cc8b5 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/PowerTopologyCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/PowerTopologyCluster.kt @@ -17,384 +17,433 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.UIntSubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState +import matter.controller.UByteSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath +import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader +import matter.tlv.TlvWriter -class PowerTopologyCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class AvailableEndpointsAttribute(val value: List?) +class PowerTopologyCluster(private val controller: MatterController, private val endpointId: UShort) {class AvailableEndpointsAttribute( + val value: List? + ) sealed class AvailableEndpointsAttributeSubscriptionState { - data class Success(val value: List?) : AvailableEndpointsAttributeSubscriptionState() - + data class Success( + val value: List? + ) : AvailableEndpointsAttributeSubscriptionState() + data class Error(val exception: Exception) : AvailableEndpointsAttributeSubscriptionState() - object SubscriptionEstablished : AvailableEndpointsAttributeSubscriptionState() - } - - class ActiveEndpointsAttribute(val value: List?) + object SubscriptionEstablished : AvailableEndpointsAttributeSubscriptionState() + } +class ActiveEndpointsAttribute( + val value: List? + ) sealed class ActiveEndpointsAttributeSubscriptionState { - data class Success(val value: List?) : ActiveEndpointsAttributeSubscriptionState() - + data class Success( + val value: List? + ) : ActiveEndpointsAttributeSubscriptionState() + data class Error(val exception: Exception) : ActiveEndpointsAttributeSubscriptionState() - object SubscriptionEstablished : ActiveEndpointsAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : ActiveEndpointsAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } - - suspend fun readAvailableEndpointsAttribute(): AvailableEndpointsAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } +suspend fun readAvailableEndpointsAttribute(): AvailableEndpointsAttribute {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}") - } + 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) { "Availableendpoints attribute not found in response" } + } + + requireNotNull(attributeData) { + "Availableendpoints attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getUShort(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUShort(AnonymousTag)) } + tlvReader.exitContainer() + } + } else { + null + } + return AvailableEndpointsAttribute(decodedValue) } suspend fun subscribeAvailableEndpointsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - AvailableEndpointsAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(AvailableEndpointsAttributeSubscriptionState.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) { - "Availableendpoints attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Availableendpoints attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getUShort(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { emit(AvailableEndpointsAttributeSubscriptionState.Success(it)) } + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUShort(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { + emit(AvailableEndpointsAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(AvailableEndpointsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readActiveEndpointsAttribute(): ActiveEndpointsAttribute { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readActiveEndpointsAttribute(): ActiveEndpointsAttribute {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}") - } + 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) { "Activeendpoints attribute not found in response" } + } + + requireNotNull(attributeData) { + "Activeendpoints attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getUShort(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUShort(AnonymousTag)) } + tlvReader.exitContainer() + } + } else { + null + } + return ActiveEndpointsAttribute(decodedValue) } suspend fun subscribeActiveEndpointsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ActiveEndpointsAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ActiveEndpointsAttributeSubscriptionState.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) { - "Activeendpoints attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Activeendpoints attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getUShort(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { emit(ActiveEndpointsAttributeSubscriptionState.Success(it)) } + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUShort(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { + emit(ActiveEndpointsAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ActiveEndpointsAttributeSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -402,96 +451,97 @@ class PowerTopologyCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -499,94 +549,97 @@ class PowerTopologyCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -594,94 +647,97 @@ class PowerTopologyCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -689,76 +745,81 @@ class PowerTopologyCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -770,77 +831,80 @@ class PowerTopologyCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -853,7 +917,7 @@ class PowerTopologyCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/PressureMeasurementCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/PressureMeasurementCluster.kt index fe46298d0def38..e8726e5f3a3cac 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/PressureMeasurementCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/PressureMeasurementCluster.kt @@ -17,1080 +17,1176 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.ByteSubscriptionState import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.UIntSubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState +import matter.controller.UByteSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath +import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader +import matter.tlv.TlvWriter -class PressureMeasurementCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class MeasuredValueAttribute(val value: Short?) +class PressureMeasurementCluster(private val controller: MatterController, private val endpointId: UShort) {class MeasuredValueAttribute( + val value: Short? + ) sealed class MeasuredValueAttributeSubscriptionState { - data class Success(val value: Short?) : MeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Short? + ) : MeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() - } - - class MinMeasuredValueAttribute(val value: Short?) + object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() + } +class MinMeasuredValueAttribute( + val value: Short? + ) sealed class MinMeasuredValueAttributeSubscriptionState { - data class Success(val value: Short?) : MinMeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Short? + ) : MinMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MinMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() - } - - class MaxMeasuredValueAttribute(val value: Short?) + object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() + } +class MaxMeasuredValueAttribute( + val value: Short? + ) sealed class MaxMeasuredValueAttributeSubscriptionState { - data class Success(val value: Short?) : MaxMeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Short? + ) : MaxMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MaxMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() - } - - class ScaledValueAttribute(val value: Short?) + object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() + } +class ScaledValueAttribute( + val value: Short? + ) sealed class ScaledValueAttributeSubscriptionState { - data class Success(val value: Short?) : ScaledValueAttributeSubscriptionState() - + data class Success( + val value: Short? + ) : ScaledValueAttributeSubscriptionState() + data class Error(val exception: Exception) : ScaledValueAttributeSubscriptionState() - object SubscriptionEstablished : ScaledValueAttributeSubscriptionState() - } - - class MinScaledValueAttribute(val value: Short?) + object SubscriptionEstablished : ScaledValueAttributeSubscriptionState() + } +class MinScaledValueAttribute( + val value: Short? + ) sealed class MinScaledValueAttributeSubscriptionState { - data class Success(val value: Short?) : MinScaledValueAttributeSubscriptionState() - + data class Success( + val value: Short? + ) : MinScaledValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MinScaledValueAttributeSubscriptionState() - object SubscriptionEstablished : MinScaledValueAttributeSubscriptionState() - } - - class MaxScaledValueAttribute(val value: Short?) + object SubscriptionEstablished : MinScaledValueAttributeSubscriptionState() + } +class MaxScaledValueAttribute( + val value: Short? + ) sealed class MaxScaledValueAttributeSubscriptionState { - data class Success(val value: Short?) : MaxScaledValueAttributeSubscriptionState() - + data class Success( + val value: Short? + ) : MaxScaledValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MaxScaledValueAttributeSubscriptionState() - object SubscriptionEstablished : MaxScaledValueAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : MaxScaledValueAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } - - suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } +suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute {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}") - } + 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) { "Measuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Measuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (!tlvReader.isNull()) { - tlvReader.getShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Short? = if (!tlvReader.isNull()) { + tlvReader.getShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MeasuredValueAttribute(decodedValue) } suspend fun subscribeMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MeasuredValueAttributeSubscriptionState.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) { "Measuredvalue attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Measuredvalue attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (!tlvReader.isNull()) { - tlvReader.getShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Short? = if (!tlvReader.isNull()) { + tlvReader.getShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute {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}") - } + 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) { "Minmeasuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Minmeasuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (!tlvReader.isNull()) { - tlvReader.getShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Short? = if (!tlvReader.isNull()) { + tlvReader.getShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MinMeasuredValueAttribute(decodedValue) } suspend fun subscribeMinMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MinMeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MinMeasuredValueAttributeSubscriptionState.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) { - "Minmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Minmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (!tlvReader.isNull()) { - tlvReader.getShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Short? = if (!tlvReader.isNull()) { + tlvReader.getShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MinMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute {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}") - } + 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) { "Maxmeasuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Maxmeasuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (!tlvReader.isNull()) { - tlvReader.getShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Short? = if (!tlvReader.isNull()) { + tlvReader.getShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MaxMeasuredValueAttribute(decodedValue) } suspend fun subscribeMaxMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MaxMeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MaxMeasuredValueAttributeSubscriptionState.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) { - "Maxmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Maxmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (!tlvReader.isNull()) { - tlvReader.getShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Short? = if (!tlvReader.isNull()) { + tlvReader.getShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MaxMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readToleranceAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readToleranceAttribute(): UShort? {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}") - } + 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) { "Tolerance attribute not found in response" } + } + + requireNotNull(attributeData) { + "Tolerance 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeToleranceAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Tolerance attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Tolerance 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)) } + 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 readScaledValueAttribute(): ScaledValueAttribute { - val ATTRIBUTE_ID: UInt = 16u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readScaledValueAttribute(): ScaledValueAttribute {val ATTRIBUTE_ID: UInt = 16u + + 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}") - } + 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) { "Scaledvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Scaledvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Short? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return ScaledValueAttribute(decodedValue) } suspend fun subscribeScaledValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ScaledValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ScaledValueAttributeSubscriptionState.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) { "Scaledvalue attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Scaledvalue attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(ScaledValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Short? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(ScaledValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ScaledValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readMinScaledValueAttribute(): MinScaledValueAttribute { - val ATTRIBUTE_ID: UInt = 17u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMinScaledValueAttribute(): MinScaledValueAttribute {val ATTRIBUTE_ID: UInt = 17u + + 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}") - } + 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) { "Minscaledvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Minscaledvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Short? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MinScaledValueAttribute(decodedValue) } suspend fun subscribeMinScaledValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 17u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MinScaledValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MinScaledValueAttributeSubscriptionState.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) { - "Minscaledvalue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Minscaledvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MinScaledValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Short? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MinScaledValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MinScaledValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readMaxScaledValueAttribute(): MaxScaledValueAttribute { - val ATTRIBUTE_ID: UInt = 18u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMaxScaledValueAttribute(): MaxScaledValueAttribute {val ATTRIBUTE_ID: UInt = 18u + + 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}") - } + 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) { "Maxscaledvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Maxscaledvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Short? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MaxScaledValueAttribute(decodedValue) } suspend fun subscribeMaxScaledValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 18u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MaxScaledValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MaxScaledValueAttributeSubscriptionState.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) { - "Maxscaledvalue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Maxscaledvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MaxScaledValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Short? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MaxScaledValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MaxScaledValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readScaledToleranceAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 19u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readScaledToleranceAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 19u + + 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}") - } + 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) { "Scaledtolerance attribute not found in response" } + } + + requireNotNull(attributeData) { + "Scaledtolerance 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeScaledToleranceAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 19u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Scaledtolerance attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Scaledtolerance 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)) } + 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 readScaleAttribute(): Byte? { - val ATTRIBUTE_ID: UInt = 20u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readScaleAttribute(): Byte? {val ATTRIBUTE_ID: UInt = 20u + + 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}") - } + 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) { "Scale attribute not found in response" } + } + + requireNotNull(attributeData) { + "Scale attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Byte? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByte(AnonymousTag) - } else { - null - } + val decodedValue: Byte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeScaleAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 20u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ByteSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ByteSubscriptionState.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) { "Scale attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Scale attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Byte? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByte(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(ByteSubscriptionState.Success(it)) } + val decodedValue: Byte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByte(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(ByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ByteSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1098,96 +1194,97 @@ class PressureMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1195,94 +1292,97 @@ class PressureMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1290,94 +1390,97 @@ class PressureMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1385,76 +1488,81 @@ class PressureMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1466,77 +1574,80 @@ class PressureMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1549,7 +1660,7 @@ class PressureMeasurementCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/ProxyConfigurationCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/ProxyConfigurationCluster.kt index 30c37cc34c5ccb..b08df6933b9fd1 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/ProxyConfigurationCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/ProxyConfigurationCluster.kt @@ -17,154 +17,189 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.UIntSubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState +import matter.controller.UByteSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath +import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader +import matter.tlv.TlvWriter -class ProxyConfigurationCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class GeneratedCommandListAttribute(val value: List) +class ProxyConfigurationCluster(private val controller: MatterController, private val endpointId: UShort) {class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } - - 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)) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -172,96 +207,97 @@ class ProxyConfigurationCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -269,94 +305,97 @@ class ProxyConfigurationCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -364,94 +403,97 @@ class ProxyConfigurationCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -459,76 +501,81 @@ class ProxyConfigurationCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -540,77 +587,80 @@ class ProxyConfigurationCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -623,7 +673,7 @@ class ProxyConfigurationCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/ProxyDiscoveryCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/ProxyDiscoveryCluster.kt index b3059610100e44..42d50e762f785c 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/ProxyDiscoveryCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/ProxyDiscoveryCluster.kt @@ -17,154 +17,189 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.UIntSubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState +import matter.controller.UByteSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath +import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader +import matter.tlv.TlvWriter -class ProxyDiscoveryCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class GeneratedCommandListAttribute(val value: List) +class ProxyDiscoveryCluster(private val controller: MatterController, private val endpointId: UShort) {class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } - - 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)) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -172,96 +207,97 @@ class ProxyDiscoveryCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -269,94 +305,97 @@ class ProxyDiscoveryCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -364,94 +403,97 @@ class ProxyDiscoveryCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -459,76 +501,81 @@ class ProxyDiscoveryCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -540,77 +587,80 @@ class ProxyDiscoveryCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -623,7 +673,7 @@ class ProxyDiscoveryCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/ProxyValidCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/ProxyValidCluster.kt index c615844ad6a6f3..79217bb65e2c72 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/ProxyValidCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/ProxyValidCluster.kt @@ -17,151 +17,189 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.UIntSubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState +import matter.controller.UByteSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath +import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader +import matter.tlv.TlvWriter -class ProxyValidCluster(private val controller: MatterController, private val endpointId: UShort) { - class GeneratedCommandListAttribute(val value: List) +class ProxyValidCluster(private val controller: MatterController, private val endpointId: UShort) {class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } - - 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)) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -169,96 +207,97 @@ class ProxyValidCluster(private val controller: MatterController, private val en 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -266,94 +305,97 @@ class ProxyValidCluster(private val controller: MatterController, private val en 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -361,94 +403,97 @@ class ProxyValidCluster(private val controller: MatterController, private val en 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -456,76 +501,81 @@ class ProxyValidCluster(private val controller: MatterController, private val en 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -537,77 +587,80 @@ class ProxyValidCluster(private val controller: MatterController, private val en 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -620,7 +673,7 @@ class ProxyValidCluster(private val controller: MatterController, private val en emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/PulseWidthModulationCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/PulseWidthModulationCluster.kt index e4548cf40a2413..0ae147a5169862 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/PulseWidthModulationCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/PulseWidthModulationCluster.kt @@ -17,154 +17,189 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.UIntSubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState +import matter.controller.UByteSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath +import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader +import matter.tlv.TlvWriter -class PulseWidthModulationCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class GeneratedCommandListAttribute(val value: List) +class PulseWidthModulationCluster(private val controller: MatterController, private val endpointId: UShort) {class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } - - 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)) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -172,96 +207,97 @@ class PulseWidthModulationCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -269,94 +305,97 @@ class PulseWidthModulationCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -364,94 +403,97 @@ class PulseWidthModulationCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -459,76 +501,81 @@ class PulseWidthModulationCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -540,77 +587,80 @@ class PulseWidthModulationCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -623,7 +673,7 @@ class PulseWidthModulationCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/PumpConfigurationAndControlCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/PumpConfigurationAndControlCluster.kt index a39b8376dfd650..77f27057b0a555 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/PumpConfigurationAndControlCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/PumpConfigurationAndControlCluster.kt @@ -17,1708 +17,1870 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.cluster.structs.* +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath +import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class PumpConfigurationAndControlCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class MaxPressureAttribute(val value: Short?) +class PumpConfigurationAndControlCluster(private val controller: MatterController, private val endpointId: UShort) {class MaxPressureAttribute( + val value: Short? + ) sealed class MaxPressureAttributeSubscriptionState { - data class Success(val value: Short?) : MaxPressureAttributeSubscriptionState() - + data class Success( + val value: Short? + ) : MaxPressureAttributeSubscriptionState() + data class Error(val exception: Exception) : MaxPressureAttributeSubscriptionState() - object SubscriptionEstablished : MaxPressureAttributeSubscriptionState() - } - - class MaxSpeedAttribute(val value: UShort?) + object SubscriptionEstablished : MaxPressureAttributeSubscriptionState() + } +class MaxSpeedAttribute( + val value: UShort? + ) sealed class MaxSpeedAttributeSubscriptionState { - data class Success(val value: UShort?) : MaxSpeedAttributeSubscriptionState() - + data class Success( + val value: UShort? + ) : MaxSpeedAttributeSubscriptionState() + data class Error(val exception: Exception) : MaxSpeedAttributeSubscriptionState() - object SubscriptionEstablished : MaxSpeedAttributeSubscriptionState() - } - - class MaxFlowAttribute(val value: UShort?) + object SubscriptionEstablished : MaxSpeedAttributeSubscriptionState() + } +class MaxFlowAttribute( + val value: UShort? + ) sealed class MaxFlowAttributeSubscriptionState { - data class Success(val value: UShort?) : MaxFlowAttributeSubscriptionState() - + data class Success( + val value: UShort? + ) : MaxFlowAttributeSubscriptionState() + data class Error(val exception: Exception) : MaxFlowAttributeSubscriptionState() - object SubscriptionEstablished : MaxFlowAttributeSubscriptionState() - } - - class MinConstPressureAttribute(val value: Short?) + object SubscriptionEstablished : MaxFlowAttributeSubscriptionState() + } +class MinConstPressureAttribute( + val value: Short? + ) sealed class MinConstPressureAttributeSubscriptionState { - data class Success(val value: Short?) : MinConstPressureAttributeSubscriptionState() - + data class Success( + val value: Short? + ) : MinConstPressureAttributeSubscriptionState() + data class Error(val exception: Exception) : MinConstPressureAttributeSubscriptionState() - object SubscriptionEstablished : MinConstPressureAttributeSubscriptionState() - } - - class MaxConstPressureAttribute(val value: Short?) + object SubscriptionEstablished : MinConstPressureAttributeSubscriptionState() + } +class MaxConstPressureAttribute( + val value: Short? + ) sealed class MaxConstPressureAttributeSubscriptionState { - data class Success(val value: Short?) : MaxConstPressureAttributeSubscriptionState() - + data class Success( + val value: Short? + ) : MaxConstPressureAttributeSubscriptionState() + data class Error(val exception: Exception) : MaxConstPressureAttributeSubscriptionState() - object SubscriptionEstablished : MaxConstPressureAttributeSubscriptionState() - } - - class MinCompPressureAttribute(val value: Short?) + object SubscriptionEstablished : MaxConstPressureAttributeSubscriptionState() + } +class MinCompPressureAttribute( + val value: Short? + ) sealed class MinCompPressureAttributeSubscriptionState { - data class Success(val value: Short?) : MinCompPressureAttributeSubscriptionState() - + data class Success( + val value: Short? + ) : MinCompPressureAttributeSubscriptionState() + data class Error(val exception: Exception) : MinCompPressureAttributeSubscriptionState() - object SubscriptionEstablished : MinCompPressureAttributeSubscriptionState() - } - - class MaxCompPressureAttribute(val value: Short?) + object SubscriptionEstablished : MinCompPressureAttributeSubscriptionState() + } +class MaxCompPressureAttribute( + val value: Short? + ) sealed class MaxCompPressureAttributeSubscriptionState { - data class Success(val value: Short?) : MaxCompPressureAttributeSubscriptionState() - + data class Success( + val value: Short? + ) : MaxCompPressureAttributeSubscriptionState() + data class Error(val exception: Exception) : MaxCompPressureAttributeSubscriptionState() - object SubscriptionEstablished : MaxCompPressureAttributeSubscriptionState() - } - - class MinConstSpeedAttribute(val value: UShort?) + object SubscriptionEstablished : MaxCompPressureAttributeSubscriptionState() + } +class MinConstSpeedAttribute( + val value: UShort? + ) sealed class MinConstSpeedAttributeSubscriptionState { - data class Success(val value: UShort?) : MinConstSpeedAttributeSubscriptionState() - + data class Success( + val value: UShort? + ) : MinConstSpeedAttributeSubscriptionState() + data class Error(val exception: Exception) : MinConstSpeedAttributeSubscriptionState() - object SubscriptionEstablished : MinConstSpeedAttributeSubscriptionState() - } - - class MaxConstSpeedAttribute(val value: UShort?) + object SubscriptionEstablished : MinConstSpeedAttributeSubscriptionState() + } +class MaxConstSpeedAttribute( + val value: UShort? + ) sealed class MaxConstSpeedAttributeSubscriptionState { - data class Success(val value: UShort?) : MaxConstSpeedAttributeSubscriptionState() - + data class Success( + val value: UShort? + ) : MaxConstSpeedAttributeSubscriptionState() + data class Error(val exception: Exception) : MaxConstSpeedAttributeSubscriptionState() - object SubscriptionEstablished : MaxConstSpeedAttributeSubscriptionState() - } - - class MinConstFlowAttribute(val value: UShort?) + object SubscriptionEstablished : MaxConstSpeedAttributeSubscriptionState() + } +class MinConstFlowAttribute( + val value: UShort? + ) sealed class MinConstFlowAttributeSubscriptionState { - data class Success(val value: UShort?) : MinConstFlowAttributeSubscriptionState() - + data class Success( + val value: UShort? + ) : MinConstFlowAttributeSubscriptionState() + data class Error(val exception: Exception) : MinConstFlowAttributeSubscriptionState() - object SubscriptionEstablished : MinConstFlowAttributeSubscriptionState() - } - - class MaxConstFlowAttribute(val value: UShort?) + object SubscriptionEstablished : MinConstFlowAttributeSubscriptionState() + } +class MaxConstFlowAttribute( + val value: UShort? + ) sealed class MaxConstFlowAttributeSubscriptionState { - data class Success(val value: UShort?) : MaxConstFlowAttributeSubscriptionState() - + data class Success( + val value: UShort? + ) : MaxConstFlowAttributeSubscriptionState() + data class Error(val exception: Exception) : MaxConstFlowAttributeSubscriptionState() - object SubscriptionEstablished : MaxConstFlowAttributeSubscriptionState() - } - - class MinConstTempAttribute(val value: Short?) + object SubscriptionEstablished : MaxConstFlowAttributeSubscriptionState() + } +class MinConstTempAttribute( + val value: Short? + ) sealed class MinConstTempAttributeSubscriptionState { - data class Success(val value: Short?) : MinConstTempAttributeSubscriptionState() - + data class Success( + val value: Short? + ) : MinConstTempAttributeSubscriptionState() + data class Error(val exception: Exception) : MinConstTempAttributeSubscriptionState() - object SubscriptionEstablished : MinConstTempAttributeSubscriptionState() - } - - class MaxConstTempAttribute(val value: Short?) + object SubscriptionEstablished : MinConstTempAttributeSubscriptionState() + } +class MaxConstTempAttribute( + val value: Short? + ) sealed class MaxConstTempAttributeSubscriptionState { - data class Success(val value: Short?) : MaxConstTempAttributeSubscriptionState() - + data class Success( + val value: Short? + ) : MaxConstTempAttributeSubscriptionState() + data class Error(val exception: Exception) : MaxConstTempAttributeSubscriptionState() - object SubscriptionEstablished : MaxConstTempAttributeSubscriptionState() - } - - class CapacityAttribute(val value: Short?) + object SubscriptionEstablished : MaxConstTempAttributeSubscriptionState() + } +class CapacityAttribute( + val value: Short? + ) sealed class CapacityAttributeSubscriptionState { - data class Success(val value: Short?) : CapacityAttributeSubscriptionState() - + data class Success( + val value: Short? + ) : CapacityAttributeSubscriptionState() + data class Error(val exception: Exception) : CapacityAttributeSubscriptionState() - object SubscriptionEstablished : CapacityAttributeSubscriptionState() - } - - class SpeedAttribute(val value: UShort?) + object SubscriptionEstablished : CapacityAttributeSubscriptionState() + } +class SpeedAttribute( + val value: UShort? + ) sealed class SpeedAttributeSubscriptionState { - data class Success(val value: UShort?) : SpeedAttributeSubscriptionState() - + data class Success( + val value: UShort? + ) : SpeedAttributeSubscriptionState() + data class Error(val exception: Exception) : SpeedAttributeSubscriptionState() - object SubscriptionEstablished : SpeedAttributeSubscriptionState() - } - - class LifetimeRunningHoursAttribute(val value: UInt?) + object SubscriptionEstablished : SpeedAttributeSubscriptionState() + } +class LifetimeRunningHoursAttribute( + val value: UInt? + ) sealed class LifetimeRunningHoursAttributeSubscriptionState { - data class Success(val value: UInt?) : LifetimeRunningHoursAttributeSubscriptionState() - + data class Success( + val value: UInt? + ) : LifetimeRunningHoursAttributeSubscriptionState() + data class Error(val exception: Exception) : LifetimeRunningHoursAttributeSubscriptionState() - object SubscriptionEstablished : LifetimeRunningHoursAttributeSubscriptionState() - } - - class PowerAttribute(val value: UInt?) + object SubscriptionEstablished : LifetimeRunningHoursAttributeSubscriptionState() + } +class PowerAttribute( + val value: UInt? + ) sealed class PowerAttributeSubscriptionState { - data class Success(val value: UInt?) : PowerAttributeSubscriptionState() - + data class Success( + val value: UInt? + ) : PowerAttributeSubscriptionState() + data class Error(val exception: Exception) : PowerAttributeSubscriptionState() - object SubscriptionEstablished : PowerAttributeSubscriptionState() - } - - class LifetimeEnergyConsumedAttribute(val value: UInt?) + object SubscriptionEstablished : PowerAttributeSubscriptionState() + } +class LifetimeEnergyConsumedAttribute( + val value: UInt? + ) sealed class LifetimeEnergyConsumedAttributeSubscriptionState { - data class Success(val value: UInt?) : LifetimeEnergyConsumedAttributeSubscriptionState() - + data class Success( + val value: UInt? + ) : LifetimeEnergyConsumedAttributeSubscriptionState() + data class Error(val exception: Exception) : LifetimeEnergyConsumedAttributeSubscriptionState() - object SubscriptionEstablished : LifetimeEnergyConsumedAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : LifetimeEnergyConsumedAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } - - suspend fun readMaxPressureAttribute(): MaxPressureAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } +suspend fun readMaxPressureAttribute(): MaxPressureAttribute {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}") - } + 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) { "Maxpressure attribute not found in response" } + } + + requireNotNull(attributeData) { + "Maxpressure attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (!tlvReader.isNull()) { - tlvReader.getShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Short? = if (!tlvReader.isNull()) { + tlvReader.getShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MaxPressureAttribute(decodedValue) } suspend fun subscribeMaxPressureAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MaxPressureAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MaxPressureAttributeSubscriptionState.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) { "Maxpressure attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Maxpressure attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (!tlvReader.isNull()) { - tlvReader.getShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Short? = if (!tlvReader.isNull()) { + tlvReader.getShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(MaxPressureAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(MaxPressureAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MaxPressureAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readMaxSpeedAttribute(): MaxSpeedAttribute {val ATTRIBUTE_ID: UInt = 1u - suspend fun readMaxSpeedAttribute(): MaxSpeedAttribute { - 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 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}") - } + 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) { "Maxspeed attribute not found in response" } + } + + requireNotNull(attributeData) { + "Maxspeed attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = - if (!tlvReader.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MaxSpeedAttribute(decodedValue) } suspend fun subscribeMaxSpeedAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MaxSpeedAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MaxSpeedAttributeSubscriptionState.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) { "Maxspeed attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Maxspeed 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.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(MaxSpeedAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(MaxSpeedAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MaxSpeedAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readMaxFlowAttribute(): MaxFlowAttribute {val ATTRIBUTE_ID: UInt = 2u - suspend fun readMaxFlowAttribute(): MaxFlowAttribute { - 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 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}") - } + 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) { "Maxflow attribute not found in response" } + } + + requireNotNull(attributeData) { + "Maxflow attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = - if (!tlvReader.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MaxFlowAttribute(decodedValue) } suspend fun subscribeMaxFlowAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MaxFlowAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MaxFlowAttributeSubscriptionState.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) { "Maxflow attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Maxflow 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.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(MaxFlowAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(MaxFlowAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MaxFlowAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readMinConstPressureAttribute(): MinConstPressureAttribute {val ATTRIBUTE_ID: UInt = 3u - suspend fun readMinConstPressureAttribute(): MinConstPressureAttribute { - 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 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}") - } + 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) { "Minconstpressure attribute not found in response" } + } + + requireNotNull(attributeData) { + "Minconstpressure attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Short? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MinConstPressureAttribute(decodedValue) } suspend fun subscribeMinConstPressureAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MinConstPressureAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MinConstPressureAttributeSubscriptionState.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) { - "Minconstpressure attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Minconstpressure attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MinConstPressureAttributeSubscriptionState.Success(it)) } + val decodedValue: Short? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MinConstPressureAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MinConstPressureAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readMaxConstPressureAttribute(): MaxConstPressureAttribute {val ATTRIBUTE_ID: UInt = 4u - suspend fun readMaxConstPressureAttribute(): MaxConstPressureAttribute { - 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 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}") - } + 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) { "Maxconstpressure attribute not found in response" } + } + + requireNotNull(attributeData) { + "Maxconstpressure attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Short? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MaxConstPressureAttribute(decodedValue) } suspend fun subscribeMaxConstPressureAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MaxConstPressureAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MaxConstPressureAttributeSubscriptionState.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) { - "Maxconstpressure attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Maxconstpressure attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MaxConstPressureAttributeSubscriptionState.Success(it)) } + val decodedValue: Short? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MaxConstPressureAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MaxConstPressureAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readMinCompPressureAttribute(): MinCompPressureAttribute {val ATTRIBUTE_ID: UInt = 5u - suspend fun readMinCompPressureAttribute(): MinCompPressureAttribute { - 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 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}") - } + 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) { "Mincomppressure attribute not found in response" } + } + + requireNotNull(attributeData) { + "Mincomppressure attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Short? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MinCompPressureAttribute(decodedValue) } suspend fun subscribeMinCompPressureAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MinCompPressureAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MinCompPressureAttributeSubscriptionState.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) { - "Mincomppressure attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Mincomppressure attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MinCompPressureAttributeSubscriptionState.Success(it)) } + val decodedValue: Short? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MinCompPressureAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MinCompPressureAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readMaxCompPressureAttribute(): MaxCompPressureAttribute {val ATTRIBUTE_ID: UInt = 6u - suspend fun readMaxCompPressureAttribute(): MaxCompPressureAttribute { - 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 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}") - } + 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) { "Maxcomppressure attribute not found in response" } + } + + requireNotNull(attributeData) { + "Maxcomppressure attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Short? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MaxCompPressureAttribute(decodedValue) } suspend fun subscribeMaxCompPressureAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MaxCompPressureAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MaxCompPressureAttributeSubscriptionState.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) { - "Maxcomppressure attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Maxcomppressure attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MaxCompPressureAttributeSubscriptionState.Success(it)) } + val decodedValue: Short? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MaxCompPressureAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MaxCompPressureAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readMinConstSpeedAttribute(): MinConstSpeedAttribute {val ATTRIBUTE_ID: UInt = 7u - suspend fun readMinConstSpeedAttribute(): MinConstSpeedAttribute { - 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 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}") - } + 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) { "Minconstspeed attribute not found in response" } + } + + requireNotNull(attributeData) { + "Minconstspeed attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MinConstSpeedAttribute(decodedValue) } suspend fun subscribeMinConstSpeedAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MinConstSpeedAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MinConstSpeedAttributeSubscriptionState.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) { "Minconstspeed attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Minconstspeed 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MinConstSpeedAttributeSubscriptionState.Success(it)) } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MinConstSpeedAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MinConstSpeedAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readMaxConstSpeedAttribute(): MaxConstSpeedAttribute {val ATTRIBUTE_ID: UInt = 8u - suspend fun readMaxConstSpeedAttribute(): MaxConstSpeedAttribute { - val ATTRIBUTE_ID: UInt = 8u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Maxconstspeed attribute not found in response" } + } + + requireNotNull(attributeData) { + "Maxconstspeed attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MaxConstSpeedAttribute(decodedValue) } suspend fun subscribeMaxConstSpeedAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MaxConstSpeedAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MaxConstSpeedAttributeSubscriptionState.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) { "Maxconstspeed attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Maxconstspeed 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MaxConstSpeedAttributeSubscriptionState.Success(it)) } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MaxConstSpeedAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MaxConstSpeedAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readMinConstFlowAttribute(): MinConstFlowAttribute {val ATTRIBUTE_ID: UInt = 9u - suspend fun readMinConstFlowAttribute(): MinConstFlowAttribute { - val ATTRIBUTE_ID: UInt = 9u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Minconstflow attribute not found in response" } + } + + requireNotNull(attributeData) { + "Minconstflow attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MinConstFlowAttribute(decodedValue) } suspend fun subscribeMinConstFlowAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MinConstFlowAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MinConstFlowAttributeSubscriptionState.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) { "Minconstflow attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Minconstflow 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MinConstFlowAttributeSubscriptionState.Success(it)) } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MinConstFlowAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MinConstFlowAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readMaxConstFlowAttribute(): MaxConstFlowAttribute {val ATTRIBUTE_ID: UInt = 10u - suspend fun readMaxConstFlowAttribute(): MaxConstFlowAttribute { - val ATTRIBUTE_ID: UInt = 10u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Maxconstflow attribute not found in response" } + } + + requireNotNull(attributeData) { + "Maxconstflow attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MaxConstFlowAttribute(decodedValue) } suspend fun subscribeMaxConstFlowAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MaxConstFlowAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MaxConstFlowAttributeSubscriptionState.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) { "Maxconstflow attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Maxconstflow 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MaxConstFlowAttributeSubscriptionState.Success(it)) } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MaxConstFlowAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MaxConstFlowAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readMinConstTempAttribute(): MinConstTempAttribute {val ATTRIBUTE_ID: UInt = 11u - suspend fun readMinConstTempAttribute(): MinConstTempAttribute { - val ATTRIBUTE_ID: UInt = 11u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Minconsttemp attribute not found in response" } + } + + requireNotNull(attributeData) { + "Minconsttemp attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Short? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MinConstTempAttribute(decodedValue) } suspend fun subscribeMinConstTempAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 11u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MinConstTempAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MinConstTempAttributeSubscriptionState.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) { "Minconsttemp attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Minconsttemp attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MinConstTempAttributeSubscriptionState.Success(it)) } + val decodedValue: Short? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MinConstTempAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MinConstTempAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readMaxConstTempAttribute(): MaxConstTempAttribute {val ATTRIBUTE_ID: UInt = 12u - suspend fun readMaxConstTempAttribute(): MaxConstTempAttribute { - val ATTRIBUTE_ID: UInt = 12u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Maxconsttemp attribute not found in response" } + } + + requireNotNull(attributeData) { + "Maxconsttemp attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Short? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MaxConstTempAttribute(decodedValue) } suspend fun subscribeMaxConstTempAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 12u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MaxConstTempAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MaxConstTempAttributeSubscriptionState.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) { "Maxconsttemp attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Maxconsttemp attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MaxConstTempAttributeSubscriptionState.Success(it)) } + val decodedValue: Short? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MaxConstTempAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MaxConstTempAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readPumpStatusAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 16u - suspend fun readPumpStatusAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 16u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Pumpstatus attribute not found in response" } + } + + requireNotNull(attributeData) { + "Pumpstatus 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribePumpStatusAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Pumpstatus attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Pumpstatus 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } - } - - suspend fun readEffectiveOperationModeAttribute(): UByte { - val ATTRIBUTE_ID: UInt = 17u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + } + } +suspend fun readEffectiveOperationModeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 17u - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Effectiveoperationmode attribute not found in response" } + } + + requireNotNull(attributeData) { + "Effectiveoperationmode 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 subscribeEffectiveOperationModeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 17u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Effectiveoperationmode attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Effectiveoperationmode attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -1731,77 +1893,80 @@ class PumpConfigurationAndControlCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readEffectiveControlModeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 18u - suspend fun readEffectiveControlModeAttribute(): UByte { - val ATTRIBUTE_ID: UInt = 18u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Effectivecontrolmode attribute not found in response" } + } + + requireNotNull(attributeData) { + "Effectivecontrolmode 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 subscribeEffectiveControlModeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 18u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Effectivecontrolmode attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Effectivecontrolmode attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -1814,261 +1979,283 @@ class PumpConfigurationAndControlCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readCapacityAttribute(): CapacityAttribute {val ATTRIBUTE_ID: UInt = 19u - suspend fun readCapacityAttribute(): CapacityAttribute { - val ATTRIBUTE_ID: UInt = 19u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Capacity attribute not found in response" } + } + + requireNotNull(attributeData) { + "Capacity attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (!tlvReader.isNull()) { - tlvReader.getShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Short? = if (!tlvReader.isNull()) { + tlvReader.getShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return CapacityAttribute(decodedValue) } suspend fun subscribeCapacityAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 19u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - CapacityAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(CapacityAttributeSubscriptionState.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) { "Capacity attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Capacity attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (!tlvReader.isNull()) { - tlvReader.getShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Short? = if (!tlvReader.isNull()) { + tlvReader.getShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(CapacityAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(CapacityAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(CapacityAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readSpeedAttribute(): SpeedAttribute {val ATTRIBUTE_ID: UInt = 20u - suspend fun readSpeedAttribute(): SpeedAttribute { - val ATTRIBUTE_ID: UInt = 20u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Speed attribute not found in response" } + } + + requireNotNull(attributeData) { + "Speed attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return SpeedAttribute(decodedValue) } suspend fun subscribeSpeedAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 20u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - SpeedAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(SpeedAttributeSubscriptionState.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) { "Speed attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Speed 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(SpeedAttributeSubscriptionState.Success(it)) } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(SpeedAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(SpeedAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readLifetimeRunningHoursAttribute(): LifetimeRunningHoursAttribute {val ATTRIBUTE_ID: UInt = 21u - suspend fun readLifetimeRunningHoursAttribute(): LifetimeRunningHoursAttribute { - val ATTRIBUTE_ID: UInt = 21u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Lifetimerunninghours attribute not found in response" } + } + + requireNotNull(attributeData) { + "Lifetimerunninghours attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return LifetimeRunningHoursAttribute(decodedValue) } - suspend fun writeLifetimeRunningHoursAttribute(value: UInt, timedWriteTimeout: Duration? = null) { + suspend fun writeLifetimeRunningHoursAttribute( + value: UInt, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 21u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -2089,233 +2276,244 @@ class PumpConfigurationAndControlCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeLifetimeRunningHoursAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 21u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - LifetimeRunningHoursAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(LifetimeRunningHoursAttributeSubscriptionState.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) { - "Lifetimerunninghours attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Lifetimerunninghours attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(LifetimeRunningHoursAttributeSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(LifetimeRunningHoursAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(LifetimeRunningHoursAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readPowerAttribute(): PowerAttribute {val ATTRIBUTE_ID: UInt = 22u - suspend fun readPowerAttribute(): PowerAttribute { - val ATTRIBUTE_ID: UInt = 22u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Power attribute not found in response" } + } + + requireNotNull(attributeData) { + "Power attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return PowerAttribute(decodedValue) } suspend fun subscribePowerAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 22u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - PowerAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(PowerAttributeSubscriptionState.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) { "Power attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Power attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(PowerAttributeSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(PowerAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(PowerAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readLifetimeEnergyConsumedAttribute(): LifetimeEnergyConsumedAttribute {val ATTRIBUTE_ID: UInt = 23u - suspend fun readLifetimeEnergyConsumedAttribute(): LifetimeEnergyConsumedAttribute { - val ATTRIBUTE_ID: UInt = 23u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Lifetimeenergyconsumed attribute not found in response" } + } + + requireNotNull(attributeData) { + "Lifetimeenergyconsumed attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return LifetimeEnergyConsumedAttribute(decodedValue) } suspend fun writeLifetimeEnergyConsumedAttribute( value: UInt, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 23u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -2336,119 +2534,128 @@ class PumpConfigurationAndControlCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeLifetimeEnergyConsumedAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 23u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - LifetimeEnergyConsumedAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(LifetimeEnergyConsumedAttributeSubscriptionState.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) { - "Lifetimeenergyconsumed attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Lifetimeenergyconsumed attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(LifetimeEnergyConsumedAttributeSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(LifetimeEnergyConsumedAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(LifetimeEnergyConsumedAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readOperationModeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 32u - suspend fun readOperationModeAttribute(): UByte { - val ATTRIBUTE_ID: UInt = 32u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Operationmode attribute not found in response" } + } + + requireNotNull(attributeData) { + "Operationmode 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 writeOperationModeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeOperationModeAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 32u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -2469,45 +2676,43 @@ class PumpConfigurationAndControlCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeOperationModeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 32u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Operationmode attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Operationmode attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -2519,62 +2724,72 @@ class PumpConfigurationAndControlCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readControlModeAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 33u - suspend fun readControlModeAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 33u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Controlmode attribute not found in response" } + } + + requireNotNull(attributeData) { + "Controlmode 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } - suspend fun writeControlModeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeControlModeAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 33u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -2595,151 +2810,152 @@ class PumpConfigurationAndControlCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeControlModeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 33u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Controlmode attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Controlmode 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65528u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -2747,96 +2963,97 @@ class PumpConfigurationAndControlCluster( emit(GeneratedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65529u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -2844,94 +3061,97 @@ class PumpConfigurationAndControlCluster( emit(AcceptedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt = 65530u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -2939,94 +3159,97 @@ class PumpConfigurationAndControlCluster( emit(EventListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ID: UInt = 65531u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -3034,76 +3257,81 @@ class PumpConfigurationAndControlCluster( emit(AttributeListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u - 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 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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -3115,77 +3343,80 @@ class PumpConfigurationAndControlCluster( emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 65533u - 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 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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -3198,7 +3429,7 @@ class PumpConfigurationAndControlCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/RadonConcentrationMeasurementCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/RadonConcentrationMeasurementCluster.kt index 0f8a0720b9fd89..05e3ef50cbd96d 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/RadonConcentrationMeasurementCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/RadonConcentrationMeasurementCluster.kt @@ -17,1273 +17,1371 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.FloatSubscriptionState import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath +import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader +import matter.tlv.TlvWriter -class RadonConcentrationMeasurementCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class MeasuredValueAttribute(val value: Float?) +class RadonConcentrationMeasurementCluster(private val controller: MatterController, private val endpointId: UShort) {class MeasuredValueAttribute( + val value: Float? + ) sealed class MeasuredValueAttributeSubscriptionState { - data class Success(val value: Float?) : MeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Float? + ) : MeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() - } - - class MinMeasuredValueAttribute(val value: Float?) + object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() + } +class MinMeasuredValueAttribute( + val value: Float? + ) sealed class MinMeasuredValueAttributeSubscriptionState { - data class Success(val value: Float?) : MinMeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Float? + ) : MinMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MinMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() - } - - class MaxMeasuredValueAttribute(val value: Float?) + object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() + } +class MaxMeasuredValueAttribute( + val value: Float? + ) sealed class MaxMeasuredValueAttributeSubscriptionState { - data class Success(val value: Float?) : MaxMeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Float? + ) : MaxMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MaxMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() - } - - class PeakMeasuredValueAttribute(val value: Float?) + object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() + } +class PeakMeasuredValueAttribute( + val value: Float? + ) sealed class PeakMeasuredValueAttributeSubscriptionState { - data class Success(val value: Float?) : PeakMeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Float? + ) : PeakMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : PeakMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : PeakMeasuredValueAttributeSubscriptionState() - } - - class AverageMeasuredValueAttribute(val value: Float?) + object SubscriptionEstablished : PeakMeasuredValueAttributeSubscriptionState() + } +class AverageMeasuredValueAttribute( + val value: Float? + ) sealed class AverageMeasuredValueAttributeSubscriptionState { - data class Success(val value: Float?) : AverageMeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Float? + ) : AverageMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : AverageMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : AverageMeasuredValueAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : AverageMeasuredValueAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } - - suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } +suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute {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}") - } + 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) { "Measuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Measuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MeasuredValueAttribute(decodedValue) } suspend fun subscribeMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MeasuredValueAttributeSubscriptionState.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) { "Measuredvalue attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Measuredvalue attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute {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}") - } + 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) { "Minmeasuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Minmeasuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MinMeasuredValueAttribute(decodedValue) } suspend fun subscribeMinMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MinMeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MinMeasuredValueAttributeSubscriptionState.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) { - "Minmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Minmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MinMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute {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}") - } + 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) { "Maxmeasuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Maxmeasuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MaxMeasuredValueAttribute(decodedValue) } suspend fun subscribeMaxMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MaxMeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MaxMeasuredValueAttributeSubscriptionState.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) { - "Maxmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Maxmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MaxMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readPeakMeasuredValueAttribute(): PeakMeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readPeakMeasuredValueAttribute(): PeakMeasuredValueAttribute {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}") - } + 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) { "Peakmeasuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Peakmeasuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return PeakMeasuredValueAttribute(decodedValue) } suspend fun subscribePeakMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - PeakMeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(PeakMeasuredValueAttributeSubscriptionState.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) { - "Peakmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Peakmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(PeakMeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(PeakMeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(PeakMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readPeakMeasuredValueWindowAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 4u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readPeakMeasuredValueWindowAttribute(): UInt? {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}") - } + 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) { "Peakmeasuredvaluewindow attribute not found in response" } + } + + requireNotNull(attributeData) { + "Peakmeasuredvaluewindow attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribePeakMeasuredValueWindowAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Peakmeasuredvaluewindow attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Peakmeasuredvaluewindow attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readAverageMeasuredValueAttribute(): AverageMeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 5u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readAverageMeasuredValueAttribute(): AverageMeasuredValueAttribute {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}") - } + 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) { "Averagemeasuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Averagemeasuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return AverageMeasuredValueAttribute(decodedValue) } suspend fun subscribeAverageMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - AverageMeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(AverageMeasuredValueAttributeSubscriptionState.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) { - "Averagemeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Averagemeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(AverageMeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(AverageMeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(AverageMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readAverageMeasuredValueWindowAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 6u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readAverageMeasuredValueWindowAttribute(): UInt? {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}") - } + 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) { "Averagemeasuredvaluewindow attribute not found in response" } + } + + requireNotNull(attributeData) { + "Averagemeasuredvaluewindow attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeAverageMeasuredValueWindowAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Averagemeasuredvaluewindow attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Averagemeasuredvaluewindow attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readUncertaintyAttribute(): Float? { - val ATTRIBUTE_ID: UInt = 7u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readUncertaintyAttribute(): Float? {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}") - } + 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) { "Uncertainty attribute not found in response" } + } + + requireNotNull(attributeData) { + "Uncertainty attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } + val decodedValue: Float? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeUncertaintyAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - FloatSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(FloatSubscriptionState.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) { "Uncertainty attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Uncertainty attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(FloatSubscriptionState.Success(it)) } + val decodedValue: Float? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(FloatSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(FloatSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readMeasurementUnitAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 8u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMeasurementUnitAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 8u + + 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}") - } + 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) { "Measurementunit attribute not found in response" } + } + + requireNotNull(attributeData) { + "Measurementunit 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeMeasurementUnitAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Measurementunit attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Measurementunit 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)) } + 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 readMeasurementMediumAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 9u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMeasurementMediumAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 9u + + 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}") - } + 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) { "Measurementmedium attribute not found in response" } + } + + requireNotNull(attributeData) { + "Measurementmedium 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeMeasurementMediumAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Measurementmedium attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Measurementmedium 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)) } + 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 readLevelValueAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 10u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readLevelValueAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 10u + + 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}") - } + 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) { "Levelvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Levelvalue 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeLevelValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Levelvalue attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Levelvalue 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)) } + 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 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1291,96 +1389,97 @@ class RadonConcentrationMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1388,94 +1487,97 @@ class RadonConcentrationMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1483,94 +1585,97 @@ class RadonConcentrationMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1578,76 +1683,81 @@ class RadonConcentrationMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1659,77 +1769,80 @@ class RadonConcentrationMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1742,7 +1855,7 @@ class RadonConcentrationMeasurementCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/RefrigeratorAlarmCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/RefrigeratorAlarmCluster.kt index a25f0f3349b6fb..fc8ca10f3d18d2 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/RefrigeratorAlarmCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/RefrigeratorAlarmCluster.kt @@ -17,134 +17,173 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.UIntSubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState +import matter.controller.UByteSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath +import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader +import matter.tlv.TlvWriter -class RefrigeratorAlarmCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class GeneratedCommandListAttribute(val value: List) +class RefrigeratorAlarmCluster(private val controller: MatterController, private val endpointId: UShort) {class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } - - suspend fun readMaskAttribute(): UInt { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } +suspend fun readMaskAttribute(): UInt {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}") - } + 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) { "Mask attribute not found in response" } + } + + requireNotNull(attributeData) { + "Mask 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 subscribeMaskAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Mask attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Mask attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -156,76 +195,81 @@ class RefrigeratorAlarmCluster( emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readStateAttribute(): UInt { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readStateAttribute(): UInt {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}") - } + 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) { "State attribute not found in response" } + } + + requireNotNull(attributeData) { + "State 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 subscribeStateAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "State attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "State attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -237,76 +281,81 @@ class RefrigeratorAlarmCluster( emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readSupportedAttribute(): UInt { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readSupportedAttribute(): UInt {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}") - } + 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) { "Supported attribute not found in response" } + } + + requireNotNull(attributeData) { + "Supported 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 subscribeSupportedAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Supported attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Supported attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -318,96 +367,97 @@ class RefrigeratorAlarmCluster( emit(UIntSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -415,96 +465,97 @@ class RefrigeratorAlarmCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -512,94 +563,97 @@ class RefrigeratorAlarmCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -607,94 +661,97 @@ class RefrigeratorAlarmCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -702,76 +759,81 @@ class RefrigeratorAlarmCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -783,77 +845,80 @@ class RefrigeratorAlarmCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -866,7 +931,7 @@ class RefrigeratorAlarmCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/RefrigeratorAndTemperatureControlledCabinetModeCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/RefrigeratorAndTemperatureControlledCabinetModeCluster.kt index 4dae3004f2a277..ce6565c3397935 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/RefrigeratorAndTemperatureControlledCabinetModeCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/RefrigeratorAndTemperatureControlledCabinetModeCluster.kt @@ -17,130 +17,161 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.cluster.structs.* +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class RefrigeratorAndTemperatureControlledCabinetModeCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class ChangeToModeResponse(val status: UByte, val statusText: String?) - - class SupportedModesAttribute( +class RefrigeratorAndTemperatureControlledCabinetModeCluster(private val controller: MatterController, private val endpointId: UShort) { + class ChangeToModeResponse( + val status: UByte, + val statusText: String? + ) +class SupportedModesAttribute( val value: List ) sealed class SupportedModesAttributeSubscriptionState { data class Success( - val value: List + val value: List ) : SupportedModesAttributeSubscriptionState() - + data class Error(val exception: Exception) : SupportedModesAttributeSubscriptionState() - object SubscriptionEstablished : SupportedModesAttributeSubscriptionState() - } - - class StartUpModeAttribute(val value: UByte?) + object SubscriptionEstablished : SupportedModesAttributeSubscriptionState() + } +class StartUpModeAttribute( + val value: UByte? + ) sealed class StartUpModeAttributeSubscriptionState { - data class Success(val value: UByte?) : StartUpModeAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : StartUpModeAttributeSubscriptionState() + data class Error(val exception: Exception) : StartUpModeAttributeSubscriptionState() - object SubscriptionEstablished : StartUpModeAttributeSubscriptionState() - } - - class OnModeAttribute(val value: UByte?) + object SubscriptionEstablished : StartUpModeAttributeSubscriptionState() + } +class OnModeAttribute( + val value: UByte? + ) sealed class OnModeAttributeSubscriptionState { - data class Success(val value: UByte?) : OnModeAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : OnModeAttributeSubscriptionState() + data class Error(val exception: Exception) : OnModeAttributeSubscriptionState() - object SubscriptionEstablished : OnModeAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : OnModeAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun changeToMode( - newMode: UByte, - timedInvokeTimeout: Duration? = null, - ): ChangeToModeResponse { + suspend fun changeToMode(newMode: UByte + ,timedInvokeTimeout: Duration? = null): ChangeToModeResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_NEW_MODE_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_NEW_MODE_REQ), newMode) + tlvWriter.put(ContextSpecificTag(TAG_NEW_MODE_REQ), newMode) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -150,141 +181,140 @@ class RefrigeratorAndTemperatureControlledCabinetModeCluster( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_STATUS_TEXT: Int = 1 var statusText_decoded: String? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_STATUS)) { - status_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_STATUS_TEXT)) { - statusText_decoded = + + if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_STATUS_TEXT)) {statusText_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - } - } else { + tlvReader.getString(tag) + } else { + null + } + }} + + + else { tlvReader.skipElement() } } + + if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } + + + tlvReader.exitContainer() - return ChangeToModeResponse(status_decoded, statusText_decoded) + return ChangeToModeResponse( + status_decoded, + statusText_decoded + ) } - - suspend fun readSupportedModesAttribute(): SupportedModesAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readSupportedModesAttribute(): SupportedModesAttribute {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}") - } + 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) { "Supportedmodes attribute not found in response" } + } + + requireNotNull(attributeData) { + "Supportedmodes 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( - RefrigeratorAndTemperatureControlledCabinetModeClusterModeOptionStruct.fromTlv( - AnonymousTag, - tlvReader, - ) - ) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(RefrigeratorAndTemperatureControlledCabinetModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + return SupportedModesAttribute(decodedValue) } suspend fun subscribeSupportedModesAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - SupportedModesAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(SupportedModesAttributeSubscriptionState.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) { - "Supportedmodes attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Supportedmodes 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( - RefrigeratorAndTemperatureControlledCabinetModeClusterModeOptionStruct.fromTlv( - AnonymousTag, - tlvReader, - ) - ) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(RefrigeratorAndTemperatureControlledCabinetModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(SupportedModesAttributeSubscriptionState.Success(decodedValue)) } @@ -292,76 +322,81 @@ class RefrigeratorAndTemperatureControlledCabinetModeCluster( emit(SupportedModesAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readCurrentModeAttribute(): 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)) - +suspend fun readCurrentModeAttribute(): 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}") - } + 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) { "Currentmode attribute not found in response" } + } + + requireNotNull(attributeData) { + "Currentmode 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 subscribeCurrentModeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Currentmode attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Currentmode attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -373,67 +408,77 @@ class RefrigeratorAndTemperatureControlledCabinetModeCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readStartUpModeAttribute(): StartUpModeAttribute { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readStartUpModeAttribute(): StartUpModeAttribute {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}") - } + 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) { "Startupmode attribute not found in response" } + } + + requireNotNull(attributeData) { + "Startupmode attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return StartUpModeAttribute(decodedValue) } - suspend fun writeStartUpModeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeStartUpModeAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 2u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -454,127 +499,137 @@ class RefrigeratorAndTemperatureControlledCabinetModeCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeStartUpModeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StartUpModeAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StartUpModeAttributeSubscriptionState.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) { "Startupmode attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Startupmode 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(StartUpModeAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(StartUpModeAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(StartUpModeAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readOnModeAttribute(): OnModeAttribute { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readOnModeAttribute(): OnModeAttribute {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}") - } + 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) { "Onmode attribute not found in response" } + } + + requireNotNull(attributeData) { + "Onmode attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return OnModeAttribute(decodedValue) } - suspend fun writeOnModeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeOnModeAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 3u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -595,156 +650,157 @@ class RefrigeratorAndTemperatureControlledCabinetModeCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeOnModeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - OnModeAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(OnModeAttributeSubscriptionState.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) { "Onmode attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Onmode 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(OnModeAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(OnModeAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(OnModeAttributeSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -752,96 +808,97 @@ class RefrigeratorAndTemperatureControlledCabinetModeCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -849,94 +906,97 @@ class RefrigeratorAndTemperatureControlledCabinetModeCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -944,94 +1004,97 @@ class RefrigeratorAndTemperatureControlledCabinetModeCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1039,76 +1102,81 @@ class RefrigeratorAndTemperatureControlledCabinetModeCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1120,77 +1188,80 @@ class RefrigeratorAndTemperatureControlledCabinetModeCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1203,12 +1274,11 @@ class RefrigeratorAndTemperatureControlledCabinetModeCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { - private val logger = - Logger.getLogger(RefrigeratorAndTemperatureControlledCabinetModeCluster::class.java.name) + private val logger = Logger.getLogger(RefrigeratorAndTemperatureControlledCabinetModeCluster::class.java.name) const val CLUSTER_ID: UInt = 82u } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/RelativeHumidityMeasurementCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/RelativeHumidityMeasurementCluster.kt index 94ed23289669b2..c7f6f1f5cc66a8 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/RelativeHumidityMeasurementCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/RelativeHumidityMeasurementCluster.kt @@ -17,558 +17,622 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.UIntSubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState +import matter.controller.UByteSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath +import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader +import matter.tlv.TlvWriter -class RelativeHumidityMeasurementCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class MeasuredValueAttribute(val value: UShort?) +class RelativeHumidityMeasurementCluster(private val controller: MatterController, private val endpointId: UShort) {class MeasuredValueAttribute( + val value: UShort? + ) sealed class MeasuredValueAttributeSubscriptionState { - data class Success(val value: UShort?) : MeasuredValueAttributeSubscriptionState() - + data class Success( + val value: UShort? + ) : MeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() - } - - class MinMeasuredValueAttribute(val value: UShort?) + object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() + } +class MinMeasuredValueAttribute( + val value: UShort? + ) sealed class MinMeasuredValueAttributeSubscriptionState { - data class Success(val value: UShort?) : MinMeasuredValueAttributeSubscriptionState() - + data class Success( + val value: UShort? + ) : MinMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MinMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() - } - - class MaxMeasuredValueAttribute(val value: UShort?) + object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() + } +class MaxMeasuredValueAttribute( + val value: UShort? + ) sealed class MaxMeasuredValueAttributeSubscriptionState { - data class Success(val value: UShort?) : MaxMeasuredValueAttributeSubscriptionState() - + data class Success( + val value: UShort? + ) : MaxMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MaxMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } - - suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } +suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute {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}") - } + 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) { "Measuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Measuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = - if (!tlvReader.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MeasuredValueAttribute(decodedValue) } suspend fun subscribeMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MeasuredValueAttributeSubscriptionState.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) { "Measuredvalue attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Measuredvalue 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.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute {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}") - } + 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) { "Minmeasuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Minmeasuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = - if (!tlvReader.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MinMeasuredValueAttribute(decodedValue) } suspend fun subscribeMinMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MinMeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MinMeasuredValueAttributeSubscriptionState.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) { - "Minmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Minmeasuredvalue 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.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MinMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute {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}") - } + 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) { "Maxmeasuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Maxmeasuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = - if (!tlvReader.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MaxMeasuredValueAttribute(decodedValue) } suspend fun subscribeMaxMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MaxMeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MaxMeasuredValueAttributeSubscriptionState.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) { - "Maxmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Maxmeasuredvalue 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.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MaxMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readToleranceAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readToleranceAttribute(): UShort? {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}") - } + 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) { "Tolerance attribute not found in response" } + } + + requireNotNull(attributeData) { + "Tolerance 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeToleranceAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Tolerance attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Tolerance 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)) } + 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 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -576,96 +640,97 @@ class RelativeHumidityMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -673,94 +738,97 @@ class RelativeHumidityMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -768,94 +836,97 @@ class RelativeHumidityMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -863,76 +934,81 @@ class RelativeHumidityMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -944,77 +1020,80 @@ class RelativeHumidityMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1027,7 +1106,7 @@ class RelativeHumidityMeasurementCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/RvcCleanModeCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/RvcCleanModeCluster.kt index af5017f099437a..7ac51acbac5c46 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/RvcCleanModeCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/RvcCleanModeCluster.kt @@ -17,104 +17,135 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class RvcCleanModeCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class ChangeToModeResponse(val status: UByte, val statusText: String?) - - class SupportedModesAttribute(val value: List) +class RvcCleanModeCluster(private val controller: MatterController, private val endpointId: UShort) { + class ChangeToModeResponse( + val status: UByte, + val statusText: String? + ) +class SupportedModesAttribute( + val value: List + ) sealed class SupportedModesAttributeSubscriptionState { - data class Success(val value: List) : - SupportedModesAttributeSubscriptionState() - + data class Success( + val value: List + ) : SupportedModesAttributeSubscriptionState() + data class Error(val exception: Exception) : SupportedModesAttributeSubscriptionState() - object SubscriptionEstablished : SupportedModesAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : SupportedModesAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun changeToMode( - newMode: UByte, - timedInvokeTimeout: Duration? = null, - ): ChangeToModeResponse { + suspend fun changeToMode(newMode: UByte + ,timedInvokeTimeout: Duration? = null): ChangeToModeResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_NEW_MODE_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_NEW_MODE_REQ), newMode) + tlvWriter.put(ContextSpecificTag(TAG_NEW_MODE_REQ), newMode) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -124,130 +155,140 @@ class RvcCleanModeCluster( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_STATUS_TEXT: Int = 1 var statusText_decoded: String? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_STATUS)) { - status_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_STATUS_TEXT)) { - statusText_decoded = + + if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_STATUS_TEXT)) {statusText_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - } - } else { + tlvReader.getString(tag) + } else { + null + } + }} + + + else { tlvReader.skipElement() } } + + if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } + + + tlvReader.exitContainer() - return ChangeToModeResponse(status_decoded, statusText_decoded) + return ChangeToModeResponse( + status_decoded, + statusText_decoded + ) } - - suspend fun readSupportedModesAttribute(): SupportedModesAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readSupportedModesAttribute(): SupportedModesAttribute {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}") - } + 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) { "Supportedmodes attribute not found in response" } + } + + requireNotNull(attributeData) { + "Supportedmodes 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(RvcCleanModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(RvcCleanModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + return SupportedModesAttribute(decodedValue) } suspend fun subscribeSupportedModesAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - SupportedModesAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(SupportedModesAttributeSubscriptionState.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) { - "Supportedmodes attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Supportedmodes 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(RvcCleanModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(RvcCleanModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(SupportedModesAttributeSubscriptionState.Success(decodedValue)) } @@ -255,76 +296,81 @@ class RvcCleanModeCluster( emit(SupportedModesAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readCurrentModeAttribute(): 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)) - +suspend fun readCurrentModeAttribute(): 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}") - } + 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) { "Currentmode attribute not found in response" } + } + + requireNotNull(attributeData) { + "Currentmode 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 subscribeCurrentModeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Currentmode attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Currentmode attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -336,96 +382,97 @@ class RvcCleanModeCluster( emit(UByteSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -433,96 +480,97 @@ class RvcCleanModeCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -530,94 +578,97 @@ class RvcCleanModeCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -625,94 +676,97 @@ class RvcCleanModeCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -720,76 +774,81 @@ class RvcCleanModeCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -801,77 +860,80 @@ class RvcCleanModeCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -884,7 +946,7 @@ class RvcCleanModeCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/RvcOperationalStateCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/RvcOperationalStateCluster.kt index 6f60044e8ef432..87da9febd27bcd 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/RvcOperationalStateCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/RvcOperationalStateCluster.kt @@ -17,143 +17,182 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class RvcOperationalStateCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { +class RvcOperationalStateCluster(private val controller: MatterController, private val endpointId: UShort) { class OperationalCommandResponse( val commandResponseState: RvcOperationalStateClusterErrorStateStruct ) - - class PhaseListAttribute(val value: List?) +class PhaseListAttribute( + val value: List? + ) sealed class PhaseListAttributeSubscriptionState { - data class Success(val value: List?) : PhaseListAttributeSubscriptionState() - + data class Success( + val value: List? + ) : PhaseListAttributeSubscriptionState() + data class Error(val exception: Exception) : PhaseListAttributeSubscriptionState() - object SubscriptionEstablished : PhaseListAttributeSubscriptionState() - } - - class CurrentPhaseAttribute(val value: UByte?) + object SubscriptionEstablished : PhaseListAttributeSubscriptionState() + } +class CurrentPhaseAttribute( + val value: UByte? + ) sealed class CurrentPhaseAttributeSubscriptionState { - data class Success(val value: UByte?) : CurrentPhaseAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : CurrentPhaseAttributeSubscriptionState() + data class Error(val exception: Exception) : CurrentPhaseAttributeSubscriptionState() - object SubscriptionEstablished : CurrentPhaseAttributeSubscriptionState() - } - - class CountdownTimeAttribute(val value: UInt?) + object SubscriptionEstablished : CurrentPhaseAttributeSubscriptionState() + } +class CountdownTimeAttribute( + val value: UInt? + ) sealed class CountdownTimeAttributeSubscriptionState { - data class Success(val value: UInt?) : CountdownTimeAttributeSubscriptionState() - + data class Success( + val value: UInt? + ) : CountdownTimeAttributeSubscriptionState() + data class Error(val exception: Exception) : CountdownTimeAttributeSubscriptionState() - object SubscriptionEstablished : CountdownTimeAttributeSubscriptionState() - } - - class OperationalStateListAttribute( + object SubscriptionEstablished : CountdownTimeAttributeSubscriptionState() + } +class OperationalStateListAttribute( val value: List ) sealed class OperationalStateListAttributeSubscriptionState { - data class Success(val value: List) : - OperationalStateListAttributeSubscriptionState() - + data class Success( + val value: List + ) : OperationalStateListAttributeSubscriptionState() + data class Error(val exception: Exception) : OperationalStateListAttributeSubscriptionState() - object SubscriptionEstablished : OperationalStateListAttributeSubscriptionState() - } - - class OperationalErrorAttribute(val value: RvcOperationalStateClusterErrorStateStruct) + object SubscriptionEstablished : OperationalStateListAttributeSubscriptionState() + } +class OperationalErrorAttribute( + val value: RvcOperationalStateClusterErrorStateStruct + ) sealed class OperationalErrorAttributeSubscriptionState { - data class Success(val value: RvcOperationalStateClusterErrorStateStruct) : - OperationalErrorAttributeSubscriptionState() - + data class Success( + val value: RvcOperationalStateClusterErrorStateStruct + ) : OperationalErrorAttributeSubscriptionState() + data class Error(val exception: Exception) : OperationalErrorAttributeSubscriptionState() - object SubscriptionEstablished : OperationalErrorAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : OperationalErrorAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } suspend fun pause(timedInvokeTimeout: Duration? = null): OperationalCommandResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -163,39 +202,46 @@ class RvcOperationalStateCluster( tlvReader.enterStructure(AnonymousTag) val TAG_COMMAND_RESPONSE_STATE: Int = 0 var commandResponseState_decoded: RvcOperationalStateClusterErrorStateStruct? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_COMMAND_RESPONSE_STATE)) { - commandResponseState_decoded = - RvcOperationalStateClusterErrorStateStruct.fromTlv(tag, tlvReader) - } else { + + if (tag == ContextSpecificTag(TAG_COMMAND_RESPONSE_STATE)) {commandResponseState_decoded = RvcOperationalStateClusterErrorStateStruct.fromTlv(tag, tlvReader)} + + + else { tlvReader.skipElement() } } + + if (commandResponseState_decoded == null) { - throw IllegalStateException("commandResponseState not found in TLV") + throw IllegalStateException("commandResponseState not found in TLV") } + tlvReader.exitContainer() - return OperationalCommandResponse(commandResponseState_decoded) + return OperationalCommandResponse( + commandResponseState_decoded + ) } suspend fun resume(timedInvokeTimeout: Duration? = null): OperationalCommandResponse { val commandId: UInt = 3u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -205,39 +251,46 @@ class RvcOperationalStateCluster( tlvReader.enterStructure(AnonymousTag) val TAG_COMMAND_RESPONSE_STATE: Int = 0 var commandResponseState_decoded: RvcOperationalStateClusterErrorStateStruct? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_COMMAND_RESPONSE_STATE)) { - commandResponseState_decoded = - RvcOperationalStateClusterErrorStateStruct.fromTlv(tag, tlvReader) - } else { + + if (tag == ContextSpecificTag(TAG_COMMAND_RESPONSE_STATE)) {commandResponseState_decoded = RvcOperationalStateClusterErrorStateStruct.fromTlv(tag, tlvReader)} + + + else { tlvReader.skipElement() } } + + if (commandResponseState_decoded == null) { - throw IllegalStateException("commandResponseState not found in TLV") + throw IllegalStateException("commandResponseState not found in TLV") } + tlvReader.exitContainer() - return OperationalCommandResponse(commandResponseState_decoded) + return OperationalCommandResponse( + commandResponseState_decoded + ) } suspend fun goHome(timedInvokeTimeout: Duration? = null): OperationalCommandResponse { val commandId: UInt = 128u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -247,415 +300,439 @@ class RvcOperationalStateCluster( tlvReader.enterStructure(AnonymousTag) val TAG_COMMAND_RESPONSE_STATE: Int = 0 var commandResponseState_decoded: RvcOperationalStateClusterErrorStateStruct? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_COMMAND_RESPONSE_STATE)) { - commandResponseState_decoded = - RvcOperationalStateClusterErrorStateStruct.fromTlv(tag, tlvReader) - } else { + + if (tag == ContextSpecificTag(TAG_COMMAND_RESPONSE_STATE)) {commandResponseState_decoded = RvcOperationalStateClusterErrorStateStruct.fromTlv(tag, tlvReader)} + + + else { tlvReader.skipElement() } } + + if (commandResponseState_decoded == null) { - throw IllegalStateException("commandResponseState not found in TLV") + throw IllegalStateException("commandResponseState not found in TLV") } + tlvReader.exitContainer() - return OperationalCommandResponse(commandResponseState_decoded) + return OperationalCommandResponse( + commandResponseState_decoded + ) } - - suspend fun readPhaseListAttribute(): PhaseListAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readPhaseListAttribute(): PhaseListAttribute {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}") - } + 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) { "Phaselist attribute not found in response" } + } + + requireNotNull(attributeData) { + "Phaselist attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (!tlvReader.isNull()) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getString(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - tlvReader.getNull(AnonymousTag) - null + val decodedValue: List? = if (!tlvReader.isNull()) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getString(AnonymousTag)) } + tlvReader.exitContainer() + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return PhaseListAttribute(decodedValue) } suspend fun subscribePhaseListAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - PhaseListAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(PhaseListAttributeSubscriptionState.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) { "Phaselist attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Phaselist attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (!tlvReader.isNull()) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getString(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(PhaseListAttributeSubscriptionState.Success(it)) } + val decodedValue: List? = if (!tlvReader.isNull()) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getString(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(PhaseListAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(PhaseListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readCurrentPhaseAttribute(): CurrentPhaseAttribute { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readCurrentPhaseAttribute(): CurrentPhaseAttribute {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}") - } + 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) { "Currentphase attribute not found in response" } + } + + requireNotNull(attributeData) { + "Currentphase attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return CurrentPhaseAttribute(decodedValue) } suspend fun subscribeCurrentPhaseAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - CurrentPhaseAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(CurrentPhaseAttributeSubscriptionState.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) { "Currentphase attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Currentphase 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.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(CurrentPhaseAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(CurrentPhaseAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(CurrentPhaseAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readCountdownTimeAttribute(): CountdownTimeAttribute { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readCountdownTimeAttribute(): CountdownTimeAttribute {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}") - } + 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) { "Countdowntime attribute not found in response" } + } + + requireNotNull(attributeData) { + "Countdowntime attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return CountdownTimeAttribute(decodedValue) } suspend fun subscribeCountdownTimeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - CountdownTimeAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(CountdownTimeAttributeSubscriptionState.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) { "Countdowntime attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Countdowntime attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(CountdownTimeAttributeSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(CountdownTimeAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(CountdownTimeAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readOperationalStateListAttribute(): OperationalStateListAttribute { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readOperationalStateListAttribute(): OperationalStateListAttribute {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}") - } + 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) { "Operationalstatelist attribute not found in response" } + } + + requireNotNull(attributeData) { + "Operationalstatelist 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(RvcOperationalStateClusterOperationalStateStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(RvcOperationalStateClusterOperationalStateStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + return OperationalStateListAttribute(decodedValue) } suspend fun subscribeOperationalStateListAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - OperationalStateListAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(OperationalStateListAttributeSubscriptionState.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) { - "Operationalstatelist attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Operationalstatelist 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( - RvcOperationalStateClusterOperationalStateStruct.fromTlv(AnonymousTag, tlvReader) - ) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(RvcOperationalStateClusterOperationalStateStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(OperationalStateListAttributeSubscriptionState.Success(decodedValue)) } @@ -663,77 +740,80 @@ class RvcOperationalStateCluster( emit(OperationalStateListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readOperationalStateAttribute(): 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)) - +suspend fun readOperationalStateAttribute(): 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}") - } + 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) { "Operationalstate attribute not found in response" } + } + + requireNotNull(attributeData) { + "Operationalstate 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 subscribeOperationalStateAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Operationalstate attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Operationalstate attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -746,84 +826,85 @@ class RvcOperationalStateCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readOperationalErrorAttribute(): OperationalErrorAttribute { - val ATTRIBUTE_ID: UInt = 5u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readOperationalErrorAttribute(): OperationalErrorAttribute {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}") - } + 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) { "Operationalerror attribute not found in response" } + } + + requireNotNull(attributeData) { + "Operationalerror attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: RvcOperationalStateClusterErrorStateStruct = - RvcOperationalStateClusterErrorStateStruct.fromTlv(AnonymousTag, tlvReader) + val decodedValue: RvcOperationalStateClusterErrorStateStruct = RvcOperationalStateClusterErrorStateStruct.fromTlv(AnonymousTag, tlvReader) + return OperationalErrorAttribute(decodedValue) } suspend fun subscribeOperationalErrorAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - OperationalErrorAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(OperationalErrorAttributeSubscriptionState.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) { - "Operationalerror attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Operationalerror attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: RvcOperationalStateClusterErrorStateStruct = - RvcOperationalStateClusterErrorStateStruct.fromTlv(AnonymousTag, tlvReader) + val decodedValue: RvcOperationalStateClusterErrorStateStruct = RvcOperationalStateClusterErrorStateStruct.fromTlv(AnonymousTag, tlvReader) emit(OperationalErrorAttributeSubscriptionState.Success(decodedValue)) } @@ -831,96 +912,97 @@ class RvcOperationalStateCluster( emit(OperationalErrorAttributeSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -928,96 +1010,97 @@ class RvcOperationalStateCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1025,94 +1108,97 @@ class RvcOperationalStateCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1120,94 +1206,97 @@ class RvcOperationalStateCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1215,76 +1304,81 @@ class RvcOperationalStateCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1296,77 +1390,80 @@ class RvcOperationalStateCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1379,7 +1476,7 @@ class RvcOperationalStateCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/RvcRunModeCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/RvcRunModeCluster.kt index 931b95c4a3ab6d..e1baabf44d5473 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/RvcRunModeCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/RvcRunModeCluster.kt @@ -17,101 +17,135 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter class RvcRunModeCluster(private val controller: MatterController, private val endpointId: UShort) { - class ChangeToModeResponse(val status: UByte, val statusText: String?) - - class SupportedModesAttribute(val value: List) + class ChangeToModeResponse( + val status: UByte, + val statusText: String? + ) +class SupportedModesAttribute( + val value: List + ) sealed class SupportedModesAttributeSubscriptionState { - data class Success(val value: List) : - SupportedModesAttributeSubscriptionState() - + data class Success( + val value: List + ) : SupportedModesAttributeSubscriptionState() + data class Error(val exception: Exception) : SupportedModesAttributeSubscriptionState() - object SubscriptionEstablished : SupportedModesAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : SupportedModesAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun changeToMode( - newMode: UByte, - timedInvokeTimeout: Duration? = null, - ): ChangeToModeResponse { + suspend fun changeToMode(newMode: UByte + ,timedInvokeTimeout: Duration? = null): ChangeToModeResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_NEW_MODE_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_NEW_MODE_REQ), newMode) + tlvWriter.put(ContextSpecificTag(TAG_NEW_MODE_REQ), newMode) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -121,130 +155,140 @@ class RvcRunModeCluster(private val controller: MatterController, private val en tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_STATUS_TEXT: Int = 1 var statusText_decoded: String? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_STATUS)) { - status_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_STATUS_TEXT)) { - statusText_decoded = + + if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_STATUS_TEXT)) {statusText_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - } - } else { + tlvReader.getString(tag) + } else { + null + } + }} + + + else { tlvReader.skipElement() } } + + if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } + + + tlvReader.exitContainer() - return ChangeToModeResponse(status_decoded, statusText_decoded) + return ChangeToModeResponse( + status_decoded, + statusText_decoded + ) } - - suspend fun readSupportedModesAttribute(): SupportedModesAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readSupportedModesAttribute(): SupportedModesAttribute {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}") - } + 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) { "Supportedmodes attribute not found in response" } + } + + requireNotNull(attributeData) { + "Supportedmodes 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(RvcRunModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(RvcRunModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + return SupportedModesAttribute(decodedValue) } suspend fun subscribeSupportedModesAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - SupportedModesAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(SupportedModesAttributeSubscriptionState.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) { - "Supportedmodes attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Supportedmodes 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(RvcRunModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(RvcRunModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(SupportedModesAttributeSubscriptionState.Success(decodedValue)) } @@ -252,76 +296,81 @@ class RvcRunModeCluster(private val controller: MatterController, private val en emit(SupportedModesAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readCurrentModeAttribute(): 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)) - +suspend fun readCurrentModeAttribute(): 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}") - } + 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) { "Currentmode attribute not found in response" } + } + + requireNotNull(attributeData) { + "Currentmode 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 subscribeCurrentModeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Currentmode attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Currentmode attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -333,96 +382,97 @@ class RvcRunModeCluster(private val controller: MatterController, private val en emit(UByteSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -430,96 +480,97 @@ class RvcRunModeCluster(private val controller: MatterController, private val en 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -527,94 +578,97 @@ class RvcRunModeCluster(private val controller: MatterController, private val en 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -622,94 +676,97 @@ class RvcRunModeCluster(private val controller: MatterController, private val en 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -717,76 +774,81 @@ class RvcRunModeCluster(private val controller: MatterController, private val en 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -798,77 +860,80 @@ class RvcRunModeCluster(private val controller: MatterController, private val en 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -881,7 +946,7 @@ class RvcRunModeCluster(private val controller: MatterController, private val en emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/SampleMeiCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/SampleMeiCluster.kt index 0c96750d8a58e5..9d5b10e9a5a6ce 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/SampleMeiCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/SampleMeiCluster.kt @@ -17,98 +17,126 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration 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.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.UIntSubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState +import matter.controller.UByteSubscriptionState import matter.controller.UShortSubscriptionState +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.cluster.structs.* +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter class SampleMeiCluster(private val controller: MatterController, private val endpointId: UShort) { - class AddArgumentsResponse(val returnValue: UByte) - - class GeneratedCommandListAttribute(val value: List) + class AddArgumentsResponse( + val returnValue: UByte + ) +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } suspend fun ping(timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun addArguments( - arg1: UByte, - arg2: UByte, - timedInvokeTimeout: Duration? = null, - ): AddArgumentsResponse { + suspend fun addArguments(arg1: UByte + ,arg2: UByte + ,timedInvokeTimeout: Duration? = null): AddArgumentsResponse { val commandId: UInt = 2u val tlvWriter = TlvWriter() @@ -118,14 +146,14 @@ class SampleMeiCluster(private val controller: MatterController, private val end tlvWriter.put(ContextSpecificTag(TAG_ARG1_REQ), arg1) val TAG_ARG2_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_ARG2_REQ), arg2) + tlvWriter.put(ContextSpecificTag(TAG_ARG2_REQ), arg2) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -135,74 +163,93 @@ class SampleMeiCluster(private val controller: MatterController, private val end tlvReader.enterStructure(AnonymousTag) val TAG_RETURN_VALUE: Int = 0 var returnValue_decoded: UByte? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_RETURN_VALUE)) { - returnValue_decoded = tlvReader.getUByte(tag) - } else { + + if (tag == ContextSpecificTag(TAG_RETURN_VALUE)) {returnValue_decoded = tlvReader.getUByte(tag)} + + + else { tlvReader.skipElement() } } + + if (returnValue_decoded == null) { - throw IllegalStateException("returnValue not found in TLV") + throw IllegalStateException("returnValue not found in TLV") } + tlvReader.exitContainer() - return AddArgumentsResponse(returnValue_decoded) + return AddArgumentsResponse( + returnValue_decoded + ) } - - suspend fun readFlipFlopAttribute(): Boolean { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readFlipFlopAttribute(): Boolean {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}") - } + 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) { "Flipflop attribute not found in response" } + } + + requireNotNull(attributeData) { + "Flipflop attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Boolean = tlvReader.getBoolean(AnonymousTag) + return decodedValue } - suspend fun writeFlipFlopAttribute(value: Boolean, timedWriteTimeout: Duration? = null) { + suspend fun writeFlipFlopAttribute( + value: Boolean, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -223,45 +270,43 @@ class SampleMeiCluster(private val controller: MatterController, private val end throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeFlipFlopAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Flipflop attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Flipflop attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -273,96 +318,97 @@ class SampleMeiCluster(private val controller: MatterController, private val end emit(BooleanSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -370,96 +416,97 @@ class SampleMeiCluster(private val controller: MatterController, private val end 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -467,94 +514,97 @@ class SampleMeiCluster(private val controller: MatterController, private val end 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -562,94 +612,97 @@ class SampleMeiCluster(private val controller: MatterController, private val end 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -657,76 +710,81 @@ class SampleMeiCluster(private val controller: MatterController, private val end 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -738,77 +796,80 @@ class SampleMeiCluster(private val controller: MatterController, private val end 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -821,7 +882,7 @@ class SampleMeiCluster(private val controller: MatterController, private val end emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/ScenesManagementCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/ScenesManagementCluster.kt index e363f8c88f37f3..2a67e9827d36a1 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/ScenesManagementCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/ScenesManagementCluster.kt @@ -17,131 +17,178 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.UIntSubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState +import matter.controller.UByteSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class ScenesManagementCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class AddSceneResponse(val status: UByte, val groupID: UShort, val sceneID: UByte) +class ScenesManagementCluster(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: UInt?, - val sceneName: String?, - val extensionFieldSets: List?, + val status: UByte, + val groupID: UShort, + val sceneID: UByte, + val transitionTime: UInt?, + val sceneName: String?, + val extensionFieldSets: List? ) - class RemoveSceneResponse(val status: UByte, val groupID: UShort, val sceneID: UByte) + class RemoveSceneResponse( + val status: UByte, + val groupID: UShort, + val sceneID: UByte + ) - class RemoveAllScenesResponse(val status: UByte, val groupID: UShort) + class RemoveAllScenesResponse( + val status: UByte, + val groupID: UShort + ) - class StoreSceneResponse(val status: UByte, val groupID: UShort, val sceneID: UByte) + 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?, + val status: UByte, + val capacity: UByte?, + val groupID: UShort, + val sceneList: List? ) class CopySceneResponse( - val status: UByte, - val groupIdentifierFrom: UShort, - val sceneIdentifierFrom: UByte, + val status: UByte, + val groupIdentifierFrom: UShort, + val sceneIdentifierFrom: UByte + ) +class LastConfiguredByAttribute( + val value: ULong? ) - - class LastConfiguredByAttribute(val value: ULong?) sealed class LastConfiguredByAttributeSubscriptionState { - data class Success(val value: ULong?) : LastConfiguredByAttributeSubscriptionState() - + data class Success( + val value: ULong? + ) : LastConfiguredByAttributeSubscriptionState() + data class Error(val exception: Exception) : LastConfiguredByAttributeSubscriptionState() - object SubscriptionEstablished : LastConfiguredByAttributeSubscriptionState() - } - - class FabricSceneInfoAttribute(val value: List) + object SubscriptionEstablished : LastConfiguredByAttributeSubscriptionState() + } +class FabricSceneInfoAttribute( + val value: List + ) sealed class FabricSceneInfoAttributeSubscriptionState { - data class Success(val value: List) : - FabricSceneInfoAttributeSubscriptionState() - + data class Success( + val value: List + ) : FabricSceneInfoAttributeSubscriptionState() + data class Error(val exception: Exception) : FabricSceneInfoAttributeSubscriptionState() - object SubscriptionEstablished : FabricSceneInfoAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : FabricSceneInfoAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun addScene( - groupID: UShort, - sceneID: UByte, - transitionTime: UInt, - sceneName: String, - extensionFieldSets: List, - timedInvokeTimeout: Duration? = null, - ): AddSceneResponse { + suspend fun addScene(groupID: UShort + ,sceneID: UByte + ,transitionTime: UInt + ,sceneName: String + ,extensionFieldSets: List + ,timedInvokeTimeout: Duration? = null): AddSceneResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() @@ -161,17 +208,17 @@ class ScenesManagementCluster( 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() + 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, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -181,53 +228,59 @@ class ScenesManagementCluster( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_GROUP_ID: Int = 1 var groupID_decoded: UShort? = null - + val TAG_SCENE_ID: 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_ID)) { - groupID_decoded = tlvReader.getUShort(tag) - } + + if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_GROUP_ID)) {groupID_decoded = tlvReader.getUShort(tag)} + + if (tag == ContextSpecificTag(TAG_SCENE_ID)) {sceneID_decoded = tlvReader.getUByte(tag)} + - if (tag == ContextSpecificTag(TAG_SCENE_ID)) { - sceneID_decoded = tlvReader.getUByte(tag) - } else { + else { tlvReader.skipElement() } } + + if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - + + if (groupID_decoded == null) { - throw IllegalStateException("groupID not found in TLV") + throw IllegalStateException("groupID not found in TLV") } - + + if (sceneID_decoded == null) { - throw IllegalStateException("sceneID not found in TLV") + throw IllegalStateException("sceneID not found in TLV") } + tlvReader.exitContainer() - return AddSceneResponse(status_decoded, groupID_decoded, sceneID_decoded) + return AddSceneResponse( + status_decoded, + groupID_decoded, + sceneID_decoded + ) } - suspend fun viewScene( - groupID: UShort, - sceneID: UByte, - timedInvokeTimeout: Duration? = null, - ): ViewSceneResponse { + suspend fun viewScene(groupID: UShort + ,sceneID: UByte + ,timedInvokeTimeout: Duration? = null): ViewSceneResponse { val commandId: UInt = 1u val tlvWriter = TlvWriter() @@ -237,14 +290,14 @@ class ScenesManagementCluster( tlvWriter.put(ContextSpecificTag(TAG_GROUP_ID_REQ), groupID) val TAG_SCENE_ID_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_SCENE_ID_REQ), sceneID) + tlvWriter.put(ContextSpecificTag(TAG_SCENE_ID_REQ), sceneID) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -254,99 +307,103 @@ class ScenesManagementCluster( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_GROUP_ID: Int = 1 var groupID_decoded: UShort? = null - + val TAG_SCENE_ID: Int = 2 var sceneID_decoded: UByte? = null - + val TAG_TRANSITION_TIME: Int = 3 var transitionTime_decoded: UInt? = 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_ID)) { - groupID_decoded = tlvReader.getUShort(tag) - } - - if (tag == ContextSpecificTag(TAG_SCENE_ID)) { - sceneID_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_TRANSITION_TIME)) { - transitionTime_decoded = + + if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_GROUP_ID)) {groupID_decoded = tlvReader.getUShort(tag)} + + if (tag == ContextSpecificTag(TAG_SCENE_ID)) {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.getUInt(tag) - } else { - null - } - } - } - - if (tag == ContextSpecificTag(TAG_SCENE_NAME)) { - sceneName_decoded = + tlvReader.getUInt(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 = + 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(ScenesManagementClusterExtensionFieldSet.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null - } - } - } else { + buildList { + tlvReader.enterArray(tag) + while(!tlvReader.isEndOfContainer()) { + add(ScenesManagementClusterExtensionFieldSet.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null + } + }} + + + else { tlvReader.skipElement() } } + + if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - + + if (groupID_decoded == null) { - throw IllegalStateException("groupID not found in TLV") + throw IllegalStateException("groupID not found in TLV") } - + + if (sceneID_decoded == null) { - throw IllegalStateException("sceneID not found in TLV") + throw IllegalStateException("sceneID not found in TLV") } + + + + + + + tlvReader.exitContainer() @@ -356,15 +413,13 @@ class ScenesManagementCluster( sceneID_decoded, transitionTime_decoded, sceneName_decoded, - extensionFieldSets_decoded, + extensionFieldSets_decoded ) } - suspend fun removeScene( - groupID: UShort, - sceneID: UByte, - timedInvokeTimeout: Duration? = null, - ): RemoveSceneResponse { + suspend fun removeScene(groupID: UShort + ,sceneID: UByte + ,timedInvokeTimeout: Duration? = null): RemoveSceneResponse { val commandId: UInt = 2u val tlvWriter = TlvWriter() @@ -374,14 +429,14 @@ class ScenesManagementCluster( tlvWriter.put(ContextSpecificTag(TAG_GROUP_ID_REQ), groupID) val TAG_SCENE_ID_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_SCENE_ID_REQ), sceneID) + tlvWriter.put(ContextSpecificTag(TAG_SCENE_ID_REQ), sceneID) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -391,66 +446,72 @@ class ScenesManagementCluster( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_GROUP_ID: Int = 1 var groupID_decoded: UShort? = null - + val TAG_SCENE_ID: 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_ID)) { - groupID_decoded = tlvReader.getUShort(tag) - } + + if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_GROUP_ID)) {groupID_decoded = tlvReader.getUShort(tag)} + + if (tag == ContextSpecificTag(TAG_SCENE_ID)) {sceneID_decoded = tlvReader.getUByte(tag)} + - if (tag == ContextSpecificTag(TAG_SCENE_ID)) { - sceneID_decoded = tlvReader.getUByte(tag) - } else { + else { tlvReader.skipElement() } } + + if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - + + if (groupID_decoded == null) { - throw IllegalStateException("groupID not found in TLV") + throw IllegalStateException("groupID not found in TLV") } - + + if (sceneID_decoded == null) { - throw IllegalStateException("sceneID not found in TLV") + throw IllegalStateException("sceneID not found in TLV") } + tlvReader.exitContainer() - return RemoveSceneResponse(status_decoded, groupID_decoded, sceneID_decoded) + return RemoveSceneResponse( + status_decoded, + groupID_decoded, + sceneID_decoded + ) } - suspend fun removeAllScenes( - groupID: UShort, - timedInvokeTimeout: Duration? = null, - ): RemoveAllScenesResponse { + suspend fun removeAllScenes(groupID: UShort + ,timedInvokeTimeout: Duration? = null): RemoveAllScenesResponse { val commandId: UInt = 3u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_GROUP_ID_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_GROUP_ID_REQ), groupID) + tlvWriter.put(ContextSpecificTag(TAG_GROUP_ID_REQ), groupID) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -460,42 +521,48 @@ class ScenesManagementCluster( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_GROUP_ID: 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_STATUS)) {status_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_GROUP_ID)) {groupID_decoded = tlvReader.getUShort(tag)} + - if (tag == ContextSpecificTag(TAG_GROUP_ID)) { - groupID_decoded = tlvReader.getUShort(tag) - } else { + else { tlvReader.skipElement() } } + + if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - + + if (groupID_decoded == null) { - throw IllegalStateException("groupID not found in TLV") + throw IllegalStateException("groupID not found in TLV") } + tlvReader.exitContainer() - return RemoveAllScenesResponse(status_decoded, groupID_decoded) + return RemoveAllScenesResponse( + status_decoded, + groupID_decoded + ) } - suspend fun storeScene( - groupID: UShort, - sceneID: UByte, - timedInvokeTimeout: Duration? = null, - ): StoreSceneResponse { + suspend fun storeScene(groupID: UShort + ,sceneID: UByte + ,timedInvokeTimeout: Duration? = null): StoreSceneResponse { val commandId: UInt = 4u val tlvWriter = TlvWriter() @@ -505,14 +572,14 @@ class ScenesManagementCluster( tlvWriter.put(ContextSpecificTag(TAG_GROUP_ID_REQ), groupID) val TAG_SCENE_ID_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_SCENE_ID_REQ), sceneID) + tlvWriter.put(ContextSpecificTag(TAG_SCENE_ID_REQ), sceneID) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -522,54 +589,60 @@ class ScenesManagementCluster( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_GROUP_ID: Int = 1 var groupID_decoded: UShort? = null - + val TAG_SCENE_ID: 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_STATUS)) {status_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_GROUP_ID)) {groupID_decoded = tlvReader.getUShort(tag)} + + if (tag == ContextSpecificTag(TAG_SCENE_ID)) {sceneID_decoded = tlvReader.getUByte(tag)} + - if (tag == ContextSpecificTag(TAG_GROUP_ID)) { - groupID_decoded = tlvReader.getUShort(tag) - } - - if (tag == ContextSpecificTag(TAG_SCENE_ID)) { - sceneID_decoded = tlvReader.getUByte(tag) - } else { + else { tlvReader.skipElement() } } + + if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - + + if (groupID_decoded == null) { - throw IllegalStateException("groupID not found in TLV") + throw IllegalStateException("groupID not found in TLV") } - + + if (sceneID_decoded == null) { - throw IllegalStateException("sceneID not found in TLV") + throw IllegalStateException("sceneID not found in TLV") } + tlvReader.exitContainer() - return StoreSceneResponse(status_decoded, groupID_decoded, sceneID_decoded) + return StoreSceneResponse( + status_decoded, + groupID_decoded, + sceneID_decoded + ) } - suspend fun recallScene( - groupID: UShort, - sceneID: UByte, - transitionTime: UInt?, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun recallScene(groupID: UShort + ,sceneID: UByte + ,transitionTime: UInt? + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 5u val tlvWriter = TlvWriter() @@ -584,38 +657,36 @@ class ScenesManagementCluster( 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, + 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 { + suspend fun getSceneMembership(groupID: UShort + ,timedInvokeTimeout: Duration? = null): GetSceneMembershipResponse { val commandId: UInt = 6u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_GROUP_ID_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_GROUP_ID_REQ), groupID) + tlvWriter.put(ContextSpecificTag(TAG_GROUP_ID_REQ), groupID) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -625,72 +696,77 @@ class ScenesManagementCluster( 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_ID: 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 (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_ID)) { - groupID_decoded = tlvReader.getUShort(tag) - } - - if (tag == ContextSpecificTag(TAG_SCENE_LIST)) { - sceneList_decoded = + tlvReader.getUByte(tag) + } else { + tlvReader.getNull(tag) + null + } + }} + + if (tag == ContextSpecificTag(TAG_GROUP_ID)) {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 { + 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") + throw IllegalStateException("status not found in TLV") } - + + + + if (groupID_decoded == null) { - throw IllegalStateException("groupID not found in TLV") + throw IllegalStateException("groupID not found in TLV") } + + + tlvReader.exitContainer() @@ -698,18 +774,16 @@ class ScenesManagementCluster( status_decoded, capacity_decoded, groupID_decoded, - sceneList_decoded, + sceneList_decoded ) } - suspend fun copyScene( - mode: UByte, - groupIdentifierFrom: UShort, - sceneIdentifierFrom: UByte, - groupIdentifierTo: UShort, - sceneIdentifierTo: UByte, - timedInvokeTimeout: Duration? = null, - ): CopySceneResponse { + suspend fun copyScene(mode: UByte + ,groupIdentifierFrom: UShort + ,sceneIdentifierFrom: UByte + ,groupIdentifierTo: UShort + ,sceneIdentifierTo: UByte + ,timedInvokeTimeout: Duration? = null): CopySceneResponse { val commandId: UInt = 64u val tlvWriter = TlvWriter() @@ -728,14 +802,14 @@ class ScenesManagementCluster( 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.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, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -745,223 +819,234 @@ class ScenesManagementCluster( 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_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)} + - if (tag == ContextSpecificTag(TAG_SCENE_IDENTIFIER_FROM)) { - sceneIdentifierFrom_decoded = tlvReader.getUByte(tag) - } else { + else { tlvReader.skipElement() } } + + if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - + + if (groupIdentifierFrom_decoded == null) { - throw IllegalStateException("groupIdentifierFrom not found in TLV") + throw IllegalStateException("groupIdentifierFrom not found in TLV") } - + + if (sceneIdentifierFrom_decoded == null) { - throw IllegalStateException("sceneIdentifierFrom not found in TLV") + throw IllegalStateException("sceneIdentifierFrom not found in TLV") } + tlvReader.exitContainer() return CopySceneResponse( status_decoded, groupIdentifierFrom_decoded, - sceneIdentifierFrom_decoded, + sceneIdentifierFrom_decoded ) } +suspend fun readLastConfiguredByAttribute(): LastConfiguredByAttribute {val ATTRIBUTE_ID: UInt = 0u - suspend fun readLastConfiguredByAttribute(): LastConfiguredByAttribute { - 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 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}") - } + 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" } + } + + 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 - } + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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)) } + 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 = 1u - suspend fun readSceneTableSizeAttribute(): UShort { - 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 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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -974,96 +1059,97 @@ class ScenesManagementCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readFabricSceneInfoAttribute(): FabricSceneInfoAttribute {val ATTRIBUTE_ID: UInt = 2u - suspend fun readFabricSceneInfoAttribute(): FabricSceneInfoAttribute { - 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 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}") - } + 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" } + } + + 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(ScenesManagementClusterSceneInfoStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(ScenesManagementClusterSceneInfoStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + return FabricSceneInfoAttribute(decodedValue) } suspend fun subscribeFabricSceneInfoAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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(ScenesManagementClusterSceneInfoStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(ScenesManagementClusterSceneInfoStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(FabricSceneInfoAttributeSubscriptionState.Success(decodedValue)) } @@ -1071,96 +1157,97 @@ class ScenesManagementCluster( emit(FabricSceneInfoAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65528u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1168,96 +1255,97 @@ class ScenesManagementCluster( emit(GeneratedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65529u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1265,94 +1353,97 @@ class ScenesManagementCluster( emit(AcceptedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt = 65530u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1360,94 +1451,97 @@ class ScenesManagementCluster( emit(EventListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ID: UInt = 65531u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1455,76 +1549,81 @@ class ScenesManagementCluster( emit(AttributeListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u - 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 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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1536,77 +1635,80 @@ class ScenesManagementCluster( emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 65533u - 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 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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1619,7 +1721,7 @@ class ScenesManagementCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/ServiceAreaCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/ServiceAreaCluster.kt index b526c0ea4c38b9..a79587828803e2 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/ServiceAreaCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/ServiceAreaCluster.kt @@ -17,140 +17,191 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.UIntSubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState +import matter.controller.UByteSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter class ServiceAreaCluster(private val controller: MatterController, private val endpointId: UShort) { - class SelectAreasResponse(val status: UByte, val statusText: String) - - class SkipAreaResponse(val status: UByte, val statusText: String) - - class SupportedAreasAttribute(val value: List) + class SelectAreasResponse( + val status: UByte, + val statusText: String + ) + + class SkipAreaResponse( + val status: UByte, + val statusText: String + ) +class SupportedAreasAttribute( + val value: List + ) sealed class SupportedAreasAttributeSubscriptionState { - data class Success(val value: List) : - SupportedAreasAttributeSubscriptionState() - + data class Success( + val value: List + ) : SupportedAreasAttributeSubscriptionState() + data class Error(val exception: Exception) : SupportedAreasAttributeSubscriptionState() - object SubscriptionEstablished : SupportedAreasAttributeSubscriptionState() - } - - class SupportedMapsAttribute(val value: List?) + object SubscriptionEstablished : SupportedAreasAttributeSubscriptionState() + } +class SupportedMapsAttribute( + val value: List? + ) sealed class SupportedMapsAttributeSubscriptionState { - data class Success(val value: List?) : - SupportedMapsAttributeSubscriptionState() - + data class Success( + val value: List? + ) : SupportedMapsAttributeSubscriptionState() + data class Error(val exception: Exception) : SupportedMapsAttributeSubscriptionState() - object SubscriptionEstablished : SupportedMapsAttributeSubscriptionState() - } - - class SelectedAreasAttribute(val value: List) + object SubscriptionEstablished : SupportedMapsAttributeSubscriptionState() + } +class SelectedAreasAttribute( + val value: List + ) sealed class SelectedAreasAttributeSubscriptionState { - data class Success(val value: List) : SelectedAreasAttributeSubscriptionState() - + data class Success( + val value: List + ) : SelectedAreasAttributeSubscriptionState() + data class Error(val exception: Exception) : SelectedAreasAttributeSubscriptionState() - object SubscriptionEstablished : SelectedAreasAttributeSubscriptionState() - } - - class CurrentAreaAttribute(val value: UInt?) + object SubscriptionEstablished : SelectedAreasAttributeSubscriptionState() + } +class CurrentAreaAttribute( + val value: UInt? + ) sealed class CurrentAreaAttributeSubscriptionState { - data class Success(val value: UInt?) : CurrentAreaAttributeSubscriptionState() - + data class Success( + val value: UInt? + ) : CurrentAreaAttributeSubscriptionState() + data class Error(val exception: Exception) : CurrentAreaAttributeSubscriptionState() - object SubscriptionEstablished : CurrentAreaAttributeSubscriptionState() - } - - class EstimatedEndTimeAttribute(val value: UInt?) + object SubscriptionEstablished : CurrentAreaAttributeSubscriptionState() + } +class EstimatedEndTimeAttribute( + val value: UInt? + ) sealed class EstimatedEndTimeAttributeSubscriptionState { - data class Success(val value: UInt?) : EstimatedEndTimeAttributeSubscriptionState() - + data class Success( + val value: UInt? + ) : EstimatedEndTimeAttributeSubscriptionState() + data class Error(val exception: Exception) : EstimatedEndTimeAttributeSubscriptionState() - object SubscriptionEstablished : EstimatedEndTimeAttributeSubscriptionState() - } - - class ProgressAttribute(val value: List?) + object SubscriptionEstablished : EstimatedEndTimeAttributeSubscriptionState() + } +class ProgressAttribute( + val value: List? + ) sealed class ProgressAttributeSubscriptionState { - data class Success(val value: List?) : - ProgressAttributeSubscriptionState() - + data class Success( + val value: List? + ) : ProgressAttributeSubscriptionState() + data class Error(val exception: Exception) : ProgressAttributeSubscriptionState() - object SubscriptionEstablished : ProgressAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : ProgressAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun selectAreas( - newAreas: List, - timedInvokeTimeout: Duration? = null, - ): SelectAreasResponse { + suspend fun selectAreas(newAreas: List + ,timedInvokeTimeout: Duration? = null): SelectAreasResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() @@ -158,17 +209,17 @@ class ServiceAreaCluster(private val controller: MatterController, private val e val TAG_NEW_AREAS_REQ: Int = 0 tlvWriter.startArray(ContextSpecificTag(TAG_NEW_AREAS_REQ)) - for (item in newAreas.iterator()) { - tlvWriter.put(AnonymousTag, item) - } - tlvWriter.endArray() + for (item in newAreas.iterator()) { + tlvWriter.put(AnonymousTag, item) + } + tlvWriter.endArray() tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -178,52 +229,61 @@ class ServiceAreaCluster(private val controller: MatterController, private val e tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_STATUS_TEXT: Int = 1 var statusText_decoded: String? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_STATUS)) { - status_decoded = tlvReader.getUByte(tag) - } + + if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_STATUS_TEXT)) {statusText_decoded = tlvReader.getString(tag)} + - if (tag == ContextSpecificTag(TAG_STATUS_TEXT)) { - statusText_decoded = tlvReader.getString(tag) - } else { + else { tlvReader.skipElement() } } + + if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - + + if (statusText_decoded == null) { - throw IllegalStateException("statusText not found in TLV") + throw IllegalStateException("statusText not found in TLV") } + tlvReader.exitContainer() - return SelectAreasResponse(status_decoded, statusText_decoded) + return SelectAreasResponse( + status_decoded, + statusText_decoded + ) } - suspend fun skipArea(skippedArea: UInt, timedInvokeTimeout: Duration? = null): SkipAreaResponse { + suspend fun skipArea(skippedArea: UInt + ,timedInvokeTimeout: Duration? = null): SkipAreaResponse { val commandId: UInt = 2u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_SKIPPED_AREA_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_SKIPPED_AREA_REQ), skippedArea) + tlvWriter.put(ContextSpecificTag(TAG_SKIPPED_AREA_REQ), skippedArea) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -233,124 +293,133 @@ class ServiceAreaCluster(private val controller: MatterController, private val e tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_STATUS_TEXT: Int = 1 var statusText_decoded: String? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_STATUS)) { - status_decoded = tlvReader.getUByte(tag) - } + + if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_STATUS_TEXT)) {statusText_decoded = tlvReader.getString(tag)} + - if (tag == ContextSpecificTag(TAG_STATUS_TEXT)) { - statusText_decoded = tlvReader.getString(tag) - } else { + else { tlvReader.skipElement() } } + + if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - + + if (statusText_decoded == null) { - throw IllegalStateException("statusText not found in TLV") + throw IllegalStateException("statusText not found in TLV") } + tlvReader.exitContainer() - return SkipAreaResponse(status_decoded, statusText_decoded) + return SkipAreaResponse( + status_decoded, + statusText_decoded + ) } - - suspend fun readSupportedAreasAttribute(): SupportedAreasAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readSupportedAreasAttribute(): SupportedAreasAttribute {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}") - } + 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) { "Supportedareas attribute not found in response" } + } + + requireNotNull(attributeData) { + "Supportedareas 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(ServiceAreaClusterAreaStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(ServiceAreaClusterAreaStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + return SupportedAreasAttribute(decodedValue) } suspend fun subscribeSupportedAreasAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - SupportedAreasAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(SupportedAreasAttributeSubscriptionState.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) { - "Supportedareas attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Supportedareas 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(ServiceAreaClusterAreaStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(ServiceAreaClusterAreaStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(SupportedAreasAttributeSubscriptionState.Success(decodedValue)) } @@ -358,197 +427,206 @@ class ServiceAreaCluster(private val controller: MatterController, private val e emit(SupportedAreasAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readSupportedMapsAttribute(): SupportedMapsAttribute { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readSupportedMapsAttribute(): SupportedMapsAttribute {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}") - } + 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) { "Supportedmaps attribute not found in response" } + } + + requireNotNull(attributeData) { + "Supportedmaps attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(ServiceAreaClusterMapStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(ServiceAreaClusterMapStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + } else { + null + } + return SupportedMapsAttribute(decodedValue) } suspend fun subscribeSupportedMapsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - SupportedMapsAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(SupportedMapsAttributeSubscriptionState.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) { "Supportedmaps attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Supportedmaps attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(ServiceAreaClusterMapStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { emit(SupportedMapsAttributeSubscriptionState.Success(it)) } + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(ServiceAreaClusterMapStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { + emit(SupportedMapsAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(SupportedMapsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readSelectedAreasAttribute(): SelectedAreasAttribute { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readSelectedAreasAttribute(): SelectedAreasAttribute {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}") - } + 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) { "Selectedareas attribute not found in response" } + } + + requireNotNull(attributeData) { + "Selectedareas 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() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) } + tlvReader.exitContainer() + } + return SelectedAreasAttribute(decodedValue) } suspend fun subscribeSelectedAreasAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - SelectedAreasAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(SelectedAreasAttributeSubscriptionState.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) { "Selectedareas attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Selectedareas 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(SelectedAreasAttributeSubscriptionState.Success(decodedValue)) } @@ -556,403 +634,420 @@ class ServiceAreaCluster(private val controller: MatterController, private val e emit(SelectedAreasAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readCurrentAreaAttribute(): CurrentAreaAttribute { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readCurrentAreaAttribute(): CurrentAreaAttribute {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}") - } + 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) { "Currentarea attribute not found in response" } + } + + requireNotNull(attributeData) { + "Currentarea attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return CurrentAreaAttribute(decodedValue) } suspend fun subscribeCurrentAreaAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - CurrentAreaAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(CurrentAreaAttributeSubscriptionState.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) { "Currentarea attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Currentarea attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(CurrentAreaAttributeSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(CurrentAreaAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(CurrentAreaAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readEstimatedEndTimeAttribute(): EstimatedEndTimeAttribute { - val ATTRIBUTE_ID: UInt = 4u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readEstimatedEndTimeAttribute(): EstimatedEndTimeAttribute {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}") - } + 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) { "Estimatedendtime attribute not found in response" } + } + + requireNotNull(attributeData) { + "Estimatedendtime attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return EstimatedEndTimeAttribute(decodedValue) } suspend fun subscribeEstimatedEndTimeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - EstimatedEndTimeAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(EstimatedEndTimeAttributeSubscriptionState.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) { - "Estimatedendtime attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Estimatedendtime attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(EstimatedEndTimeAttributeSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(EstimatedEndTimeAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(EstimatedEndTimeAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readProgressAttribute(): ProgressAttribute { - val ATTRIBUTE_ID: UInt = 5u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readProgressAttribute(): ProgressAttribute {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}") - } + 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) { "Progress attribute not found in response" } + } + + requireNotNull(attributeData) { + "Progress attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(ServiceAreaClusterProgressStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(ServiceAreaClusterProgressStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + } else { + null + } + return ProgressAttribute(decodedValue) } suspend fun subscribeProgressAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ProgressAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ProgressAttributeSubscriptionState.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) { "Progress attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Progress attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(ServiceAreaClusterProgressStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { emit(ProgressAttributeSubscriptionState.Success(it)) } + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(ServiceAreaClusterProgressStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { + emit(ProgressAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ProgressAttributeSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -960,96 +1055,97 @@ class ServiceAreaCluster(private val controller: MatterController, private val e 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1057,94 +1153,97 @@ class ServiceAreaCluster(private val controller: MatterController, private val e 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1152,94 +1251,97 @@ class ServiceAreaCluster(private val controller: MatterController, private val e 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1247,76 +1349,81 @@ class ServiceAreaCluster(private val controller: MatterController, private val e 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1328,77 +1435,80 @@ class ServiceAreaCluster(private val controller: MatterController, private val e 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1411,7 +1521,7 @@ class ServiceAreaCluster(private val controller: MatterController, private val e emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/SmokeCoAlarmCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/SmokeCoAlarmCluster.kt index f859709eaf7aab..ec9ca8d0e7e65a 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/SmokeCoAlarmCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/SmokeCoAlarmCluster.kt @@ -17,162 +17,190 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration 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.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.cluster.structs.* +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class SmokeCoAlarmCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class GeneratedCommandListAttribute(val value: List) +class SmokeCoAlarmCluster(private val controller: MatterController, private val endpointId: UShort) {class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } suspend fun selfTestRequest(timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - - suspend fun readExpressedStateAttribute(): 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)) - +suspend fun readExpressedStateAttribute(): 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}") - } + 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) { "Expressedstate attribute not found in response" } + } + + requireNotNull(attributeData) { + "Expressedstate 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 subscribeExpressedStateAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Expressedstate attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Expressedstate attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -185,258 +213,275 @@ class SmokeCoAlarmCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readSmokeStateAttribute(): 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)) - +suspend fun readSmokeStateAttribute(): 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}") - } + 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) { "Smokestate attribute not found in response" } + } + + requireNotNull(attributeData) { + "Smokestate 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeSmokeStateAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Smokestate attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Smokestate 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)) } + 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 readCOStateAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readCOStateAttribute(): UByte? {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}") - } + 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) { "Costate attribute not found in response" } + } + + requireNotNull(attributeData) { + "Costate 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeCOStateAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Costate attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Costate 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)) } + 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 readBatteryAlertAttribute(): UByte { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readBatteryAlertAttribute(): UByte {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}") - } + 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) { "Batteryalert attribute not found in response" } + } + + requireNotNull(attributeData) { + "Batteryalert 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 subscribeBatteryAlertAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Batteryalert attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Batteryalert attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -448,168 +493,177 @@ class SmokeCoAlarmCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readDeviceMutedAttribute(): 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)) - +suspend fun readDeviceMutedAttribute(): 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}") - } + 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) { "Devicemuted attribute not found in response" } + } + + requireNotNull(attributeData) { + "Devicemuted 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeDeviceMutedAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Devicemuted attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Devicemuted 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)) } + 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 readTestInProgressAttribute(): Boolean { - val ATTRIBUTE_ID: UInt = 5u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readTestInProgressAttribute(): Boolean {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}") - } + 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) { "Testinprogress attribute not found in response" } + } + + requireNotNull(attributeData) { + "Testinprogress attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Boolean = tlvReader.getBoolean(AnonymousTag) + return decodedValue } suspend fun subscribeTestInProgressAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Testinprogress attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Testinprogress attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -622,77 +676,80 @@ class SmokeCoAlarmCluster( emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readHardwareFaultAlertAttribute(): Boolean { - val ATTRIBUTE_ID: UInt = 6u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readHardwareFaultAlertAttribute(): Boolean {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}") - } + 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) { "Hardwarefaultalert attribute not found in response" } + } + + requireNotNull(attributeData) { + "Hardwarefaultalert attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Boolean = tlvReader.getBoolean(AnonymousTag) + return decodedValue } suspend fun subscribeHardwareFaultAlertAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Hardwarefaultalert attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Hardwarefaultalert attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -705,77 +762,80 @@ class SmokeCoAlarmCluster( emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readEndOfServiceAlertAttribute(): UByte { - val ATTRIBUTE_ID: UInt = 7u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readEndOfServiceAlertAttribute(): UByte {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}") - } + 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) { "Endofservicealert attribute not found in response" } + } + + requireNotNull(attributeData) { + "Endofservicealert 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 subscribeEndOfServiceAlertAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Endofservicealert attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Endofservicealert attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -788,344 +848,363 @@ class SmokeCoAlarmCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readInterconnectSmokeAlarmAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 8u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readInterconnectSmokeAlarmAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 8u + + 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}") - } + 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) { "Interconnectsmokealarm attribute not found in response" } + } + + requireNotNull(attributeData) { + "Interconnectsmokealarm 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeInterconnectSmokeAlarmAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Interconnectsmokealarm attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Interconnectsmokealarm 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)) } + 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 readInterconnectCOAlarmAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 9u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readInterconnectCOAlarmAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 9u + + 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}") - } + 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) { "Interconnectcoalarm attribute not found in response" } + } + + requireNotNull(attributeData) { + "Interconnectcoalarm 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeInterconnectCOAlarmAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Interconnectcoalarm attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Interconnectcoalarm 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)) } + 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 readContaminationStateAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 10u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readContaminationStateAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 10u + + 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}") - } + 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) { "Contaminationstate attribute not found in response" } + } + + requireNotNull(attributeData) { + "Contaminationstate 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeContaminationStateAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Contaminationstate attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Contaminationstate 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)) } + 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 readSmokeSensitivityLevelAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 11u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readSmokeSensitivityLevelAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 11u + + 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}") - } + 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) { "Smokesensitivitylevel attribute not found in response" } + } + + requireNotNull(attributeData) { + "Smokesensitivitylevel 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun writeSmokeSensitivityLevelAttribute( value: UByte, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 11u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -1146,244 +1225,249 @@ class SmokeCoAlarmCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeSmokeSensitivityLevelAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 11u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Smokesensitivitylevel attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Smokesensitivitylevel 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)) } + 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 readExpiryDateAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 12u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readExpiryDateAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 12u + + 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}") - } + 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) { "Expirydate attribute not found in response" } + } + + requireNotNull(attributeData) { + "Expirydate attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeExpiryDateAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 12u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Expirydate attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Expirydate attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1391,96 +1475,97 @@ class SmokeCoAlarmCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1488,94 +1573,97 @@ class SmokeCoAlarmCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1583,94 +1671,97 @@ class SmokeCoAlarmCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1678,76 +1769,81 @@ class SmokeCoAlarmCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1759,77 +1855,80 @@ class SmokeCoAlarmCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1842,7 +1941,7 @@ class SmokeCoAlarmCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/SoftwareDiagnosticsCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/SoftwareDiagnosticsCluster.kt index e9b7a01ed3b816..3e60be49a852ca 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/SoftwareDiagnosticsCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/SoftwareDiagnosticsCluster.kt @@ -17,572 +17,620 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState +import matter.controller.UByteSubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState import matter.controller.ULongSubscriptionState -import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class SoftwareDiagnosticsCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class ThreadMetricsAttribute(val value: List?) +class SoftwareDiagnosticsCluster(private val controller: MatterController, private val endpointId: UShort) {class ThreadMetricsAttribute( + val value: List? + ) sealed class ThreadMetricsAttributeSubscriptionState { - data class Success(val value: List?) : - ThreadMetricsAttributeSubscriptionState() - + data class Success( + val value: List? + ) : ThreadMetricsAttributeSubscriptionState() + data class Error(val exception: Exception) : ThreadMetricsAttributeSubscriptionState() - object SubscriptionEstablished : ThreadMetricsAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : ThreadMetricsAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } suspend fun resetWatermarks(timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - - suspend fun readThreadMetricsAttribute(): ThreadMetricsAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readThreadMetricsAttribute(): ThreadMetricsAttribute {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}") - } + 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) { "Threadmetrics attribute not found in response" } + } + + requireNotNull(attributeData) { + "Threadmetrics attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(SoftwareDiagnosticsClusterThreadMetricsStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(SoftwareDiagnosticsClusterThreadMetricsStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + } else { + null + } + return ThreadMetricsAttribute(decodedValue) } suspend fun subscribeThreadMetricsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ThreadMetricsAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ThreadMetricsAttributeSubscriptionState.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) { "Threadmetrics attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Threadmetrics attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add( - SoftwareDiagnosticsClusterThreadMetricsStruct.fromTlv(AnonymousTag, tlvReader) - ) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { emit(ThreadMetricsAttributeSubscriptionState.Success(it)) } + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(SoftwareDiagnosticsClusterThreadMetricsStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { + emit(ThreadMetricsAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ThreadMetricsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readCurrentHeapFreeAttribute(): ULong? { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readCurrentHeapFreeAttribute(): ULong? {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}") - } + 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) { "Currentheapfree attribute not found in response" } + } + + requireNotNull(attributeData) { + "Currentheapfree attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ULong? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getULong(AnonymousTag) - } else { - null - } + val decodedValue: ULong? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeCurrentHeapFreeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ULongSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ULongSubscriptionState.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) { - "Currentheapfree attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Currentheapfree 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.isNextTag(AnonymousTag)) { - tlvReader.getULong(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(ULongSubscriptionState.Success(it)) } + val decodedValue: ULong? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(ULongSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ULongSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readCurrentHeapUsedAttribute(): ULong? { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readCurrentHeapUsedAttribute(): ULong? {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}") - } + 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) { "Currentheapused attribute not found in response" } + } + + requireNotNull(attributeData) { + "Currentheapused attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ULong? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getULong(AnonymousTag) - } else { - null - } + val decodedValue: ULong? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeCurrentHeapUsedAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ULongSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ULongSubscriptionState.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) { - "Currentheapused attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Currentheapused 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.isNextTag(AnonymousTag)) { - tlvReader.getULong(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(ULongSubscriptionState.Success(it)) } + val decodedValue: ULong? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(ULongSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ULongSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readCurrentHeapHighWatermarkAttribute(): ULong? { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readCurrentHeapHighWatermarkAttribute(): ULong? {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}") - } + 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) { "Currentheaphighwatermark attribute not found in response" } + } + + requireNotNull(attributeData) { + "Currentheaphighwatermark attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ULong? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getULong(AnonymousTag) - } else { - null - } + val decodedValue: ULong? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeCurrentHeapHighWatermarkAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ULongSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ULongSubscriptionState.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) { - "Currentheaphighwatermark attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Currentheaphighwatermark 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.isNextTag(AnonymousTag)) { - tlvReader.getULong(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(ULongSubscriptionState.Success(it)) } + val decodedValue: ULong? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(ULongSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ULongSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -590,96 +638,97 @@ class SoftwareDiagnosticsCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -687,94 +736,97 @@ class SoftwareDiagnosticsCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -782,94 +834,97 @@ class SoftwareDiagnosticsCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -877,76 +932,81 @@ class SoftwareDiagnosticsCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -958,77 +1018,80 @@ class SoftwareDiagnosticsCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1041,7 +1104,7 @@ class SoftwareDiagnosticsCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/SwitchCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/SwitchCluster.kt index 8f509aeedab056..0462ac9b0c886c 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/SwitchCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/SwitchCluster.kt @@ -17,133 +17,172 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath +import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader +import matter.tlv.TlvWriter -class SwitchCluster(private val controller: MatterController, private val endpointId: UShort) { - class GeneratedCommandListAttribute(val value: List) +class SwitchCluster(private val controller: MatterController, private val endpointId: UShort) {class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } - - suspend fun readNumberOfPositionsAttribute(): 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)) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } +suspend fun readNumberOfPositionsAttribute(): 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}") - } + 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) { "Numberofpositions attribute not found in response" } + } + + requireNotNull(attributeData) { + "Numberofpositions 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 subscribeNumberOfPositionsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Numberofpositions attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Numberofpositions attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -156,77 +195,80 @@ class SwitchCluster(private val controller: MatterController, private val endpoi emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readCurrentPositionAttribute(): 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)) - +suspend fun readCurrentPositionAttribute(): 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}") - } + 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) { "Currentposition attribute not found in response" } + } + + requireNotNull(attributeData) { + "Currentposition 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 subscribeCurrentPositionAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Currentposition attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Currentposition attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -239,187 +281,194 @@ class SwitchCluster(private val controller: MatterController, private val endpoi emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readMultiPressMaxAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMultiPressMaxAttribute(): UByte? {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}") - } + 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) { "Multipressmax attribute not found in response" } + } + + requireNotNull(attributeData) { + "Multipressmax 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeMultiPressMaxAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Multipressmax attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Multipressmax 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)) } + 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 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -427,96 +476,97 @@ class SwitchCluster(private val controller: MatterController, private val endpoi 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -524,94 +574,97 @@ class SwitchCluster(private val controller: MatterController, private val endpoi 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -619,94 +672,97 @@ class SwitchCluster(private val controller: MatterController, private val endpoi 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -714,76 +770,81 @@ class SwitchCluster(private val controller: MatterController, private val endpoi 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -795,77 +856,80 @@ class SwitchCluster(private val controller: MatterController, private val endpoi 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -878,7 +942,7 @@ class SwitchCluster(private val controller: MatterController, private val endpoi emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/TargetNavigatorCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/TargetNavigatorCluster.kt index 79ab138ac63767..c7aee150c59e6c 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/TargetNavigatorCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/TargetNavigatorCluster.kt @@ -17,91 +17,122 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class TargetNavigatorCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class NavigateTargetResponse(val status: UByte, val data: String?) - - class TargetListAttribute(val value: List) +class TargetNavigatorCluster(private val controller: MatterController, private val endpointId: UShort) { + class NavigateTargetResponse( + val status: UByte, + val data: String? + ) +class TargetListAttribute( + val value: List + ) sealed class TargetListAttributeSubscriptionState { - data class Success(val value: List) : - TargetListAttributeSubscriptionState() - + data class Success( + val value: List + ) : TargetListAttributeSubscriptionState() + data class Error(val exception: Exception) : TargetListAttributeSubscriptionState() - object SubscriptionEstablished : TargetListAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : TargetListAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun navigateTarget( - target: UByte, - data: String?, - timedInvokeTimeout: Duration? = null, - ): NavigateTargetResponse { + suspend fun navigateTarget(target: UByte + ,data: String? + ,timedInvokeTimeout: Duration? = null): NavigateTargetResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() @@ -111,14 +142,16 @@ class TargetNavigatorCluster( tlvWriter.put(ContextSpecificTag(TAG_TARGET_REQ), target) val TAG_DATA_REQ: Int = 1 - data?.let { tlvWriter.put(ContextSpecificTag(TAG_DATA_REQ), data) } + data?.let { + tlvWriter.put(ContextSpecificTag(TAG_DATA_REQ), data) + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -128,128 +161,140 @@ class TargetNavigatorCluster( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_DATA: Int = 1 var data_decoded: String? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_STATUS)) { - status_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_DATA)) { - data_decoded = + + if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_DATA)) {data_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - } - } else { + tlvReader.getString(tag) + } else { + null + } + }} + + + else { tlvReader.skipElement() } } + + if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } + + + tlvReader.exitContainer() - return NavigateTargetResponse(status_decoded, data_decoded) + return NavigateTargetResponse( + status_decoded, + data_decoded + ) } - - suspend fun readTargetListAttribute(): TargetListAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readTargetListAttribute(): TargetListAttribute {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}") - } + 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) { "Targetlist attribute not found in response" } + } + + requireNotNull(attributeData) { + "Targetlist 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(TargetNavigatorClusterTargetInfoStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(TargetNavigatorClusterTargetInfoStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + return TargetListAttribute(decodedValue) } suspend fun subscribeTargetListAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - TargetListAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(TargetListAttributeSubscriptionState.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) { "Targetlist attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Targetlist 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(TargetNavigatorClusterTargetInfoStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(TargetNavigatorClusterTargetInfoStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(TargetListAttributeSubscriptionState.Success(decodedValue)) } @@ -257,187 +302,194 @@ class TargetNavigatorCluster( emit(TargetListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readCurrentTargetAttribute(): 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)) - +suspend fun readCurrentTargetAttribute(): 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}") - } + 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) { "Currenttarget attribute not found in response" } + } + + requireNotNull(attributeData) { + "Currenttarget 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeCurrentTargetAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Currenttarget attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Currenttarget 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)) } + 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 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -445,96 +497,97 @@ class TargetNavigatorCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -542,94 +595,97 @@ class TargetNavigatorCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -637,94 +693,97 @@ class TargetNavigatorCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -732,76 +791,81 @@ class TargetNavigatorCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -813,77 +877,80 @@ class TargetNavigatorCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -896,7 +963,7 @@ class TargetNavigatorCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/TemperatureControlCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/TemperatureControlCluster.kt index 414914cd5a45f2..879479e9577967 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/TemperatureControlCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/TemperatureControlCluster.kt @@ -17,91 +17,117 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest -import matter.controller.ShortSubscriptionState +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class TemperatureControlCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class SupportedTemperatureLevelsAttribute(val value: List?) +class TemperatureControlCluster(private val controller: MatterController, private val endpointId: UShort) {class SupportedTemperatureLevelsAttribute( + val value: List? + ) sealed class SupportedTemperatureLevelsAttributeSubscriptionState { - data class Success(val value: List?) : - SupportedTemperatureLevelsAttributeSubscriptionState() - - data class Error(val exception: Exception) : - SupportedTemperatureLevelsAttributeSubscriptionState() - - object SubscriptionEstablished : SupportedTemperatureLevelsAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + data class Success( + val value: List? + ) : SupportedTemperatureLevelsAttributeSubscriptionState() + + data class Error(val exception: Exception) : SupportedTemperatureLevelsAttributeSubscriptionState() + + object SubscriptionEstablished : SupportedTemperatureLevelsAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun setTemperature( - targetTemperature: Short?, - targetTemperatureLevel: UByte?, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun setTemperature(targetTemperature: Short? + ,targetTemperatureLevel: UByte? + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() @@ -115,677 +141,702 @@ class TemperatureControlCluster( val TAG_TARGET_TEMPERATURE_LEVEL_REQ: Int = 1 targetTemperatureLevel?.let { tlvWriter.put(ContextSpecificTag(TAG_TARGET_TEMPERATURE_LEVEL_REQ), targetTemperatureLevel) - } + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - - suspend fun readTemperatureSetpointAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readTemperatureSetpointAttribute(): Short? {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}") - } + 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) { "Temperaturesetpoint attribute not found in response" } + } + + requireNotNull(attributeData) { + "Temperaturesetpoint attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeTemperatureSetpointAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Temperaturesetpoint attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Temperaturesetpoint attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readMinTemperatureAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMinTemperatureAttribute(): Short? {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}") - } + 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) { "Mintemperature attribute not found in response" } + } + + requireNotNull(attributeData) { + "Mintemperature attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeMinTemperatureAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Mintemperature attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Mintemperature attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readMaxTemperatureAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMaxTemperatureAttribute(): Short? {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}") - } + 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) { "Maxtemperature attribute not found in response" } + } + + requireNotNull(attributeData) { + "Maxtemperature attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeMaxTemperatureAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Maxtemperature attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Maxtemperature attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readStepAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readStepAttribute(): Short? {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}") - } + 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) { "Step attribute not found in response" } + } + + requireNotNull(attributeData) { + "Step attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeStepAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { "Step attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Step attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readSelectedTemperatureLevelAttribute(): 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)) - +suspend fun readSelectedTemperatureLevelAttribute(): 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}") - } + 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) { "Selectedtemperaturelevel attribute not found in response" } + } + + requireNotNull(attributeData) { + "Selectedtemperaturelevel 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeSelectedTemperatureLevelAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Selectedtemperaturelevel attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Selectedtemperaturelevel 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)) } + 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 readSupportedTemperatureLevelsAttribute(): SupportedTemperatureLevelsAttribute { - val ATTRIBUTE_ID: UInt = 5u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readSupportedTemperatureLevelsAttribute(): SupportedTemperatureLevelsAttribute {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}") - } + 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) { "Supportedtemperaturelevels attribute not found in response" } + } + + requireNotNull(attributeData) { + "Supportedtemperaturelevels attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getString(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getString(AnonymousTag)) } + tlvReader.exitContainer() + } + } else { + null + } + return SupportedTemperatureLevelsAttribute(decodedValue) } suspend fun subscribeSupportedTemperatureLevelsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - SupportedTemperatureLevelsAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(SupportedTemperatureLevelsAttributeSubscriptionState.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) { - "Supportedtemperaturelevels attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Supportedtemperaturelevels attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getString(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null - } + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getString(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null + } decodedValue?.let { emit(SupportedTemperatureLevelsAttributeSubscriptionState.Success(it)) } + } SubscriptionState.SubscriptionEstablished -> { emit(SupportedTemperatureLevelsAttributeSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -793,96 +844,97 @@ class TemperatureControlCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -890,94 +942,97 @@ class TemperatureControlCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -985,94 +1040,97 @@ class TemperatureControlCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1080,76 +1138,81 @@ class TemperatureControlCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1161,77 +1224,80 @@ class TemperatureControlCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1244,7 +1310,7 @@ class TemperatureControlCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/TemperatureMeasurementCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/TemperatureMeasurementCluster.kt index 60b2bc3e6f90b6..ef6d1043bbbf5b 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/TemperatureMeasurementCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/TemperatureMeasurementCluster.kt @@ -17,558 +17,622 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.UIntSubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState +import matter.controller.UByteSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath +import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader +import matter.tlv.TlvWriter -class TemperatureMeasurementCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class MeasuredValueAttribute(val value: Short?) +class TemperatureMeasurementCluster(private val controller: MatterController, private val endpointId: UShort) {class MeasuredValueAttribute( + val value: Short? + ) sealed class MeasuredValueAttributeSubscriptionState { - data class Success(val value: Short?) : MeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Short? + ) : MeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() - } - - class MinMeasuredValueAttribute(val value: Short?) + object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() + } +class MinMeasuredValueAttribute( + val value: Short? + ) sealed class MinMeasuredValueAttributeSubscriptionState { - data class Success(val value: Short?) : MinMeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Short? + ) : MinMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MinMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() - } - - class MaxMeasuredValueAttribute(val value: Short?) + object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() + } +class MaxMeasuredValueAttribute( + val value: Short? + ) sealed class MaxMeasuredValueAttributeSubscriptionState { - data class Success(val value: Short?) : MaxMeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Short? + ) : MaxMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MaxMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } - - suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } +suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute {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}") - } + 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) { "Measuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Measuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (!tlvReader.isNull()) { - tlvReader.getShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Short? = if (!tlvReader.isNull()) { + tlvReader.getShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MeasuredValueAttribute(decodedValue) } suspend fun subscribeMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MeasuredValueAttributeSubscriptionState.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) { "Measuredvalue attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Measuredvalue attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (!tlvReader.isNull()) { - tlvReader.getShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Short? = if (!tlvReader.isNull()) { + tlvReader.getShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute {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}") - } + 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) { "Minmeasuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Minmeasuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (!tlvReader.isNull()) { - tlvReader.getShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Short? = if (!tlvReader.isNull()) { + tlvReader.getShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MinMeasuredValueAttribute(decodedValue) } suspend fun subscribeMinMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MinMeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MinMeasuredValueAttributeSubscriptionState.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) { - "Minmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Minmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (!tlvReader.isNull()) { - tlvReader.getShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Short? = if (!tlvReader.isNull()) { + tlvReader.getShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MinMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute {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}") - } + 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) { "Maxmeasuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Maxmeasuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (!tlvReader.isNull()) { - tlvReader.getShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Short? = if (!tlvReader.isNull()) { + tlvReader.getShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MaxMeasuredValueAttribute(decodedValue) } suspend fun subscribeMaxMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MaxMeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MaxMeasuredValueAttributeSubscriptionState.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) { - "Maxmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Maxmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (!tlvReader.isNull()) { - tlvReader.getShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Short? = if (!tlvReader.isNull()) { + tlvReader.getShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MaxMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readToleranceAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readToleranceAttribute(): UShort? {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}") - } + 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) { "Tolerance attribute not found in response" } + } + + requireNotNull(attributeData) { + "Tolerance 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeToleranceAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Tolerance attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Tolerance 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)) } + 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 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -576,96 +640,97 @@ class TemperatureMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -673,94 +738,97 @@ class TemperatureMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -768,94 +836,97 @@ class TemperatureMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -863,76 +934,81 @@ class TemperatureMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -944,77 +1020,80 @@ class TemperatureMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1027,7 +1106,7 @@ class TemperatureMeasurementCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/ThermostatCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/ThermostatCluster.kt index b9166c12e937a1..8024c0d931b0b7 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/ThermostatCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/ThermostatCluster.kt @@ -17,288 +17,364 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.ByteSubscriptionState -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest -import matter.controller.ShortSubscriptionState +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.cluster.structs.* +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter class ThermostatCluster(private val controller: MatterController, private val endpointId: UShort) { class GetWeeklyScheduleResponse( - val numberOfTransitionsForSequence: UByte, - val dayOfWeekForSequence: UByte, - val modeForSequence: UByte, - val transitions: List, + val numberOfTransitionsForSequence: UByte, + val dayOfWeekForSequence: UByte, + val modeForSequence: UByte, + val transitions: List ) class AtomicResponse( - val statusCode: UByte, - val attributeStatus: List, - val timeout: UShort?, + val statusCode: UByte, + val attributeStatus: List, + val timeout: UShort? + ) +class LocalTemperatureAttribute( + val value: Short? ) - - class LocalTemperatureAttribute(val value: Short?) sealed class LocalTemperatureAttributeSubscriptionState { - data class Success(val value: Short?) : LocalTemperatureAttributeSubscriptionState() - + data class Success( + val value: Short? + ) : LocalTemperatureAttributeSubscriptionState() + data class Error(val exception: Exception) : LocalTemperatureAttributeSubscriptionState() - object SubscriptionEstablished : LocalTemperatureAttributeSubscriptionState() - } - - class OutdoorTemperatureAttribute(val value: Short?) + object SubscriptionEstablished : LocalTemperatureAttributeSubscriptionState() + } +class OutdoorTemperatureAttribute( + val value: Short? + ) sealed class OutdoorTemperatureAttributeSubscriptionState { - data class Success(val value: Short?) : OutdoorTemperatureAttributeSubscriptionState() - + data class Success( + val value: Short? + ) : OutdoorTemperatureAttributeSubscriptionState() + data class Error(val exception: Exception) : OutdoorTemperatureAttributeSubscriptionState() - object SubscriptionEstablished : OutdoorTemperatureAttributeSubscriptionState() - } - - class TemperatureSetpointHoldDurationAttribute(val value: UShort?) + object SubscriptionEstablished : OutdoorTemperatureAttributeSubscriptionState() + } +class TemperatureSetpointHoldDurationAttribute( + val value: UShort? + ) sealed class TemperatureSetpointHoldDurationAttributeSubscriptionState { - data class Success(val value: UShort?) : - TemperatureSetpointHoldDurationAttributeSubscriptionState() - - data class Error(val exception: Exception) : - TemperatureSetpointHoldDurationAttributeSubscriptionState() - - object SubscriptionEstablished : TemperatureSetpointHoldDurationAttributeSubscriptionState() - } - - class SetpointChangeAmountAttribute(val value: Short?) + data class Success( + val value: UShort? + ) : TemperatureSetpointHoldDurationAttributeSubscriptionState() + + data class Error(val exception: Exception) : TemperatureSetpointHoldDurationAttributeSubscriptionState() + + object SubscriptionEstablished : TemperatureSetpointHoldDurationAttributeSubscriptionState() + } +class SetpointChangeAmountAttribute( + val value: Short? + ) sealed class SetpointChangeAmountAttributeSubscriptionState { - data class Success(val value: Short?) : SetpointChangeAmountAttributeSubscriptionState() - + data class Success( + val value: Short? + ) : SetpointChangeAmountAttributeSubscriptionState() + data class Error(val exception: Exception) : SetpointChangeAmountAttributeSubscriptionState() - object SubscriptionEstablished : SetpointChangeAmountAttributeSubscriptionState() - } - - class OccupiedSetbackAttribute(val value: UByte?) + object SubscriptionEstablished : SetpointChangeAmountAttributeSubscriptionState() + } +class OccupiedSetbackAttribute( + val value: UByte? + ) sealed class OccupiedSetbackAttributeSubscriptionState { - data class Success(val value: UByte?) : OccupiedSetbackAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : OccupiedSetbackAttributeSubscriptionState() + data class Error(val exception: Exception) : OccupiedSetbackAttributeSubscriptionState() - object SubscriptionEstablished : OccupiedSetbackAttributeSubscriptionState() - } - - class OccupiedSetbackMinAttribute(val value: UByte?) + object SubscriptionEstablished : OccupiedSetbackAttributeSubscriptionState() + } +class OccupiedSetbackMinAttribute( + val value: UByte? + ) sealed class OccupiedSetbackMinAttributeSubscriptionState { - data class Success(val value: UByte?) : OccupiedSetbackMinAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : OccupiedSetbackMinAttributeSubscriptionState() + data class Error(val exception: Exception) : OccupiedSetbackMinAttributeSubscriptionState() - object SubscriptionEstablished : OccupiedSetbackMinAttributeSubscriptionState() - } - - class OccupiedSetbackMaxAttribute(val value: UByte?) + object SubscriptionEstablished : OccupiedSetbackMinAttributeSubscriptionState() + } +class OccupiedSetbackMaxAttribute( + val value: UByte? + ) sealed class OccupiedSetbackMaxAttributeSubscriptionState { - data class Success(val value: UByte?) : OccupiedSetbackMaxAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : OccupiedSetbackMaxAttributeSubscriptionState() + data class Error(val exception: Exception) : OccupiedSetbackMaxAttributeSubscriptionState() - object SubscriptionEstablished : OccupiedSetbackMaxAttributeSubscriptionState() - } - - class UnoccupiedSetbackAttribute(val value: UByte?) + object SubscriptionEstablished : OccupiedSetbackMaxAttributeSubscriptionState() + } +class UnoccupiedSetbackAttribute( + val value: UByte? + ) sealed class UnoccupiedSetbackAttributeSubscriptionState { - data class Success(val value: UByte?) : UnoccupiedSetbackAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : UnoccupiedSetbackAttributeSubscriptionState() + data class Error(val exception: Exception) : UnoccupiedSetbackAttributeSubscriptionState() - object SubscriptionEstablished : UnoccupiedSetbackAttributeSubscriptionState() - } - - class UnoccupiedSetbackMinAttribute(val value: UByte?) + object SubscriptionEstablished : UnoccupiedSetbackAttributeSubscriptionState() + } +class UnoccupiedSetbackMinAttribute( + val value: UByte? + ) sealed class UnoccupiedSetbackMinAttributeSubscriptionState { - data class Success(val value: UByte?) : UnoccupiedSetbackMinAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : UnoccupiedSetbackMinAttributeSubscriptionState() + data class Error(val exception: Exception) : UnoccupiedSetbackMinAttributeSubscriptionState() - object SubscriptionEstablished : UnoccupiedSetbackMinAttributeSubscriptionState() - } - - class UnoccupiedSetbackMaxAttribute(val value: UByte?) + object SubscriptionEstablished : UnoccupiedSetbackMinAttributeSubscriptionState() + } +class UnoccupiedSetbackMaxAttribute( + val value: UByte? + ) sealed class UnoccupiedSetbackMaxAttributeSubscriptionState { - data class Success(val value: UByte?) : UnoccupiedSetbackMaxAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : UnoccupiedSetbackMaxAttributeSubscriptionState() + data class Error(val exception: Exception) : UnoccupiedSetbackMaxAttributeSubscriptionState() - object SubscriptionEstablished : UnoccupiedSetbackMaxAttributeSubscriptionState() - } - - class ACCoilTemperatureAttribute(val value: Short?) + object SubscriptionEstablished : UnoccupiedSetbackMaxAttributeSubscriptionState() + } +class ACCoilTemperatureAttribute( + val value: Short? + ) sealed class ACCoilTemperatureAttributeSubscriptionState { - data class Success(val value: Short?) : ACCoilTemperatureAttributeSubscriptionState() - + data class Success( + val value: Short? + ) : ACCoilTemperatureAttributeSubscriptionState() + data class Error(val exception: Exception) : ACCoilTemperatureAttributeSubscriptionState() - object SubscriptionEstablished : ACCoilTemperatureAttributeSubscriptionState() - } - - class PresetTypesAttribute(val value: List?) + object SubscriptionEstablished : ACCoilTemperatureAttributeSubscriptionState() + } +class PresetTypesAttribute( + val value: List? + ) sealed class PresetTypesAttributeSubscriptionState { - data class Success(val value: List?) : - PresetTypesAttributeSubscriptionState() - + data class Success( + val value: List? + ) : PresetTypesAttributeSubscriptionState() + data class Error(val exception: Exception) : PresetTypesAttributeSubscriptionState() - object SubscriptionEstablished : PresetTypesAttributeSubscriptionState() - } - - class ScheduleTypesAttribute(val value: List?) + object SubscriptionEstablished : PresetTypesAttributeSubscriptionState() + } +class ScheduleTypesAttribute( + val value: List? + ) sealed class ScheduleTypesAttributeSubscriptionState { - data class Success(val value: List?) : - ScheduleTypesAttributeSubscriptionState() - + data class Success( + val value: List? + ) : ScheduleTypesAttributeSubscriptionState() + data class Error(val exception: Exception) : ScheduleTypesAttributeSubscriptionState() - object SubscriptionEstablished : ScheduleTypesAttributeSubscriptionState() - } - - class NumberOfScheduleTransitionPerDayAttribute(val value: UByte?) + object SubscriptionEstablished : ScheduleTypesAttributeSubscriptionState() + } +class NumberOfScheduleTransitionPerDayAttribute( + val value: UByte? + ) sealed class NumberOfScheduleTransitionPerDayAttributeSubscriptionState { - data class Success(val value: UByte?) : - NumberOfScheduleTransitionPerDayAttributeSubscriptionState() - - data class Error(val exception: Exception) : - NumberOfScheduleTransitionPerDayAttributeSubscriptionState() - - object SubscriptionEstablished : NumberOfScheduleTransitionPerDayAttributeSubscriptionState() - } - - class ActivePresetHandleAttribute(val value: ByteArray?) + data class Success( + val value: UByte? + ) : NumberOfScheduleTransitionPerDayAttributeSubscriptionState() + + data class Error(val exception: Exception) : NumberOfScheduleTransitionPerDayAttributeSubscriptionState() + + object SubscriptionEstablished : NumberOfScheduleTransitionPerDayAttributeSubscriptionState() + } +class ActivePresetHandleAttribute( + val value: ByteArray? + ) sealed class ActivePresetHandleAttributeSubscriptionState { - data class Success(val value: ByteArray?) : ActivePresetHandleAttributeSubscriptionState() - + data class Success( + val value: ByteArray? + ) : ActivePresetHandleAttributeSubscriptionState() + data class Error(val exception: Exception) : ActivePresetHandleAttributeSubscriptionState() - object SubscriptionEstablished : ActivePresetHandleAttributeSubscriptionState() - } - - class ActiveScheduleHandleAttribute(val value: ByteArray?) + object SubscriptionEstablished : ActivePresetHandleAttributeSubscriptionState() + } +class ActiveScheduleHandleAttribute( + val value: ByteArray? + ) sealed class ActiveScheduleHandleAttributeSubscriptionState { - data class Success(val value: ByteArray?) : ActiveScheduleHandleAttributeSubscriptionState() - + data class Success( + val value: ByteArray? + ) : ActiveScheduleHandleAttributeSubscriptionState() + data class Error(val exception: Exception) : ActiveScheduleHandleAttributeSubscriptionState() - object SubscriptionEstablished : ActiveScheduleHandleAttributeSubscriptionState() - } - - class PresetsAttribute(val value: List?) + object SubscriptionEstablished : ActiveScheduleHandleAttributeSubscriptionState() + } +class PresetsAttribute( + val value: List? + ) sealed class PresetsAttributeSubscriptionState { - data class Success(val value: List?) : - PresetsAttributeSubscriptionState() - + data class Success( + val value: List? + ) : PresetsAttributeSubscriptionState() + data class Error(val exception: Exception) : PresetsAttributeSubscriptionState() - object SubscriptionEstablished : PresetsAttributeSubscriptionState() - } - - class SchedulesAttribute(val value: List?) + object SubscriptionEstablished : PresetsAttributeSubscriptionState() + } +class SchedulesAttribute( + val value: List? + ) sealed class SchedulesAttributeSubscriptionState { - data class Success(val value: List?) : - SchedulesAttributeSubscriptionState() - + data class Success( + val value: List? + ) : SchedulesAttributeSubscriptionState() + data class Error(val exception: Exception) : SchedulesAttributeSubscriptionState() - object SubscriptionEstablished : SchedulesAttributeSubscriptionState() - } - - class SetpointHoldExpiryTimestampAttribute(val value: UInt?) + object SubscriptionEstablished : SchedulesAttributeSubscriptionState() + } +class SetpointHoldExpiryTimestampAttribute( + val value: UInt? + ) sealed class SetpointHoldExpiryTimestampAttributeSubscriptionState { - data class Success(val value: UInt?) : SetpointHoldExpiryTimestampAttributeSubscriptionState() - - data class Error(val exception: Exception) : - SetpointHoldExpiryTimestampAttributeSubscriptionState() - - object SubscriptionEstablished : SetpointHoldExpiryTimestampAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + data class Success( + val value: UInt? + ) : SetpointHoldExpiryTimestampAttributeSubscriptionState() + + data class Error(val exception: Exception) : SetpointHoldExpiryTimestampAttributeSubscriptionState() + + object SubscriptionEstablished : SetpointHoldExpiryTimestampAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun setpointRaiseLower(mode: UByte, amount: Byte, timedInvokeTimeout: Duration? = null) { + suspend fun setpointRaiseLower(mode: UByte + ,amount: Byte + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() @@ -308,37 +384,32 @@ class ThermostatCluster(private val controller: MatterController, private val en tlvWriter.put(ContextSpecificTag(TAG_MODE_REQ), mode) val TAG_AMOUNT_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_AMOUNT_REQ), amount) + tlvWriter.put(ContextSpecificTag(TAG_AMOUNT_REQ), amount) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun setWeeklySchedule( - numberOfTransitionsForSequence: UByte, - dayOfWeekForSequence: UByte, - modeForSequence: UByte, - transitions: List, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun setWeeklySchedule(numberOfTransitionsForSequence: UByte + ,dayOfWeekForSequence: UByte + ,modeForSequence: UByte + ,transitions: List + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 1u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_NUMBER_OF_TRANSITIONS_FOR_SEQUENCE_REQ: Int = 0 - tlvWriter.put( - ContextSpecificTag(TAG_NUMBER_OF_TRANSITIONS_FOR_SEQUENCE_REQ), - numberOfTransitionsForSequence, - ) + tlvWriter.put(ContextSpecificTag(TAG_NUMBER_OF_TRANSITIONS_FOR_SEQUENCE_REQ), numberOfTransitionsForSequence) val TAG_DAY_OF_WEEK_FOR_SEQUENCE_REQ: Int = 1 tlvWriter.put(ContextSpecificTag(TAG_DAY_OF_WEEK_FOR_SEQUENCE_REQ), dayOfWeekForSequence) @@ -348,28 +419,26 @@ class ThermostatCluster(private val controller: MatterController, private val en val TAG_TRANSITIONS_REQ: Int = 3 tlvWriter.startArray(ContextSpecificTag(TAG_TRANSITIONS_REQ)) - for (item in transitions.iterator()) { - item.toTlv(AnonymousTag, tlvWriter) - } - tlvWriter.endArray() + for (item in transitions.iterator()) { + item.toTlv(AnonymousTag, tlvWriter) + } + tlvWriter.endArray() tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun getWeeklySchedule( - daysToReturn: UByte, - modeToReturn: UByte, - timedInvokeTimeout: Duration? = null, - ): GetWeeklyScheduleResponse { + suspend fun getWeeklySchedule(daysToReturn: UByte + ,modeToReturn: UByte + ,timedInvokeTimeout: Duration? = null): GetWeeklyScheduleResponse { val commandId: UInt = 2u val tlvWriter = TlvWriter() @@ -379,14 +448,14 @@ class ThermostatCluster(private val controller: MatterController, private val en tlvWriter.put(ContextSpecificTag(TAG_DAYS_TO_RETURN_REQ), daysToReturn) val TAG_MODE_TO_RETURN_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_MODE_TO_RETURN_REQ), modeToReturn) + tlvWriter.put(ContextSpecificTag(TAG_MODE_TO_RETURN_REQ), modeToReturn) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -396,60 +465,62 @@ class ThermostatCluster(private val controller: MatterController, private val en tlvReader.enterStructure(AnonymousTag) val TAG_NUMBER_OF_TRANSITIONS_FOR_SEQUENCE: Int = 0 var numberOfTransitionsForSequence_decoded: UByte? = null - + val TAG_DAY_OF_WEEK_FOR_SEQUENCE: Int = 1 var dayOfWeekForSequence_decoded: UByte? = null - + val TAG_MODE_FOR_SEQUENCE: Int = 2 var modeForSequence_decoded: UByte? = null - + val TAG_TRANSITIONS: Int = 3 var transitions_decoded: List? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_NUMBER_OF_TRANSITIONS_FOR_SEQUENCE)) { - numberOfTransitionsForSequence_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_DAY_OF_WEEK_FOR_SEQUENCE)) { - dayOfWeekForSequence_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_MODE_FOR_SEQUENCE)) { - modeForSequence_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_TRANSITIONS)) { - transitions_decoded = - buildList { - tlvReader.enterArray(tag) - while (!tlvReader.isEndOfContainer()) { - add(ThermostatClusterWeeklyScheduleTransitionStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { + + if (tag == ContextSpecificTag(TAG_NUMBER_OF_TRANSITIONS_FOR_SEQUENCE)) {numberOfTransitionsForSequence_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_DAY_OF_WEEK_FOR_SEQUENCE)) {dayOfWeekForSequence_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_MODE_FOR_SEQUENCE)) {modeForSequence_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_TRANSITIONS)) {transitions_decoded = buildList { + tlvReader.enterArray(tag) + while(!tlvReader.isEndOfContainer()) { + add(ThermostatClusterWeeklyScheduleTransitionStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + }} + + + else { tlvReader.skipElement() } } + + if (numberOfTransitionsForSequence_decoded == null) { - throw IllegalStateException("numberOfTransitionsForSequence not found in TLV") + throw IllegalStateException("numberOfTransitionsForSequence not found in TLV") } - + + if (dayOfWeekForSequence_decoded == null) { - throw IllegalStateException("dayOfWeekForSequence not found in TLV") + throw IllegalStateException("dayOfWeekForSequence not found in TLV") } - + + if (modeForSequence_decoded == null) { - throw IllegalStateException("modeForSequence not found in TLV") + throw IllegalStateException("modeForSequence not found in TLV") } - + + if (transitions_decoded == null) { - throw IllegalStateException("transitions not found in TLV") + throw IllegalStateException("transitions not found in TLV") } + tlvReader.exitContainer() @@ -457,7 +528,7 @@ class ThermostatCluster(private val controller: MatterController, private val en numberOfTransitionsForSequence_decoded, dayOfWeekForSequence_decoded, modeForSequence_decoded, - transitions_decoded, + transitions_decoded ) } @@ -465,74 +536,68 @@ class ThermostatCluster(private val controller: MatterController, private val en val commandId: UInt = 3u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun setActiveScheduleRequest( - scheduleHandle: ByteArray, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun setActiveScheduleRequest(scheduleHandle: ByteArray + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 5u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_SCHEDULE_HANDLE_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_SCHEDULE_HANDLE_REQ), scheduleHandle) + tlvWriter.put(ContextSpecificTag(TAG_SCHEDULE_HANDLE_REQ), scheduleHandle) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun setActivePresetRequest( - presetHandle: ByteArray, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun setActivePresetRequest(presetHandle: ByteArray + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 6u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_PRESET_HANDLE_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_PRESET_HANDLE_REQ), presetHandle) + tlvWriter.put(ContextSpecificTag(TAG_PRESET_HANDLE_REQ), presetHandle) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun atomicRequest( - requestType: UByte, - attributeRequests: List, - timeout: UShort?, - timedInvokeTimeout: Duration? = null, - ): AtomicResponse { + suspend fun atomicRequest(requestType: UByte + ,attributeRequests: List + ,timeout: UShort? + ,timedInvokeTimeout: Duration? = null): AtomicResponse { val commandId: UInt = 254u val tlvWriter = TlvWriter() @@ -543,20 +608,22 @@ class ThermostatCluster(private val controller: MatterController, private val en val TAG_ATTRIBUTE_REQUESTS_REQ: Int = 1 tlvWriter.startArray(ContextSpecificTag(TAG_ATTRIBUTE_REQUESTS_REQ)) - for (item in attributeRequests.iterator()) { - tlvWriter.put(AnonymousTag, item) - } - tlvWriter.endArray() + for (item in attributeRequests.iterator()) { + tlvWriter.put(AnonymousTag, item) + } + tlvWriter.endArray() val TAG_TIMEOUT_REQ: Int = 2 - timeout?.let { tlvWriter.put(ContextSpecificTag(TAG_TIMEOUT_REQ), timeout) } + timeout?.let { + tlvWriter.put(ContextSpecificTag(TAG_TIMEOUT_REQ), timeout) + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -566,964 +633,1017 @@ class ThermostatCluster(private val controller: MatterController, private val en tlvReader.enterStructure(AnonymousTag) val TAG_STATUS_CODE: Int = 0 var statusCode_decoded: UByte? = null - + val TAG_ATTRIBUTE_STATUS: Int = 1 var attributeStatus_decoded: List? = null - + val TAG_TIMEOUT: Int = 2 var timeout_decoded: UShort? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_STATUS_CODE)) { - statusCode_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_ATTRIBUTE_STATUS)) { - attributeStatus_decoded = - buildList { - tlvReader.enterArray(tag) - while (!tlvReader.isEndOfContainer()) { - add(ThermostatClusterAtomicAttributeStatusStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } - - if (tag == ContextSpecificTag(TAG_TIMEOUT)) { - timeout_decoded = + + if (tag == ContextSpecificTag(TAG_STATUS_CODE)) {statusCode_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_ATTRIBUTE_STATUS)) {attributeStatus_decoded = buildList { + tlvReader.enterArray(tag) + while(!tlvReader.isEndOfContainer()) { + add(ThermostatClusterAtomicAttributeStatusStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + }} + + if (tag == ContextSpecificTag(TAG_TIMEOUT)) {timeout_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getUShort(tag) - } else { - null - } - } - } else { + tlvReader.getUShort(tag) + } else { + null + } + }} + + + else { tlvReader.skipElement() } } + + if (statusCode_decoded == null) { - throw IllegalStateException("statusCode not found in TLV") + throw IllegalStateException("statusCode not found in TLV") } - + + if (attributeStatus_decoded == null) { - throw IllegalStateException("attributeStatus not found in TLV") + throw IllegalStateException("attributeStatus not found in TLV") } + + + tlvReader.exitContainer() - return AtomicResponse(statusCode_decoded, attributeStatus_decoded, timeout_decoded) + return AtomicResponse( + statusCode_decoded, + attributeStatus_decoded, + timeout_decoded + ) } +suspend fun readLocalTemperatureAttribute(): LocalTemperatureAttribute {val ATTRIBUTE_ID: UInt = 0u - suspend fun readLocalTemperatureAttribute(): LocalTemperatureAttribute { - 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 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}") - } + 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) { "Localtemperature attribute not found in response" } + } + + requireNotNull(attributeData) { + "Localtemperature attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (!tlvReader.isNull()) { - tlvReader.getShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Short? = if (!tlvReader.isNull()) { + tlvReader.getShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return LocalTemperatureAttribute(decodedValue) } suspend fun subscribeLocalTemperatureAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - LocalTemperatureAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(LocalTemperatureAttributeSubscriptionState.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) { - "Localtemperature attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Localtemperature attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (!tlvReader.isNull()) { - tlvReader.getShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Short? = if (!tlvReader.isNull()) { + tlvReader.getShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(LocalTemperatureAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(LocalTemperatureAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(LocalTemperatureAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readOutdoorTemperatureAttribute(): OutdoorTemperatureAttribute {val ATTRIBUTE_ID: UInt = 1u - suspend fun readOutdoorTemperatureAttribute(): OutdoorTemperatureAttribute { - 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 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}") - } + 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) { "Outdoortemperature attribute not found in response" } + } + + requireNotNull(attributeData) { + "Outdoortemperature attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Short? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return OutdoorTemperatureAttribute(decodedValue) } suspend fun subscribeOutdoorTemperatureAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - OutdoorTemperatureAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(OutdoorTemperatureAttributeSubscriptionState.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) { - "Outdoortemperature attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Outdoortemperature attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(OutdoorTemperatureAttributeSubscriptionState.Success(it)) } + val decodedValue: Short? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(OutdoorTemperatureAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(OutdoorTemperatureAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readOccupancyAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 2u - suspend fun readOccupancyAttribute(): UByte? { - 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 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}") - } + 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) { "Occupancy attribute not found in response" } + } + + requireNotNull(attributeData) { + "Occupancy 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeOccupancyAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Occupancy attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Occupancy 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAbsMinHeatSetpointLimitAttribute(): Short? {val ATTRIBUTE_ID: UInt = 3u - suspend fun readAbsMinHeatSetpointLimitAttribute(): Short? { - 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 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}") - } + 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) { "Absminheatsetpointlimit attribute not found in response" } + } + + requireNotNull(attributeData) { + "Absminheatsetpointlimit attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeAbsMinHeatSetpointLimitAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Absminheatsetpointlimit attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Absminheatsetpointlimit attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAbsMaxHeatSetpointLimitAttribute(): Short? {val ATTRIBUTE_ID: UInt = 4u - suspend fun readAbsMaxHeatSetpointLimitAttribute(): Short? { - 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 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}") - } + 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) { "Absmaxheatsetpointlimit attribute not found in response" } + } + + requireNotNull(attributeData) { + "Absmaxheatsetpointlimit attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeAbsMaxHeatSetpointLimitAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Absmaxheatsetpointlimit attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Absmaxheatsetpointlimit attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAbsMinCoolSetpointLimitAttribute(): Short? {val ATTRIBUTE_ID: UInt = 5u - suspend fun readAbsMinCoolSetpointLimitAttribute(): Short? { - 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 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}") - } + 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) { "Absmincoolsetpointlimit attribute not found in response" } + } + + requireNotNull(attributeData) { + "Absmincoolsetpointlimit attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeAbsMinCoolSetpointLimitAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Absmincoolsetpointlimit attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Absmincoolsetpointlimit attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAbsMaxCoolSetpointLimitAttribute(): Short? {val ATTRIBUTE_ID: UInt = 6u - suspend fun readAbsMaxCoolSetpointLimitAttribute(): Short? { - 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 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}") - } + 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) { "Absmaxcoolsetpointlimit attribute not found in response" } + } + + requireNotNull(attributeData) { + "Absmaxcoolsetpointlimit attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeAbsMaxCoolSetpointLimitAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Absmaxcoolsetpointlimit attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Absmaxcoolsetpointlimit attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readPICoolingDemandAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 7u - suspend fun readPICoolingDemandAttribute(): UByte? { - 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 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}") - } + 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) { "Picoolingdemand attribute not found in response" } + } + + requireNotNull(attributeData) { + "Picoolingdemand 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribePICoolingDemandAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Picoolingdemand attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Picoolingdemand 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readPIHeatingDemandAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 8u - suspend fun readPIHeatingDemandAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 8u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Piheatingdemand attribute not found in response" } + } + + requireNotNull(attributeData) { + "Piheatingdemand 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribePIHeatingDemandAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Piheatingdemand attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Piheatingdemand 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readHVACSystemTypeConfigurationAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 9u - suspend fun readHVACSystemTypeConfigurationAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 9u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Hvacsystemtypeconfiguration attribute not found in response" } + } + + requireNotNull(attributeData) { + "Hvacsystemtypeconfiguration 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun writeHVACSystemTypeConfigurationAttribute( value: UByte, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 9u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -1544,122 +1664,127 @@ class ThermostatCluster(private val controller: MatterController, private val en throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeHVACSystemTypeConfigurationAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Hvacsystemtypeconfiguration attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Hvacsystemtypeconfiguration 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readLocalTemperatureCalibrationAttribute(): Byte? {val ATTRIBUTE_ID: UInt = 16u - suspend fun readLocalTemperatureCalibrationAttribute(): Byte? { - val ATTRIBUTE_ID: UInt = 16u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Localtemperaturecalibration attribute not found in response" } + } + + requireNotNull(attributeData) { + "Localtemperaturecalibration attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Byte? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByte(AnonymousTag) - } else { - null - } + val decodedValue: Byte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun writeLocalTemperatureCalibrationAttribute( value: Byte, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -1680,122 +1805,127 @@ class ThermostatCluster(private val controller: MatterController, private val en throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeLocalTemperatureCalibrationAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ByteSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ByteSubscriptionState.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) { - "Localtemperaturecalibration attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Localtemperaturecalibration attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Byte? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByte(AnonymousTag) - } else { - null - } + val decodedValue: Byte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readOccupiedCoolingSetpointAttribute(): Short? {val ATTRIBUTE_ID: UInt = 17u - suspend fun readOccupiedCoolingSetpointAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 17u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Occupiedcoolingsetpoint attribute not found in response" } + } + + requireNotNull(attributeData) { + "Occupiedcoolingsetpoint attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun writeOccupiedCoolingSetpointAttribute( value: Short, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 17u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -1816,122 +1946,127 @@ class ThermostatCluster(private val controller: MatterController, private val en throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeOccupiedCoolingSetpointAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 17u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Occupiedcoolingsetpoint attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Occupiedcoolingsetpoint attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readOccupiedHeatingSetpointAttribute(): Short? {val ATTRIBUTE_ID: UInt = 18u - suspend fun readOccupiedHeatingSetpointAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 18u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Occupiedheatingsetpoint attribute not found in response" } + } + + requireNotNull(attributeData) { + "Occupiedheatingsetpoint attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun writeOccupiedHeatingSetpointAttribute( value: Short, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 18u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -1952,122 +2087,127 @@ class ThermostatCluster(private val controller: MatterController, private val en throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeOccupiedHeatingSetpointAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 18u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Occupiedheatingsetpoint attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Occupiedheatingsetpoint attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readUnoccupiedCoolingSetpointAttribute(): Short? {val ATTRIBUTE_ID: UInt = 19u - suspend fun readUnoccupiedCoolingSetpointAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 19u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Unoccupiedcoolingsetpoint attribute not found in response" } + } + + requireNotNull(attributeData) { + "Unoccupiedcoolingsetpoint attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun writeUnoccupiedCoolingSetpointAttribute( value: Short, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 19u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -2088,122 +2228,127 @@ class ThermostatCluster(private val controller: MatterController, private val en throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeUnoccupiedCoolingSetpointAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 19u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Unoccupiedcoolingsetpoint attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Unoccupiedcoolingsetpoint attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readUnoccupiedHeatingSetpointAttribute(): Short? {val ATTRIBUTE_ID: UInt = 20u - suspend fun readUnoccupiedHeatingSetpointAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 20u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Unoccupiedheatingsetpoint attribute not found in response" } + } + + requireNotNull(attributeData) { + "Unoccupiedheatingsetpoint attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun writeUnoccupiedHeatingSetpointAttribute( value: Short, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 20u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -2224,122 +2369,127 @@ class ThermostatCluster(private val controller: MatterController, private val en throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeUnoccupiedHeatingSetpointAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 20u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Unoccupiedheatingsetpoint attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Unoccupiedheatingsetpoint attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readMinHeatSetpointLimitAttribute(): Short? {val ATTRIBUTE_ID: UInt = 21u - suspend fun readMinHeatSetpointLimitAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 21u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Minheatsetpointlimit attribute not found in response" } + } + + requireNotNull(attributeData) { + "Minheatsetpointlimit attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun writeMinHeatSetpointLimitAttribute( value: Short, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 21u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -2360,122 +2510,127 @@ class ThermostatCluster(private val controller: MatterController, private val en throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeMinHeatSetpointLimitAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 21u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Minheatsetpointlimit attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Minheatsetpointlimit attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readMaxHeatSetpointLimitAttribute(): Short? {val ATTRIBUTE_ID: UInt = 22u - suspend fun readMaxHeatSetpointLimitAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 22u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Maxheatsetpointlimit attribute not found in response" } + } + + requireNotNull(attributeData) { + "Maxheatsetpointlimit attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun writeMaxHeatSetpointLimitAttribute( value: Short, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 22u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -2496,122 +2651,127 @@ class ThermostatCluster(private val controller: MatterController, private val en throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeMaxHeatSetpointLimitAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 22u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Maxheatsetpointlimit attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Maxheatsetpointlimit attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readMinCoolSetpointLimitAttribute(): Short? {val ATTRIBUTE_ID: UInt = 23u - suspend fun readMinCoolSetpointLimitAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 23u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Mincoolsetpointlimit attribute not found in response" } + } + + requireNotNull(attributeData) { + "Mincoolsetpointlimit attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun writeMinCoolSetpointLimitAttribute( value: Short, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 23u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -2632,122 +2792,127 @@ class ThermostatCluster(private val controller: MatterController, private val en throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeMinCoolSetpointLimitAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 23u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Mincoolsetpointlimit attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Mincoolsetpointlimit attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readMaxCoolSetpointLimitAttribute(): Short? {val ATTRIBUTE_ID: UInt = 24u - suspend fun readMaxCoolSetpointLimitAttribute(): Short? { - val ATTRIBUTE_ID: UInt = 24u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Maxcoolsetpointlimit attribute not found in response" } + } + + requireNotNull(attributeData) { + "Maxcoolsetpointlimit attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun writeMaxCoolSetpointLimitAttribute( value: Short, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 24u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -2768,119 +2933,127 @@ class ThermostatCluster(private val controller: MatterController, private val en throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeMaxCoolSetpointLimitAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 24u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Maxcoolsetpointlimit attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Maxcoolsetpointlimit attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readMinSetpointDeadBandAttribute(): Byte? {val ATTRIBUTE_ID: UInt = 25u - suspend fun readMinSetpointDeadBandAttribute(): Byte? { - val ATTRIBUTE_ID: UInt = 25u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Minsetpointdeadband attribute not found in response" } + } + + requireNotNull(attributeData) { + "Minsetpointdeadband attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Byte? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByte(AnonymousTag) - } else { - null - } + val decodedValue: Byte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByte(AnonymousTag) + } else { + null + } + return decodedValue } - suspend fun writeMinSetpointDeadBandAttribute(value: Byte, timedWriteTimeout: Duration? = null) { + suspend fun writeMinSetpointDeadBandAttribute( + value: Byte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 25u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -2901,119 +3074,127 @@ class ThermostatCluster(private val controller: MatterController, private val en throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeMinSetpointDeadBandAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 25u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ByteSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ByteSubscriptionState.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) { - "Minsetpointdeadband attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Minsetpointdeadband attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Byte? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByte(AnonymousTag) - } else { - null - } + val decodedValue: Byte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRemoteSensingAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 26u - suspend fun readRemoteSensingAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 26u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Remotesensing attribute not found in response" } + } + + requireNotNull(attributeData) { + "Remotesensing 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } - suspend fun writeRemoteSensingAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeRemoteSensingAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 26u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -3034,115 +3215,123 @@ class ThermostatCluster(private val controller: MatterController, private val en throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeRemoteSensingAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 26u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Remotesensing attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Remotesensing 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readControlSequenceOfOperationAttribute(): UByte {val ATTRIBUTE_ID: UInt = 27u - suspend fun readControlSequenceOfOperationAttribute(): UByte { - val ATTRIBUTE_ID: UInt = 27u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Controlsequenceofoperation attribute not found in response" } + } + + requireNotNull(attributeData) { + "Controlsequenceofoperation 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 writeControlSequenceOfOperationAttribute( value: UByte, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 27u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -3163,46 +3352,42 @@ class ThermostatCluster(private val controller: MatterController, private val en throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeControlSequenceOfOperationAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 27u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Controlsequenceofoperation attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Controlsequenceofoperation attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -3215,57 +3400,68 @@ class ThermostatCluster(private val controller: MatterController, private val en emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readSystemModeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 28u - suspend fun readSystemModeAttribute(): UByte { - val ATTRIBUTE_ID: UInt = 28u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Systemmode attribute not found in response" } + } + + requireNotNull(attributeData) { + "Systemmode 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 writeSystemModeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeSystemModeAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 28u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -3286,45 +3482,43 @@ class ThermostatCluster(private val controller: MatterController, private val en throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeSystemModeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 28u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Systemmode attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Systemmode attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -3336,435 +3530,460 @@ class ThermostatCluster(private val controller: MatterController, private val en emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readThermostatRunningModeAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 30u - suspend fun readThermostatRunningModeAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 30u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Thermostatrunningmode attribute not found in response" } + } + + requireNotNull(attributeData) { + "Thermostatrunningmode 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeThermostatRunningModeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 30u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Thermostatrunningmode attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Thermostatrunningmode 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readStartOfWeekAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 32u - suspend fun readStartOfWeekAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 32u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Startofweek attribute not found in response" } + } + + requireNotNull(attributeData) { + "Startofweek 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeStartOfWeekAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 32u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Startofweek attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Startofweek 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNumberOfWeeklyTransitionsAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 33u - suspend fun readNumberOfWeeklyTransitionsAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 33u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Numberofweeklytransitions attribute not found in response" } + } + + requireNotNull(attributeData) { + "Numberofweeklytransitions 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeNumberOfWeeklyTransitionsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 33u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Numberofweeklytransitions attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Numberofweeklytransitions 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNumberOfDailyTransitionsAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 34u - suspend fun readNumberOfDailyTransitionsAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 34u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Numberofdailytransitions attribute not found in response" } + } + + requireNotNull(attributeData) { + "Numberofdailytransitions 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeNumberOfDailyTransitionsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 34u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Numberofdailytransitions attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Numberofdailytransitions 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readTemperatureSetpointHoldAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 35u - suspend fun readTemperatureSetpointHoldAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 35u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Temperaturesetpointhold attribute not found in response" } + } + + requireNotNull(attributeData) { + "Temperaturesetpointhold 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun writeTemperatureSetpointHoldAttribute( value: UByte, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 35u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -3785,130 +4004,132 @@ class ThermostatCluster(private val controller: MatterController, private val en throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeTemperatureSetpointHoldAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 35u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Temperaturesetpointhold attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Temperaturesetpointhold 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readTemperatureSetpointHoldDurationAttribute(): TemperatureSetpointHoldDurationAttribute {val ATTRIBUTE_ID: UInt = 36u - suspend fun readTemperatureSetpointHoldDurationAttribute(): - TemperatureSetpointHoldDurationAttribute { - val ATTRIBUTE_ID: UInt = 36u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { - "Temperaturesetpointholdduration attribute not found in response" + } + + requireNotNull(attributeData) { + "Temperaturesetpointholdduration attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return TemperatureSetpointHoldDurationAttribute(decodedValue) } suspend fun writeTemperatureSetpointHoldDurationAttribute( value: UShort, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 36u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -3929,131 +4150,132 @@ class ThermostatCluster(private val controller: MatterController, private val en throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeTemperatureSetpointHoldDurationAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 36u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - TemperatureSetpointHoldDurationAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(TemperatureSetpointHoldDurationAttributeSubscriptionState.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) { - "Temperaturesetpointholdduration attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Temperaturesetpointholdduration 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } decodedValue?.let { emit(TemperatureSetpointHoldDurationAttributeSubscriptionState.Success(it)) } + } SubscriptionState.SubscriptionEstablished -> { emit(TemperatureSetpointHoldDurationAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readThermostatProgrammingOperationModeAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 37u - suspend fun readThermostatProgrammingOperationModeAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 37u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { - "Thermostatprogrammingoperationmode attribute not found in response" + } + + requireNotNull(attributeData) { + "Thermostatprogrammingoperationmode 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun writeThermostatProgrammingOperationModeAttribute( value: UByte, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 37u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -4074,508 +4296,530 @@ class ThermostatCluster(private val controller: MatterController, private val en throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeThermostatProgrammingOperationModeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 37u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Thermostatprogrammingoperationmode attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Thermostatprogrammingoperationmode 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readThermostatRunningStateAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 41u - suspend fun readThermostatRunningStateAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 41u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Thermostatrunningstate attribute not found in response" } + } + + requireNotNull(attributeData) { + "Thermostatrunningstate 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeThermostatRunningStateAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 41u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Thermostatrunningstate attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Thermostatrunningstate 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readSetpointChangeSourceAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 48u - suspend fun readSetpointChangeSourceAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 48u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Setpointchangesource attribute not found in response" } + } + + requireNotNull(attributeData) { + "Setpointchangesource 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeSetpointChangeSourceAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 48u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Setpointchangesource attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Setpointchangesource 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readSetpointChangeAmountAttribute(): SetpointChangeAmountAttribute {val ATTRIBUTE_ID: UInt = 49u - suspend fun readSetpointChangeAmountAttribute(): SetpointChangeAmountAttribute { - val ATTRIBUTE_ID: UInt = 49u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Setpointchangeamount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Setpointchangeamount attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Short? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return SetpointChangeAmountAttribute(decodedValue) } suspend fun subscribeSetpointChangeAmountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 49u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - SetpointChangeAmountAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(SetpointChangeAmountAttributeSubscriptionState.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) { - "Setpointchangeamount attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Setpointchangeamount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(SetpointChangeAmountAttributeSubscriptionState.Success(it)) } + val decodedValue: Short? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(SetpointChangeAmountAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(SetpointChangeAmountAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readSetpointChangeSourceTimestampAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 50u - suspend fun readSetpointChangeSourceTimestampAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 50u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { - "Setpointchangesourcetimestamp attribute not found in response" + } + + requireNotNull(attributeData) { + "Setpointchangesourcetimestamp attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeSetpointChangeSourceTimestampAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 50u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Setpointchangesourcetimestamp attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Setpointchangesourcetimestamp attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readOccupiedSetbackAttribute(): OccupiedSetbackAttribute {val ATTRIBUTE_ID: UInt = 52u - suspend fun readOccupiedSetbackAttribute(): OccupiedSetbackAttribute { - val ATTRIBUTE_ID: UInt = 52u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Occupiedsetback attribute not found in response" } + } + + requireNotNull(attributeData) { + "Occupiedsetback attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return OccupiedSetbackAttribute(decodedValue) } - suspend fun writeOccupiedSetbackAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeOccupiedSetbackAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 52u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -4596,335 +4840,351 @@ class ThermostatCluster(private val controller: MatterController, private val en throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeOccupiedSetbackAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 52u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - OccupiedSetbackAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(OccupiedSetbackAttributeSubscriptionState.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) { - "Occupiedsetback attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Occupiedsetback 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(OccupiedSetbackAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(OccupiedSetbackAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(OccupiedSetbackAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readOccupiedSetbackMinAttribute(): OccupiedSetbackMinAttribute {val ATTRIBUTE_ID: UInt = 53u - suspend fun readOccupiedSetbackMinAttribute(): OccupiedSetbackMinAttribute { - val ATTRIBUTE_ID: UInt = 53u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Occupiedsetbackmin attribute not found in response" } + } + + requireNotNull(attributeData) { + "Occupiedsetbackmin attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return OccupiedSetbackMinAttribute(decodedValue) } suspend fun subscribeOccupiedSetbackMinAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 53u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - OccupiedSetbackMinAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(OccupiedSetbackMinAttributeSubscriptionState.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) { - "Occupiedsetbackmin attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Occupiedsetbackmin 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(OccupiedSetbackMinAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(OccupiedSetbackMinAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(OccupiedSetbackMinAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readOccupiedSetbackMaxAttribute(): OccupiedSetbackMaxAttribute {val ATTRIBUTE_ID: UInt = 54u - suspend fun readOccupiedSetbackMaxAttribute(): OccupiedSetbackMaxAttribute { - val ATTRIBUTE_ID: UInt = 54u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Occupiedsetbackmax attribute not found in response" } + } + + requireNotNull(attributeData) { + "Occupiedsetbackmax attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return OccupiedSetbackMaxAttribute(decodedValue) } suspend fun subscribeOccupiedSetbackMaxAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 54u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - OccupiedSetbackMaxAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(OccupiedSetbackMaxAttributeSubscriptionState.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) { - "Occupiedsetbackmax attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Occupiedsetbackmax 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(OccupiedSetbackMaxAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(OccupiedSetbackMaxAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(OccupiedSetbackMaxAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readUnoccupiedSetbackAttribute(): UnoccupiedSetbackAttribute {val ATTRIBUTE_ID: UInt = 55u - suspend fun readUnoccupiedSetbackAttribute(): UnoccupiedSetbackAttribute { - val ATTRIBUTE_ID: UInt = 55u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Unoccupiedsetback attribute not found in response" } + } + + requireNotNull(attributeData) { + "Unoccupiedsetback attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return UnoccupiedSetbackAttribute(decodedValue) } - suspend fun writeUnoccupiedSetbackAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeUnoccupiedSetbackAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 55u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -4945,330 +5205,346 @@ class ThermostatCluster(private val controller: MatterController, private val en throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeUnoccupiedSetbackAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 55u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - UnoccupiedSetbackAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(UnoccupiedSetbackAttributeSubscriptionState.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) { - "Unoccupiedsetback attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Unoccupiedsetback 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(UnoccupiedSetbackAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(UnoccupiedSetbackAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UnoccupiedSetbackAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readUnoccupiedSetbackMinAttribute(): UnoccupiedSetbackMinAttribute {val ATTRIBUTE_ID: UInt = 56u - suspend fun readUnoccupiedSetbackMinAttribute(): UnoccupiedSetbackMinAttribute { - val ATTRIBUTE_ID: UInt = 56u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Unoccupiedsetbackmin attribute not found in response" } + } + + requireNotNull(attributeData) { + "Unoccupiedsetbackmin attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return UnoccupiedSetbackMinAttribute(decodedValue) } suspend fun subscribeUnoccupiedSetbackMinAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 56u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - UnoccupiedSetbackMinAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(UnoccupiedSetbackMinAttributeSubscriptionState.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) { - "Unoccupiedsetbackmin attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Unoccupiedsetbackmin 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(UnoccupiedSetbackMinAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(UnoccupiedSetbackMinAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UnoccupiedSetbackMinAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readUnoccupiedSetbackMaxAttribute(): UnoccupiedSetbackMaxAttribute {val ATTRIBUTE_ID: UInt = 57u - suspend fun readUnoccupiedSetbackMaxAttribute(): UnoccupiedSetbackMaxAttribute { - val ATTRIBUTE_ID: UInt = 57u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Unoccupiedsetbackmax attribute not found in response" } + } + + requireNotNull(attributeData) { + "Unoccupiedsetbackmax attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return UnoccupiedSetbackMaxAttribute(decodedValue) } suspend fun subscribeUnoccupiedSetbackMaxAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 57u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - UnoccupiedSetbackMaxAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(UnoccupiedSetbackMaxAttributeSubscriptionState.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) { - "Unoccupiedsetbackmax attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Unoccupiedsetbackmax 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(UnoccupiedSetbackMaxAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(UnoccupiedSetbackMaxAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UnoccupiedSetbackMaxAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readEmergencyHeatDeltaAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 58u - suspend fun readEmergencyHeatDeltaAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 58u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Emergencyheatdelta attribute not found in response" } + } + + requireNotNull(attributeData) { + "Emergencyheatdelta 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } - suspend fun writeEmergencyHeatDeltaAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeEmergencyHeatDeltaAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 58u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -5289,119 +5565,127 @@ class ThermostatCluster(private val controller: MatterController, private val en throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeEmergencyHeatDeltaAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 58u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Emergencyheatdelta attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Emergencyheatdelta 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readACTypeAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 64u - suspend fun readACTypeAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 64u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Actype attribute not found in response" } + } + + requireNotNull(attributeData) { + "Actype 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } - suspend fun writeACTypeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeACTypeAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 64u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -5422,117 +5706,127 @@ class ThermostatCluster(private val controller: MatterController, private val en throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeACTypeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 64u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Actype attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Actype 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readACCapacityAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 65u - suspend fun readACCapacityAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 65u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Accapacity attribute not found in response" } + } + + requireNotNull(attributeData) { + "Accapacity 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } - suspend fun writeACCapacityAttribute(value: UShort, timedWriteTimeout: Duration? = null) { + suspend fun writeACCapacityAttribute( + value: UShort, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 65u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -5553,117 +5847,127 @@ class ThermostatCluster(private val controller: MatterController, private val en throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeACCapacityAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Accapacity attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Accapacity 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readACRefrigerantTypeAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 66u - suspend fun readACRefrigerantTypeAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 66u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Acrefrigeranttype attribute not found in response" } + } + + requireNotNull(attributeData) { + "Acrefrigeranttype 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } - suspend fun writeACRefrigerantTypeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeACRefrigerantTypeAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 66u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -5684,119 +5988,127 @@ class ThermostatCluster(private val controller: MatterController, private val en throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeACRefrigerantTypeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 66u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Acrefrigeranttype attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Acrefrigeranttype 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readACCompressorTypeAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 67u - suspend fun readACCompressorTypeAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 67u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Accompressortype attribute not found in response" } + } + + requireNotNull(attributeData) { + "Accompressortype 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } - suspend fun writeACCompressorTypeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeACCompressorTypeAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 67u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -5817,119 +6129,127 @@ class ThermostatCluster(private val controller: MatterController, private val en throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeACCompressorTypeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 67u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Accompressortype attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Accompressortype 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readACErrorCodeAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 68u - suspend fun readACErrorCodeAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 68u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Acerrorcode attribute not found in response" } + } + + requireNotNull(attributeData) { + "Acerrorcode attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } - suspend fun writeACErrorCodeAttribute(value: UInt, timedWriteTimeout: Duration? = null) { + suspend fun writeACErrorCodeAttribute( + value: UInt, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 68u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -5950,117 +6270,127 @@ class ThermostatCluster(private val controller: MatterController, private val en throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeACErrorCodeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 68u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Acerrorcode attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Acerrorcode attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readACLouverPositionAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 69u - suspend fun readACLouverPositionAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 69u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Aclouverposition attribute not found in response" } + } + + requireNotNull(attributeData) { + "Aclouverposition 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } - suspend fun writeACLouverPositionAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeACLouverPositionAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 69u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -6081,222 +6411,234 @@ class ThermostatCluster(private val controller: MatterController, private val en throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeACLouverPositionAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 69u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Aclouverposition attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Aclouverposition 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readACCoilTemperatureAttribute(): ACCoilTemperatureAttribute {val ATTRIBUTE_ID: UInt = 70u - suspend fun readACCoilTemperatureAttribute(): ACCoilTemperatureAttribute { - val ATTRIBUTE_ID: UInt = 70u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Accoiltemperature attribute not found in response" } + } + + requireNotNull(attributeData) { + "Accoiltemperature attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Short? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return ACCoilTemperatureAttribute(decodedValue) } suspend fun subscribeACCoilTemperatureAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 70u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ACCoilTemperatureAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ACCoilTemperatureAttributeSubscriptionState.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) { - "Accoiltemperature attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Accoiltemperature attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(ACCoilTemperatureAttributeSubscriptionState.Success(it)) } + val decodedValue: Short? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(ACCoilTemperatureAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ACCoilTemperatureAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readACCapacityformatAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 71u - suspend fun readACCapacityformatAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 71u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Accapacityformat attribute not found in response" } + } + + requireNotNull(attributeData) { + "Accapacityformat 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } - suspend fun writeACCapacityformatAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeACCapacityformatAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 71u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -6317,931 +6659,967 @@ class ThermostatCluster(private val controller: MatterController, private val en throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeACCapacityformatAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 71u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Accapacityformat attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Accapacityformat 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readPresetTypesAttribute(): PresetTypesAttribute {val ATTRIBUTE_ID: UInt = 72u - suspend fun readPresetTypesAttribute(): PresetTypesAttribute { - val ATTRIBUTE_ID: UInt = 72u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Presettypes attribute not found in response" } + } + + requireNotNull(attributeData) { + "Presettypes attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(ThermostatClusterPresetTypeStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(ThermostatClusterPresetTypeStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + } else { + null + } + return PresetTypesAttribute(decodedValue) } suspend fun subscribePresetTypesAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 72u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - PresetTypesAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(PresetTypesAttributeSubscriptionState.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) { "Presettypes attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Presettypes attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(ThermostatClusterPresetTypeStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { emit(PresetTypesAttributeSubscriptionState.Success(it)) } + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(ThermostatClusterPresetTypeStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { + emit(PresetTypesAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(PresetTypesAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readScheduleTypesAttribute(): ScheduleTypesAttribute {val ATTRIBUTE_ID: UInt = 73u - suspend fun readScheduleTypesAttribute(): ScheduleTypesAttribute { - val ATTRIBUTE_ID: UInt = 73u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Scheduletypes attribute not found in response" } + } + + requireNotNull(attributeData) { + "Scheduletypes attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(ThermostatClusterScheduleTypeStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(ThermostatClusterScheduleTypeStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + } else { + null + } + return ScheduleTypesAttribute(decodedValue) } suspend fun subscribeScheduleTypesAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 73u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ScheduleTypesAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ScheduleTypesAttributeSubscriptionState.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) { "Scheduletypes attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Scheduletypes attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(ThermostatClusterScheduleTypeStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { emit(ScheduleTypesAttributeSubscriptionState.Success(it)) } + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(ThermostatClusterScheduleTypeStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { + emit(ScheduleTypesAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ScheduleTypesAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNumberOfPresetsAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 74u - suspend fun readNumberOfPresetsAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 74u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Numberofpresets attribute not found in response" } + } + + requireNotNull(attributeData) { + "Numberofpresets 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeNumberOfPresetsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 74u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Numberofpresets attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Numberofpresets 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNumberOfSchedulesAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 75u - suspend fun readNumberOfSchedulesAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 75u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Numberofschedules attribute not found in response" } + } + + requireNotNull(attributeData) { + "Numberofschedules 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeNumberOfSchedulesAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 75u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Numberofschedules attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Numberofschedules 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNumberOfScheduleTransitionsAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 76u - suspend fun readNumberOfScheduleTransitionsAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 76u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Numberofscheduletransitions attribute not found in response" } + } + + requireNotNull(attributeData) { + "Numberofscheduletransitions 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeNumberOfScheduleTransitionsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 76u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Numberofscheduletransitions attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Numberofscheduletransitions 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNumberOfScheduleTransitionPerDayAttribute(): NumberOfScheduleTransitionPerDayAttribute {val ATTRIBUTE_ID: UInt = 77u - suspend fun readNumberOfScheduleTransitionPerDayAttribute(): - NumberOfScheduleTransitionPerDayAttribute { - val ATTRIBUTE_ID: UInt = 77u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { - "Numberofscheduletransitionperday attribute not found in response" + } + + requireNotNull(attributeData) { + "Numberofscheduletransitionperday attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return NumberOfScheduleTransitionPerDayAttribute(decodedValue) } suspend fun subscribeNumberOfScheduleTransitionPerDayAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 77u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - NumberOfScheduleTransitionPerDayAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(NumberOfScheduleTransitionPerDayAttributeSubscriptionState.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) { - "Numberofscheduletransitionperday attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Numberofscheduletransitionperday 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } decodedValue?.let { emit(NumberOfScheduleTransitionPerDayAttributeSubscriptionState.Success(it)) } + } SubscriptionState.SubscriptionEstablished -> { emit(NumberOfScheduleTransitionPerDayAttributeSubscriptionState.SubscriptionEstablished) } - } - } - } - - suspend fun readActivePresetHandleAttribute(): ActivePresetHandleAttribute { - val ATTRIBUTE_ID: UInt = 78u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + } + } + } +suspend fun readActivePresetHandleAttribute(): ActivePresetHandleAttribute {val ATTRIBUTE_ID: UInt = 78u - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Activepresethandle attribute not found in response" } + } + + requireNotNull(attributeData) { + "Activepresethandle attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByteArray(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ByteArray? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByteArray(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return ActivePresetHandleAttribute(decodedValue) } suspend fun subscribeActivePresetHandleAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 78u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ActivePresetHandleAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ActivePresetHandleAttributeSubscriptionState.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) { - "Activepresethandle attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Activepresethandle attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByteArray(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(ActivePresetHandleAttributeSubscriptionState.Success(it)) } + val decodedValue: ByteArray? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByteArray(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(ActivePresetHandleAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ActivePresetHandleAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readActiveScheduleHandleAttribute(): ActiveScheduleHandleAttribute {val ATTRIBUTE_ID: UInt = 79u - suspend fun readActiveScheduleHandleAttribute(): ActiveScheduleHandleAttribute { - val ATTRIBUTE_ID: UInt = 79u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Activeschedulehandle attribute not found in response" } + } + + requireNotNull(attributeData) { + "Activeschedulehandle attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByteArray(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ByteArray? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByteArray(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return ActiveScheduleHandleAttribute(decodedValue) } suspend fun subscribeActiveScheduleHandleAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 79u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ActiveScheduleHandleAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ActiveScheduleHandleAttributeSubscriptionState.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) { - "Activeschedulehandle attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Activeschedulehandle attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByteArray(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(ActiveScheduleHandleAttributeSubscriptionState.Success(it)) } + val decodedValue: ByteArray? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByteArray(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(ActiveScheduleHandleAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ActiveScheduleHandleAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readPresetsAttribute(): PresetsAttribute {val ATTRIBUTE_ID: UInt = 80u - suspend fun readPresetsAttribute(): PresetsAttribute { - val ATTRIBUTE_ID: UInt = 80u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Presets attribute not found in response" } + } + + requireNotNull(attributeData) { + "Presets attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(ThermostatClusterPresetStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(ThermostatClusterPresetStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + } else { + null + } + return PresetsAttribute(decodedValue) } suspend fun writePresetsAttribute( value: List, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 80u val tlvWriter = TlvWriter() tlvWriter.startArray(AnonymousTag) - for (item in value.iterator()) { - item.toTlv(AnonymousTag, tlvWriter) - } - tlvWriter.endArray() + for (item in value.iterator()) { + item.toTlv(AnonymousTag, tlvWriter) + } + tlvWriter.endArray() val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -7262,136 +7640,143 @@ class ThermostatCluster(private val controller: MatterController, private val en throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribePresetsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 80u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - PresetsAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(PresetsAttributeSubscriptionState.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) { "Presets attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Presets attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(ThermostatClusterPresetStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { emit(PresetsAttributeSubscriptionState.Success(it)) } + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(ThermostatClusterPresetStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { + emit(PresetsAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(PresetsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readSchedulesAttribute(): SchedulesAttribute {val ATTRIBUTE_ID: UInt = 81u - suspend fun readSchedulesAttribute(): SchedulesAttribute { - val ATTRIBUTE_ID: UInt = 81u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Schedules attribute not found in response" } + } + + requireNotNull(attributeData) { + "Schedules attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(ThermostatClusterScheduleStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(ThermostatClusterScheduleStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + } else { + null + } + return SchedulesAttribute(decodedValue) } suspend fun writeSchedulesAttribute( value: List, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 81u val tlvWriter = TlvWriter() tlvWriter.startArray(AnonymousTag) - for (item in value.iterator()) { - item.toTlv(AnonymousTag, tlvWriter) - } - tlvWriter.endArray() + for (item in value.iterator()) { + item.toTlv(AnonymousTag, tlvWriter) + } + tlvWriter.endArray() val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -7412,262 +7797,265 @@ class ThermostatCluster(private val controller: MatterController, private val en throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeSchedulesAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 81u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - SchedulesAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(SchedulesAttributeSubscriptionState.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) { "Schedules attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Schedules attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(ThermostatClusterScheduleStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { emit(SchedulesAttributeSubscriptionState.Success(it)) } + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(ThermostatClusterScheduleStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { + emit(SchedulesAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(SchedulesAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readSetpointHoldExpiryTimestampAttribute(): SetpointHoldExpiryTimestampAttribute {val ATTRIBUTE_ID: UInt = 82u - suspend fun readSetpointHoldExpiryTimestampAttribute(): SetpointHoldExpiryTimestampAttribute { - val ATTRIBUTE_ID: UInt = 82u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Setpointholdexpirytimestamp attribute not found in response" } + } + + requireNotNull(attributeData) { + "Setpointholdexpirytimestamp attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return SetpointHoldExpiryTimestampAttribute(decodedValue) } suspend fun subscribeSetpointHoldExpiryTimestampAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 82u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - SetpointHoldExpiryTimestampAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(SetpointHoldExpiryTimestampAttributeSubscriptionState.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) { - "Setpointholdexpirytimestamp attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Setpointholdexpirytimestamp attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } decodedValue?.let { emit(SetpointHoldExpiryTimestampAttributeSubscriptionState.Success(it)) } + } SubscriptionState.SubscriptionEstablished -> { emit(SetpointHoldExpiryTimestampAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65528u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -7675,96 +8063,97 @@ class ThermostatCluster(private val controller: MatterController, private val en emit(GeneratedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65529u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -7772,94 +8161,97 @@ class ThermostatCluster(private val controller: MatterController, private val en emit(AcceptedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt = 65530u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -7867,94 +8259,97 @@ class ThermostatCluster(private val controller: MatterController, private val en emit(EventListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ID: UInt = 65531u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -7962,76 +8357,81 @@ class ThermostatCluster(private val controller: MatterController, private val en emit(AttributeListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u - 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 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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -8043,77 +8443,80 @@ class ThermostatCluster(private val controller: MatterController, private val en emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 65533u - 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 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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -8126,7 +8529,7 @@ class ThermostatCluster(private val controller: MatterController, private val en emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/ThermostatUserInterfaceConfigurationCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/ThermostatUserInterfaceConfigurationCluster.kt index fb4c3e71c7a672..f766146a4a3b89 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/ThermostatUserInterfaceConfigurationCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/ThermostatUserInterfaceConfigurationCluster.kt @@ -17,123 +17,160 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.cluster.structs.* +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath +import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class ThermostatUserInterfaceConfigurationCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class GeneratedCommandListAttribute(val value: List) +class ThermostatUserInterfaceConfigurationCluster(private val controller: MatterController, private val endpointId: UShort) {class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } - - suspend fun readTemperatureDisplayModeAttribute(): 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)) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } +suspend fun readTemperatureDisplayModeAttribute(): 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}") - } + 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) { "Temperaturedisplaymode attribute not found in response" } + } + + requireNotNull(attributeData) { + "Temperaturedisplaymode 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 writeTemperatureDisplayModeAttribute( value: UByte, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -154,46 +191,42 @@ class ThermostatUserInterfaceConfigurationCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeTemperatureDisplayModeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Temperaturedisplaymode attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Temperaturedisplaymode attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -206,57 +239,68 @@ class ThermostatUserInterfaceConfigurationCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readKeypadLockoutAttribute(): 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)) - +suspend fun readKeypadLockoutAttribute(): 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}") - } + 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) { "Keypadlockout attribute not found in response" } + } + + requireNotNull(attributeData) { + "Keypadlockout 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 writeKeypadLockoutAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeKeypadLockoutAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 1u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -277,45 +321,43 @@ class ThermostatUserInterfaceConfigurationCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeKeypadLockoutAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Keypadlockout attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Keypadlockout attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -327,67 +369,72 @@ class ThermostatUserInterfaceConfigurationCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readScheduleProgrammingVisibilityAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readScheduleProgrammingVisibilityAttribute(): UByte? {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}") - } + 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) { - "Scheduleprogrammingvisibility attribute not found in response" + } + + requireNotNull(attributeData) { + "Scheduleprogrammingvisibility 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun writeScheduleProgrammingVisibilityAttribute( value: UByte, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 2u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -408,153 +455,152 @@ class ThermostatUserInterfaceConfigurationCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeScheduleProgrammingVisibilityAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Scheduleprogrammingvisibility attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Scheduleprogrammingvisibility 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)) } + 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 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -562,96 +608,97 @@ class ThermostatUserInterfaceConfigurationCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -659,94 +706,97 @@ class ThermostatUserInterfaceConfigurationCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -754,94 +804,97 @@ class ThermostatUserInterfaceConfigurationCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -849,76 +902,81 @@ class ThermostatUserInterfaceConfigurationCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -930,77 +988,80 @@ class ThermostatUserInterfaceConfigurationCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1013,12 +1074,11 @@ class ThermostatUserInterfaceConfigurationCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { - private val logger = - Logger.getLogger(ThermostatUserInterfaceConfigurationCluster::class.java.name) + private val logger = Logger.getLogger(ThermostatUserInterfaceConfigurationCluster::class.java.name) const val CLUSTER_ID: UInt = 516u } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/ThreadBorderRouterManagementCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/ThreadBorderRouterManagementCluster.kt index efbb1b5baff7e4..08d68ff29f3eda 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/ThreadBorderRouterManagementCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/ThreadBorderRouterManagementCluster.kt @@ -17,110 +17,143 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.BooleanSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest -import matter.controller.StringSubscriptionState +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.UIntSubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState +import matter.controller.UByteSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class ThreadBorderRouterManagementCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class DatasetResponse(val dataset: ByteArray) - - class ActiveDatasetTimestampAttribute(val value: ULong?) +class ThreadBorderRouterManagementCluster(private val controller: MatterController, private val endpointId: UShort) { + class DatasetResponse( + val dataset: ByteArray + ) +class ActiveDatasetTimestampAttribute( + val value: ULong? + ) sealed class ActiveDatasetTimestampAttributeSubscriptionState { - data class Success(val value: ULong?) : ActiveDatasetTimestampAttributeSubscriptionState() - + data class Success( + val value: ULong? + ) : ActiveDatasetTimestampAttributeSubscriptionState() + data class Error(val exception: Exception) : ActiveDatasetTimestampAttributeSubscriptionState() - object SubscriptionEstablished : ActiveDatasetTimestampAttributeSubscriptionState() - } - - class PendingDatasetTimestampAttribute(val value: ULong?) + object SubscriptionEstablished : ActiveDatasetTimestampAttributeSubscriptionState() + } +class PendingDatasetTimestampAttribute( + val value: ULong? + ) sealed class PendingDatasetTimestampAttributeSubscriptionState { - data class Success(val value: ULong?) : PendingDatasetTimestampAttributeSubscriptionState() - - data class Error(val exception: Exception) : - PendingDatasetTimestampAttributeSubscriptionState() - - object SubscriptionEstablished : PendingDatasetTimestampAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + data class Success( + val value: ULong? + ) : PendingDatasetTimestampAttributeSubscriptionState() + + data class Error(val exception: Exception) : PendingDatasetTimestampAttributeSubscriptionState() + + object SubscriptionEstablished : PendingDatasetTimestampAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } suspend fun getActiveDatasetRequest(timedInvokeTimeout: Duration? = null): DatasetResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -130,38 +163,46 @@ class ThreadBorderRouterManagementCluster( tlvReader.enterStructure(AnonymousTag) val TAG_DATASET: Int = 0 var dataset_decoded: ByteArray? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_DATASET)) { - dataset_decoded = tlvReader.getByteArray(tag) - } else { + + if (tag == ContextSpecificTag(TAG_DATASET)) {dataset_decoded = tlvReader.getByteArray(tag)} + + + else { tlvReader.skipElement() } } + + if (dataset_decoded == null) { - throw IllegalStateException("dataset not found in TLV") + throw IllegalStateException("dataset not found in TLV") } + tlvReader.exitContainer() - return DatasetResponse(dataset_decoded) + return DatasetResponse( + dataset_decoded + ) } suspend fun getPendingDatasetRequest(timedInvokeTimeout: Duration? = null): DatasetResponse { val commandId: UInt = 1u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -171,31 +212,37 @@ class ThreadBorderRouterManagementCluster( tlvReader.enterStructure(AnonymousTag) val TAG_DATASET: Int = 0 var dataset_decoded: ByteArray? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_DATASET)) { - dataset_decoded = tlvReader.getByteArray(tag) - } else { + + if (tag == ContextSpecificTag(TAG_DATASET)) {dataset_decoded = tlvReader.getByteArray(tag)} + + + else { tlvReader.skipElement() } } + + if (dataset_decoded == null) { - throw IllegalStateException("dataset not found in TLV") + throw IllegalStateException("dataset not found in TLV") } + tlvReader.exitContainer() - return DatasetResponse(dataset_decoded) + return DatasetResponse( + dataset_decoded + ) } - suspend fun setActiveDatasetRequest( - activeDataset: ByteArray, - breadcrumb: ULong?, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun setActiveDatasetRequest(activeDataset: ByteArray + ,breadcrumb: ULong? + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 3u val tlvWriter = TlvWriter() @@ -205,112 +252,115 @@ class ThreadBorderRouterManagementCluster( tlvWriter.put(ContextSpecificTag(TAG_ACTIVE_DATASET_REQ), activeDataset) val TAG_BREADCRUMB_REQ: Int = 1 - breadcrumb?.let { tlvWriter.put(ContextSpecificTag(TAG_BREADCRUMB_REQ), breadcrumb) } + breadcrumb?.let { + tlvWriter.put(ContextSpecificTag(TAG_BREADCRUMB_REQ), breadcrumb) + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun setPendingDatasetRequest( - pendingDataset: ByteArray, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun setPendingDatasetRequest(pendingDataset: ByteArray + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 4u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_PENDING_DATASET_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_PENDING_DATASET_REQ), pendingDataset) + tlvWriter.put(ContextSpecificTag(TAG_PENDING_DATASET_REQ), pendingDataset) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - - suspend fun readBorderRouterNameAttribute(): String { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readBorderRouterNameAttribute(): String {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}") - } + 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) { "Borderroutername attribute not found in response" } + } + + requireNotNull(attributeData) { + "Borderroutername attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: String = tlvReader.getString(AnonymousTag) + return decodedValue } suspend fun subscribeBorderRouterNameAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StringSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StringSubscriptionState.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) { - "Borderroutername attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Borderroutername attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -323,76 +373,81 @@ class ThreadBorderRouterManagementCluster( emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readBorderAgentIDAttribute(): ByteArray { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readBorderAgentIDAttribute(): ByteArray {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}") - } + 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) { "Borderagentid attribute not found in response" } + } + + requireNotNull(attributeData) { + "Borderagentid attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: ByteArray = tlvReader.getByteArray(AnonymousTag) + return decodedValue } suspend fun subscribeBorderAgentIDAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ByteArraySubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ByteArraySubscriptionState.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) { "Borderagentid attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Borderagentid attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -404,76 +459,81 @@ class ThreadBorderRouterManagementCluster( emit(ByteArraySubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readThreadVersionAttribute(): 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)) - +suspend fun readThreadVersionAttribute(): 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}") - } + 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) { "Threadversion attribute not found in response" } + } + + requireNotNull(attributeData) { + "Threadversion 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 subscribeThreadVersionAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Threadversion attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Threadversion attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -485,77 +545,80 @@ class ThreadBorderRouterManagementCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readInterfaceEnabledAttribute(): 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)) - +suspend fun readInterfaceEnabledAttribute(): 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}") - } + 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) { "Interfaceenabled attribute not found in response" } + } + + requireNotNull(attributeData) { + "Interfaceenabled attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Boolean = tlvReader.getBoolean(AnonymousTag) + return decodedValue } suspend fun subscribeInterfaceEnabledAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Interfaceenabled attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Interfaceenabled attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -568,286 +631,295 @@ class ThreadBorderRouterManagementCluster( emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readActiveDatasetTimestampAttribute(): ActiveDatasetTimestampAttribute { - val ATTRIBUTE_ID: UInt = 4u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readActiveDatasetTimestampAttribute(): ActiveDatasetTimestampAttribute {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}") - } + 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) { "Activedatasettimestamp attribute not found in response" } + } + + requireNotNull(attributeData) { + "Activedatasettimestamp attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ULong? = - if (!tlvReader.isNull()) { - tlvReader.getULong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ULong? = if (!tlvReader.isNull()) { + tlvReader.getULong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return ActiveDatasetTimestampAttribute(decodedValue) } suspend fun subscribeActiveDatasetTimestampAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ActiveDatasetTimestampAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ActiveDatasetTimestampAttributeSubscriptionState.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) { - "Activedatasettimestamp attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Activedatasettimestamp 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()) { - tlvReader.getULong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(ActiveDatasetTimestampAttributeSubscriptionState.Success(it)) } + val decodedValue: ULong? = if (!tlvReader.isNull()) { + tlvReader.getULong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(ActiveDatasetTimestampAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ActiveDatasetTimestampAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readPendingDatasetTimestampAttribute(): PendingDatasetTimestampAttribute { - val ATTRIBUTE_ID: UInt = 5u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readPendingDatasetTimestampAttribute(): PendingDatasetTimestampAttribute {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}") - } + 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) { "Pendingdatasettimestamp attribute not found in response" } + } + + requireNotNull(attributeData) { + "Pendingdatasettimestamp attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ULong? = - if (!tlvReader.isNull()) { - tlvReader.getULong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ULong? = if (!tlvReader.isNull()) { + tlvReader.getULong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return PendingDatasetTimestampAttribute(decodedValue) } suspend fun subscribePendingDatasetTimestampAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - PendingDatasetTimestampAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(PendingDatasetTimestampAttributeSubscriptionState.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) { - "Pendingdatasettimestamp attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Pendingdatasettimestamp 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()) { - tlvReader.getULong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(PendingDatasetTimestampAttributeSubscriptionState.Success(it)) } + val decodedValue: ULong? = if (!tlvReader.isNull()) { + tlvReader.getULong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(PendingDatasetTimestampAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(PendingDatasetTimestampAttributeSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -855,96 +927,97 @@ class ThreadBorderRouterManagementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -952,94 +1025,97 @@ class ThreadBorderRouterManagementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1047,94 +1123,97 @@ class ThreadBorderRouterManagementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1142,76 +1221,81 @@ class ThreadBorderRouterManagementCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1223,77 +1307,80 @@ class ThreadBorderRouterManagementCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1306,7 +1393,7 @@ class ThreadBorderRouterManagementCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/ThreadNetworkDiagnosticsCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/ThreadNetworkDiagnosticsCluster.kt index 4950900b057665..865e7b62d0545d 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/ThreadNetworkDiagnosticsCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/ThreadNetworkDiagnosticsCluster.kt @@ -17,1040 +17,1158 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState +import matter.controller.UByteSubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState import matter.controller.ULongSubscriptionState -import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class ThreadNetworkDiagnosticsCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class ChannelAttribute(val value: UShort?) +class ThreadNetworkDiagnosticsCluster(private val controller: MatterController, private val endpointId: UShort) {class ChannelAttribute( + val value: UShort? + ) sealed class ChannelAttributeSubscriptionState { - data class Success(val value: UShort?) : ChannelAttributeSubscriptionState() - + data class Success( + val value: UShort? + ) : ChannelAttributeSubscriptionState() + data class Error(val exception: Exception) : ChannelAttributeSubscriptionState() - object SubscriptionEstablished : ChannelAttributeSubscriptionState() - } - - class RoutingRoleAttribute(val value: UByte?) + object SubscriptionEstablished : ChannelAttributeSubscriptionState() + } +class RoutingRoleAttribute( + val value: UByte? + ) sealed class RoutingRoleAttributeSubscriptionState { - data class Success(val value: UByte?) : RoutingRoleAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : RoutingRoleAttributeSubscriptionState() + data class Error(val exception: Exception) : RoutingRoleAttributeSubscriptionState() - object SubscriptionEstablished : RoutingRoleAttributeSubscriptionState() - } - - class NetworkNameAttribute(val value: String?) + object SubscriptionEstablished : RoutingRoleAttributeSubscriptionState() + } +class NetworkNameAttribute( + val value: String? + ) sealed class NetworkNameAttributeSubscriptionState { - data class Success(val value: String?) : NetworkNameAttributeSubscriptionState() - + data class Success( + val value: String? + ) : NetworkNameAttributeSubscriptionState() + data class Error(val exception: Exception) : NetworkNameAttributeSubscriptionState() - object SubscriptionEstablished : NetworkNameAttributeSubscriptionState() - } - - class PanIdAttribute(val value: UShort?) + object SubscriptionEstablished : NetworkNameAttributeSubscriptionState() + } +class PanIdAttribute( + val value: UShort? + ) sealed class PanIdAttributeSubscriptionState { - data class Success(val value: UShort?) : PanIdAttributeSubscriptionState() - + data class Success( + val value: UShort? + ) : PanIdAttributeSubscriptionState() + data class Error(val exception: Exception) : PanIdAttributeSubscriptionState() - object SubscriptionEstablished : PanIdAttributeSubscriptionState() - } - - class ExtendedPanIdAttribute(val value: ULong?) + object SubscriptionEstablished : PanIdAttributeSubscriptionState() + } +class ExtendedPanIdAttribute( + val value: ULong? + ) sealed class ExtendedPanIdAttributeSubscriptionState { - data class Success(val value: ULong?) : ExtendedPanIdAttributeSubscriptionState() - + data class Success( + val value: ULong? + ) : ExtendedPanIdAttributeSubscriptionState() + data class Error(val exception: Exception) : ExtendedPanIdAttributeSubscriptionState() - object SubscriptionEstablished : ExtendedPanIdAttributeSubscriptionState() - } - - class MeshLocalPrefixAttribute(val value: ByteArray?) + object SubscriptionEstablished : ExtendedPanIdAttributeSubscriptionState() + } +class MeshLocalPrefixAttribute( + val value: ByteArray? + ) sealed class MeshLocalPrefixAttributeSubscriptionState { - data class Success(val value: ByteArray?) : MeshLocalPrefixAttributeSubscriptionState() - + data class Success( + val value: ByteArray? + ) : MeshLocalPrefixAttributeSubscriptionState() + data class Error(val exception: Exception) : MeshLocalPrefixAttributeSubscriptionState() - object SubscriptionEstablished : MeshLocalPrefixAttributeSubscriptionState() - } - - class NeighborTableAttribute(val value: List) + object SubscriptionEstablished : MeshLocalPrefixAttributeSubscriptionState() + } +class NeighborTableAttribute( + val value: List + ) sealed class NeighborTableAttributeSubscriptionState { - data class Success(val value: List) : - NeighborTableAttributeSubscriptionState() - + data class Success( + val value: List + ) : NeighborTableAttributeSubscriptionState() + data class Error(val exception: Exception) : NeighborTableAttributeSubscriptionState() - object SubscriptionEstablished : NeighborTableAttributeSubscriptionState() - } - - class RouteTableAttribute(val value: List) + object SubscriptionEstablished : NeighborTableAttributeSubscriptionState() + } +class RouteTableAttribute( + val value: List + ) sealed class RouteTableAttributeSubscriptionState { - data class Success(val value: List) : - RouteTableAttributeSubscriptionState() - + data class Success( + val value: List + ) : RouteTableAttributeSubscriptionState() + data class Error(val exception: Exception) : RouteTableAttributeSubscriptionState() - object SubscriptionEstablished : RouteTableAttributeSubscriptionState() - } - - class PartitionIdAttribute(val value: UInt?) + object SubscriptionEstablished : RouteTableAttributeSubscriptionState() + } +class PartitionIdAttribute( + val value: UInt? + ) sealed class PartitionIdAttributeSubscriptionState { - data class Success(val value: UInt?) : PartitionIdAttributeSubscriptionState() - + data class Success( + val value: UInt? + ) : PartitionIdAttributeSubscriptionState() + data class Error(val exception: Exception) : PartitionIdAttributeSubscriptionState() - object SubscriptionEstablished : PartitionIdAttributeSubscriptionState() - } - - class WeightingAttribute(val value: UShort?) + object SubscriptionEstablished : PartitionIdAttributeSubscriptionState() + } +class WeightingAttribute( + val value: UShort? + ) sealed class WeightingAttributeSubscriptionState { - data class Success(val value: UShort?) : WeightingAttributeSubscriptionState() - + data class Success( + val value: UShort? + ) : WeightingAttributeSubscriptionState() + data class Error(val exception: Exception) : WeightingAttributeSubscriptionState() - object SubscriptionEstablished : WeightingAttributeSubscriptionState() - } - - class DataVersionAttribute(val value: UShort?) + object SubscriptionEstablished : WeightingAttributeSubscriptionState() + } +class DataVersionAttribute( + val value: UShort? + ) sealed class DataVersionAttributeSubscriptionState { - data class Success(val value: UShort?) : DataVersionAttributeSubscriptionState() - + data class Success( + val value: UShort? + ) : DataVersionAttributeSubscriptionState() + data class Error(val exception: Exception) : DataVersionAttributeSubscriptionState() - object SubscriptionEstablished : DataVersionAttributeSubscriptionState() - } - - class StableDataVersionAttribute(val value: UShort?) + object SubscriptionEstablished : DataVersionAttributeSubscriptionState() + } +class StableDataVersionAttribute( + val value: UShort? + ) sealed class StableDataVersionAttributeSubscriptionState { - data class Success(val value: UShort?) : StableDataVersionAttributeSubscriptionState() - + data class Success( + val value: UShort? + ) : StableDataVersionAttributeSubscriptionState() + data class Error(val exception: Exception) : StableDataVersionAttributeSubscriptionState() - object SubscriptionEstablished : StableDataVersionAttributeSubscriptionState() - } - - class LeaderRouterIdAttribute(val value: UByte?) + object SubscriptionEstablished : StableDataVersionAttributeSubscriptionState() + } +class LeaderRouterIdAttribute( + val value: UByte? + ) sealed class LeaderRouterIdAttributeSubscriptionState { - data class Success(val value: UByte?) : LeaderRouterIdAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : LeaderRouterIdAttributeSubscriptionState() + data class Error(val exception: Exception) : LeaderRouterIdAttributeSubscriptionState() - object SubscriptionEstablished : LeaderRouterIdAttributeSubscriptionState() - } - - class ActiveTimestampAttribute(val value: ULong?) + object SubscriptionEstablished : LeaderRouterIdAttributeSubscriptionState() + } +class ActiveTimestampAttribute( + val value: ULong? + ) sealed class ActiveTimestampAttributeSubscriptionState { - data class Success(val value: ULong?) : ActiveTimestampAttributeSubscriptionState() - + data class Success( + val value: ULong? + ) : ActiveTimestampAttributeSubscriptionState() + data class Error(val exception: Exception) : ActiveTimestampAttributeSubscriptionState() - object SubscriptionEstablished : ActiveTimestampAttributeSubscriptionState() - } - - class PendingTimestampAttribute(val value: ULong?) + object SubscriptionEstablished : ActiveTimestampAttributeSubscriptionState() + } +class PendingTimestampAttribute( + val value: ULong? + ) sealed class PendingTimestampAttributeSubscriptionState { - data class Success(val value: ULong?) : PendingTimestampAttributeSubscriptionState() - + data class Success( + val value: ULong? + ) : PendingTimestampAttributeSubscriptionState() + data class Error(val exception: Exception) : PendingTimestampAttributeSubscriptionState() - object SubscriptionEstablished : PendingTimestampAttributeSubscriptionState() - } - - class DelayAttribute(val value: UInt?) + object SubscriptionEstablished : PendingTimestampAttributeSubscriptionState() + } +class DelayAttribute( + val value: UInt? + ) sealed class DelayAttributeSubscriptionState { - data class Success(val value: UInt?) : DelayAttributeSubscriptionState() - + data class Success( + val value: UInt? + ) : DelayAttributeSubscriptionState() + data class Error(val exception: Exception) : DelayAttributeSubscriptionState() - object SubscriptionEstablished : DelayAttributeSubscriptionState() - } - - class SecurityPolicyAttribute(val value: ThreadNetworkDiagnosticsClusterSecurityPolicy?) + object SubscriptionEstablished : DelayAttributeSubscriptionState() + } +class SecurityPolicyAttribute( + val value: ThreadNetworkDiagnosticsClusterSecurityPolicy? + ) sealed class SecurityPolicyAttributeSubscriptionState { - data class Success(val value: ThreadNetworkDiagnosticsClusterSecurityPolicy?) : - SecurityPolicyAttributeSubscriptionState() - + data class Success( + val value: ThreadNetworkDiagnosticsClusterSecurityPolicy? + ) : SecurityPolicyAttributeSubscriptionState() + data class Error(val exception: Exception) : SecurityPolicyAttributeSubscriptionState() - object SubscriptionEstablished : SecurityPolicyAttributeSubscriptionState() - } - - class ChannelPage0MaskAttribute(val value: ByteArray?) + object SubscriptionEstablished : SecurityPolicyAttributeSubscriptionState() + } +class ChannelPage0MaskAttribute( + val value: ByteArray? + ) sealed class ChannelPage0MaskAttributeSubscriptionState { - data class Success(val value: ByteArray?) : ChannelPage0MaskAttributeSubscriptionState() - + data class Success( + val value: ByteArray? + ) : ChannelPage0MaskAttributeSubscriptionState() + data class Error(val exception: Exception) : ChannelPage0MaskAttributeSubscriptionState() - object SubscriptionEstablished : ChannelPage0MaskAttributeSubscriptionState() - } - - class OperationalDatasetComponentsAttribute( + object SubscriptionEstablished : ChannelPage0MaskAttributeSubscriptionState() + } +class OperationalDatasetComponentsAttribute( val value: ThreadNetworkDiagnosticsClusterOperationalDatasetComponents? ) sealed class OperationalDatasetComponentsAttributeSubscriptionState { - data class Success(val value: ThreadNetworkDiagnosticsClusterOperationalDatasetComponents?) : - OperationalDatasetComponentsAttributeSubscriptionState() - - data class Error(val exception: Exception) : - OperationalDatasetComponentsAttributeSubscriptionState() - - object SubscriptionEstablished : OperationalDatasetComponentsAttributeSubscriptionState() - } - - class ActiveNetworkFaultsListAttribute(val value: List) + data class Success( + val value: ThreadNetworkDiagnosticsClusterOperationalDatasetComponents? + ) : OperationalDatasetComponentsAttributeSubscriptionState() + + data class Error(val exception: Exception) : OperationalDatasetComponentsAttributeSubscriptionState() + + object SubscriptionEstablished : OperationalDatasetComponentsAttributeSubscriptionState() + } +class ActiveNetworkFaultsListAttribute( + val value: List + ) sealed class ActiveNetworkFaultsListAttributeSubscriptionState { - data class Success(val value: List) : - ActiveNetworkFaultsListAttributeSubscriptionState() - - data class Error(val exception: Exception) : - ActiveNetworkFaultsListAttributeSubscriptionState() - - object SubscriptionEstablished : ActiveNetworkFaultsListAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + data class Success( + val value: List + ) : ActiveNetworkFaultsListAttributeSubscriptionState() + + data class Error(val exception: Exception) : ActiveNetworkFaultsListAttributeSubscriptionState() + + object SubscriptionEstablished : ActiveNetworkFaultsListAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } suspend fun resetCounts(timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } +suspend fun readChannelAttribute(): ChannelAttribute {val ATTRIBUTE_ID: UInt = 0u - suspend fun readChannelAttribute(): ChannelAttribute { - 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 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}") - } + 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) { "Channel attribute not found in response" } + } + + requireNotNull(attributeData) { + "Channel attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = - if (!tlvReader.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return ChannelAttribute(decodedValue) } suspend fun subscribeChannelAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ChannelAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ChannelAttributeSubscriptionState.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) { "Channel attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Channel 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.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(ChannelAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ChannelAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ChannelAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRoutingRoleAttribute(): RoutingRoleAttribute {val ATTRIBUTE_ID: UInt = 1u - suspend fun readRoutingRoleAttribute(): RoutingRoleAttribute { - 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 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}") - } + 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) { "Routingrole attribute not found in response" } + } + + requireNotNull(attributeData) { + "Routingrole attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return RoutingRoleAttribute(decodedValue) } suspend fun subscribeRoutingRoleAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - RoutingRoleAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(RoutingRoleAttributeSubscriptionState.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) { "Routingrole attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Routingrole 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.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(RoutingRoleAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(RoutingRoleAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(RoutingRoleAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNetworkNameAttribute(): NetworkNameAttribute {val ATTRIBUTE_ID: UInt = 2u - suspend fun readNetworkNameAttribute(): NetworkNameAttribute { - 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 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}") - } + 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) { "Networkname attribute not found in response" } + } + + requireNotNull(attributeData) { + "Networkname attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (!tlvReader.isNull()) { - tlvReader.getString(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: String? = if (!tlvReader.isNull()) { + tlvReader.getString(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return NetworkNameAttribute(decodedValue) } suspend fun subscribeNetworkNameAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - NetworkNameAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(NetworkNameAttributeSubscriptionState.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) { "Networkname attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Networkname attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (!tlvReader.isNull()) { - tlvReader.getString(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: String? = if (!tlvReader.isNull()) { + tlvReader.getString(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(NetworkNameAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(NetworkNameAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(NetworkNameAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readPanIdAttribute(): PanIdAttribute {val ATTRIBUTE_ID: UInt = 3u - suspend fun readPanIdAttribute(): PanIdAttribute { - 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 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}") - } + 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) { "Panid attribute not found in response" } + } + + requireNotNull(attributeData) { + "Panid attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = - if (!tlvReader.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return PanIdAttribute(decodedValue) } suspend fun subscribePanIdAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - PanIdAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(PanIdAttributeSubscriptionState.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) { "Panid attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Panid 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.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(PanIdAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(PanIdAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(PanIdAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readExtendedPanIdAttribute(): ExtendedPanIdAttribute {val ATTRIBUTE_ID: UInt = 4u - suspend fun readExtendedPanIdAttribute(): ExtendedPanIdAttribute { - 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 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}") - } + 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) { "Extendedpanid attribute not found in response" } + } + + requireNotNull(attributeData) { + "Extendedpanid attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ULong? = - if (!tlvReader.isNull()) { - tlvReader.getULong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ULong? = if (!tlvReader.isNull()) { + tlvReader.getULong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return ExtendedPanIdAttribute(decodedValue) } suspend fun subscribeExtendedPanIdAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ExtendedPanIdAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ExtendedPanIdAttributeSubscriptionState.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) { "Extendedpanid attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Extendedpanid 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()) { - tlvReader.getULong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ULong? = if (!tlvReader.isNull()) { + tlvReader.getULong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(ExtendedPanIdAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ExtendedPanIdAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ExtendedPanIdAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readMeshLocalPrefixAttribute(): MeshLocalPrefixAttribute {val ATTRIBUTE_ID: UInt = 5u - suspend fun readMeshLocalPrefixAttribute(): MeshLocalPrefixAttribute { - 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 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}") - } + 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) { "Meshlocalprefix attribute not found in response" } + } + + requireNotNull(attributeData) { + "Meshlocalprefix attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = - if (!tlvReader.isNull()) { - tlvReader.getByteArray(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ByteArray? = if (!tlvReader.isNull()) { + tlvReader.getByteArray(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MeshLocalPrefixAttribute(decodedValue) } suspend fun subscribeMeshLocalPrefixAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MeshLocalPrefixAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MeshLocalPrefixAttributeSubscriptionState.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) { - "Meshlocalprefix attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Meshlocalprefix attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = - if (!tlvReader.isNull()) { - tlvReader.getByteArray(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ByteArray? = if (!tlvReader.isNull()) { + tlvReader.getByteArray(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(MeshLocalPrefixAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(MeshLocalPrefixAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MeshLocalPrefixAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readOverrunCountAttribute(): ULong? {val ATTRIBUTE_ID: UInt = 6u - suspend fun readOverrunCountAttribute(): ULong? { - 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 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}") - } + 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) { "Overruncount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Overruncount attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ULong? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getULong(AnonymousTag) - } else { - null - } + val decodedValue: ULong? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeOverrunCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ULongSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ULongSubscriptionState.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) { "Overruncount attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Overruncount 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.isNextTag(AnonymousTag)) { - tlvReader.getULong(AnonymousTag) - } else { - null - } + val decodedValue: ULong? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(ULongSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ULongSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ULongSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNeighborTableAttribute(): NeighborTableAttribute {val ATTRIBUTE_ID: UInt = 7u - suspend fun readNeighborTableAttribute(): NeighborTableAttribute { - 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 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}") - } + 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) { "Neighbortable attribute not found in response" } + } + + requireNotNull(attributeData) { + "Neighbortable 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(ThreadNetworkDiagnosticsClusterNeighborTableStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(ThreadNetworkDiagnosticsClusterNeighborTableStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + return NeighborTableAttribute(decodedValue) } suspend fun subscribeNeighborTableAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - NeighborTableAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(NeighborTableAttributeSubscriptionState.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) { "Neighbortable attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Neighbortable 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( - ThreadNetworkDiagnosticsClusterNeighborTableStruct.fromTlv( - AnonymousTag, - tlvReader, - ) - ) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(ThreadNetworkDiagnosticsClusterNeighborTableStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(NeighborTableAttributeSubscriptionState.Success(decodedValue)) } @@ -1058,96 +1176,97 @@ class ThreadNetworkDiagnosticsCluster( emit(NeighborTableAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRouteTableAttribute(): RouteTableAttribute {val ATTRIBUTE_ID: UInt = 8u - suspend fun readRouteTableAttribute(): RouteTableAttribute { - val ATTRIBUTE_ID: UInt = 8u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Routetable attribute not found in response" } + } + + requireNotNull(attributeData) { + "Routetable 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(ThreadNetworkDiagnosticsClusterRouteTableStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(ThreadNetworkDiagnosticsClusterRouteTableStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + return RouteTableAttribute(decodedValue) } suspend fun subscribeRouteTableAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - RouteTableAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(RouteTableAttributeSubscriptionState.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) { "Routetable attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Routetable 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( - ThreadNetworkDiagnosticsClusterRouteTableStruct.fromTlv(AnonymousTag, tlvReader) - ) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(ThreadNetworkDiagnosticsClusterRouteTableStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(RouteTableAttributeSubscriptionState.Success(decodedValue)) } @@ -1155,5046 +1274,5284 @@ class ThreadNetworkDiagnosticsCluster( emit(RouteTableAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readPartitionIdAttribute(): PartitionIdAttribute {val ATTRIBUTE_ID: UInt = 9u - suspend fun readPartitionIdAttribute(): PartitionIdAttribute { - val ATTRIBUTE_ID: UInt = 9u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Partitionid attribute not found in response" } + } + + requireNotNull(attributeData) { + "Partitionid attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - tlvReader.getUInt(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + tlvReader.getUInt(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return PartitionIdAttribute(decodedValue) } suspend fun subscribePartitionIdAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - PartitionIdAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(PartitionIdAttributeSubscriptionState.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) { "Partitionid attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Partitionid attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - tlvReader.getUInt(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + tlvReader.getUInt(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(PartitionIdAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(PartitionIdAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(PartitionIdAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readWeightingAttribute(): WeightingAttribute {val ATTRIBUTE_ID: UInt = 10u - suspend fun readWeightingAttribute(): WeightingAttribute { - val ATTRIBUTE_ID: UInt = 10u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Weighting attribute not found in response" } + } + + requireNotNull(attributeData) { + "Weighting attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = - if (!tlvReader.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return WeightingAttribute(decodedValue) } suspend fun subscribeWeightingAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - WeightingAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(WeightingAttributeSubscriptionState.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) { "Weighting attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Weighting 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.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(WeightingAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(WeightingAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(WeightingAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readDataVersionAttribute(): DataVersionAttribute {val ATTRIBUTE_ID: UInt = 11u - suspend fun readDataVersionAttribute(): DataVersionAttribute { - val ATTRIBUTE_ID: UInt = 11u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Dataversion attribute not found in response" } + } + + requireNotNull(attributeData) { + "Dataversion attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = - if (!tlvReader.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return DataVersionAttribute(decodedValue) } suspend fun subscribeDataVersionAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 11u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - DataVersionAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(DataVersionAttributeSubscriptionState.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) { "Dataversion attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Dataversion 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.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(DataVersionAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(DataVersionAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(DataVersionAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readStableDataVersionAttribute(): StableDataVersionAttribute {val ATTRIBUTE_ID: UInt = 12u - suspend fun readStableDataVersionAttribute(): StableDataVersionAttribute { - val ATTRIBUTE_ID: UInt = 12u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Stabledataversion attribute not found in response" } + } + + requireNotNull(attributeData) { + "Stabledataversion attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = - if (!tlvReader.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return StableDataVersionAttribute(decodedValue) } suspend fun subscribeStableDataVersionAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 12u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StableDataVersionAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StableDataVersionAttributeSubscriptionState.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) { - "Stabledataversion attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Stabledataversion 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.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(StableDataVersionAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(StableDataVersionAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(StableDataVersionAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readLeaderRouterIdAttribute(): LeaderRouterIdAttribute {val ATTRIBUTE_ID: UInt = 13u - suspend fun readLeaderRouterIdAttribute(): LeaderRouterIdAttribute { - val ATTRIBUTE_ID: UInt = 13u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Leaderrouterid attribute not found in response" } + } + + requireNotNull(attributeData) { + "Leaderrouterid attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return LeaderRouterIdAttribute(decodedValue) } suspend fun subscribeLeaderRouterIdAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 13u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - LeaderRouterIdAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(LeaderRouterIdAttributeSubscriptionState.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) { - "Leaderrouterid attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Leaderrouterid 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.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(LeaderRouterIdAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(LeaderRouterIdAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(LeaderRouterIdAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readDetachedRoleCountAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 14u - suspend fun readDetachedRoleCountAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 14u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Detachedrolecount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Detachedrolecount 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeDetachedRoleCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 14u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Detachedrolecount attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Detachedrolecount 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readChildRoleCountAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 15u - suspend fun readChildRoleCountAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 15u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Childrolecount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Childrolecount 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeChildRoleCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 15u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Childrolecount attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Childrolecount 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRouterRoleCountAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 16u - suspend fun readRouterRoleCountAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 16u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Routerrolecount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Routerrolecount 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeRouterRoleCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Routerrolecount attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Routerrolecount 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readLeaderRoleCountAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 17u - suspend fun readLeaderRoleCountAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 17u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Leaderrolecount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Leaderrolecount 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeLeaderRoleCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 17u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Leaderrolecount attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Leaderrolecount 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAttachAttemptCountAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 18u - suspend fun readAttachAttemptCountAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 18u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Attachattemptcount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Attachattemptcount 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeAttachAttemptCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 18u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Attachattemptcount attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Attachattemptcount 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readPartitionIdChangeCountAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 19u - suspend fun readPartitionIdChangeCountAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 19u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Partitionidchangecount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Partitionidchangecount 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribePartitionIdChangeCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 19u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Partitionidchangecount attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Partitionidchangecount 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readBetterPartitionAttachAttemptCountAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 20u - suspend fun readBetterPartitionAttachAttemptCountAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 20u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { - "Betterpartitionattachattemptcount attribute not found in response" + } + + requireNotNull(attributeData) { + "Betterpartitionattachattemptcount 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeBetterPartitionAttachAttemptCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 20u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Betterpartitionattachattemptcount attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Betterpartitionattachattemptcount 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readParentChangeCountAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 21u - suspend fun readParentChangeCountAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 21u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Parentchangecount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Parentchangecount 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeParentChangeCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 21u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Parentchangecount attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Parentchangecount 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readTxTotalCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 22u - suspend fun readTxTotalCountAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 22u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Txtotalcount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Txtotalcount attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeTxTotalCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 22u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Txtotalcount attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Txtotalcount attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readTxUnicastCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 23u - suspend fun readTxUnicastCountAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 23u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Txunicastcount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Txunicastcount attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeTxUnicastCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 23u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Txunicastcount attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Txunicastcount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readTxBroadcastCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 24u - suspend fun readTxBroadcastCountAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 24u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Txbroadcastcount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Txbroadcastcount attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeTxBroadcastCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 24u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Txbroadcastcount attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Txbroadcastcount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readTxAckRequestedCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 25u - suspend fun readTxAckRequestedCountAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 25u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Txackrequestedcount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Txackrequestedcount attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeTxAckRequestedCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 25u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Txackrequestedcount attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Txackrequestedcount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readTxAckedCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 26u - suspend fun readTxAckedCountAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 26u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Txackedcount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Txackedcount attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeTxAckedCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 26u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Txackedcount attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Txackedcount attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readTxNoAckRequestedCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 27u - suspend fun readTxNoAckRequestedCountAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 27u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Txnoackrequestedcount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Txnoackrequestedcount attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeTxNoAckRequestedCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 27u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Txnoackrequestedcount attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Txnoackrequestedcount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readTxDataCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 28u - suspend fun readTxDataCountAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 28u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Txdatacount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Txdatacount attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeTxDataCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 28u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Txdatacount attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Txdatacount attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readTxDataPollCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 29u - suspend fun readTxDataPollCountAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 29u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Txdatapollcount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Txdatapollcount attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeTxDataPollCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 29u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Txdatapollcount attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Txdatapollcount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readTxBeaconCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 30u - suspend fun readTxBeaconCountAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 30u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Txbeaconcount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Txbeaconcount attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeTxBeaconCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 30u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Txbeaconcount attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Txbeaconcount attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readTxBeaconRequestCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 31u - suspend fun readTxBeaconRequestCountAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 31u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Txbeaconrequestcount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Txbeaconrequestcount attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeTxBeaconRequestCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 31u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Txbeaconrequestcount attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Txbeaconrequestcount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readTxOtherCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 32u - suspend fun readTxOtherCountAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 32u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Txothercount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Txothercount attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeTxOtherCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 32u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Txothercount attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Txothercount attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readTxRetryCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 33u - suspend fun readTxRetryCountAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 33u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Txretrycount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Txretrycount attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeTxRetryCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 33u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Txretrycount attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Txretrycount attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readTxDirectMaxRetryExpiryCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 34u - suspend fun readTxDirectMaxRetryExpiryCountAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 34u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Txdirectmaxretryexpirycount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Txdirectmaxretryexpirycount attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeTxDirectMaxRetryExpiryCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 34u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Txdirectmaxretryexpirycount attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Txdirectmaxretryexpirycount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readTxIndirectMaxRetryExpiryCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 35u - suspend fun readTxIndirectMaxRetryExpiryCountAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 35u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { - "Txindirectmaxretryexpirycount attribute not found in response" + } + + requireNotNull(attributeData) { + "Txindirectmaxretryexpirycount attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeTxIndirectMaxRetryExpiryCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 35u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Txindirectmaxretryexpirycount attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Txindirectmaxretryexpirycount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readTxErrCcaCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 36u - suspend fun readTxErrCcaCountAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 36u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Txerrccacount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Txerrccacount attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeTxErrCcaCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 36u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Txerrccacount attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Txerrccacount attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readTxErrAbortCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 37u - suspend fun readTxErrAbortCountAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 37u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Txerrabortcount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Txerrabortcount attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeTxErrAbortCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 37u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Txerrabortcount attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Txerrabortcount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readTxErrBusyChannelCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 38u - suspend fun readTxErrBusyChannelCountAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 38u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Txerrbusychannelcount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Txerrbusychannelcount attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeTxErrBusyChannelCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 38u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Txerrbusychannelcount attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Txerrbusychannelcount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRxTotalCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 39u - suspend fun readRxTotalCountAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 39u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rxtotalcount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rxtotalcount attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeRxTotalCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 39u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Rxtotalcount attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rxtotalcount attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRxUnicastCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 40u - suspend fun readRxUnicastCountAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 40u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rxunicastcount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rxunicastcount attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeRxUnicastCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 40u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Rxunicastcount attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rxunicastcount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRxBroadcastCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 41u - suspend fun readRxBroadcastCountAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 41u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rxbroadcastcount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rxbroadcastcount attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeRxBroadcastCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 41u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Rxbroadcastcount attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rxbroadcastcount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRxDataCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 42u - suspend fun readRxDataCountAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 42u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rxdatacount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rxdatacount attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeRxDataCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 42u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Rxdatacount attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rxdatacount attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRxDataPollCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 43u - suspend fun readRxDataPollCountAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 43u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rxdatapollcount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rxdatapollcount attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeRxDataPollCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 43u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Rxdatapollcount attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rxdatapollcount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRxBeaconCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 44u - suspend fun readRxBeaconCountAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 44u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rxbeaconcount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rxbeaconcount attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeRxBeaconCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 44u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Rxbeaconcount attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rxbeaconcount attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRxBeaconRequestCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 45u - suspend fun readRxBeaconRequestCountAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 45u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rxbeaconrequestcount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rxbeaconrequestcount attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeRxBeaconRequestCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 45u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Rxbeaconrequestcount attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rxbeaconrequestcount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRxOtherCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 46u - suspend fun readRxOtherCountAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 46u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rxothercount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rxothercount attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeRxOtherCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 46u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Rxothercount attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rxothercount attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRxAddressFilteredCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 47u - suspend fun readRxAddressFilteredCountAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 47u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rxaddressfilteredcount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rxaddressfilteredcount attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeRxAddressFilteredCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 47u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Rxaddressfilteredcount attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rxaddressfilteredcount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRxDestAddrFilteredCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 48u - suspend fun readRxDestAddrFilteredCountAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 48u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rxdestaddrfilteredcount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rxdestaddrfilteredcount attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeRxDestAddrFilteredCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 48u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Rxdestaddrfilteredcount attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rxdestaddrfilteredcount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRxDuplicatedCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 49u - suspend fun readRxDuplicatedCountAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 49u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rxduplicatedcount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rxduplicatedcount attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeRxDuplicatedCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 49u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Rxduplicatedcount attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rxduplicatedcount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRxErrNoFrameCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 50u - suspend fun readRxErrNoFrameCountAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 50u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rxerrnoframecount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rxerrnoframecount attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeRxErrNoFrameCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 50u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Rxerrnoframecount attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rxerrnoframecount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRxErrUnknownNeighborCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 51u - suspend fun readRxErrUnknownNeighborCountAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 51u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rxerrunknownneighborcount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rxerrunknownneighborcount attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeRxErrUnknownNeighborCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 51u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Rxerrunknownneighborcount attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rxerrunknownneighborcount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRxErrInvalidSrcAddrCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 52u - suspend fun readRxErrInvalidSrcAddrCountAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 52u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rxerrinvalidsrcaddrcount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rxerrinvalidsrcaddrcount attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeRxErrInvalidSrcAddrCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 52u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Rxerrinvalidsrcaddrcount attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rxerrinvalidsrcaddrcount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRxErrSecCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 53u - suspend fun readRxErrSecCountAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 53u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rxerrseccount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rxerrseccount attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeRxErrSecCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 53u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Rxerrseccount attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rxerrseccount attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRxErrFcsCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 54u - suspend fun readRxErrFcsCountAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 54u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rxerrfcscount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rxerrfcscount attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeRxErrFcsCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 54u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Rxerrfcscount attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rxerrfcscount attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRxErrOtherCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 55u - suspend fun readRxErrOtherCountAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 55u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rxerrothercount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rxerrothercount attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeRxErrOtherCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 55u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Rxerrothercount attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rxerrothercount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readActiveTimestampAttribute(): ActiveTimestampAttribute {val ATTRIBUTE_ID: UInt = 56u - suspend fun readActiveTimestampAttribute(): ActiveTimestampAttribute { - val ATTRIBUTE_ID: UInt = 56u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Activetimestamp attribute not found in response" } + } + + requireNotNull(attributeData) { + "Activetimestamp 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 - } + val decodedValue: ULong? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return ActiveTimestampAttribute(decodedValue) } suspend fun subscribeActiveTimestampAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 56u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ActiveTimestampAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ActiveTimestampAttributeSubscriptionState.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) { - "Activetimestamp attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Activetimestamp 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(ActiveTimestampAttributeSubscriptionState.Success(it)) } + val decodedValue: ULong? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(ActiveTimestampAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ActiveTimestampAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readPendingTimestampAttribute(): PendingTimestampAttribute {val ATTRIBUTE_ID: UInt = 57u - suspend fun readPendingTimestampAttribute(): PendingTimestampAttribute { - val ATTRIBUTE_ID: UInt = 57u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Pendingtimestamp attribute not found in response" } + } + + requireNotNull(attributeData) { + "Pendingtimestamp 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 - } + val decodedValue: ULong? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return PendingTimestampAttribute(decodedValue) } suspend fun subscribePendingTimestampAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 57u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - PendingTimestampAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(PendingTimestampAttributeSubscriptionState.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) { - "Pendingtimestamp attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Pendingtimestamp 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(PendingTimestampAttributeSubscriptionState.Success(it)) } + val decodedValue: ULong? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(PendingTimestampAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(PendingTimestampAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readDelayAttribute(): DelayAttribute {val ATTRIBUTE_ID: UInt = 58u - suspend fun readDelayAttribute(): DelayAttribute { - val ATTRIBUTE_ID: UInt = 58u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Delay attribute not found in response" } + } + + requireNotNull(attributeData) { + "Delay attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return DelayAttribute(decodedValue) } suspend fun subscribeDelayAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 58u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - DelayAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(DelayAttributeSubscriptionState.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) { "Delay attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Delay attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(DelayAttributeSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(DelayAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(DelayAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readSecurityPolicyAttribute(): SecurityPolicyAttribute {val ATTRIBUTE_ID: UInt = 59u - suspend fun readSecurityPolicyAttribute(): SecurityPolicyAttribute { - val ATTRIBUTE_ID: UInt = 59u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Securitypolicy attribute not found in response" } + } + + requireNotNull(attributeData) { + "Securitypolicy attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ThreadNetworkDiagnosticsClusterSecurityPolicy? = - if (!tlvReader.isNull()) { - ThreadNetworkDiagnosticsClusterSecurityPolicy.fromTlv(AnonymousTag, tlvReader) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ThreadNetworkDiagnosticsClusterSecurityPolicy? = if (!tlvReader.isNull()) { + ThreadNetworkDiagnosticsClusterSecurityPolicy.fromTlv(AnonymousTag, tlvReader) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return SecurityPolicyAttribute(decodedValue) } suspend fun subscribeSecurityPolicyAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 59u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - SecurityPolicyAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(SecurityPolicyAttributeSubscriptionState.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) { - "Securitypolicy attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Securitypolicy attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ThreadNetworkDiagnosticsClusterSecurityPolicy? = - if (!tlvReader.isNull()) { - ThreadNetworkDiagnosticsClusterSecurityPolicy.fromTlv(AnonymousTag, tlvReader) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ThreadNetworkDiagnosticsClusterSecurityPolicy? = if (!tlvReader.isNull()) { + ThreadNetworkDiagnosticsClusterSecurityPolicy.fromTlv(AnonymousTag, tlvReader) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(SecurityPolicyAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(SecurityPolicyAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(SecurityPolicyAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readChannelPage0MaskAttribute(): ChannelPage0MaskAttribute {val ATTRIBUTE_ID: UInt = 60u - suspend fun readChannelPage0MaskAttribute(): ChannelPage0MaskAttribute { - val ATTRIBUTE_ID: UInt = 60u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Channelpage0mask attribute not found in response" } + } + + requireNotNull(attributeData) { + "Channelpage0mask attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = - if (!tlvReader.isNull()) { - tlvReader.getByteArray(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ByteArray? = if (!tlvReader.isNull()) { + tlvReader.getByteArray(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return ChannelPage0MaskAttribute(decodedValue) } suspend fun subscribeChannelPage0MaskAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 60u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ChannelPage0MaskAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ChannelPage0MaskAttributeSubscriptionState.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) { - "Channelpage0mask attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Channelpage0mask attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = - if (!tlvReader.isNull()) { - tlvReader.getByteArray(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ByteArray? = if (!tlvReader.isNull()) { + tlvReader.getByteArray(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(ChannelPage0MaskAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(ChannelPage0MaskAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ChannelPage0MaskAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readOperationalDatasetComponentsAttribute(): OperationalDatasetComponentsAttribute {val ATTRIBUTE_ID: UInt = 61u - suspend fun readOperationalDatasetComponentsAttribute(): OperationalDatasetComponentsAttribute { - val ATTRIBUTE_ID: UInt = 61u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Operationaldatasetcomponents attribute not found in response" } + } + + requireNotNull(attributeData) { + "Operationaldatasetcomponents attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ThreadNetworkDiagnosticsClusterOperationalDatasetComponents? = - if (!tlvReader.isNull()) { - ThreadNetworkDiagnosticsClusterOperationalDatasetComponents.fromTlv(AnonymousTag, tlvReader) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ThreadNetworkDiagnosticsClusterOperationalDatasetComponents? = if (!tlvReader.isNull()) { + ThreadNetworkDiagnosticsClusterOperationalDatasetComponents.fromTlv(AnonymousTag, tlvReader) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return OperationalDatasetComponentsAttribute(decodedValue) } suspend fun subscribeOperationalDatasetComponentsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 61u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - OperationalDatasetComponentsAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(OperationalDatasetComponentsAttributeSubscriptionState.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) { - "Operationaldatasetcomponents attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Operationaldatasetcomponents attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ThreadNetworkDiagnosticsClusterOperationalDatasetComponents? = - if (!tlvReader.isNull()) { - ThreadNetworkDiagnosticsClusterOperationalDatasetComponents.fromTlv( - AnonymousTag, - tlvReader, - ) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ThreadNetworkDiagnosticsClusterOperationalDatasetComponents? = if (!tlvReader.isNull()) { + ThreadNetworkDiagnosticsClusterOperationalDatasetComponents.fromTlv(AnonymousTag, tlvReader) + } else { + tlvReader.getNull(AnonymousTag) + null + } decodedValue?.let { emit(OperationalDatasetComponentsAttributeSubscriptionState.Success(it)) } + } SubscriptionState.SubscriptionEstablished -> { emit(OperationalDatasetComponentsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readActiveNetworkFaultsListAttribute(): ActiveNetworkFaultsListAttribute {val ATTRIBUTE_ID: UInt = 62u - suspend fun readActiveNetworkFaultsListAttribute(): ActiveNetworkFaultsListAttribute { - val ATTRIBUTE_ID: UInt = 62u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Activenetworkfaultslist attribute not found in response" } + } + + requireNotNull(attributeData) { + "Activenetworkfaultslist 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.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) } + tlvReader.exitContainer() + } + return ActiveNetworkFaultsListAttribute(decodedValue) } suspend fun subscribeActiveNetworkFaultsListAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 62u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ActiveNetworkFaultsListAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ActiveNetworkFaultsListAttributeSubscriptionState.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) { - "Activenetworkfaultslist attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Activenetworkfaultslist 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.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(ActiveNetworkFaultsListAttributeSubscriptionState.Success(decodedValue)) } @@ -6202,96 +6559,97 @@ class ThreadNetworkDiagnosticsCluster( emit(ActiveNetworkFaultsListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65528u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -6299,96 +6657,97 @@ class ThreadNetworkDiagnosticsCluster( emit(GeneratedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65529u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -6396,94 +6755,97 @@ class ThreadNetworkDiagnosticsCluster( emit(AcceptedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt = 65530u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -6491,94 +6853,97 @@ class ThreadNetworkDiagnosticsCluster( emit(EventListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ID: UInt = 65531u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -6586,76 +6951,81 @@ class ThreadNetworkDiagnosticsCluster( emit(AttributeListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u - 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 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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -6667,77 +7037,80 @@ class ThreadNetworkDiagnosticsCluster( emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 65533u - 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 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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -6750,7 +7123,7 @@ class ThreadNetworkDiagnosticsCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/ThreadNetworkDirectoryCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/ThreadNetworkDirectoryCluster.kt index ee5b2e9aea94ec..6066a25d681365 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/ThreadNetworkDirectoryCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/ThreadNetworkDirectoryCluster.kt @@ -17,159 +17,191 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.cluster.structs.* +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class ThreadNetworkDirectoryCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class OperationalDatasetResponse(val operationalDataset: ByteArray) - - class PreferredExtendedPanIDAttribute(val value: ByteArray?) +class ThreadNetworkDirectoryCluster(private val controller: MatterController, private val endpointId: UShort) { + class OperationalDatasetResponse( + val operationalDataset: ByteArray + ) +class PreferredExtendedPanIDAttribute( + val value: ByteArray? + ) sealed class PreferredExtendedPanIDAttributeSubscriptionState { - data class Success(val value: ByteArray?) : PreferredExtendedPanIDAttributeSubscriptionState() - + data class Success( + val value: ByteArray? + ) : PreferredExtendedPanIDAttributeSubscriptionState() + data class Error(val exception: Exception) : PreferredExtendedPanIDAttributeSubscriptionState() - object SubscriptionEstablished : PreferredExtendedPanIDAttributeSubscriptionState() - } - - class ThreadNetworksAttribute(val value: List) + object SubscriptionEstablished : PreferredExtendedPanIDAttributeSubscriptionState() + } +class ThreadNetworksAttribute( + val value: List + ) sealed class ThreadNetworksAttributeSubscriptionState { - data class Success(val value: List) : - ThreadNetworksAttributeSubscriptionState() - + data class Success( + val value: List + ) : ThreadNetworksAttributeSubscriptionState() + data class Error(val exception: Exception) : ThreadNetworksAttributeSubscriptionState() - object SubscriptionEstablished : ThreadNetworksAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : ThreadNetworksAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun addNetwork(operationalDataset: ByteArray, timedInvokeTimeout: Duration) { + suspend fun addNetwork(operationalDataset: ByteArray + ,timedInvokeTimeout: Duration) { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_OPERATIONAL_DATASET_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_OPERATIONAL_DATASET_REQ), operationalDataset) + tlvWriter.put(ContextSpecificTag(TAG_OPERATIONAL_DATASET_REQ), operationalDataset) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun removeNetwork(extendedPanID: ByteArray, timedInvokeTimeout: Duration) { + suspend fun removeNetwork(extendedPanID: ByteArray + ,timedInvokeTimeout: Duration) { val commandId: UInt = 1u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_EXTENDED_PAN_ID_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_EXTENDED_PAN_ID_REQ), extendedPanID) + tlvWriter.put(ContextSpecificTag(TAG_EXTENDED_PAN_ID_REQ), extendedPanID) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun getOperationalDataset( - extendedPanID: ByteArray, - timedInvokeTimeout: Duration? = null, - ): OperationalDatasetResponse { + suspend fun getOperationalDataset(extendedPanID: ByteArray + ,timedInvokeTimeout: Duration? = null): OperationalDatasetResponse { val commandId: UInt = 2u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_EXTENDED_PAN_ID_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_EXTENDED_PAN_ID_REQ), extendedPanID) + tlvWriter.put(ContextSpecificTag(TAG_EXTENDED_PAN_ID_REQ), extendedPanID) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -179,83 +211,98 @@ class ThreadNetworkDirectoryCluster( tlvReader.enterStructure(AnonymousTag) val TAG_OPERATIONAL_DATASET: Int = 0 var operationalDataset_decoded: ByteArray? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_OPERATIONAL_DATASET)) { - operationalDataset_decoded = tlvReader.getByteArray(tag) - } else { + + if (tag == ContextSpecificTag(TAG_OPERATIONAL_DATASET)) {operationalDataset_decoded = tlvReader.getByteArray(tag)} + + + else { tlvReader.skipElement() } } + + if (operationalDataset_decoded == null) { - throw IllegalStateException("operationalDataset not found in TLV") + throw IllegalStateException("operationalDataset not found in TLV") } + tlvReader.exitContainer() - return OperationalDatasetResponse(operationalDataset_decoded) + return OperationalDatasetResponse( + operationalDataset_decoded + ) } - - suspend fun readPreferredExtendedPanIDAttribute(): PreferredExtendedPanIDAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readPreferredExtendedPanIDAttribute(): PreferredExtendedPanIDAttribute {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}") - } + 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) { "Preferredextendedpanid attribute not found in response" } + } + + requireNotNull(attributeData) { + "Preferredextendedpanid attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = - if (!tlvReader.isNull()) { - tlvReader.getByteArray(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ByteArray? = if (!tlvReader.isNull()) { + tlvReader.getByteArray(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return PreferredExtendedPanIDAttribute(decodedValue) } suspend fun writePreferredExtendedPanIDAttribute( value: ByteArray, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -276,156 +323,153 @@ class ThreadNetworkDirectoryCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribePreferredExtendedPanIDAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - PreferredExtendedPanIDAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(PreferredExtendedPanIDAttributeSubscriptionState.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) { - "Preferredextendedpanid attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Preferredextendedpanid attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = - if (!tlvReader.isNull()) { - tlvReader.getByteArray(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(PreferredExtendedPanIDAttributeSubscriptionState.Success(it)) } + val decodedValue: ByteArray? = if (!tlvReader.isNull()) { + tlvReader.getByteArray(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(PreferredExtendedPanIDAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(PreferredExtendedPanIDAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readThreadNetworksAttribute(): ThreadNetworksAttribute { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readThreadNetworksAttribute(): ThreadNetworksAttribute {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}") - } + 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) { "Threadnetworks attribute not found in response" } + } + + requireNotNull(attributeData) { + "Threadnetworks 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(ThreadNetworkDirectoryClusterThreadNetworkStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(ThreadNetworkDirectoryClusterThreadNetworkStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + return ThreadNetworksAttribute(decodedValue) } suspend fun subscribeThreadNetworksAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ThreadNetworksAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ThreadNetworksAttributeSubscriptionState.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) { - "Threadnetworks attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Threadnetworks 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( - ThreadNetworkDirectoryClusterThreadNetworkStruct.fromTlv(AnonymousTag, tlvReader) - ) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(ThreadNetworkDirectoryClusterThreadNetworkStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(ThreadNetworksAttributeSubscriptionState.Success(decodedValue)) } @@ -433,77 +477,80 @@ class ThreadNetworkDirectoryCluster( emit(ThreadNetworksAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readThreadNetworkTableSizeAttribute(): UByte { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readThreadNetworkTableSizeAttribute(): UByte {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}") - } + 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) { "Threadnetworktablesize attribute not found in response" } + } + + requireNotNull(attributeData) { + "Threadnetworktablesize 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 subscribeThreadNetworkTableSizeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Threadnetworktablesize attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Threadnetworktablesize attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -516,96 +563,97 @@ class ThreadNetworkDirectoryCluster( emit(UByteSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -613,96 +661,97 @@ class ThreadNetworkDirectoryCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -710,94 +759,97 @@ class ThreadNetworkDirectoryCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -805,94 +857,97 @@ class ThreadNetworkDirectoryCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -900,76 +955,81 @@ class ThreadNetworkDirectoryCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -981,77 +1041,80 @@ class ThreadNetworkDirectoryCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1064,7 +1127,7 @@ class ThreadNetworkDirectoryCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/TimeFormatLocalizationCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/TimeFormatLocalizationCluster.kt index f5f404c56a0534..0a6b84266fe5f8 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/TimeFormatLocalizationCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/TimeFormatLocalizationCluster.kt @@ -17,131 +17,173 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.cluster.structs.* +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath +import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class TimeFormatLocalizationCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class SupportedCalendarTypesAttribute(val value: List?) +class TimeFormatLocalizationCluster(private val controller: MatterController, private val endpointId: UShort) {class SupportedCalendarTypesAttribute( + val value: List? + ) sealed class SupportedCalendarTypesAttributeSubscriptionState { - data class Success(val value: List?) : - SupportedCalendarTypesAttributeSubscriptionState() - + data class Success( + val value: List? + ) : SupportedCalendarTypesAttributeSubscriptionState() + data class Error(val exception: Exception) : SupportedCalendarTypesAttributeSubscriptionState() - object SubscriptionEstablished : SupportedCalendarTypesAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : SupportedCalendarTypesAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } - - suspend fun readHourFormatAttribute(): 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)) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } +suspend fun readHourFormatAttribute(): 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}") - } + 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) { "Hourformat attribute not found in response" } + } + + requireNotNull(attributeData) { + "Hourformat 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 writeHourFormatAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeHourFormatAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -162,45 +204,43 @@ class TimeFormatLocalizationCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeHourFormatAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Hourformat attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Hourformat attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -212,62 +252,72 @@ class TimeFormatLocalizationCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readActiveCalendarTypeAttribute(): 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)) - +suspend fun readActiveCalendarTypeAttribute(): 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}") - } + 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) { "Activecalendartype attribute not found in response" } + } + + requireNotNull(attributeData) { + "Activecalendartype 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } - suspend fun writeActiveCalendarTypeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeActiveCalendarTypeAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 1u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -288,258 +338,261 @@ class TimeFormatLocalizationCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeActiveCalendarTypeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Activecalendartype attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Activecalendartype 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)) } + 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 readSupportedCalendarTypesAttribute(): SupportedCalendarTypesAttribute { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readSupportedCalendarTypesAttribute(): SupportedCalendarTypesAttribute {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}") - } + 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) { "Supportedcalendartypes attribute not found in response" } + } + + requireNotNull(attributeData) { + "Supportedcalendartypes attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) } + tlvReader.exitContainer() + } + } else { + null + } + return SupportedCalendarTypesAttribute(decodedValue) } suspend fun subscribeSupportedCalendarTypesAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - SupportedCalendarTypesAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(SupportedCalendarTypesAttributeSubscriptionState.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) { - "Supportedcalendartypes attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Supportedcalendartypes attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { emit(SupportedCalendarTypesAttributeSubscriptionState.Success(it)) } + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { + emit(SupportedCalendarTypesAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(SupportedCalendarTypesAttributeSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -547,96 +600,97 @@ class TimeFormatLocalizationCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -644,94 +698,97 @@ class TimeFormatLocalizationCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -739,94 +796,97 @@ class TimeFormatLocalizationCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -834,76 +894,81 @@ class TimeFormatLocalizationCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -915,77 +980,80 @@ class TimeFormatLocalizationCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -998,7 +1066,7 @@ class TimeFormatLocalizationCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/TimeSynchronizationCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/TimeSynchronizationCluster.kt index c968311230c6cb..56f5d04c0e1a03 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/TimeSynchronizationCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/TimeSynchronizationCluster.kt @@ -17,145 +17,187 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration 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.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class TimeSynchronizationCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class SetTimeZoneResponse(val DSTOffsetRequired: Boolean) - - class UTCTimeAttribute(val value: ULong?) +class TimeSynchronizationCluster(private val controller: MatterController, private val endpointId: UShort) { + class SetTimeZoneResponse( + val DSTOffsetRequired: Boolean + ) +class UTCTimeAttribute( + val value: ULong? + ) sealed class UTCTimeAttributeSubscriptionState { - data class Success(val value: ULong?) : UTCTimeAttributeSubscriptionState() - + data class Success( + val value: ULong? + ) : UTCTimeAttributeSubscriptionState() + data class Error(val exception: Exception) : UTCTimeAttributeSubscriptionState() - object SubscriptionEstablished : UTCTimeAttributeSubscriptionState() - } - - class TrustedTimeSourceAttribute(val value: TimeSynchronizationClusterTrustedTimeSourceStruct?) + object SubscriptionEstablished : UTCTimeAttributeSubscriptionState() + } +class TrustedTimeSourceAttribute( + val value: TimeSynchronizationClusterTrustedTimeSourceStruct? + ) sealed class TrustedTimeSourceAttributeSubscriptionState { - data class Success(val value: TimeSynchronizationClusterTrustedTimeSourceStruct?) : - TrustedTimeSourceAttributeSubscriptionState() - + data class Success( + val value: TimeSynchronizationClusterTrustedTimeSourceStruct? + ) : TrustedTimeSourceAttributeSubscriptionState() + data class Error(val exception: Exception) : TrustedTimeSourceAttributeSubscriptionState() - object SubscriptionEstablished : TrustedTimeSourceAttributeSubscriptionState() - } - - class DefaultNTPAttribute(val value: String?) + object SubscriptionEstablished : TrustedTimeSourceAttributeSubscriptionState() + } +class DefaultNTPAttribute( + val value: String? + ) sealed class DefaultNTPAttributeSubscriptionState { - data class Success(val value: String?) : DefaultNTPAttributeSubscriptionState() - + data class Success( + val value: String? + ) : DefaultNTPAttributeSubscriptionState() + data class Error(val exception: Exception) : DefaultNTPAttributeSubscriptionState() - object SubscriptionEstablished : DefaultNTPAttributeSubscriptionState() - } - - class TimeZoneAttribute(val value: List?) + object SubscriptionEstablished : DefaultNTPAttributeSubscriptionState() + } +class TimeZoneAttribute( + val value: List? + ) sealed class TimeZoneAttributeSubscriptionState { - data class Success(val value: List?) : - TimeZoneAttributeSubscriptionState() - + data class Success( + val value: List? + ) : TimeZoneAttributeSubscriptionState() + data class Error(val exception: Exception) : TimeZoneAttributeSubscriptionState() - object SubscriptionEstablished : TimeZoneAttributeSubscriptionState() - } - - class DSTOffsetAttribute(val value: List?) + object SubscriptionEstablished : TimeZoneAttributeSubscriptionState() + } +class DSTOffsetAttribute( + val value: List? + ) sealed class DSTOffsetAttributeSubscriptionState { - data class Success(val value: List?) : - DSTOffsetAttributeSubscriptionState() - + data class Success( + val value: List? + ) : DSTOffsetAttributeSubscriptionState() + data class Error(val exception: Exception) : DSTOffsetAttributeSubscriptionState() - object SubscriptionEstablished : DSTOffsetAttributeSubscriptionState() - } - - class LocalTimeAttribute(val value: ULong?) + object SubscriptionEstablished : DSTOffsetAttributeSubscriptionState() + } +class LocalTimeAttribute( + val value: ULong? + ) sealed class LocalTimeAttributeSubscriptionState { - data class Success(val value: ULong?) : LocalTimeAttributeSubscriptionState() - + data class Success( + val value: ULong? + ) : LocalTimeAttributeSubscriptionState() + data class Error(val exception: Exception) : LocalTimeAttributeSubscriptionState() - object SubscriptionEstablished : LocalTimeAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : LocalTimeAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun setUTCTime( - UTCTime: ULong, - granularity: UByte, - timeSource: UByte?, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun setUTCTime(UTCTime: ULong + ,granularity: UByte + ,timeSource: UByte? + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() @@ -168,24 +210,24 @@ class TimeSynchronizationCluster( tlvWriter.put(ContextSpecificTag(TAG_GRANULARITY_REQ), granularity) val TAG_TIME_SOURCE_REQ: Int = 2 - timeSource?.let { tlvWriter.put(ContextSpecificTag(TAG_TIME_SOURCE_REQ), timeSource) } + timeSource?.let { + tlvWriter.put(ContextSpecificTag(TAG_TIME_SOURCE_REQ), timeSource) + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun setTrustedTimeSource( - trustedTimeSource: TimeSynchronizationClusterFabricScopedTrustedTimeSourceStruct?, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun setTrustedTimeSource(trustedTimeSource: TimeSynchronizationClusterFabricScopedTrustedTimeSourceStruct? + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 1u val tlvWriter = TlvWriter() @@ -194,24 +236,22 @@ class TimeSynchronizationCluster( val TAG_TRUSTED_TIME_SOURCE_REQ: Int = 0 trustedTimeSource?.let { trustedTimeSource.toTlv(ContextSpecificTag(TAG_TRUSTED_TIME_SOURCE_REQ), tlvWriter) - } + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun setTimeZone( - timeZone: List, - timedInvokeTimeout: Duration? = null, - ): SetTimeZoneResponse { + suspend fun setTimeZone(timeZone: List + ,timedInvokeTimeout: Duration? = null): SetTimeZoneResponse { val commandId: UInt = 2u val tlvWriter = TlvWriter() @@ -219,17 +259,17 @@ class TimeSynchronizationCluster( val TAG_TIME_ZONE_REQ: Int = 0 tlvWriter.startArray(ContextSpecificTag(TAG_TIME_ZONE_REQ)) - for (item in timeZone.iterator()) { - item.toTlv(AnonymousTag, tlvWriter) - } - tlvWriter.endArray() + for (item in timeZone.iterator()) { + item.toTlv(AnonymousTag, tlvWriter) + } + tlvWriter.endArray() tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -239,30 +279,36 @@ class TimeSynchronizationCluster( tlvReader.enterStructure(AnonymousTag) val TAG_DST_OFFSET_REQUIRED: Int = 0 var DSTOffsetRequired_decoded: Boolean? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_DST_OFFSET_REQUIRED)) { - DSTOffsetRequired_decoded = tlvReader.getBoolean(tag) - } else { + + if (tag == ContextSpecificTag(TAG_DST_OFFSET_REQUIRED)) {DSTOffsetRequired_decoded = tlvReader.getBoolean(tag)} + + + else { tlvReader.skipElement() } } + + if (DSTOffsetRequired_decoded == null) { - throw IllegalStateException("DSTOffsetRequired not found in TLV") + throw IllegalStateException("DSTOffsetRequired not found in TLV") } + tlvReader.exitContainer() - return SetTimeZoneResponse(DSTOffsetRequired_decoded) + return SetTimeZoneResponse( + DSTOffsetRequired_decoded + ) } - suspend fun setDSTOffset( - DSTOffset: List, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun setDSTOffset(DSTOffset: List + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 4u val tlvWriter = TlvWriter() @@ -270,204 +316,218 @@ class TimeSynchronizationCluster( val TAG_DST_OFFSET_REQ: Int = 0 tlvWriter.startArray(ContextSpecificTag(TAG_DST_OFFSET_REQ)) - for (item in DSTOffset.iterator()) { - item.toTlv(AnonymousTag, tlvWriter) - } - tlvWriter.endArray() + for (item in DSTOffset.iterator()) { + item.toTlv(AnonymousTag, tlvWriter) + } + tlvWriter.endArray() tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun setDefaultNTP(defaultNTP: String?, timedInvokeTimeout: Duration? = null) { + suspend fun setDefaultNTP(defaultNTP: String? + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 5u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_DEFAULT_NTP_REQ: Int = 0 - defaultNTP?.let { tlvWriter.put(ContextSpecificTag(TAG_DEFAULT_NTP_REQ), defaultNTP) } + defaultNTP?.let { + tlvWriter.put(ContextSpecificTag(TAG_DEFAULT_NTP_REQ), defaultNTP) + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - - suspend fun readUTCTimeAttribute(): UTCTimeAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readUTCTimeAttribute(): UTCTimeAttribute {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}") - } + 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) { "Utctime attribute not found in response" } + } + + requireNotNull(attributeData) { + "Utctime attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ULong? = - if (!tlvReader.isNull()) { - tlvReader.getULong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ULong? = if (!tlvReader.isNull()) { + tlvReader.getULong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return UTCTimeAttribute(decodedValue) } suspend fun subscribeUTCTimeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - UTCTimeAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(UTCTimeAttributeSubscriptionState.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) { "Utctime attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Utctime 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()) { - tlvReader.getULong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(UTCTimeAttributeSubscriptionState.Success(it)) } + val decodedValue: ULong? = if (!tlvReader.isNull()) { + tlvReader.getULong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(UTCTimeAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UTCTimeAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readGranularityAttribute(): 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)) - +suspend fun readGranularityAttribute(): 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}") - } + 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) { "Granularity attribute not found in response" } + } + + requireNotNull(attributeData) { + "Granularity 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 subscribeGranularityAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Granularity attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Granularity attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -479,1163 +539,1218 @@ class TimeSynchronizationCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readTimeSourceAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readTimeSourceAttribute(): UByte? {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}") - } + 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) { "Timesource attribute not found in response" } + } + + requireNotNull(attributeData) { + "Timesource 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeTimeSourceAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Timesource attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Timesource 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)) } + 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 readTrustedTimeSourceAttribute(): TrustedTimeSourceAttribute { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readTrustedTimeSourceAttribute(): TrustedTimeSourceAttribute {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}") - } + 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) { "Trustedtimesource attribute not found in response" } + } + + requireNotNull(attributeData) { + "Trustedtimesource attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: TimeSynchronizationClusterTrustedTimeSourceStruct? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - TimeSynchronizationClusterTrustedTimeSourceStruct.fromTlv(AnonymousTag, tlvReader) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: TimeSynchronizationClusterTrustedTimeSourceStruct? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + TimeSynchronizationClusterTrustedTimeSourceStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return TrustedTimeSourceAttribute(decodedValue) } suspend fun subscribeTrustedTimeSourceAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - TrustedTimeSourceAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(TrustedTimeSourceAttributeSubscriptionState.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) { - "Trustedtimesource attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Trustedtimesource attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: TimeSynchronizationClusterTrustedTimeSourceStruct? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - TimeSynchronizationClusterTrustedTimeSourceStruct.fromTlv(AnonymousTag, tlvReader) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(TrustedTimeSourceAttributeSubscriptionState.Success(it)) } + val decodedValue: TimeSynchronizationClusterTrustedTimeSourceStruct? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + TimeSynchronizationClusterTrustedTimeSourceStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(TrustedTimeSourceAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(TrustedTimeSourceAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readDefaultNTPAttribute(): DefaultNTPAttribute { - val ATTRIBUTE_ID: UInt = 4u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readDefaultNTPAttribute(): DefaultNTPAttribute {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}") - } + 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) { "Defaultntp attribute not found in response" } + } + + requireNotNull(attributeData) { + "Defaultntp attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: String? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return DefaultNTPAttribute(decodedValue) } suspend fun subscribeDefaultNTPAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - DefaultNTPAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(DefaultNTPAttributeSubscriptionState.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) { "Defaultntp attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Defaultntp attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(DefaultNTPAttributeSubscriptionState.Success(it)) } + val decodedValue: String? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(DefaultNTPAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(DefaultNTPAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readTimeZoneAttribute(): TimeZoneAttribute { - val ATTRIBUTE_ID: UInt = 5u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readTimeZoneAttribute(): TimeZoneAttribute {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}") - } + 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) { "Timezone attribute not found in response" } + } + + requireNotNull(attributeData) { + "Timezone attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(TimeSynchronizationClusterTimeZoneStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(TimeSynchronizationClusterTimeZoneStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + } else { + null + } + return TimeZoneAttribute(decodedValue) } suspend fun subscribeTimeZoneAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - TimeZoneAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(TimeZoneAttributeSubscriptionState.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) { "Timezone attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Timezone attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(TimeSynchronizationClusterTimeZoneStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { emit(TimeZoneAttributeSubscriptionState.Success(it)) } + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(TimeSynchronizationClusterTimeZoneStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { + emit(TimeZoneAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(TimeZoneAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readDSTOffsetAttribute(): DSTOffsetAttribute { - val ATTRIBUTE_ID: UInt = 6u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readDSTOffsetAttribute(): DSTOffsetAttribute {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}") - } + 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) { "Dstoffset attribute not found in response" } + } + + requireNotNull(attributeData) { + "Dstoffset attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(TimeSynchronizationClusterDSTOffsetStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(TimeSynchronizationClusterDSTOffsetStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + } else { + null + } + return DSTOffsetAttribute(decodedValue) } suspend fun subscribeDSTOffsetAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - DSTOffsetAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(DSTOffsetAttributeSubscriptionState.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) { "Dstoffset attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Dstoffset attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(TimeSynchronizationClusterDSTOffsetStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { emit(DSTOffsetAttributeSubscriptionState.Success(it)) } + val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(TimeSynchronizationClusterDSTOffsetStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { + emit(DSTOffsetAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(DSTOffsetAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readLocalTimeAttribute(): LocalTimeAttribute { - val ATTRIBUTE_ID: UInt = 7u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readLocalTimeAttribute(): LocalTimeAttribute {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}") - } + 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) { "Localtime attribute not found in response" } + } + + requireNotNull(attributeData) { + "Localtime 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 - } + val decodedValue: ULong? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return LocalTimeAttribute(decodedValue) } suspend fun subscribeLocalTimeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - LocalTimeAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(LocalTimeAttributeSubscriptionState.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) { "Localtime attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Localtime 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(LocalTimeAttributeSubscriptionState.Success(it)) } + val decodedValue: ULong? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(LocalTimeAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(LocalTimeAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readTimeZoneDatabaseAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 8u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readTimeZoneDatabaseAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 8u + + 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}") - } + 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) { "Timezonedatabase attribute not found in response" } + } + + requireNotNull(attributeData) { + "Timezonedatabase 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeTimeZoneDatabaseAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Timezonedatabase attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Timezonedatabase 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)) } + 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 readNTPServerAvailableAttribute(): Boolean? { - val ATTRIBUTE_ID: UInt = 9u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readNTPServerAvailableAttribute(): Boolean? {val ATTRIBUTE_ID: UInt = 9u + + 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}") - } + 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) { "Ntpserveravailable attribute not found in response" } + } + + requireNotNull(attributeData) { + "Ntpserveravailable 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 - } + val decodedValue: Boolean? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeNTPServerAvailableAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Ntpserveravailable attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Ntpserveravailable 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)) } + 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 readTimeZoneListMaxSizeAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 10u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readTimeZoneListMaxSizeAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 10u + + 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}") - } + 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) { "Timezonelistmaxsize attribute not found in response" } + } + + requireNotNull(attributeData) { + "Timezonelistmaxsize 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeTimeZoneListMaxSizeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Timezonelistmaxsize attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Timezonelistmaxsize 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)) } + 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 readDSTOffsetListMaxSizeAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 11u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readDSTOffsetListMaxSizeAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 11u + + 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}") - } + 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) { "Dstoffsetlistmaxsize attribute not found in response" } + } + + requireNotNull(attributeData) { + "Dstoffsetlistmaxsize 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeDSTOffsetListMaxSizeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 11u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Dstoffsetlistmaxsize attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Dstoffsetlistmaxsize 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)) } + 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 readSupportsDNSResolveAttribute(): Boolean? { - val ATTRIBUTE_ID: UInt = 12u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readSupportsDNSResolveAttribute(): Boolean? {val ATTRIBUTE_ID: UInt = 12u + + 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}") - } + 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) { "Supportsdnsresolve attribute not found in response" } + } + + requireNotNull(attributeData) { + "Supportsdnsresolve 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 - } + val decodedValue: Boolean? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeSupportsDNSResolveAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 12u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Supportsdnsresolve attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Supportsdnsresolve 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)) } + 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 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1643,96 +1758,97 @@ class TimeSynchronizationCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1740,94 +1856,97 @@ class TimeSynchronizationCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1835,94 +1954,97 @@ class TimeSynchronizationCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1930,76 +2052,81 @@ class TimeSynchronizationCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -2011,77 +2138,80 @@ class TimeSynchronizationCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -2094,7 +2224,7 @@ class TimeSynchronizationCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/TimerCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/TimerCluster.kt index 3d87e60a1eb9f2..e974a2ed351918 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/TimerCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/TimerCluster.kt @@ -17,85 +17,117 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class TimerCluster(private val controller: MatterController, private val endpointId: UShort) { - class GeneratedCommandListAttribute(val value: List) +class TimerCluster(private val controller: MatterController, private val endpointId: UShort) {class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun setTimer(newTime: UInt, timedInvokeTimeout: Duration? = null) { + suspend fun setTimer(newTime: UInt + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_NEW_TIME_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_NEW_TIME_REQ), newTime) + tlvWriter.put(ContextSpecificTag(TAG_NEW_TIME_REQ), newTime) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -106,129 +138,136 @@ class TimerCluster(private val controller: MatterController, private val endpoin val commandId: UInt = 1u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun addTime(additionalTime: UInt, timedInvokeTimeout: Duration? = null) { + suspend fun addTime(additionalTime: UInt + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 2u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_ADDITIONAL_TIME_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_ADDITIONAL_TIME_REQ), additionalTime) + tlvWriter.put(ContextSpecificTag(TAG_ADDITIONAL_TIME_REQ), additionalTime) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun reduceTime(timeReduction: UInt, timedInvokeTimeout: Duration? = null) { + suspend fun reduceTime(timeReduction: UInt + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 3u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_TIME_REDUCTION_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_TIME_REDUCTION_REQ), timeReduction) + tlvWriter.put(ContextSpecificTag(TAG_TIME_REDUCTION_REQ), timeReduction) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - - suspend fun readSetTimeAttribute(): UInt { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readSetTimeAttribute(): UInt {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}") - } + 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) { "Settime attribute not found in response" } + } + + requireNotNull(attributeData) { + "Settime 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 subscribeSetTimeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Settime attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Settime attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -240,76 +279,81 @@ class TimerCluster(private val controller: MatterController, private val endpoin emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readTimeRemainingAttribute(): UInt { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readTimeRemainingAttribute(): UInt {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}") - } + 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) { "Timeremaining attribute not found in response" } + } + + requireNotNull(attributeData) { + "Timeremaining 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 subscribeTimeRemainingAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Timeremaining attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Timeremaining attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -321,76 +365,81 @@ class TimerCluster(private val controller: MatterController, private val endpoin emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readTimerStateAttribute(): UByte { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readTimerStateAttribute(): UByte {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}") - } + 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) { "Timerstate attribute not found in response" } + } + + requireNotNull(attributeData) { + "Timerstate 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 subscribeTimerStateAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Timerstate attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Timerstate attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -402,96 +451,97 @@ class TimerCluster(private val controller: MatterController, private val endpoin emit(UByteSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -499,96 +549,97 @@ class TimerCluster(private val controller: MatterController, private val endpoin 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -596,94 +647,97 @@ class TimerCluster(private val controller: MatterController, private val endpoin 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -691,94 +745,97 @@ class TimerCluster(private val controller: MatterController, private val endpoin 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -786,76 +843,81 @@ class TimerCluster(private val controller: MatterController, private val endpoin 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -867,77 +929,80 @@ class TimerCluster(private val controller: MatterController, private val endpoin 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -950,7 +1015,7 @@ class TimerCluster(private val controller: MatterController, private val endpoin emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/TotalVolatileOrganicCompoundsConcentrationMeasurementCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/TotalVolatileOrganicCompoundsConcentrationMeasurementCluster.kt index efa2e55b7b4ef9..acddad214ee5bc 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/TotalVolatileOrganicCompoundsConcentrationMeasurementCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/TotalVolatileOrganicCompoundsConcentrationMeasurementCluster.kt @@ -17,1273 +17,1371 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.FloatSubscriptionState import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath +import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader +import matter.tlv.TlvWriter -class TotalVolatileOrganicCompoundsConcentrationMeasurementCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class MeasuredValueAttribute(val value: Float?) +class TotalVolatileOrganicCompoundsConcentrationMeasurementCluster(private val controller: MatterController, private val endpointId: UShort) {class MeasuredValueAttribute( + val value: Float? + ) sealed class MeasuredValueAttributeSubscriptionState { - data class Success(val value: Float?) : MeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Float? + ) : MeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() - } - - class MinMeasuredValueAttribute(val value: Float?) + object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() + } +class MinMeasuredValueAttribute( + val value: Float? + ) sealed class MinMeasuredValueAttributeSubscriptionState { - data class Success(val value: Float?) : MinMeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Float? + ) : MinMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MinMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() - } - - class MaxMeasuredValueAttribute(val value: Float?) + object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() + } +class MaxMeasuredValueAttribute( + val value: Float? + ) sealed class MaxMeasuredValueAttributeSubscriptionState { - data class Success(val value: Float?) : MaxMeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Float? + ) : MaxMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MaxMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() - } - - class PeakMeasuredValueAttribute(val value: Float?) + object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() + } +class PeakMeasuredValueAttribute( + val value: Float? + ) sealed class PeakMeasuredValueAttributeSubscriptionState { - data class Success(val value: Float?) : PeakMeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Float? + ) : PeakMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : PeakMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : PeakMeasuredValueAttributeSubscriptionState() - } - - class AverageMeasuredValueAttribute(val value: Float?) + object SubscriptionEstablished : PeakMeasuredValueAttributeSubscriptionState() + } +class AverageMeasuredValueAttribute( + val value: Float? + ) sealed class AverageMeasuredValueAttributeSubscriptionState { - data class Success(val value: Float?) : AverageMeasuredValueAttributeSubscriptionState() - + data class Success( + val value: Float? + ) : AverageMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : AverageMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : AverageMeasuredValueAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : AverageMeasuredValueAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } - - suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } +suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute {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}") - } + 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) { "Measuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Measuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MeasuredValueAttribute(decodedValue) } suspend fun subscribeMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MeasuredValueAttributeSubscriptionState.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) { "Measuredvalue attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Measuredvalue attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute {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}") - } + 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) { "Minmeasuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Minmeasuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MinMeasuredValueAttribute(decodedValue) } suspend fun subscribeMinMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MinMeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MinMeasuredValueAttributeSubscriptionState.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) { - "Minmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Minmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MinMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute {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}") - } + 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) { "Maxmeasuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Maxmeasuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return MaxMeasuredValueAttribute(decodedValue) } suspend fun subscribeMaxMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - MaxMeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(MaxMeasuredValueAttributeSubscriptionState.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) { - "Maxmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Maxmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(MaxMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readPeakMeasuredValueAttribute(): PeakMeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readPeakMeasuredValueAttribute(): PeakMeasuredValueAttribute {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}") - } + 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) { "Peakmeasuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Peakmeasuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return PeakMeasuredValueAttribute(decodedValue) } suspend fun subscribePeakMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - PeakMeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(PeakMeasuredValueAttributeSubscriptionState.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) { - "Peakmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Peakmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(PeakMeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(PeakMeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(PeakMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readPeakMeasuredValueWindowAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 4u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readPeakMeasuredValueWindowAttribute(): UInt? {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}") - } + 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) { "Peakmeasuredvaluewindow attribute not found in response" } + } + + requireNotNull(attributeData) { + "Peakmeasuredvaluewindow attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribePeakMeasuredValueWindowAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Peakmeasuredvaluewindow attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Peakmeasuredvaluewindow attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readAverageMeasuredValueAttribute(): AverageMeasuredValueAttribute { - val ATTRIBUTE_ID: UInt = 5u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readAverageMeasuredValueAttribute(): AverageMeasuredValueAttribute {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}") - } + 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) { "Averagemeasuredvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Averagemeasuredvalue attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return AverageMeasuredValueAttribute(decodedValue) } suspend fun subscribeAverageMeasuredValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - AverageMeasuredValueAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(AverageMeasuredValueAttributeSubscriptionState.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) { - "Averagemeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Averagemeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(AverageMeasuredValueAttributeSubscriptionState.Success(it)) } + val decodedValue: Float? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(AverageMeasuredValueAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(AverageMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readAverageMeasuredValueWindowAttribute(): UInt? { - val ATTRIBUTE_ID: UInt = 6u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readAverageMeasuredValueWindowAttribute(): UInt? {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}") - } + 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) { "Averagemeasuredvaluewindow attribute not found in response" } + } + + requireNotNull(attributeData) { + "Averagemeasuredvaluewindow attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeAverageMeasuredValueWindowAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Averagemeasuredvaluewindow attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Averagemeasuredvaluewindow attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(UIntSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readUncertaintyAttribute(): Float? { - val ATTRIBUTE_ID: UInt = 7u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readUncertaintyAttribute(): Float? {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}") - } + 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) { "Uncertainty attribute not found in response" } + } + + requireNotNull(attributeData) { + "Uncertainty attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } + val decodedValue: Float? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeUncertaintyAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - FloatSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(FloatSubscriptionState.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) { "Uncertainty attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Uncertainty attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(FloatSubscriptionState.Success(it)) } + val decodedValue: Float? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(FloatSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(FloatSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readMeasurementUnitAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 8u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMeasurementUnitAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 8u + + 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}") - } + 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) { "Measurementunit attribute not found in response" } + } + + requireNotNull(attributeData) { + "Measurementunit 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeMeasurementUnitAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Measurementunit attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Measurementunit 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)) } + 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 readMeasurementMediumAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 9u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readMeasurementMediumAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 9u + + 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}") - } + 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) { "Measurementmedium attribute not found in response" } + } + + requireNotNull(attributeData) { + "Measurementmedium 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeMeasurementMediumAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Measurementmedium attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Measurementmedium 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)) } + 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 readLevelValueAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 10u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readLevelValueAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 10u + + 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}") - } + 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) { "Levelvalue attribute not found in response" } + } + + requireNotNull(attributeData) { + "Levelvalue 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeLevelValueAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Levelvalue attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Levelvalue 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)) } + 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 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1291,96 +1389,97 @@ class TotalVolatileOrganicCompoundsConcentrationMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1388,94 +1487,97 @@ class TotalVolatileOrganicCompoundsConcentrationMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1483,94 +1585,97 @@ class TotalVolatileOrganicCompoundsConcentrationMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1578,76 +1683,81 @@ class TotalVolatileOrganicCompoundsConcentrationMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1659,77 +1769,80 @@ class TotalVolatileOrganicCompoundsConcentrationMeasurementCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1742,14 +1855,11 @@ class TotalVolatileOrganicCompoundsConcentrationMeasurementCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { - private val logger = - Logger.getLogger( - TotalVolatileOrganicCompoundsConcentrationMeasurementCluster::class.java.name - ) + private val logger = Logger.getLogger(TotalVolatileOrganicCompoundsConcentrationMeasurementCluster::class.java.name) const val CLUSTER_ID: UInt = 1070u } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/UnitLocalizationCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/UnitLocalizationCluster.kt index af500e1b1cdce6..7d5cb6ca7abba9 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/UnitLocalizationCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/UnitLocalizationCluster.kt @@ -17,125 +17,164 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.cluster.structs.* +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath +import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class UnitLocalizationCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class GeneratedCommandListAttribute(val value: List) +class UnitLocalizationCluster(private val controller: MatterController, private val endpointId: UShort) {class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } - - suspend fun readTemperatureUnitAttribute(): 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)) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } +suspend fun readTemperatureUnitAttribute(): 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}") - } + 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) { "Temperatureunit attribute not found in response" } + } + + requireNotNull(attributeData) { + "Temperatureunit 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } - suspend fun writeTemperatureUnitAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeTemperatureUnitAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -156,153 +195,152 @@ class UnitLocalizationCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeTemperatureUnitAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Temperatureunit attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Temperatureunit 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)) } + 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 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -310,96 +348,97 @@ class UnitLocalizationCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -407,94 +446,97 @@ class UnitLocalizationCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -502,94 +544,97 @@ class UnitLocalizationCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -597,76 +642,81 @@ class UnitLocalizationCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -678,77 +728,80 @@ class UnitLocalizationCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -761,7 +814,7 @@ class UnitLocalizationCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/UnitTestingCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/UnitTestingCluster.kt index 74402b19dcfdf3..f62caafde01495 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/UnitTestingCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/UnitTestingCluster.kt @@ -17,616 +17,774 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.BooleanSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse -import matter.controller.LongSubscriptionState import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest -import matter.controller.ShortSubscriptionState -import matter.controller.StringSubscriptionState +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState import matter.controller.ULongSubscriptionState -import matter.controller.UShortSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.cluster.structs.* +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter class UnitTestingCluster(private val controller: MatterController, private val endpointId: UShort) { - class TestSpecificResponse(val returnValue: UByte) + class TestSpecificResponse( + val returnValue: UByte + ) - class TestAddArgumentsResponse(val returnValue: UByte) + class TestAddArgumentsResponse( + val returnValue: UByte + ) - class TestSimpleArgumentResponse(val returnValue: Boolean) + class TestSimpleArgumentResponse( + val returnValue: Boolean + ) class TestStructArrayArgumentResponse( - val arg1: List, - val arg2: List, - val arg3: List, - val arg4: List, - val arg5: UByte, - val arg6: Boolean, + val arg1: List, + val arg2: List, + val arg3: List, + val arg4: List, + val arg5: UByte, + val arg6: Boolean ) - class BooleanResponse(val value: Boolean) + class BooleanResponse( + val value: Boolean + ) - class TestListInt8UReverseResponse(val arg1: List) + class TestListInt8UReverseResponse( + val arg1: List + ) - class TestEnumsResponse(val arg1: UShort, val arg2: UByte) + class TestEnumsResponse( + val arg1: UShort, + val arg2: UByte + ) class TestNullableOptionalResponse( - val wasPresent: Boolean, - val wasNull: Boolean?, - val value: UByte?, - val originalValue: UByte?, + val wasPresent: Boolean, + val wasNull: Boolean?, + val value: UByte?, + val originalValue: UByte? ) class TestComplexNullableOptionalResponse( - val nullableIntWasNull: Boolean, - val nullableIntValue: UShort?, - val optionalIntWasPresent: Boolean, - val optionalIntValue: UShort?, - val nullableOptionalIntWasPresent: Boolean, - val nullableOptionalIntWasNull: Boolean?, - val nullableOptionalIntValue: UShort?, - val nullableStringWasNull: Boolean, - val nullableStringValue: String?, - val optionalStringWasPresent: Boolean, - val optionalStringValue: String?, - val nullableOptionalStringWasPresent: Boolean, - val nullableOptionalStringWasNull: Boolean?, - val nullableOptionalStringValue: String?, - val nullableStructWasNull: Boolean, - val nullableStructValue: UnitTestingClusterSimpleStruct?, - val optionalStructWasPresent: Boolean, - val optionalStructValue: UnitTestingClusterSimpleStruct?, - val nullableOptionalStructWasPresent: Boolean, - val nullableOptionalStructWasNull: Boolean?, - val nullableOptionalStructValue: UnitTestingClusterSimpleStruct?, - val nullableListWasNull: Boolean, - val nullableListValue: List?, - val optionalListWasPresent: Boolean, - val optionalListValue: List?, - val nullableOptionalListWasPresent: Boolean, - val nullableOptionalListWasNull: Boolean?, - val nullableOptionalListValue: List?, + val nullableIntWasNull: Boolean, + val nullableIntValue: UShort?, + val optionalIntWasPresent: Boolean, + val optionalIntValue: UShort?, + val nullableOptionalIntWasPresent: Boolean, + val nullableOptionalIntWasNull: Boolean?, + val nullableOptionalIntValue: UShort?, + val nullableStringWasNull: Boolean, + val nullableStringValue: String?, + val optionalStringWasPresent: Boolean, + val optionalStringValue: String?, + val nullableOptionalStringWasPresent: Boolean, + val nullableOptionalStringWasNull: Boolean?, + val nullableOptionalStringValue: String?, + val nullableStructWasNull: Boolean, + val nullableStructValue: UnitTestingClusterSimpleStruct?, + val optionalStructWasPresent: Boolean, + val optionalStructValue: UnitTestingClusterSimpleStruct?, + val nullableOptionalStructWasPresent: Boolean, + val nullableOptionalStructWasNull: Boolean?, + val nullableOptionalStructValue: UnitTestingClusterSimpleStruct?, + val nullableListWasNull: Boolean, + val nullableListValue: List?, + val optionalListWasPresent: Boolean, + val optionalListValue: List?, + val nullableOptionalListWasPresent: Boolean, + val nullableOptionalListWasNull: Boolean?, + val nullableOptionalListValue: List? ) - class SimpleStructResponse(val arg1: UnitTestingClusterSimpleStruct) - - class TestEmitTestEventResponse(val value: ULong) + class SimpleStructResponse( + val arg1: UnitTestingClusterSimpleStruct + ) - class TestEmitTestFabricScopedEventResponse(val value: ULong) + class TestEmitTestEventResponse( + val value: ULong + ) - class TestBatchHelperResponse(val buffer: ByteArray) + class TestEmitTestFabricScopedEventResponse( + val value: ULong + ) - class StringEchoResponse(val payload: ByteArray) + class TestBatchHelperResponse( + val buffer: ByteArray + ) - class GlobalEchoResponse(val field1: UnitTestingClusterTestGlobalStruct, val field2: UByte) + class StringEchoResponse( + val payload: ByteArray + ) - class TestDifferentVendorMeiResponse(val arg1: UByte, val eventNumber: ULong) + class GlobalEchoResponse( + val field1: UnitTestingClusterTestGlobalStruct, + val field2: UByte + ) - class ListInt8uAttribute(val value: List) + class TestDifferentVendorMeiResponse( + val arg1: UByte, + val eventNumber: ULong + ) +class ListInt8uAttribute( + val value: List + ) sealed class ListInt8uAttributeSubscriptionState { - data class Success(val value: List) : ListInt8uAttributeSubscriptionState() - + data class Success( + val value: List + ) : ListInt8uAttributeSubscriptionState() + data class Error(val exception: Exception) : ListInt8uAttributeSubscriptionState() - object SubscriptionEstablished : ListInt8uAttributeSubscriptionState() - } - - class ListOctetStringAttribute(val value: List) + object SubscriptionEstablished : ListInt8uAttributeSubscriptionState() + } +class ListOctetStringAttribute( + val value: List + ) sealed class ListOctetStringAttributeSubscriptionState { - data class Success(val value: List) : ListOctetStringAttributeSubscriptionState() - + data class Success( + val value: List + ) : ListOctetStringAttributeSubscriptionState() + data class Error(val exception: Exception) : ListOctetStringAttributeSubscriptionState() - object SubscriptionEstablished : ListOctetStringAttributeSubscriptionState() - } - - class ListStructOctetStringAttribute(val value: List) + object SubscriptionEstablished : ListOctetStringAttributeSubscriptionState() + } +class ListStructOctetStringAttribute( + val value: List + ) sealed class ListStructOctetStringAttributeSubscriptionState { - data class Success(val value: List) : - ListStructOctetStringAttributeSubscriptionState() - + data class Success( + val value: List + ) : ListStructOctetStringAttributeSubscriptionState() + data class Error(val exception: Exception) : ListStructOctetStringAttributeSubscriptionState() - object SubscriptionEstablished : ListStructOctetStringAttributeSubscriptionState() - } - - class ListNullablesAndOptionalsStructAttribute( + object SubscriptionEstablished : ListStructOctetStringAttributeSubscriptionState() + } +class ListNullablesAndOptionalsStructAttribute( val value: List ) sealed class ListNullablesAndOptionalsStructAttributeSubscriptionState { - data class Success(val value: List) : - ListNullablesAndOptionalsStructAttributeSubscriptionState() - - data class Error(val exception: Exception) : - ListNullablesAndOptionalsStructAttributeSubscriptionState() - - object SubscriptionEstablished : ListNullablesAndOptionalsStructAttributeSubscriptionState() - } - - class StructAttrAttribute(val value: UnitTestingClusterSimpleStruct) + data class Success( + val value: List + ) : ListNullablesAndOptionalsStructAttributeSubscriptionState() + + data class Error(val exception: Exception) : ListNullablesAndOptionalsStructAttributeSubscriptionState() + + object SubscriptionEstablished : ListNullablesAndOptionalsStructAttributeSubscriptionState() + } +class StructAttrAttribute( + val value: UnitTestingClusterSimpleStruct + ) sealed class StructAttrAttributeSubscriptionState { - data class Success(val value: UnitTestingClusterSimpleStruct) : - StructAttrAttributeSubscriptionState() - + data class Success( + val value: UnitTestingClusterSimpleStruct + ) : StructAttrAttributeSubscriptionState() + data class Error(val exception: Exception) : StructAttrAttributeSubscriptionState() - object SubscriptionEstablished : StructAttrAttributeSubscriptionState() - } - - class ListLongOctetStringAttribute(val value: List) + object SubscriptionEstablished : StructAttrAttributeSubscriptionState() + } +class ListLongOctetStringAttribute( + val value: List + ) sealed class ListLongOctetStringAttributeSubscriptionState { - data class Success(val value: List) : - ListLongOctetStringAttributeSubscriptionState() - + data class Success( + val value: List + ) : ListLongOctetStringAttributeSubscriptionState() + data class Error(val exception: Exception) : ListLongOctetStringAttributeSubscriptionState() - object SubscriptionEstablished : ListLongOctetStringAttributeSubscriptionState() - } - - class ListFabricScopedAttribute(val value: List) + object SubscriptionEstablished : ListLongOctetStringAttributeSubscriptionState() + } +class ListFabricScopedAttribute( + val value: List + ) sealed class ListFabricScopedAttributeSubscriptionState { - data class Success(val value: List) : - ListFabricScopedAttributeSubscriptionState() - + data class Success( + val value: List + ) : ListFabricScopedAttributeSubscriptionState() + data class Error(val exception: Exception) : ListFabricScopedAttributeSubscriptionState() - object SubscriptionEstablished : ListFabricScopedAttributeSubscriptionState() - } - - class GlobalStructAttribute(val value: UnitTestingClusterTestGlobalStruct) + object SubscriptionEstablished : ListFabricScopedAttributeSubscriptionState() + } +class GlobalStructAttribute( + val value: UnitTestingClusterTestGlobalStruct + ) sealed class GlobalStructAttributeSubscriptionState { - data class Success(val value: UnitTestingClusterTestGlobalStruct) : - GlobalStructAttributeSubscriptionState() - + data class Success( + val value: UnitTestingClusterTestGlobalStruct + ) : GlobalStructAttributeSubscriptionState() + data class Error(val exception: Exception) : GlobalStructAttributeSubscriptionState() - object SubscriptionEstablished : GlobalStructAttributeSubscriptionState() - } - - class NullableBooleanAttribute(val value: Boolean?) + object SubscriptionEstablished : GlobalStructAttributeSubscriptionState() + } +class NullableBooleanAttribute( + val value: Boolean? + ) sealed class NullableBooleanAttributeSubscriptionState { - data class Success(val value: Boolean?) : NullableBooleanAttributeSubscriptionState() - + data class Success( + val value: Boolean? + ) : NullableBooleanAttributeSubscriptionState() + data class Error(val exception: Exception) : NullableBooleanAttributeSubscriptionState() - object SubscriptionEstablished : NullableBooleanAttributeSubscriptionState() - } - - class NullableBitmap8Attribute(val value: UByte?) + object SubscriptionEstablished : NullableBooleanAttributeSubscriptionState() + } +class NullableBitmap8Attribute( + val value: UByte? + ) sealed class NullableBitmap8AttributeSubscriptionState { - data class Success(val value: UByte?) : NullableBitmap8AttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : NullableBitmap8AttributeSubscriptionState() + data class Error(val exception: Exception) : NullableBitmap8AttributeSubscriptionState() - object SubscriptionEstablished : NullableBitmap8AttributeSubscriptionState() - } - - class NullableBitmap16Attribute(val value: UShort?) + object SubscriptionEstablished : NullableBitmap8AttributeSubscriptionState() + } +class NullableBitmap16Attribute( + val value: UShort? + ) sealed class NullableBitmap16AttributeSubscriptionState { - data class Success(val value: UShort?) : NullableBitmap16AttributeSubscriptionState() - + data class Success( + val value: UShort? + ) : NullableBitmap16AttributeSubscriptionState() + data class Error(val exception: Exception) : NullableBitmap16AttributeSubscriptionState() - object SubscriptionEstablished : NullableBitmap16AttributeSubscriptionState() - } - - class NullableBitmap32Attribute(val value: UInt?) + object SubscriptionEstablished : NullableBitmap16AttributeSubscriptionState() + } +class NullableBitmap32Attribute( + val value: UInt? + ) sealed class NullableBitmap32AttributeSubscriptionState { - data class Success(val value: UInt?) : NullableBitmap32AttributeSubscriptionState() - + data class Success( + val value: UInt? + ) : NullableBitmap32AttributeSubscriptionState() + data class Error(val exception: Exception) : NullableBitmap32AttributeSubscriptionState() - object SubscriptionEstablished : NullableBitmap32AttributeSubscriptionState() - } - - class NullableBitmap64Attribute(val value: ULong?) + object SubscriptionEstablished : NullableBitmap32AttributeSubscriptionState() + } +class NullableBitmap64Attribute( + val value: ULong? + ) sealed class NullableBitmap64AttributeSubscriptionState { - data class Success(val value: ULong?) : NullableBitmap64AttributeSubscriptionState() - + data class Success( + val value: ULong? + ) : NullableBitmap64AttributeSubscriptionState() + data class Error(val exception: Exception) : NullableBitmap64AttributeSubscriptionState() - object SubscriptionEstablished : NullableBitmap64AttributeSubscriptionState() - } - - class NullableInt8uAttribute(val value: UByte?) + object SubscriptionEstablished : NullableBitmap64AttributeSubscriptionState() + } +class NullableInt8uAttribute( + val value: UByte? + ) sealed class NullableInt8uAttributeSubscriptionState { - data class Success(val value: UByte?) : NullableInt8uAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : NullableInt8uAttributeSubscriptionState() + data class Error(val exception: Exception) : NullableInt8uAttributeSubscriptionState() - object SubscriptionEstablished : NullableInt8uAttributeSubscriptionState() - } - - class NullableInt16uAttribute(val value: UShort?) + object SubscriptionEstablished : NullableInt8uAttributeSubscriptionState() + } +class NullableInt16uAttribute( + val value: UShort? + ) sealed class NullableInt16uAttributeSubscriptionState { - data class Success(val value: UShort?) : NullableInt16uAttributeSubscriptionState() - + data class Success( + val value: UShort? + ) : NullableInt16uAttributeSubscriptionState() + data class Error(val exception: Exception) : NullableInt16uAttributeSubscriptionState() - object SubscriptionEstablished : NullableInt16uAttributeSubscriptionState() - } - - class NullableInt24uAttribute(val value: UInt?) + object SubscriptionEstablished : NullableInt16uAttributeSubscriptionState() + } +class NullableInt24uAttribute( + val value: UInt? + ) sealed class NullableInt24uAttributeSubscriptionState { - data class Success(val value: UInt?) : NullableInt24uAttributeSubscriptionState() - + data class Success( + val value: UInt? + ) : NullableInt24uAttributeSubscriptionState() + data class Error(val exception: Exception) : NullableInt24uAttributeSubscriptionState() - object SubscriptionEstablished : NullableInt24uAttributeSubscriptionState() - } - - class NullableInt32uAttribute(val value: UInt?) + object SubscriptionEstablished : NullableInt24uAttributeSubscriptionState() + } +class NullableInt32uAttribute( + val value: UInt? + ) sealed class NullableInt32uAttributeSubscriptionState { - data class Success(val value: UInt?) : NullableInt32uAttributeSubscriptionState() - + data class Success( + val value: UInt? + ) : NullableInt32uAttributeSubscriptionState() + data class Error(val exception: Exception) : NullableInt32uAttributeSubscriptionState() - object SubscriptionEstablished : NullableInt32uAttributeSubscriptionState() - } - - class NullableInt40uAttribute(val value: ULong?) + object SubscriptionEstablished : NullableInt32uAttributeSubscriptionState() + } +class NullableInt40uAttribute( + val value: ULong? + ) sealed class NullableInt40uAttributeSubscriptionState { - data class Success(val value: ULong?) : NullableInt40uAttributeSubscriptionState() - + data class Success( + val value: ULong? + ) : NullableInt40uAttributeSubscriptionState() + data class Error(val exception: Exception) : NullableInt40uAttributeSubscriptionState() - object SubscriptionEstablished : NullableInt40uAttributeSubscriptionState() - } - - class NullableInt48uAttribute(val value: ULong?) + object SubscriptionEstablished : NullableInt40uAttributeSubscriptionState() + } +class NullableInt48uAttribute( + val value: ULong? + ) sealed class NullableInt48uAttributeSubscriptionState { - data class Success(val value: ULong?) : NullableInt48uAttributeSubscriptionState() - + data class Success( + val value: ULong? + ) : NullableInt48uAttributeSubscriptionState() + data class Error(val exception: Exception) : NullableInt48uAttributeSubscriptionState() - object SubscriptionEstablished : NullableInt48uAttributeSubscriptionState() - } - - class NullableInt56uAttribute(val value: ULong?) + object SubscriptionEstablished : NullableInt48uAttributeSubscriptionState() + } +class NullableInt56uAttribute( + val value: ULong? + ) sealed class NullableInt56uAttributeSubscriptionState { - data class Success(val value: ULong?) : NullableInt56uAttributeSubscriptionState() - + data class Success( + val value: ULong? + ) : NullableInt56uAttributeSubscriptionState() + data class Error(val exception: Exception) : NullableInt56uAttributeSubscriptionState() - object SubscriptionEstablished : NullableInt56uAttributeSubscriptionState() - } - - class NullableInt64uAttribute(val value: ULong?) + object SubscriptionEstablished : NullableInt56uAttributeSubscriptionState() + } +class NullableInt64uAttribute( + val value: ULong? + ) sealed class NullableInt64uAttributeSubscriptionState { - data class Success(val value: ULong?) : NullableInt64uAttributeSubscriptionState() - + data class Success( + val value: ULong? + ) : NullableInt64uAttributeSubscriptionState() + data class Error(val exception: Exception) : NullableInt64uAttributeSubscriptionState() - object SubscriptionEstablished : NullableInt64uAttributeSubscriptionState() - } - - class NullableInt8sAttribute(val value: Byte?) + object SubscriptionEstablished : NullableInt64uAttributeSubscriptionState() + } +class NullableInt8sAttribute( + val value: Byte? + ) sealed class NullableInt8sAttributeSubscriptionState { - data class Success(val value: Byte?) : NullableInt8sAttributeSubscriptionState() - + data class Success( + val value: Byte? + ) : NullableInt8sAttributeSubscriptionState() + data class Error(val exception: Exception) : NullableInt8sAttributeSubscriptionState() - object SubscriptionEstablished : NullableInt8sAttributeSubscriptionState() - } - - class NullableInt16sAttribute(val value: Short?) + object SubscriptionEstablished : NullableInt8sAttributeSubscriptionState() + } +class NullableInt16sAttribute( + val value: Short? + ) sealed class NullableInt16sAttributeSubscriptionState { - data class Success(val value: Short?) : NullableInt16sAttributeSubscriptionState() - + data class Success( + val value: Short? + ) : NullableInt16sAttributeSubscriptionState() + data class Error(val exception: Exception) : NullableInt16sAttributeSubscriptionState() - object SubscriptionEstablished : NullableInt16sAttributeSubscriptionState() - } - - class NullableInt24sAttribute(val value: Int?) + object SubscriptionEstablished : NullableInt16sAttributeSubscriptionState() + } +class NullableInt24sAttribute( + val value: Int? + ) sealed class NullableInt24sAttributeSubscriptionState { - data class Success(val value: Int?) : NullableInt24sAttributeSubscriptionState() - + data class Success( + val value: Int? + ) : NullableInt24sAttributeSubscriptionState() + data class Error(val exception: Exception) : NullableInt24sAttributeSubscriptionState() - object SubscriptionEstablished : NullableInt24sAttributeSubscriptionState() - } - - class NullableInt32sAttribute(val value: Int?) + object SubscriptionEstablished : NullableInt24sAttributeSubscriptionState() + } +class NullableInt32sAttribute( + val value: Int? + ) sealed class NullableInt32sAttributeSubscriptionState { - data class Success(val value: Int?) : NullableInt32sAttributeSubscriptionState() - + data class Success( + val value: Int? + ) : NullableInt32sAttributeSubscriptionState() + data class Error(val exception: Exception) : NullableInt32sAttributeSubscriptionState() - object SubscriptionEstablished : NullableInt32sAttributeSubscriptionState() - } - - class NullableInt40sAttribute(val value: Long?) + object SubscriptionEstablished : NullableInt32sAttributeSubscriptionState() + } +class NullableInt40sAttribute( + val value: Long? + ) sealed class NullableInt40sAttributeSubscriptionState { - data class Success(val value: Long?) : NullableInt40sAttributeSubscriptionState() - + data class Success( + val value: Long? + ) : NullableInt40sAttributeSubscriptionState() + data class Error(val exception: Exception) : NullableInt40sAttributeSubscriptionState() - object SubscriptionEstablished : NullableInt40sAttributeSubscriptionState() - } - - class NullableInt48sAttribute(val value: Long?) + object SubscriptionEstablished : NullableInt40sAttributeSubscriptionState() + } +class NullableInt48sAttribute( + val value: Long? + ) sealed class NullableInt48sAttributeSubscriptionState { - data class Success(val value: Long?) : NullableInt48sAttributeSubscriptionState() - + data class Success( + val value: Long? + ) : NullableInt48sAttributeSubscriptionState() + data class Error(val exception: Exception) : NullableInt48sAttributeSubscriptionState() - object SubscriptionEstablished : NullableInt48sAttributeSubscriptionState() - } - - class NullableInt56sAttribute(val value: Long?) + object SubscriptionEstablished : NullableInt48sAttributeSubscriptionState() + } +class NullableInt56sAttribute( + val value: Long? + ) sealed class NullableInt56sAttributeSubscriptionState { - data class Success(val value: Long?) : NullableInt56sAttributeSubscriptionState() - + data class Success( + val value: Long? + ) : NullableInt56sAttributeSubscriptionState() + data class Error(val exception: Exception) : NullableInt56sAttributeSubscriptionState() - object SubscriptionEstablished : NullableInt56sAttributeSubscriptionState() - } - - class NullableInt64sAttribute(val value: Long?) + object SubscriptionEstablished : NullableInt56sAttributeSubscriptionState() + } +class NullableInt64sAttribute( + val value: Long? + ) sealed class NullableInt64sAttributeSubscriptionState { - data class Success(val value: Long?) : NullableInt64sAttributeSubscriptionState() - + data class Success( + val value: Long? + ) : NullableInt64sAttributeSubscriptionState() + data class Error(val exception: Exception) : NullableInt64sAttributeSubscriptionState() - object SubscriptionEstablished : NullableInt64sAttributeSubscriptionState() - } - - class NullableEnum8Attribute(val value: UByte?) + object SubscriptionEstablished : NullableInt64sAttributeSubscriptionState() + } +class NullableEnum8Attribute( + val value: UByte? + ) sealed class NullableEnum8AttributeSubscriptionState { - data class Success(val value: UByte?) : NullableEnum8AttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : NullableEnum8AttributeSubscriptionState() + data class Error(val exception: Exception) : NullableEnum8AttributeSubscriptionState() - object SubscriptionEstablished : NullableEnum8AttributeSubscriptionState() - } - - class NullableEnum16Attribute(val value: UShort?) + object SubscriptionEstablished : NullableEnum8AttributeSubscriptionState() + } +class NullableEnum16Attribute( + val value: UShort? + ) sealed class NullableEnum16AttributeSubscriptionState { - data class Success(val value: UShort?) : NullableEnum16AttributeSubscriptionState() - + data class Success( + val value: UShort? + ) : NullableEnum16AttributeSubscriptionState() + data class Error(val exception: Exception) : NullableEnum16AttributeSubscriptionState() - object SubscriptionEstablished : NullableEnum16AttributeSubscriptionState() - } - - class NullableFloatSingleAttribute(val value: Float?) + object SubscriptionEstablished : NullableEnum16AttributeSubscriptionState() + } +class NullableFloatSingleAttribute( + val value: Float? + ) sealed class NullableFloatSingleAttributeSubscriptionState { - data class Success(val value: Float?) : NullableFloatSingleAttributeSubscriptionState() - + data class Success( + val value: Float? + ) : NullableFloatSingleAttributeSubscriptionState() + data class Error(val exception: Exception) : NullableFloatSingleAttributeSubscriptionState() - object SubscriptionEstablished : NullableFloatSingleAttributeSubscriptionState() - } - - class NullableFloatDoubleAttribute(val value: Double?) + object SubscriptionEstablished : NullableFloatSingleAttributeSubscriptionState() + } +class NullableFloatDoubleAttribute( + val value: Double? + ) sealed class NullableFloatDoubleAttributeSubscriptionState { - data class Success(val value: Double?) : NullableFloatDoubleAttributeSubscriptionState() - + data class Success( + val value: Double? + ) : NullableFloatDoubleAttributeSubscriptionState() + data class Error(val exception: Exception) : NullableFloatDoubleAttributeSubscriptionState() - object SubscriptionEstablished : NullableFloatDoubleAttributeSubscriptionState() - } - - class NullableOctetStringAttribute(val value: ByteArray?) + object SubscriptionEstablished : NullableFloatDoubleAttributeSubscriptionState() + } +class NullableOctetStringAttribute( + val value: ByteArray? + ) sealed class NullableOctetStringAttributeSubscriptionState { - data class Success(val value: ByteArray?) : NullableOctetStringAttributeSubscriptionState() - + data class Success( + val value: ByteArray? + ) : NullableOctetStringAttributeSubscriptionState() + data class Error(val exception: Exception) : NullableOctetStringAttributeSubscriptionState() - object SubscriptionEstablished : NullableOctetStringAttributeSubscriptionState() - } - - class NullableCharStringAttribute(val value: String?) + object SubscriptionEstablished : NullableOctetStringAttributeSubscriptionState() + } +class NullableCharStringAttribute( + val value: String? + ) sealed class NullableCharStringAttributeSubscriptionState { - data class Success(val value: String?) : NullableCharStringAttributeSubscriptionState() - + data class Success( + val value: String? + ) : NullableCharStringAttributeSubscriptionState() + data class Error(val exception: Exception) : NullableCharStringAttributeSubscriptionState() - object SubscriptionEstablished : NullableCharStringAttributeSubscriptionState() - } - - class NullableEnumAttrAttribute(val value: UByte?) + object SubscriptionEstablished : NullableCharStringAttributeSubscriptionState() + } +class NullableEnumAttrAttribute( + val value: UByte? + ) sealed class NullableEnumAttrAttributeSubscriptionState { - data class Success(val value: UByte?) : NullableEnumAttrAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : NullableEnumAttrAttributeSubscriptionState() + data class Error(val exception: Exception) : NullableEnumAttrAttributeSubscriptionState() - object SubscriptionEstablished : NullableEnumAttrAttributeSubscriptionState() - } - - class NullableStructAttribute(val value: UnitTestingClusterSimpleStruct?) + object SubscriptionEstablished : NullableEnumAttrAttributeSubscriptionState() + } +class NullableStructAttribute( + val value: UnitTestingClusterSimpleStruct? + ) sealed class NullableStructAttributeSubscriptionState { - data class Success(val value: UnitTestingClusterSimpleStruct?) : - NullableStructAttributeSubscriptionState() - + data class Success( + val value: UnitTestingClusterSimpleStruct? + ) : NullableStructAttributeSubscriptionState() + data class Error(val exception: Exception) : NullableStructAttributeSubscriptionState() - object SubscriptionEstablished : NullableStructAttributeSubscriptionState() - } - - class NullableRangeRestrictedInt8uAttribute(val value: UByte?) + object SubscriptionEstablished : NullableStructAttributeSubscriptionState() + } +class NullableRangeRestrictedInt8uAttribute( + val value: UByte? + ) sealed class NullableRangeRestrictedInt8uAttributeSubscriptionState { - data class Success(val value: UByte?) : - NullableRangeRestrictedInt8uAttributeSubscriptionState() - - data class Error(val exception: Exception) : - NullableRangeRestrictedInt8uAttributeSubscriptionState() - - object SubscriptionEstablished : NullableRangeRestrictedInt8uAttributeSubscriptionState() - } - - class NullableRangeRestrictedInt8sAttribute(val value: Byte?) + data class Success( + val value: UByte? + ) : NullableRangeRestrictedInt8uAttributeSubscriptionState() + + data class Error(val exception: Exception) : NullableRangeRestrictedInt8uAttributeSubscriptionState() + + object SubscriptionEstablished : NullableRangeRestrictedInt8uAttributeSubscriptionState() + } +class NullableRangeRestrictedInt8sAttribute( + val value: Byte? + ) sealed class NullableRangeRestrictedInt8sAttributeSubscriptionState { - data class Success(val value: Byte?) : NullableRangeRestrictedInt8sAttributeSubscriptionState() - - data class Error(val exception: Exception) : - NullableRangeRestrictedInt8sAttributeSubscriptionState() - - object SubscriptionEstablished : NullableRangeRestrictedInt8sAttributeSubscriptionState() - } - - class NullableRangeRestrictedInt16uAttribute(val value: UShort?) + data class Success( + val value: Byte? + ) : NullableRangeRestrictedInt8sAttributeSubscriptionState() + + data class Error(val exception: Exception) : NullableRangeRestrictedInt8sAttributeSubscriptionState() + + object SubscriptionEstablished : NullableRangeRestrictedInt8sAttributeSubscriptionState() + } +class NullableRangeRestrictedInt16uAttribute( + val value: UShort? + ) sealed class NullableRangeRestrictedInt16uAttributeSubscriptionState { - data class Success(val value: UShort?) : - NullableRangeRestrictedInt16uAttributeSubscriptionState() - - data class Error(val exception: Exception) : - NullableRangeRestrictedInt16uAttributeSubscriptionState() - - object SubscriptionEstablished : NullableRangeRestrictedInt16uAttributeSubscriptionState() - } - - class NullableRangeRestrictedInt16sAttribute(val value: Short?) + data class Success( + val value: UShort? + ) : NullableRangeRestrictedInt16uAttributeSubscriptionState() + + data class Error(val exception: Exception) : NullableRangeRestrictedInt16uAttributeSubscriptionState() + + object SubscriptionEstablished : NullableRangeRestrictedInt16uAttributeSubscriptionState() + } +class NullableRangeRestrictedInt16sAttribute( + val value: Short? + ) sealed class NullableRangeRestrictedInt16sAttributeSubscriptionState { - data class Success(val value: Short?) : - NullableRangeRestrictedInt16sAttributeSubscriptionState() - - data class Error(val exception: Exception) : - NullableRangeRestrictedInt16sAttributeSubscriptionState() - - object SubscriptionEstablished : NullableRangeRestrictedInt16sAttributeSubscriptionState() - } - - class NullableGlobalEnumAttribute(val value: UByte?) + data class Success( + val value: Short? + ) : NullableRangeRestrictedInt16sAttributeSubscriptionState() + + data class Error(val exception: Exception) : NullableRangeRestrictedInt16sAttributeSubscriptionState() + + object SubscriptionEstablished : NullableRangeRestrictedInt16sAttributeSubscriptionState() + } +class NullableGlobalEnumAttribute( + val value: UByte? + ) sealed class NullableGlobalEnumAttributeSubscriptionState { - data class Success(val value: UByte?) : NullableGlobalEnumAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : NullableGlobalEnumAttributeSubscriptionState() + data class Error(val exception: Exception) : NullableGlobalEnumAttributeSubscriptionState() - object SubscriptionEstablished : NullableGlobalEnumAttributeSubscriptionState() - } - - class NullableGlobalStructAttribute(val value: UnitTestingClusterTestGlobalStruct?) + object SubscriptionEstablished : NullableGlobalEnumAttributeSubscriptionState() + } +class NullableGlobalStructAttribute( + val value: UnitTestingClusterTestGlobalStruct? + ) sealed class NullableGlobalStructAttributeSubscriptionState { - data class Success(val value: UnitTestingClusterTestGlobalStruct?) : - NullableGlobalStructAttributeSubscriptionState() - + data class Success( + val value: UnitTestingClusterTestGlobalStruct? + ) : NullableGlobalStructAttributeSubscriptionState() + data class Error(val exception: Exception) : NullableGlobalStructAttributeSubscriptionState() - object SubscriptionEstablished : NullableGlobalStructAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : NullableGlobalStructAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } suspend fun test(timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -637,14 +795,14 @@ class UnitTestingCluster(private val controller: MatterController, private val e val commandId: UInt = 1u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -655,14 +813,14 @@ class UnitTestingCluster(private val controller: MatterController, private val e val commandId: UInt = 2u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -672,49 +830,55 @@ class UnitTestingCluster(private val controller: MatterController, private val e tlvReader.enterStructure(AnonymousTag) val TAG_RETURN_VALUE: Int = 0 var returnValue_decoded: UByte? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_RETURN_VALUE)) { - returnValue_decoded = tlvReader.getUByte(tag) - } else { + + if (tag == ContextSpecificTag(TAG_RETURN_VALUE)) {returnValue_decoded = tlvReader.getUByte(tag)} + + + else { tlvReader.skipElement() } } + + if (returnValue_decoded == null) { - throw IllegalStateException("returnValue not found in TLV") + throw IllegalStateException("returnValue not found in TLV") } + tlvReader.exitContainer() - return TestSpecificResponse(returnValue_decoded) + return TestSpecificResponse( + returnValue_decoded + ) } suspend fun testUnknownCommand(timedInvokeTimeout: Duration? = null) { val commandId: UInt = 3u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun testAddArguments( - arg1: UByte, - arg2: UByte, - timedInvokeTimeout: Duration? = null, - ): TestAddArgumentsResponse { + suspend fun testAddArguments(arg1: UByte + ,arg2: UByte + ,timedInvokeTimeout: Duration? = null): TestAddArgumentsResponse { val commandId: UInt = 4u val tlvWriter = TlvWriter() @@ -724,14 +888,14 @@ class UnitTestingCluster(private val controller: MatterController, private val e tlvWriter.put(ContextSpecificTag(TAG_ARG1_REQ), arg1) val TAG_ARG2_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_ARG2_REQ), arg2) + tlvWriter.put(ContextSpecificTag(TAG_ARG2_REQ), arg2) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -741,44 +905,50 @@ class UnitTestingCluster(private val controller: MatterController, private val e tlvReader.enterStructure(AnonymousTag) val TAG_RETURN_VALUE: Int = 0 var returnValue_decoded: UByte? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_RETURN_VALUE)) { - returnValue_decoded = tlvReader.getUByte(tag) - } else { + + if (tag == ContextSpecificTag(TAG_RETURN_VALUE)) {returnValue_decoded = tlvReader.getUByte(tag)} + + + else { tlvReader.skipElement() } } + + if (returnValue_decoded == null) { - throw IllegalStateException("returnValue not found in TLV") + throw IllegalStateException("returnValue not found in TLV") } + tlvReader.exitContainer() - return TestAddArgumentsResponse(returnValue_decoded) + return TestAddArgumentsResponse( + returnValue_decoded + ) } - suspend fun testSimpleArgumentRequest( - arg1: Boolean, - timedInvokeTimeout: Duration? = null, - ): TestSimpleArgumentResponse { + suspend fun testSimpleArgumentRequest(arg1: Boolean + ,timedInvokeTimeout: Duration? = null): TestSimpleArgumentResponse { val commandId: UInt = 5u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_ARG1_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_ARG1_REQ), arg1) + tlvWriter.put(ContextSpecificTag(TAG_ARG1_REQ), arg1) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -788,35 +958,41 @@ class UnitTestingCluster(private val controller: MatterController, private val e tlvReader.enterStructure(AnonymousTag) val TAG_RETURN_VALUE: Int = 0 var returnValue_decoded: Boolean? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_RETURN_VALUE)) { - returnValue_decoded = tlvReader.getBoolean(tag) - } else { + + if (tag == ContextSpecificTag(TAG_RETURN_VALUE)) {returnValue_decoded = tlvReader.getBoolean(tag)} + + + else { tlvReader.skipElement() } } + + if (returnValue_decoded == null) { - throw IllegalStateException("returnValue not found in TLV") + throw IllegalStateException("returnValue not found in TLV") } + tlvReader.exitContainer() - return TestSimpleArgumentResponse(returnValue_decoded) + return TestSimpleArgumentResponse( + returnValue_decoded + ) } - suspend fun testStructArrayArgumentRequest( - arg1: List, - arg2: List, - arg3: List, - arg4: List, - arg5: UByte, - arg6: Boolean, - timedInvokeTimeout: Duration? = null, - ): TestStructArrayArgumentResponse { + suspend fun testStructArrayArgumentRequest(arg1: List + ,arg2: List + ,arg3: List + ,arg4: List + ,arg5: UByte + ,arg6: Boolean + ,timedInvokeTimeout: Duration? = null): TestStructArrayArgumentResponse { val commandId: UInt = 6u val tlvWriter = TlvWriter() @@ -824,44 +1000,44 @@ class UnitTestingCluster(private val controller: MatterController, private val e val TAG_ARG1_REQ: Int = 0 tlvWriter.startArray(ContextSpecificTag(TAG_ARG1_REQ)) - for (item in arg1.iterator()) { - item.toTlv(AnonymousTag, tlvWriter) - } - tlvWriter.endArray() + for (item in arg1.iterator()) { + item.toTlv(AnonymousTag, tlvWriter) + } + tlvWriter.endArray() val TAG_ARG2_REQ: Int = 1 tlvWriter.startArray(ContextSpecificTag(TAG_ARG2_REQ)) - for (item in arg2.iterator()) { - item.toTlv(AnonymousTag, tlvWriter) - } - tlvWriter.endArray() + for (item in arg2.iterator()) { + item.toTlv(AnonymousTag, tlvWriter) + } + tlvWriter.endArray() val TAG_ARG3_REQ: Int = 2 tlvWriter.startArray(ContextSpecificTag(TAG_ARG3_REQ)) - for (item in arg3.iterator()) { - tlvWriter.put(AnonymousTag, item) - } - tlvWriter.endArray() + for (item in arg3.iterator()) { + tlvWriter.put(AnonymousTag, item) + } + tlvWriter.endArray() val TAG_ARG4_REQ: Int = 3 tlvWriter.startArray(ContextSpecificTag(TAG_ARG4_REQ)) - for (item in arg4.iterator()) { - tlvWriter.put(AnonymousTag, item) - } - tlvWriter.endArray() + for (item in arg4.iterator()) { + tlvWriter.put(AnonymousTag, item) + } + tlvWriter.endArray() val TAG_ARG5_REQ: Int = 4 tlvWriter.put(ContextSpecificTag(TAG_ARG5_REQ), arg5) val TAG_ARG6_REQ: Int = 5 - tlvWriter.put(ContextSpecificTag(TAG_ARG6_REQ), arg6) + tlvWriter.put(ContextSpecificTag(TAG_ARG6_REQ), arg6) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -871,103 +1047,100 @@ class UnitTestingCluster(private val controller: MatterController, private val e tlvReader.enterStructure(AnonymousTag) val TAG_ARG1: Int = 0 var arg1_decoded: List? = null - + val TAG_ARG2: Int = 1 var arg2_decoded: List? = null - + val TAG_ARG3: Int = 2 var arg3_decoded: List? = null - + val TAG_ARG4: Int = 3 var arg4_decoded: List? = null - + val TAG_ARG5: Int = 4 var arg5_decoded: UByte? = null - + val TAG_ARG6: Int = 5 var arg6_decoded: Boolean? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_ARG1)) { - arg1_decoded = - buildList { - tlvReader.enterArray(tag) - while (!tlvReader.isEndOfContainer()) { - add(UnitTestingClusterNestedStructList.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } - - if (tag == ContextSpecificTag(TAG_ARG2)) { - arg2_decoded = - buildList { - tlvReader.enterArray(tag) - while (!tlvReader.isEndOfContainer()) { - add(UnitTestingClusterSimpleStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } - - if (tag == ContextSpecificTag(TAG_ARG3)) { - arg3_decoded = - buildList { - tlvReader.enterArray(tag) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } - } - - if (tag == ContextSpecificTag(TAG_ARG4)) { - arg4_decoded = - buildList { - tlvReader.enterArray(tag) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getBoolean(AnonymousTag)) - } - tlvReader.exitContainer() - } - } - - if (tag == ContextSpecificTag(TAG_ARG5)) { - arg5_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_ARG6)) { - arg6_decoded = tlvReader.getBoolean(tag) - } else { + + if (tag == ContextSpecificTag(TAG_ARG1)) {arg1_decoded = buildList { + tlvReader.enterArray(tag) + while(!tlvReader.isEndOfContainer()) { + add(UnitTestingClusterNestedStructList.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + }} + + if (tag == ContextSpecificTag(TAG_ARG2)) {arg2_decoded = buildList { + tlvReader.enterArray(tag) + while(!tlvReader.isEndOfContainer()) { + add(UnitTestingClusterSimpleStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + }} + + if (tag == ContextSpecificTag(TAG_ARG3)) {arg3_decoded = buildList { + tlvReader.enterArray(tag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + }} + + if (tag == ContextSpecificTag(TAG_ARG4)) {arg4_decoded = buildList { + tlvReader.enterArray(tag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getBoolean(AnonymousTag)) + } + tlvReader.exitContainer() + }} + + if (tag == ContextSpecificTag(TAG_ARG5)) {arg5_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_ARG6)) {arg6_decoded = tlvReader.getBoolean(tag)} + + + else { tlvReader.skipElement() } } + + if (arg1_decoded == null) { - throw IllegalStateException("arg1 not found in TLV") + throw IllegalStateException("arg1 not found in TLV") } - + + if (arg2_decoded == null) { - throw IllegalStateException("arg2 not found in TLV") + throw IllegalStateException("arg2 not found in TLV") } - + + if (arg3_decoded == null) { - throw IllegalStateException("arg3 not found in TLV") + throw IllegalStateException("arg3 not found in TLV") } - + + if (arg4_decoded == null) { - throw IllegalStateException("arg4 not found in TLV") + throw IllegalStateException("arg4 not found in TLV") } - + + if (arg5_decoded == null) { - throw IllegalStateException("arg5 not found in TLV") + throw IllegalStateException("arg5 not found in TLV") } - + + if (arg6_decoded == null) { - throw IllegalStateException("arg6 not found in TLV") + throw IllegalStateException("arg6 not found in TLV") } + tlvReader.exitContainer() @@ -977,28 +1150,26 @@ class UnitTestingCluster(private val controller: MatterController, private val e arg3_decoded, arg4_decoded, arg5_decoded, - arg6_decoded, + arg6_decoded ) } - suspend fun testStructArgumentRequest( - arg1: UnitTestingClusterSimpleStruct, - timedInvokeTimeout: Duration? = null, - ): BooleanResponse { + suspend fun testStructArgumentRequest(arg1: UnitTestingClusterSimpleStruct + ,timedInvokeTimeout: Duration? = null): BooleanResponse { val commandId: UInt = 7u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_ARG1_REQ: Int = 0 - arg1.toTlv(ContextSpecificTag(TAG_ARG1_REQ), tlvWriter) + arg1.toTlv(ContextSpecificTag(TAG_ARG1_REQ), tlvWriter) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -1008,44 +1179,50 @@ class UnitTestingCluster(private val controller: MatterController, private val e tlvReader.enterStructure(AnonymousTag) val TAG_VALUE: Int = 0 var value_decoded: Boolean? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_VALUE)) { - value_decoded = tlvReader.getBoolean(tag) - } else { + + if (tag == ContextSpecificTag(TAG_VALUE)) {value_decoded = tlvReader.getBoolean(tag)} + + + else { tlvReader.skipElement() } } + + if (value_decoded == null) { - throw IllegalStateException("value not found in TLV") + throw IllegalStateException("value not found in TLV") } + tlvReader.exitContainer() - return BooleanResponse(value_decoded) + return BooleanResponse( + value_decoded + ) } - suspend fun testNestedStructArgumentRequest( - arg1: UnitTestingClusterNestedStruct, - timedInvokeTimeout: Duration? = null, - ): BooleanResponse { + suspend fun testNestedStructArgumentRequest(arg1: UnitTestingClusterNestedStruct + ,timedInvokeTimeout: Duration? = null): BooleanResponse { val commandId: UInt = 8u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_ARG1_REQ: Int = 0 - arg1.toTlv(ContextSpecificTag(TAG_ARG1_REQ), tlvWriter) + arg1.toTlv(ContextSpecificTag(TAG_ARG1_REQ), tlvWriter) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -1055,30 +1232,36 @@ class UnitTestingCluster(private val controller: MatterController, private val e tlvReader.enterStructure(AnonymousTag) val TAG_VALUE: Int = 0 var value_decoded: Boolean? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_VALUE)) { - value_decoded = tlvReader.getBoolean(tag) - } else { + + if (tag == ContextSpecificTag(TAG_VALUE)) {value_decoded = tlvReader.getBoolean(tag)} + + + else { tlvReader.skipElement() } } + + if (value_decoded == null) { - throw IllegalStateException("value not found in TLV") + throw IllegalStateException("value not found in TLV") } + tlvReader.exitContainer() - return BooleanResponse(value_decoded) + return BooleanResponse( + value_decoded + ) } - suspend fun testListStructArgumentRequest( - arg1: List, - timedInvokeTimeout: Duration? = null, - ): BooleanResponse { + suspend fun testListStructArgumentRequest(arg1: List + ,timedInvokeTimeout: Duration? = null): BooleanResponse { val commandId: UInt = 9u val tlvWriter = TlvWriter() @@ -1086,17 +1269,17 @@ class UnitTestingCluster(private val controller: MatterController, private val e val TAG_ARG1_REQ: Int = 0 tlvWriter.startArray(ContextSpecificTag(TAG_ARG1_REQ)) - for (item in arg1.iterator()) { - item.toTlv(AnonymousTag, tlvWriter) - } - tlvWriter.endArray() + for (item in arg1.iterator()) { + item.toTlv(AnonymousTag, tlvWriter) + } + tlvWriter.endArray() tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -1106,30 +1289,36 @@ class UnitTestingCluster(private val controller: MatterController, private val e tlvReader.enterStructure(AnonymousTag) val TAG_VALUE: Int = 0 var value_decoded: Boolean? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_VALUE)) { - value_decoded = tlvReader.getBoolean(tag) - } else { + + if (tag == ContextSpecificTag(TAG_VALUE)) {value_decoded = tlvReader.getBoolean(tag)} + + + else { tlvReader.skipElement() } } + + if (value_decoded == null) { - throw IllegalStateException("value not found in TLV") + throw IllegalStateException("value not found in TLV") } + tlvReader.exitContainer() - return BooleanResponse(value_decoded) + return BooleanResponse( + value_decoded + ) } - suspend fun testListInt8UArgumentRequest( - arg1: List, - timedInvokeTimeout: Duration? = null, - ): BooleanResponse { + suspend fun testListInt8UArgumentRequest(arg1: List + ,timedInvokeTimeout: Duration? = null): BooleanResponse { val commandId: UInt = 10u val tlvWriter = TlvWriter() @@ -1137,17 +1326,17 @@ class UnitTestingCluster(private val controller: MatterController, private val e val TAG_ARG1_REQ: Int = 0 tlvWriter.startArray(ContextSpecificTag(TAG_ARG1_REQ)) - for (item in arg1.iterator()) { - tlvWriter.put(AnonymousTag, item) - } - tlvWriter.endArray() + for (item in arg1.iterator()) { + tlvWriter.put(AnonymousTag, item) + } + tlvWriter.endArray() tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -1157,44 +1346,50 @@ class UnitTestingCluster(private val controller: MatterController, private val e tlvReader.enterStructure(AnonymousTag) val TAG_VALUE: Int = 0 var value_decoded: Boolean? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_VALUE)) { - value_decoded = tlvReader.getBoolean(tag) - } else { + + if (tag == ContextSpecificTag(TAG_VALUE)) {value_decoded = tlvReader.getBoolean(tag)} + + + else { tlvReader.skipElement() } } + + if (value_decoded == null) { - throw IllegalStateException("value not found in TLV") + throw IllegalStateException("value not found in TLV") } + tlvReader.exitContainer() - return BooleanResponse(value_decoded) + return BooleanResponse( + value_decoded + ) } - suspend fun testNestedStructListArgumentRequest( - arg1: UnitTestingClusterNestedStructList, - timedInvokeTimeout: Duration? = null, - ): BooleanResponse { + suspend fun testNestedStructListArgumentRequest(arg1: UnitTestingClusterNestedStructList + ,timedInvokeTimeout: Duration? = null): BooleanResponse { val commandId: UInt = 11u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_ARG1_REQ: Int = 0 - arg1.toTlv(ContextSpecificTag(TAG_ARG1_REQ), tlvWriter) + arg1.toTlv(ContextSpecificTag(TAG_ARG1_REQ), tlvWriter) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -1204,30 +1399,36 @@ class UnitTestingCluster(private val controller: MatterController, private val e tlvReader.enterStructure(AnonymousTag) val TAG_VALUE: Int = 0 var value_decoded: Boolean? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_VALUE)) { - value_decoded = tlvReader.getBoolean(tag) - } else { + + if (tag == ContextSpecificTag(TAG_VALUE)) {value_decoded = tlvReader.getBoolean(tag)} + + + else { tlvReader.skipElement() } } + + if (value_decoded == null) { - throw IllegalStateException("value not found in TLV") + throw IllegalStateException("value not found in TLV") } + tlvReader.exitContainer() - return BooleanResponse(value_decoded) + return BooleanResponse( + value_decoded + ) } - suspend fun testListNestedStructListArgumentRequest( - arg1: List, - timedInvokeTimeout: Duration? = null, - ): BooleanResponse { + suspend fun testListNestedStructListArgumentRequest(arg1: List + ,timedInvokeTimeout: Duration? = null): BooleanResponse { val commandId: UInt = 12u val tlvWriter = TlvWriter() @@ -1235,17 +1436,17 @@ class UnitTestingCluster(private val controller: MatterController, private val e val TAG_ARG1_REQ: Int = 0 tlvWriter.startArray(ContextSpecificTag(TAG_ARG1_REQ)) - for (item in arg1.iterator()) { - item.toTlv(AnonymousTag, tlvWriter) - } - tlvWriter.endArray() + for (item in arg1.iterator()) { + item.toTlv(AnonymousTag, tlvWriter) + } + tlvWriter.endArray() tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -1255,30 +1456,36 @@ class UnitTestingCluster(private val controller: MatterController, private val e tlvReader.enterStructure(AnonymousTag) val TAG_VALUE: Int = 0 var value_decoded: Boolean? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_VALUE)) { - value_decoded = tlvReader.getBoolean(tag) - } else { + + if (tag == ContextSpecificTag(TAG_VALUE)) {value_decoded = tlvReader.getBoolean(tag)} + + + else { tlvReader.skipElement() } } + + if (value_decoded == null) { - throw IllegalStateException("value not found in TLV") + throw IllegalStateException("value not found in TLV") } + tlvReader.exitContainer() - return BooleanResponse(value_decoded) + return BooleanResponse( + value_decoded + ) } - suspend fun testListInt8UReverseRequest( - arg1: List, - timedInvokeTimeout: Duration? = null, - ): TestListInt8UReverseResponse { + suspend fun testListInt8UReverseRequest(arg1: List + ,timedInvokeTimeout: Duration? = null): TestListInt8UReverseResponse { val commandId: UInt = 13u val tlvWriter = TlvWriter() @@ -1286,17 +1493,17 @@ class UnitTestingCluster(private val controller: MatterController, private val e val TAG_ARG1_REQ: Int = 0 tlvWriter.startArray(ContextSpecificTag(TAG_ARG1_REQ)) - for (item in arg1.iterator()) { - tlvWriter.put(AnonymousTag, item) - } - tlvWriter.endArray() + for (item in arg1.iterator()) { + tlvWriter.put(AnonymousTag, item) + } + tlvWriter.endArray() tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -1306,38 +1513,43 @@ class UnitTestingCluster(private val controller: MatterController, private val e tlvReader.enterStructure(AnonymousTag) val TAG_ARG1: Int = 0 var arg1_decoded: List? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_ARG1)) { - arg1_decoded = - buildList { - tlvReader.enterArray(tag) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { + + if (tag == ContextSpecificTag(TAG_ARG1)) {arg1_decoded = buildList { + tlvReader.enterArray(tag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + }} + + + else { tlvReader.skipElement() } } + + if (arg1_decoded == null) { - throw IllegalStateException("arg1 not found in TLV") + throw IllegalStateException("arg1 not found in TLV") } + tlvReader.exitContainer() - return TestListInt8UReverseResponse(arg1_decoded) + return TestListInt8UReverseResponse( + arg1_decoded + ) } - suspend fun testEnumsRequest( - arg1: UShort, - arg2: UByte, - timedInvokeTimeout: Duration? = null, - ): TestEnumsResponse { + suspend fun testEnumsRequest(arg1: UShort + ,arg2: UByte + ,timedInvokeTimeout: Duration? = null): TestEnumsResponse { val commandId: UInt = 14u val tlvWriter = TlvWriter() @@ -1347,14 +1559,14 @@ class UnitTestingCluster(private val controller: MatterController, private val e tlvWriter.put(ContextSpecificTag(TAG_ARG1_REQ), arg1) val TAG_ARG2_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_ARG2_REQ), arg2) + tlvWriter.put(ContextSpecificTag(TAG_ARG2_REQ), arg2) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -1364,55 +1576,63 @@ class UnitTestingCluster(private val controller: MatterController, private val e tlvReader.enterStructure(AnonymousTag) val TAG_ARG1: Int = 0 var arg1_decoded: UShort? = null - + val TAG_ARG2: Int = 1 var arg2_decoded: UByte? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_ARG1)) { - arg1_decoded = tlvReader.getUShort(tag) - } + + if (tag == ContextSpecificTag(TAG_ARG1)) {arg1_decoded = tlvReader.getUShort(tag)} + + if (tag == ContextSpecificTag(TAG_ARG2)) {arg2_decoded = tlvReader.getUByte(tag)} + - if (tag == ContextSpecificTag(TAG_ARG2)) { - arg2_decoded = tlvReader.getUByte(tag) - } else { + else { tlvReader.skipElement() } } + + if (arg1_decoded == null) { - throw IllegalStateException("arg1 not found in TLV") + throw IllegalStateException("arg1 not found in TLV") } - + + if (arg2_decoded == null) { - throw IllegalStateException("arg2 not found in TLV") + throw IllegalStateException("arg2 not found in TLV") } + tlvReader.exitContainer() - return TestEnumsResponse(arg1_decoded, arg2_decoded) + return TestEnumsResponse( + arg1_decoded, + arg2_decoded + ) } - suspend fun testNullableOptionalRequest( - arg1: UByte?, - timedInvokeTimeout: Duration? = null, - ): TestNullableOptionalResponse { + suspend fun testNullableOptionalRequest(arg1: UByte? + ,timedInvokeTimeout: Duration? = null): TestNullableOptionalResponse { val commandId: UInt = 15u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_ARG1_REQ: Int = 0 - arg1?.let { tlvWriter.put(ContextSpecificTag(TAG_ARG1_REQ), arg1) } + arg1?.let { + tlvWriter.put(ContextSpecificTag(TAG_ARG1_REQ), arg1) + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -1422,76 +1642,82 @@ class UnitTestingCluster(private val controller: MatterController, private val e tlvReader.enterStructure(AnonymousTag) val TAG_WAS_PRESENT: Int = 0 var wasPresent_decoded: Boolean? = null - + val TAG_WAS_NULL: Int = 1 var wasNull_decoded: Boolean? = null - + val TAG_VALUE: Int = 2 var value_decoded: UByte? = null - + val TAG_ORIGINAL_VALUE: Int = 3 var originalValue_decoded: UByte? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_WAS_PRESENT)) { - wasPresent_decoded = tlvReader.getBoolean(tag) - } - - if (tag == ContextSpecificTag(TAG_WAS_NULL)) { - wasNull_decoded = + + if (tag == ContextSpecificTag(TAG_WAS_PRESENT)) {wasPresent_decoded = tlvReader.getBoolean(tag)} + + if (tag == ContextSpecificTag(TAG_WAS_NULL)) {wasNull_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getBoolean(tag) - } else { - null - } - } - } - - if (tag == ContextSpecificTag(TAG_VALUE)) { - value_decoded = + tlvReader.getBoolean(tag) + } else { + null + } + }} + + if (tag == ContextSpecificTag(TAG_VALUE)) {value_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getUByte(tag) - } else { - null - } - } - } - - if (tag == ContextSpecificTag(TAG_ORIGINAL_VALUE)) { - originalValue_decoded = + tlvReader.getUByte(tag) + } else { + null + } + }} + + if (tag == ContextSpecificTag(TAG_ORIGINAL_VALUE)) {originalValue_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(tag)) { - tlvReader.getUByte(tag) - } else { - null - } - } else { - tlvReader.getNull(tag) - null - } - } - } else { + if (tlvReader.isNextTag(tag)) { + tlvReader.getUByte(tag) + } else { + null + } + } else { + tlvReader.getNull(tag) + null + } + }} + + + else { tlvReader.skipElement() } } + + if (wasPresent_decoded == null) { - throw IllegalStateException("wasPresent not found in TLV") + throw IllegalStateException("wasPresent not found in TLV") } + + + + + + + tlvReader.exitContainer() @@ -1499,35 +1725,37 @@ class UnitTestingCluster(private val controller: MatterController, private val e wasPresent_decoded, wasNull_decoded, value_decoded, - originalValue_decoded, - ) - } - - suspend fun testComplexNullableOptionalRequest( - nullableInt: UShort?, - optionalInt: UShort?, - nullableOptionalInt: UShort?, - nullableString: String?, - optionalString: String?, - nullableOptionalString: String?, - nullableStruct: UnitTestingClusterSimpleStruct?, - optionalStruct: UnitTestingClusterSimpleStruct?, - nullableOptionalStruct: UnitTestingClusterSimpleStruct?, - nullableList: List?, - optionalList: List?, - nullableOptionalList: List?, - timedInvokeTimeout: Duration? = null, - ): TestComplexNullableOptionalResponse { + originalValue_decoded + ) + } + + suspend fun testComplexNullableOptionalRequest(nullableInt: UShort? + ,optionalInt: UShort? + ,nullableOptionalInt: UShort? + ,nullableString: String? + ,optionalString: String? + ,nullableOptionalString: String? + ,nullableStruct: UnitTestingClusterSimpleStruct? + ,optionalStruct: UnitTestingClusterSimpleStruct? + ,nullableOptionalStruct: UnitTestingClusterSimpleStruct? + ,nullableList: List? + ,optionalList: List? + ,nullableOptionalList: List? + ,timedInvokeTimeout: Duration? = null): TestComplexNullableOptionalResponse { val commandId: UInt = 16u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_NULLABLE_INT_REQ: Int = 0 - nullableInt?.let { tlvWriter.put(ContextSpecificTag(TAG_NULLABLE_INT_REQ), nullableInt) } + nullableInt?.let { + tlvWriter.put(ContextSpecificTag(TAG_NULLABLE_INT_REQ), nullableInt) + } val TAG_OPTIONAL_INT_REQ: Int = 1 - optionalInt?.let { tlvWriter.put(ContextSpecificTag(TAG_OPTIONAL_INT_REQ), optionalInt) } + optionalInt?.let { + tlvWriter.put(ContextSpecificTag(TAG_OPTIONAL_INT_REQ), optionalInt) + } val TAG_NULLABLE_OPTIONAL_INT_REQ: Int = 2 nullableOptionalInt?.let { @@ -1589,14 +1817,14 @@ class UnitTestingCluster(private val controller: MatterController, private val e tlvWriter.put(AnonymousTag, item) } tlvWriter.endArray() - } + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -1606,431 +1834,426 @@ class UnitTestingCluster(private val controller: MatterController, private val e tlvReader.enterStructure(AnonymousTag) val TAG_NULLABLE_INT_WAS_NULL: Int = 0 var nullableIntWasNull_decoded: Boolean? = null - + val TAG_NULLABLE_INT_VALUE: Int = 1 var nullableIntValue_decoded: UShort? = null - + val TAG_OPTIONAL_INT_WAS_PRESENT: Int = 2 var optionalIntWasPresent_decoded: Boolean? = null - + val TAG_OPTIONAL_INT_VALUE: Int = 3 var optionalIntValue_decoded: UShort? = null - + val TAG_NULLABLE_OPTIONAL_INT_WAS_PRESENT: Int = 4 var nullableOptionalIntWasPresent_decoded: Boolean? = null - + val TAG_NULLABLE_OPTIONAL_INT_WAS_NULL: Int = 5 var nullableOptionalIntWasNull_decoded: Boolean? = null - + val TAG_NULLABLE_OPTIONAL_INT_VALUE: Int = 6 var nullableOptionalIntValue_decoded: UShort? = null - + val TAG_NULLABLE_STRING_WAS_NULL: Int = 7 var nullableStringWasNull_decoded: Boolean? = null - + val TAG_NULLABLE_STRING_VALUE: Int = 8 var nullableStringValue_decoded: String? = null - + val TAG_OPTIONAL_STRING_WAS_PRESENT: Int = 9 var optionalStringWasPresent_decoded: Boolean? = null - + val TAG_OPTIONAL_STRING_VALUE: Int = 10 var optionalStringValue_decoded: String? = null - + val TAG_NULLABLE_OPTIONAL_STRING_WAS_PRESENT: Int = 11 var nullableOptionalStringWasPresent_decoded: Boolean? = null - + val TAG_NULLABLE_OPTIONAL_STRING_WAS_NULL: Int = 12 var nullableOptionalStringWasNull_decoded: Boolean? = null - + val TAG_NULLABLE_OPTIONAL_STRING_VALUE: Int = 13 var nullableOptionalStringValue_decoded: String? = null - + val TAG_NULLABLE_STRUCT_WAS_NULL: Int = 14 var nullableStructWasNull_decoded: Boolean? = null - + val TAG_NULLABLE_STRUCT_VALUE: Int = 15 var nullableStructValue_decoded: UnitTestingClusterSimpleStruct? = null - + val TAG_OPTIONAL_STRUCT_WAS_PRESENT: Int = 16 var optionalStructWasPresent_decoded: Boolean? = null - + val TAG_OPTIONAL_STRUCT_VALUE: Int = 17 var optionalStructValue_decoded: UnitTestingClusterSimpleStruct? = null - + val TAG_NULLABLE_OPTIONAL_STRUCT_WAS_PRESENT: Int = 18 var nullableOptionalStructWasPresent_decoded: Boolean? = null - + val TAG_NULLABLE_OPTIONAL_STRUCT_WAS_NULL: Int = 19 var nullableOptionalStructWasNull_decoded: Boolean? = null - + val TAG_NULLABLE_OPTIONAL_STRUCT_VALUE: Int = 20 var nullableOptionalStructValue_decoded: UnitTestingClusterSimpleStruct? = null - + val TAG_NULLABLE_LIST_WAS_NULL: Int = 21 var nullableListWasNull_decoded: Boolean? = null - + val TAG_NULLABLE_LIST_VALUE: Int = 22 var nullableListValue_decoded: List? = null - + val TAG_OPTIONAL_LIST_WAS_PRESENT: Int = 23 var optionalListWasPresent_decoded: Boolean? = null - + val TAG_OPTIONAL_LIST_VALUE: Int = 24 var optionalListValue_decoded: List? = null - + val TAG_NULLABLE_OPTIONAL_LIST_WAS_PRESENT: Int = 25 var nullableOptionalListWasPresent_decoded: Boolean? = null - + val TAG_NULLABLE_OPTIONAL_LIST_WAS_NULL: Int = 26 var nullableOptionalListWasNull_decoded: Boolean? = null - + val TAG_NULLABLE_OPTIONAL_LIST_VALUE: Int = 27 var nullableOptionalListValue_decoded: List? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_NULLABLE_INT_WAS_NULL)) { - nullableIntWasNull_decoded = tlvReader.getBoolean(tag) - } - - if (tag == ContextSpecificTag(TAG_NULLABLE_INT_VALUE)) { - nullableIntValue_decoded = + + if (tag == ContextSpecificTag(TAG_NULLABLE_INT_WAS_NULL)) {nullableIntWasNull_decoded = tlvReader.getBoolean(tag)} + + if (tag == ContextSpecificTag(TAG_NULLABLE_INT_VALUE)) {nullableIntValue_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getUShort(tag) - } else { - null - } - } - } - - if (tag == ContextSpecificTag(TAG_OPTIONAL_INT_WAS_PRESENT)) { - optionalIntWasPresent_decoded = tlvReader.getBoolean(tag) - } - - if (tag == ContextSpecificTag(TAG_OPTIONAL_INT_VALUE)) { - optionalIntValue_decoded = + tlvReader.getUShort(tag) + } else { + null + } + }} + + if (tag == ContextSpecificTag(TAG_OPTIONAL_INT_WAS_PRESENT)) {optionalIntWasPresent_decoded = tlvReader.getBoolean(tag)} + + if (tag == ContextSpecificTag(TAG_OPTIONAL_INT_VALUE)) {optionalIntValue_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getUShort(tag) - } else { - null - } - } - } - - if (tag == ContextSpecificTag(TAG_NULLABLE_OPTIONAL_INT_WAS_PRESENT)) { - nullableOptionalIntWasPresent_decoded = tlvReader.getBoolean(tag) - } - - if (tag == ContextSpecificTag(TAG_NULLABLE_OPTIONAL_INT_WAS_NULL)) { - nullableOptionalIntWasNull_decoded = + tlvReader.getUShort(tag) + } else { + null + } + }} + + if (tag == ContextSpecificTag(TAG_NULLABLE_OPTIONAL_INT_WAS_PRESENT)) {nullableOptionalIntWasPresent_decoded = tlvReader.getBoolean(tag)} + + if (tag == ContextSpecificTag(TAG_NULLABLE_OPTIONAL_INT_WAS_NULL)) {nullableOptionalIntWasNull_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getBoolean(tag) - } else { - null - } - } - } - - if (tag == ContextSpecificTag(TAG_NULLABLE_OPTIONAL_INT_VALUE)) { - nullableOptionalIntValue_decoded = + tlvReader.getBoolean(tag) + } else { + null + } + }} + + if (tag == ContextSpecificTag(TAG_NULLABLE_OPTIONAL_INT_VALUE)) {nullableOptionalIntValue_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getUShort(tag) - } else { - null - } - } - } - - if (tag == ContextSpecificTag(TAG_NULLABLE_STRING_WAS_NULL)) { - nullableStringWasNull_decoded = tlvReader.getBoolean(tag) - } - - if (tag == ContextSpecificTag(TAG_NULLABLE_STRING_VALUE)) { - nullableStringValue_decoded = + tlvReader.getUShort(tag) + } else { + null + } + }} + + if (tag == ContextSpecificTag(TAG_NULLABLE_STRING_WAS_NULL)) {nullableStringWasNull_decoded = tlvReader.getBoolean(tag)} + + if (tag == ContextSpecificTag(TAG_NULLABLE_STRING_VALUE)) {nullableStringValue_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - } - } - - if (tag == ContextSpecificTag(TAG_OPTIONAL_STRING_WAS_PRESENT)) { - optionalStringWasPresent_decoded = tlvReader.getBoolean(tag) - } - - if (tag == ContextSpecificTag(TAG_OPTIONAL_STRING_VALUE)) { - optionalStringValue_decoded = + tlvReader.getString(tag) + } else { + null + } + }} + + if (tag == ContextSpecificTag(TAG_OPTIONAL_STRING_WAS_PRESENT)) {optionalStringWasPresent_decoded = tlvReader.getBoolean(tag)} + + if (tag == ContextSpecificTag(TAG_OPTIONAL_STRING_VALUE)) {optionalStringValue_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - } - } - - if (tag == ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRING_WAS_PRESENT)) { - nullableOptionalStringWasPresent_decoded = tlvReader.getBoolean(tag) - } - - if (tag == ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRING_WAS_NULL)) { - nullableOptionalStringWasNull_decoded = + tlvReader.getString(tag) + } else { + null + } + }} + + if (tag == ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRING_WAS_PRESENT)) {nullableOptionalStringWasPresent_decoded = tlvReader.getBoolean(tag)} + + if (tag == ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRING_WAS_NULL)) {nullableOptionalStringWasNull_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getBoolean(tag) - } else { - null - } - } - } - - if (tag == ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRING_VALUE)) { - nullableOptionalStringValue_decoded = + tlvReader.getBoolean(tag) + } else { + null + } + }} + + if (tag == ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRING_VALUE)) {nullableOptionalStringValue_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - } - } - - if (tag == ContextSpecificTag(TAG_NULLABLE_STRUCT_WAS_NULL)) { - nullableStructWasNull_decoded = tlvReader.getBoolean(tag) - } - - if (tag == ContextSpecificTag(TAG_NULLABLE_STRUCT_VALUE)) { - nullableStructValue_decoded = + tlvReader.getString(tag) + } else { + null + } + }} + + if (tag == ContextSpecificTag(TAG_NULLABLE_STRUCT_WAS_NULL)) {nullableStructWasNull_decoded = tlvReader.getBoolean(tag)} + + if (tag == ContextSpecificTag(TAG_NULLABLE_STRUCT_VALUE)) {nullableStructValue_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - UnitTestingClusterSimpleStruct.fromTlv(tag, tlvReader) - } else { - null - } - } - } - - if (tag == ContextSpecificTag(TAG_OPTIONAL_STRUCT_WAS_PRESENT)) { - optionalStructWasPresent_decoded = tlvReader.getBoolean(tag) - } - - if (tag == ContextSpecificTag(TAG_OPTIONAL_STRUCT_VALUE)) { - optionalStructValue_decoded = + UnitTestingClusterSimpleStruct.fromTlv(tag, tlvReader) + } else { + null + } + }} + + if (tag == ContextSpecificTag(TAG_OPTIONAL_STRUCT_WAS_PRESENT)) {optionalStructWasPresent_decoded = tlvReader.getBoolean(tag)} + + if (tag == ContextSpecificTag(TAG_OPTIONAL_STRUCT_VALUE)) {optionalStructValue_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - UnitTestingClusterSimpleStruct.fromTlv(tag, tlvReader) - } else { - null - } - } - } - - if (tag == ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRUCT_WAS_PRESENT)) { - nullableOptionalStructWasPresent_decoded = tlvReader.getBoolean(tag) - } - - if (tag == ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRUCT_WAS_NULL)) { - nullableOptionalStructWasNull_decoded = + UnitTestingClusterSimpleStruct.fromTlv(tag, tlvReader) + } else { + null + } + }} + + if (tag == ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRUCT_WAS_PRESENT)) {nullableOptionalStructWasPresent_decoded = tlvReader.getBoolean(tag)} + + if (tag == ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRUCT_WAS_NULL)) {nullableOptionalStructWasNull_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getBoolean(tag) - } else { - null - } - } - } - - if (tag == ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRUCT_VALUE)) { - nullableOptionalStructValue_decoded = + tlvReader.getBoolean(tag) + } else { + null + } + }} + + if (tag == ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRUCT_VALUE)) {nullableOptionalStructValue_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - UnitTestingClusterSimpleStruct.fromTlv(tag, tlvReader) - } else { - null - } - } - } - - if (tag == ContextSpecificTag(TAG_NULLABLE_LIST_WAS_NULL)) { - nullableListWasNull_decoded = tlvReader.getBoolean(tag) - } - - if (tag == ContextSpecificTag(TAG_NULLABLE_LIST_VALUE)) { - nullableListValue_decoded = + UnitTestingClusterSimpleStruct.fromTlv(tag, tlvReader) + } else { + null + } + }} + + if (tag == ContextSpecificTag(TAG_NULLABLE_LIST_WAS_NULL)) {nullableListWasNull_decoded = tlvReader.getBoolean(tag)} + + if (tag == ContextSpecificTag(TAG_NULLABLE_LIST_VALUE)) {nullableListValue_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 - } - } - } - - if (tag == ContextSpecificTag(TAG_OPTIONAL_LIST_WAS_PRESENT)) { - optionalListWasPresent_decoded = tlvReader.getBoolean(tag) - } - - if (tag == ContextSpecificTag(TAG_OPTIONAL_LIST_VALUE)) { - optionalListValue_decoded = + buildList { + tlvReader.enterArray(tag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null + } + }} + + if (tag == ContextSpecificTag(TAG_OPTIONAL_LIST_WAS_PRESENT)) {optionalListWasPresent_decoded = tlvReader.getBoolean(tag)} + + if (tag == ContextSpecificTag(TAG_OPTIONAL_LIST_VALUE)) {optionalListValue_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 - } - } - } - - if (tag == ContextSpecificTag(TAG_NULLABLE_OPTIONAL_LIST_WAS_PRESENT)) { - nullableOptionalListWasPresent_decoded = tlvReader.getBoolean(tag) - } - - if (tag == ContextSpecificTag(TAG_NULLABLE_OPTIONAL_LIST_WAS_NULL)) { - nullableOptionalListWasNull_decoded = + buildList { + tlvReader.enterArray(tag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null + } + }} + + if (tag == ContextSpecificTag(TAG_NULLABLE_OPTIONAL_LIST_WAS_PRESENT)) {nullableOptionalListWasPresent_decoded = tlvReader.getBoolean(tag)} + + if (tag == ContextSpecificTag(TAG_NULLABLE_OPTIONAL_LIST_WAS_NULL)) {nullableOptionalListWasNull_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getBoolean(tag) - } else { - null - } - } - } - - if (tag == ContextSpecificTag(TAG_NULLABLE_OPTIONAL_LIST_VALUE)) { - nullableOptionalListValue_decoded = + tlvReader.getBoolean(tag) + } else { + null + } + }} + + if (tag == ContextSpecificTag(TAG_NULLABLE_OPTIONAL_LIST_VALUE)) {nullableOptionalListValue_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 { + buildList { + tlvReader.enterArray(tag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null + } + }} + + + else { tlvReader.skipElement() } } + + if (nullableIntWasNull_decoded == null) { - throw IllegalStateException("nullableIntWasNull not found in TLV") + throw IllegalStateException("nullableIntWasNull not found in TLV") } - + + + + if (optionalIntWasPresent_decoded == null) { - throw IllegalStateException("optionalIntWasPresent not found in TLV") - } - - if (nullableOptionalIntWasPresent_decoded == null) { - throw IllegalStateException("nullableOptionalIntWasPresent not found in TLV") + throw IllegalStateException("optionalIntWasPresent not found in TLV") } - + + + + + if (nullableOptionalIntWasPresent_decoded == null) { + throw IllegalStateException("nullableOptionalIntWasPresent not found in TLV") + } + + + + + + if (nullableStringWasNull_decoded == null) { - throw IllegalStateException("nullableStringWasNull not found in TLV") + throw IllegalStateException("nullableStringWasNull not found in TLV") } - + + + + if (optionalStringWasPresent_decoded == null) { - throw IllegalStateException("optionalStringWasPresent not found in TLV") + throw IllegalStateException("optionalStringWasPresent not found in TLV") } - + + + + if (nullableOptionalStringWasPresent_decoded == null) { - throw IllegalStateException("nullableOptionalStringWasPresent not found in TLV") - } - + throw IllegalStateException("nullableOptionalStringWasPresent not found in TLV") + } + + + + + + if (nullableStructWasNull_decoded == null) { - throw IllegalStateException("nullableStructWasNull not found in TLV") + throw IllegalStateException("nullableStructWasNull not found in TLV") } - + + + + if (optionalStructWasPresent_decoded == null) { - throw IllegalStateException("optionalStructWasPresent not found in TLV") + throw IllegalStateException("optionalStructWasPresent not found in TLV") } - + + + + if (nullableOptionalStructWasPresent_decoded == null) { - throw IllegalStateException("nullableOptionalStructWasPresent not found in TLV") - } - + throw IllegalStateException("nullableOptionalStructWasPresent not found in TLV") + } + + + + + + if (nullableListWasNull_decoded == null) { - throw IllegalStateException("nullableListWasNull not found in TLV") + throw IllegalStateException("nullableListWasNull not found in TLV") } - + + + + if (optionalListWasPresent_decoded == null) { - throw IllegalStateException("optionalListWasPresent not found in TLV") + throw IllegalStateException("optionalListWasPresent not found in TLV") } - + + + + if (nullableOptionalListWasPresent_decoded == null) { - throw IllegalStateException("nullableOptionalListWasPresent not found in TLV") + throw IllegalStateException("nullableOptionalListWasPresent not found in TLV") } + + + + + tlvReader.exitContainer() @@ -2062,28 +2285,26 @@ class UnitTestingCluster(private val controller: MatterController, private val e optionalListValue_decoded, nullableOptionalListWasPresent_decoded, nullableOptionalListWasNull_decoded, - nullableOptionalListValue_decoded, + nullableOptionalListValue_decoded ) } - suspend fun simpleStructEchoRequest( - arg1: UnitTestingClusterSimpleStruct, - timedInvokeTimeout: Duration? = null, - ): SimpleStructResponse { + suspend fun simpleStructEchoRequest(arg1: UnitTestingClusterSimpleStruct + ,timedInvokeTimeout: Duration? = null): SimpleStructResponse { val commandId: UInt = 17u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_ARG1_REQ: Int = 0 - arg1.toTlv(ContextSpecificTag(TAG_ARG1_REQ), tlvWriter) + arg1.toTlv(ContextSpecificTag(TAG_ARG1_REQ), tlvWriter) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -2093,74 +2314,80 @@ class UnitTestingCluster(private val controller: MatterController, private val e tlvReader.enterStructure(AnonymousTag) val TAG_ARG1: Int = 0 var arg1_decoded: UnitTestingClusterSimpleStruct? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_ARG1)) { - arg1_decoded = UnitTestingClusterSimpleStruct.fromTlv(tag, tlvReader) - } else { + + if (tag == ContextSpecificTag(TAG_ARG1)) {arg1_decoded = UnitTestingClusterSimpleStruct.fromTlv(tag, tlvReader)} + + + else { tlvReader.skipElement() } } + + if (arg1_decoded == null) { - throw IllegalStateException("arg1 not found in TLV") + throw IllegalStateException("arg1 not found in TLV") } + tlvReader.exitContainer() - return SimpleStructResponse(arg1_decoded) + return SimpleStructResponse( + arg1_decoded + ) } suspend fun timedInvokeRequest(timedInvokeTimeout: Duration) { val commandId: UInt = 18u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun testSimpleOptionalArgumentRequest( - arg1: Boolean?, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun testSimpleOptionalArgumentRequest(arg1: Boolean? + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 19u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_ARG1_REQ: Int = 0 - arg1?.let { tlvWriter.put(ContextSpecificTag(TAG_ARG1_REQ), arg1) } + arg1?.let { + tlvWriter.put(ContextSpecificTag(TAG_ARG1_REQ), arg1) + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun testEmitTestEventRequest( - arg1: UByte, - arg2: UByte, - arg3: Boolean, - timedInvokeTimeout: Duration? = null, - ): TestEmitTestEventResponse { + suspend fun testEmitTestEventRequest(arg1: UByte + ,arg2: UByte + ,arg3: Boolean + ,timedInvokeTimeout: Duration? = null): TestEmitTestEventResponse { val commandId: UInt = 20u val tlvWriter = TlvWriter() @@ -2173,14 +2400,14 @@ class UnitTestingCluster(private val controller: MatterController, private val e tlvWriter.put(ContextSpecificTag(TAG_ARG2_REQ), arg2) val TAG_ARG3_REQ: Int = 2 - tlvWriter.put(ContextSpecificTag(TAG_ARG3_REQ), arg3) + tlvWriter.put(ContextSpecificTag(TAG_ARG3_REQ), arg3) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -2190,44 +2417,50 @@ class UnitTestingCluster(private val controller: MatterController, private val e tlvReader.enterStructure(AnonymousTag) val TAG_VALUE: Int = 0 var value_decoded: ULong? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_VALUE)) { - value_decoded = tlvReader.getULong(tag) - } else { + + if (tag == ContextSpecificTag(TAG_VALUE)) {value_decoded = tlvReader.getULong(tag)} + + + else { tlvReader.skipElement() } } + + if (value_decoded == null) { - throw IllegalStateException("value not found in TLV") + throw IllegalStateException("value not found in TLV") } + tlvReader.exitContainer() - return TestEmitTestEventResponse(value_decoded) + return TestEmitTestEventResponse( + value_decoded + ) } - suspend fun testEmitTestFabricScopedEventRequest( - arg1: UByte, - timedInvokeTimeout: Duration? = null, - ): TestEmitTestFabricScopedEventResponse { + suspend fun testEmitTestFabricScopedEventRequest(arg1: UByte + ,timedInvokeTimeout: Duration? = null): TestEmitTestFabricScopedEventResponse { val commandId: UInt = 21u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_ARG1_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_ARG1_REQ), arg1) + tlvWriter.put(ContextSpecificTag(TAG_ARG1_REQ), arg1) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -2237,55 +2470,58 @@ class UnitTestingCluster(private val controller: MatterController, private val e tlvReader.enterStructure(AnonymousTag) val TAG_VALUE: Int = 0 var value_decoded: ULong? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_VALUE)) { - value_decoded = tlvReader.getULong(tag) - } else { + + if (tag == ContextSpecificTag(TAG_VALUE)) {value_decoded = tlvReader.getULong(tag)} + + + else { tlvReader.skipElement() } } + + if (value_decoded == null) { - throw IllegalStateException("value not found in TLV") + throw IllegalStateException("value not found in TLV") } + tlvReader.exitContainer() - return TestEmitTestFabricScopedEventResponse(value_decoded) + return TestEmitTestFabricScopedEventResponse( + value_decoded + ) } - suspend fun testBatchHelperRequest( - sleepBeforeResponseTimeMs: UShort, - sizeOfResponseBuffer: UShort, - fillCharacter: UByte, - timedInvokeTimeout: Duration? = null, - ): TestBatchHelperResponse { + suspend fun testBatchHelperRequest(sleepBeforeResponseTimeMs: UShort + ,sizeOfResponseBuffer: UShort + ,fillCharacter: UByte + ,timedInvokeTimeout: Duration? = null): TestBatchHelperResponse { val commandId: UInt = 22u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_SLEEP_BEFORE_RESPONSE_TIME_MS_REQ: Int = 0 - tlvWriter.put( - ContextSpecificTag(TAG_SLEEP_BEFORE_RESPONSE_TIME_MS_REQ), - sleepBeforeResponseTimeMs, - ) + tlvWriter.put(ContextSpecificTag(TAG_SLEEP_BEFORE_RESPONSE_TIME_MS_REQ), sleepBeforeResponseTimeMs) val TAG_SIZE_OF_RESPONSE_BUFFER_REQ: Int = 1 tlvWriter.put(ContextSpecificTag(TAG_SIZE_OF_RESPONSE_BUFFER_REQ), sizeOfResponseBuffer) val TAG_FILL_CHARACTER_REQ: Int = 2 - tlvWriter.put(ContextSpecificTag(TAG_FILL_CHARACTER_REQ), fillCharacter) + tlvWriter.put(ContextSpecificTag(TAG_FILL_CHARACTER_REQ), fillCharacter) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -2295,55 +2531,58 @@ class UnitTestingCluster(private val controller: MatterController, private val e tlvReader.enterStructure(AnonymousTag) val TAG_BUFFER: Int = 0 var buffer_decoded: ByteArray? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_BUFFER)) { - buffer_decoded = tlvReader.getByteArray(tag) - } else { + + if (tag == ContextSpecificTag(TAG_BUFFER)) {buffer_decoded = tlvReader.getByteArray(tag)} + + + else { tlvReader.skipElement() } } + + if (buffer_decoded == null) { - throw IllegalStateException("buffer not found in TLV") + throw IllegalStateException("buffer not found in TLV") } + tlvReader.exitContainer() - return TestBatchHelperResponse(buffer_decoded) + return TestBatchHelperResponse( + buffer_decoded + ) } - suspend fun testSecondBatchHelperRequest( - sleepBeforeResponseTimeMs: UShort, - sizeOfResponseBuffer: UShort, - fillCharacter: UByte, - timedInvokeTimeout: Duration? = null, - ): TestBatchHelperResponse { + suspend fun testSecondBatchHelperRequest(sleepBeforeResponseTimeMs: UShort + ,sizeOfResponseBuffer: UShort + ,fillCharacter: UByte + ,timedInvokeTimeout: Duration? = null): TestBatchHelperResponse { val commandId: UInt = 23u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_SLEEP_BEFORE_RESPONSE_TIME_MS_REQ: Int = 0 - tlvWriter.put( - ContextSpecificTag(TAG_SLEEP_BEFORE_RESPONSE_TIME_MS_REQ), - sleepBeforeResponseTimeMs, - ) + tlvWriter.put(ContextSpecificTag(TAG_SLEEP_BEFORE_RESPONSE_TIME_MS_REQ), sleepBeforeResponseTimeMs) val TAG_SIZE_OF_RESPONSE_BUFFER_REQ: Int = 1 tlvWriter.put(ContextSpecificTag(TAG_SIZE_OF_RESPONSE_BUFFER_REQ), sizeOfResponseBuffer) val TAG_FILL_CHARACTER_REQ: Int = 2 - tlvWriter.put(ContextSpecificTag(TAG_FILL_CHARACTER_REQ), fillCharacter) + tlvWriter.put(ContextSpecificTag(TAG_FILL_CHARACTER_REQ), fillCharacter) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -2353,44 +2592,50 @@ class UnitTestingCluster(private val controller: MatterController, private val e tlvReader.enterStructure(AnonymousTag) val TAG_BUFFER: Int = 0 var buffer_decoded: ByteArray? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_BUFFER)) { - buffer_decoded = tlvReader.getByteArray(tag) - } else { + + if (tag == ContextSpecificTag(TAG_BUFFER)) {buffer_decoded = tlvReader.getByteArray(tag)} + + + else { tlvReader.skipElement() } } + + if (buffer_decoded == null) { - throw IllegalStateException("buffer not found in TLV") + throw IllegalStateException("buffer not found in TLV") } + tlvReader.exitContainer() - return TestBatchHelperResponse(buffer_decoded) + return TestBatchHelperResponse( + buffer_decoded + ) } - suspend fun stringEchoRequest( - payload: ByteArray, - timedInvokeTimeout: Duration? = null, - ): StringEchoResponse { + suspend fun stringEchoRequest(payload: ByteArray + ,timedInvokeTimeout: Duration? = null): StringEchoResponse { val commandId: UInt = 24u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_PAYLOAD_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_PAYLOAD_REQ), payload) + tlvWriter.put(ContextSpecificTag(TAG_PAYLOAD_REQ), payload) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -2400,31 +2645,37 @@ class UnitTestingCluster(private val controller: MatterController, private val e tlvReader.enterStructure(AnonymousTag) val TAG_PAYLOAD: Int = 0 var payload_decoded: ByteArray? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_PAYLOAD)) { - payload_decoded = tlvReader.getByteArray(tag) - } else { + + if (tag == ContextSpecificTag(TAG_PAYLOAD)) {payload_decoded = tlvReader.getByteArray(tag)} + + + else { tlvReader.skipElement() } } + + if (payload_decoded == null) { - throw IllegalStateException("payload not found in TLV") + throw IllegalStateException("payload not found in TLV") } + tlvReader.exitContainer() - return StringEchoResponse(payload_decoded) + return StringEchoResponse( + payload_decoded + ) } - suspend fun globalEchoRequest( - field1: UnitTestingClusterTestGlobalStruct, - field2: UByte, - timedInvokeTimeout: Duration? = null, - ): GlobalEchoResponse { + suspend fun globalEchoRequest(field1: UnitTestingClusterTestGlobalStruct + ,field2: UByte + ,timedInvokeTimeout: Duration? = null): GlobalEchoResponse { val commandId: UInt = 25u val tlvWriter = TlvWriter() @@ -2434,14 +2685,14 @@ class UnitTestingCluster(private val controller: MatterController, private val e field1.toTlv(ContextSpecificTag(TAG_FIELD1_REQ), tlvWriter) val TAG_FIELD2_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_FIELD2_REQ), field2) + tlvWriter.put(ContextSpecificTag(TAG_FIELD2_REQ), field2) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -2451,55 +2702,61 @@ class UnitTestingCluster(private val controller: MatterController, private val e tlvReader.enterStructure(AnonymousTag) val TAG_FIELD1: Int = 0 var field1_decoded: UnitTestingClusterTestGlobalStruct? = null - + val TAG_FIELD2: Int = 1 var field2_decoded: UByte? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_FIELD1)) { - field1_decoded = UnitTestingClusterTestGlobalStruct.fromTlv(tag, tlvReader) - } + + if (tag == ContextSpecificTag(TAG_FIELD1)) {field1_decoded = UnitTestingClusterTestGlobalStruct.fromTlv(tag, tlvReader)} + + if (tag == ContextSpecificTag(TAG_FIELD2)) {field2_decoded = tlvReader.getUByte(tag)} + - if (tag == ContextSpecificTag(TAG_FIELD2)) { - field2_decoded = tlvReader.getUByte(tag) - } else { + else { tlvReader.skipElement() } } + + if (field1_decoded == null) { - throw IllegalStateException("field1 not found in TLV") + throw IllegalStateException("field1 not found in TLV") } - + + if (field2_decoded == null) { - throw IllegalStateException("field2 not found in TLV") + throw IllegalStateException("field2 not found in TLV") } + tlvReader.exitContainer() - return GlobalEchoResponse(field1_decoded, field2_decoded) + return GlobalEchoResponse( + field1_decoded, + field2_decoded + ) } - suspend fun testDifferentVendorMeiRequest( - arg1: UByte, - timedInvokeTimeout: Duration? = null, - ): TestDifferentVendorMeiResponse { + suspend fun testDifferentVendorMeiRequest(arg1: UByte + ,timedInvokeTimeout: Duration? = null): TestDifferentVendorMeiResponse { val commandId: UInt = 4294049962u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_ARG1_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_ARG1_REQ), arg1) + tlvWriter.put(ContextSpecificTag(TAG_ARG1_REQ), arg1) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -2509,85 +2766,104 @@ class UnitTestingCluster(private val controller: MatterController, private val e tlvReader.enterStructure(AnonymousTag) val TAG_ARG1: Int = 0 var arg1_decoded: UByte? = null - + val TAG_EVENT_NUMBER: Int = 1 var eventNumber_decoded: ULong? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_ARG1)) { - arg1_decoded = tlvReader.getUByte(tag) - } + + if (tag == ContextSpecificTag(TAG_ARG1)) {arg1_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_EVENT_NUMBER)) {eventNumber_decoded = tlvReader.getULong(tag)} + - if (tag == ContextSpecificTag(TAG_EVENT_NUMBER)) { - eventNumber_decoded = tlvReader.getULong(tag) - } else { + else { tlvReader.skipElement() } } + + if (arg1_decoded == null) { - throw IllegalStateException("arg1 not found in TLV") + throw IllegalStateException("arg1 not found in TLV") } - + + if (eventNumber_decoded == null) { - throw IllegalStateException("eventNumber not found in TLV") + throw IllegalStateException("eventNumber not found in TLV") } + tlvReader.exitContainer() - return TestDifferentVendorMeiResponse(arg1_decoded, eventNumber_decoded) + return TestDifferentVendorMeiResponse( + arg1_decoded, + eventNumber_decoded + ) } +suspend fun readBooleanAttribute(): Boolean {val ATTRIBUTE_ID: UInt = 0u - suspend fun readBooleanAttribute(): Boolean { - 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 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}") - } + 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) { "Boolean attribute not found in response" } + } + + requireNotNull(attributeData) { + "Boolean attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Boolean = tlvReader.getBoolean(AnonymousTag) + return decodedValue } - suspend fun writeBooleanAttribute(value: Boolean, timedWriteTimeout: Duration? = null) { + suspend fun writeBooleanAttribute( + value: Boolean, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -2608,45 +2884,43 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeBooleanAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Boolean attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Boolean attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -2658,57 +2932,68 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readBitmap8Attribute(): UByte {val ATTRIBUTE_ID: UInt = 1u - suspend fun readBitmap8Attribute(): 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 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}") - } + 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) { "Bitmap8 attribute not found in response" } + } + + requireNotNull(attributeData) { + "Bitmap8 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 writeBitmap8Attribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeBitmap8Attribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 1u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -2729,45 +3014,43 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeBitmap8Attribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Bitmap8 attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Bitmap8 attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -2779,57 +3062,68 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readBitmap16Attribute(): UShort {val ATTRIBUTE_ID: UInt = 2u - suspend fun readBitmap16Attribute(): 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 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}") - } + 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) { "Bitmap16 attribute not found in response" } + } + + requireNotNull(attributeData) { + "Bitmap16 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 writeBitmap16Attribute(value: UShort, timedWriteTimeout: Duration? = null) { + suspend fun writeBitmap16Attribute( + value: UShort, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 2u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -2850,45 +3144,43 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeBitmap16Attribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Bitmap16 attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Bitmap16 attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -2900,57 +3192,68 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readBitmap32Attribute(): UInt {val ATTRIBUTE_ID: UInt = 3u - suspend fun readBitmap32Attribute(): UInt { - 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 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}") - } + 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) { "Bitmap32 attribute not found in response" } + } + + requireNotNull(attributeData) { + "Bitmap32 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 writeBitmap32Attribute(value: UInt, timedWriteTimeout: Duration? = null) { + suspend fun writeBitmap32Attribute( + value: UInt, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 3u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -2971,45 +3274,43 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeBitmap32Attribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Bitmap32 attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Bitmap32 attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -3021,57 +3322,68 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readBitmap64Attribute(): ULong {val ATTRIBUTE_ID: UInt = 4u - suspend fun readBitmap64Attribute(): ULong { - 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 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}") - } + 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) { "Bitmap64 attribute not found in response" } + } + + requireNotNull(attributeData) { + "Bitmap64 attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: ULong = tlvReader.getULong(AnonymousTag) + return decodedValue } - suspend fun writeBitmap64Attribute(value: ULong, timedWriteTimeout: Duration? = null) { + suspend fun writeBitmap64Attribute( + value: ULong, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 4u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -3092,45 +3404,43 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeBitmap64Attribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ULongSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ULongSubscriptionState.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) { "Bitmap64 attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Bitmap64 attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -3142,57 +3452,68 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(ULongSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readInt8uAttribute(): UByte {val ATTRIBUTE_ID: UInt = 5u - suspend fun readInt8uAttribute(): UByte { - 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 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}") - } + 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) { "Int8u attribute not found in response" } + } + + requireNotNull(attributeData) { + "Int8u 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 writeInt8uAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeInt8uAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 5u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -3213,45 +3534,43 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeInt8uAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Int8u attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Int8u attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -3263,57 +3582,68 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readInt16uAttribute(): UShort {val ATTRIBUTE_ID: UInt = 6u - suspend fun readInt16uAttribute(): 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 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}") - } + 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) { "Int16u attribute not found in response" } + } + + requireNotNull(attributeData) { + "Int16u 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 writeInt16uAttribute(value: UShort, timedWriteTimeout: Duration? = null) { + suspend fun writeInt16uAttribute( + value: UShort, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 6u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -3334,45 +3664,43 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeInt16uAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Int16u attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Int16u attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -3384,57 +3712,68 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readInt24uAttribute(): UInt {val ATTRIBUTE_ID: UInt = 7u - suspend fun readInt24uAttribute(): UInt { - 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 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}") - } + 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) { "Int24u attribute not found in response" } + } + + requireNotNull(attributeData) { + "Int24u 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 writeInt24uAttribute(value: UInt, timedWriteTimeout: Duration? = null) { + suspend fun writeInt24uAttribute( + value: UInt, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 7u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -3455,45 +3794,43 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeInt24uAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Int24u attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Int24u attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -3505,57 +3842,68 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readInt32uAttribute(): UInt {val ATTRIBUTE_ID: UInt = 8u - suspend fun readInt32uAttribute(): UInt { - val ATTRIBUTE_ID: UInt = 8u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Int32u attribute not found in response" } + } + + requireNotNull(attributeData) { + "Int32u 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 writeInt32uAttribute(value: UInt, timedWriteTimeout: Duration? = null) { + suspend fun writeInt32uAttribute( + value: UInt, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 8u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -3576,45 +3924,43 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeInt32uAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Int32u attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Int32u attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -3626,57 +3972,68 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readInt40uAttribute(): ULong {val ATTRIBUTE_ID: UInt = 9u - suspend fun readInt40uAttribute(): ULong { - val ATTRIBUTE_ID: UInt = 9u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Int40u attribute not found in response" } + } + + requireNotNull(attributeData) { + "Int40u attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: ULong = tlvReader.getULong(AnonymousTag) + return decodedValue } - suspend fun writeInt40uAttribute(value: ULong, timedWriteTimeout: Duration? = null) { + suspend fun writeInt40uAttribute( + value: ULong, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 9u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -3697,45 +4054,43 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeInt40uAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ULongSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ULongSubscriptionState.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) { "Int40u attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Int40u attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -3747,57 +4102,68 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(ULongSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readInt48uAttribute(): ULong {val ATTRIBUTE_ID: UInt = 10u - suspend fun readInt48uAttribute(): ULong { - val ATTRIBUTE_ID: UInt = 10u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Int48u attribute not found in response" } + } + + requireNotNull(attributeData) { + "Int48u attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: ULong = tlvReader.getULong(AnonymousTag) + return decodedValue } - suspend fun writeInt48uAttribute(value: ULong, timedWriteTimeout: Duration? = null) { + suspend fun writeInt48uAttribute( + value: ULong, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 10u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -3818,45 +4184,43 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeInt48uAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ULongSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ULongSubscriptionState.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) { "Int48u attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Int48u attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -3867,58 +4231,69 @@ class UnitTestingCluster(private val controller: MatterController, private val e SubscriptionState.SubscriptionEstablished -> { emit(ULongSubscriptionState.SubscriptionEstablished) } - } - } - } - - suspend fun readInt56uAttribute(): ULong { - val ATTRIBUTE_ID: UInt = 11u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + } + } + } +suspend fun readInt56uAttribute(): ULong {val ATTRIBUTE_ID: UInt = 11u - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Int56u attribute not found in response" } + } + + requireNotNull(attributeData) { + "Int56u attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: ULong = tlvReader.getULong(AnonymousTag) + return decodedValue } - suspend fun writeInt56uAttribute(value: ULong, timedWriteTimeout: Duration? = null) { + suspend fun writeInt56uAttribute( + value: ULong, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 11u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -3939,45 +4314,43 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeInt56uAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 11u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ULongSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ULongSubscriptionState.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) { "Int56u attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Int56u attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -3989,57 +4362,68 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(ULongSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readInt64uAttribute(): ULong {val ATTRIBUTE_ID: UInt = 12u - suspend fun readInt64uAttribute(): ULong { - val ATTRIBUTE_ID: UInt = 12u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Int64u attribute not found in response" } + } + + requireNotNull(attributeData) { + "Int64u attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: ULong = tlvReader.getULong(AnonymousTag) + return decodedValue } - suspend fun writeInt64uAttribute(value: ULong, timedWriteTimeout: Duration? = null) { + suspend fun writeInt64uAttribute( + value: ULong, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 12u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -4060,45 +4444,43 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeInt64uAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 12u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ULongSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ULongSubscriptionState.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) { "Int64u attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Int64u attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -4110,57 +4492,68 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(ULongSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readInt8sAttribute(): Byte {val ATTRIBUTE_ID: UInt = 13u - suspend fun readInt8sAttribute(): Byte { - val ATTRIBUTE_ID: UInt = 13u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Int8s attribute not found in response" } + } + + requireNotNull(attributeData) { + "Int8s attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Byte = tlvReader.getByte(AnonymousTag) + return decodedValue } - suspend fun writeInt8sAttribute(value: Byte, timedWriteTimeout: Duration? = null) { + suspend fun writeInt8sAttribute( + value: Byte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 13u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -4181,45 +4574,43 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeInt8sAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 13u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ByteSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ByteSubscriptionState.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) { "Int8s attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Int8s attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -4231,57 +4622,68 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(ByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readInt16sAttribute(): Short {val ATTRIBUTE_ID: UInt = 14u - suspend fun readInt16sAttribute(): Short { - val ATTRIBUTE_ID: UInt = 14u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Int16s attribute not found in response" } + } + + requireNotNull(attributeData) { + "Int16s attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Short = tlvReader.getShort(AnonymousTag) + return decodedValue } - suspend fun writeInt16sAttribute(value: Short, timedWriteTimeout: Duration? = null) { + suspend fun writeInt16sAttribute( + value: Short, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 14u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -4302,45 +4704,43 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeInt16sAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 14u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { "Int16s attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Int16s attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -4352,57 +4752,68 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readInt24sAttribute(): Int {val ATTRIBUTE_ID: UInt = 15u - suspend fun readInt24sAttribute(): Int { - val ATTRIBUTE_ID: UInt = 15u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Int24s attribute not found in response" } + } + + requireNotNull(attributeData) { + "Int24s attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Int = tlvReader.getInt(AnonymousTag) + return decodedValue } - suspend fun writeInt24sAttribute(value: Int, timedWriteTimeout: Duration? = null) { + suspend fun writeInt24sAttribute( + value: Int, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 15u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -4423,45 +4834,43 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeInt24sAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 15u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - IntSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(IntSubscriptionState.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) { "Int24s attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Int24s attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -4473,57 +4882,68 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(IntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readInt32sAttribute(): Int {val ATTRIBUTE_ID: UInt = 16u - suspend fun readInt32sAttribute(): Int { - val ATTRIBUTE_ID: UInt = 16u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Int32s attribute not found in response" } + } + + requireNotNull(attributeData) { + "Int32s attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Int = tlvReader.getInt(AnonymousTag) + return decodedValue } - suspend fun writeInt32sAttribute(value: Int, timedWriteTimeout: Duration? = null) { + suspend fun writeInt32sAttribute( + value: Int, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -4544,45 +4964,43 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeInt32sAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - IntSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(IntSubscriptionState.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) { "Int32s attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Int32s attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -4594,57 +5012,68 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(IntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readInt40sAttribute(): Long {val ATTRIBUTE_ID: UInt = 17u - suspend fun readInt40sAttribute(): Long { - val ATTRIBUTE_ID: UInt = 17u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Int40s attribute not found in response" } + } + + requireNotNull(attributeData) { + "Int40s attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Long = tlvReader.getLong(AnonymousTag) + return decodedValue } - suspend fun writeInt40sAttribute(value: Long, timedWriteTimeout: Duration? = null) { + suspend fun writeInt40sAttribute( + value: Long, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 17u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -4665,45 +5094,43 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeInt40sAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 17u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - LongSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(LongSubscriptionState.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) { "Int40s attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Int40s attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -4715,57 +5142,68 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(LongSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readInt48sAttribute(): Long {val ATTRIBUTE_ID: UInt = 18u - suspend fun readInt48sAttribute(): Long { - val ATTRIBUTE_ID: UInt = 18u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Int48s attribute not found in response" } + } + + requireNotNull(attributeData) { + "Int48s attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Long = tlvReader.getLong(AnonymousTag) + return decodedValue } - suspend fun writeInt48sAttribute(value: Long, timedWriteTimeout: Duration? = null) { + suspend fun writeInt48sAttribute( + value: Long, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 18u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -4786,45 +5224,43 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeInt48sAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 18u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - LongSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(LongSubscriptionState.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) { "Int48s attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Int48s attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -4836,57 +5272,68 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(LongSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readInt56sAttribute(): Long {val ATTRIBUTE_ID: UInt = 19u - suspend fun readInt56sAttribute(): Long { - val ATTRIBUTE_ID: UInt = 19u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Int56s attribute not found in response" } + } + + requireNotNull(attributeData) { + "Int56s attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Long = tlvReader.getLong(AnonymousTag) + return decodedValue } - suspend fun writeInt56sAttribute(value: Long, timedWriteTimeout: Duration? = null) { + suspend fun writeInt56sAttribute( + value: Long, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 19u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -4907,45 +5354,43 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeInt56sAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 19u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - LongSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(LongSubscriptionState.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) { "Int56s attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Int56s attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -4957,57 +5402,68 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(LongSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readInt64sAttribute(): Long {val ATTRIBUTE_ID: UInt = 20u - suspend fun readInt64sAttribute(): Long { - val ATTRIBUTE_ID: UInt = 20u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Int64s attribute not found in response" } + } + + requireNotNull(attributeData) { + "Int64s attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Long = tlvReader.getLong(AnonymousTag) + return decodedValue } - suspend fun writeInt64sAttribute(value: Long, timedWriteTimeout: Duration? = null) { + suspend fun writeInt64sAttribute( + value: Long, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 20u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -5028,45 +5484,43 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeInt64sAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 20u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - LongSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(LongSubscriptionState.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) { "Int64s attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Int64s attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -5078,57 +5532,68 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(LongSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readEnum8Attribute(): UByte {val ATTRIBUTE_ID: UInt = 21u - suspend fun readEnum8Attribute(): UByte { - val ATTRIBUTE_ID: UInt = 21u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Enum8 attribute not found in response" } + } + + requireNotNull(attributeData) { + "Enum8 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 writeEnum8Attribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeEnum8Attribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 21u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -5149,45 +5614,43 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeEnum8Attribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 21u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Enum8 attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Enum8 attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -5199,57 +5662,68 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readEnum16Attribute(): UShort {val ATTRIBUTE_ID: UInt = 22u - suspend fun readEnum16Attribute(): UShort { - val ATTRIBUTE_ID: UInt = 22u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Enum16 attribute not found in response" } + } + + requireNotNull(attributeData) { + "Enum16 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 writeEnum16Attribute(value: UShort, timedWriteTimeout: Duration? = null) { + suspend fun writeEnum16Attribute( + value: UShort, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 22u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -5270,45 +5744,43 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeEnum16Attribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 22u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Enum16 attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Enum16 attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -5320,57 +5792,68 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readFloatSingleAttribute(): Float {val ATTRIBUTE_ID: UInt = 23u - suspend fun readFloatSingleAttribute(): Float { - val ATTRIBUTE_ID: UInt = 23u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Floatsingle attribute not found in response" } + } + + requireNotNull(attributeData) { + "Floatsingle attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Float = tlvReader.getFloat(AnonymousTag) + return decodedValue } - suspend fun writeFloatSingleAttribute(value: Float, timedWriteTimeout: Duration? = null) { + suspend fun writeFloatSingleAttribute( + value: Float, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 23u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -5391,45 +5874,43 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeFloatSingleAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 23u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - FloatSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(FloatSubscriptionState.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) { "Floatsingle attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Floatsingle attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -5441,57 +5922,68 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(FloatSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readFloatDoubleAttribute(): Double {val ATTRIBUTE_ID: UInt = 24u - suspend fun readFloatDoubleAttribute(): Double { - val ATTRIBUTE_ID: UInt = 24u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Floatdouble attribute not found in response" } + } + + requireNotNull(attributeData) { + "Floatdouble attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Double = tlvReader.getDouble(AnonymousTag) + return decodedValue } - suspend fun writeFloatDoubleAttribute(value: Double, timedWriteTimeout: Duration? = null) { + suspend fun writeFloatDoubleAttribute( + value: Double, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 24u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -5512,45 +6004,43 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeFloatDoubleAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 24u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - DoubleSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(DoubleSubscriptionState.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) { "Floatdouble attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Floatdouble attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -5562,57 +6052,68 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(DoubleSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readOctetStringAttribute(): ByteArray {val ATTRIBUTE_ID: UInt = 25u - suspend fun readOctetStringAttribute(): ByteArray { - val ATTRIBUTE_ID: UInt = 25u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Octetstring attribute not found in response" } + } + + requireNotNull(attributeData) { + "Octetstring attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: ByteArray = tlvReader.getByteArray(AnonymousTag) + return decodedValue } - suspend fun writeOctetStringAttribute(value: ByteArray, timedWriteTimeout: Duration? = null) { + suspend fun writeOctetStringAttribute( + value: ByteArray, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 25u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -5633,45 +6134,43 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeOctetStringAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 25u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ByteArraySubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ByteArraySubscriptionState.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) { "Octetstring attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Octetstring attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -5683,68 +6182,78 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(ByteArraySubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readListInt8uAttribute(): ListInt8uAttribute {val ATTRIBUTE_ID: UInt = 26u - suspend fun readListInt8uAttribute(): ListInt8uAttribute { - val ATTRIBUTE_ID: UInt = 26u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Listint8u attribute not found in response" } + } + + requireNotNull(attributeData) { + "Listint8u 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.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) } + tlvReader.exitContainer() + } + return ListInt8uAttribute(decodedValue) } - suspend fun writeListInt8uAttribute(value: List, timedWriteTimeout: Duration? = null) { + suspend fun writeListInt8uAttribute( + value: List, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 26u val tlvWriter = TlvWriter() tlvWriter.startArray(AnonymousTag) - for (item in value.iterator()) { - tlvWriter.put(AnonymousTag, item) - } - tlvWriter.endArray() + for (item in value.iterator()) { + tlvWriter.put(AnonymousTag, item) + } + tlvWriter.endArray() val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -5765,56 +6274,53 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeListInt8uAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 26u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ListInt8uAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ListInt8uAttributeSubscriptionState.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) { "Listint8u attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Listint8u 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.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(ListInt8uAttributeSubscriptionState.Success(decodedValue)) } @@ -5822,71 +6328,78 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(ListInt8uAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readListOctetStringAttribute(): ListOctetStringAttribute {val ATTRIBUTE_ID: UInt = 27u - suspend fun readListOctetStringAttribute(): ListOctetStringAttribute { - val ATTRIBUTE_ID: UInt = 27u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Listoctetstring attribute not found in response" } + } + + requireNotNull(attributeData) { + "Listoctetstring 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.getByteArray(AnonymousTag)) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getByteArray(AnonymousTag)) } + tlvReader.exitContainer() + } + return ListOctetStringAttribute(decodedValue) } suspend fun writeListOctetStringAttribute( value: List, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 27u val tlvWriter = TlvWriter() tlvWriter.startArray(AnonymousTag) - for (item in value.iterator()) { - tlvWriter.put(AnonymousTag, item) - } - tlvWriter.endArray() + for (item in value.iterator()) { + tlvWriter.put(AnonymousTag, item) + } + tlvWriter.endArray() val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -5907,58 +6420,53 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeListOctetStringAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 27u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ListOctetStringAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ListOctetStringAttributeSubscriptionState.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) { - "Listoctetstring attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Listoctetstring 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.getByteArray(AnonymousTag)) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getByteArray(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(ListOctetStringAttributeSubscriptionState.Success(decodedValue)) } @@ -5966,71 +6474,78 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(ListOctetStringAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readListStructOctetStringAttribute(): ListStructOctetStringAttribute {val ATTRIBUTE_ID: UInt = 28u - suspend fun readListStructOctetStringAttribute(): ListStructOctetStringAttribute { - val ATTRIBUTE_ID: UInt = 28u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Liststructoctetstring attribute not found in response" } + } + + requireNotNull(attributeData) { + "Liststructoctetstring 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(UnitTestingClusterTestListStructOctet.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(UnitTestingClusterTestListStructOctet.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + return ListStructOctetStringAttribute(decodedValue) } suspend fun writeListStructOctetStringAttribute( value: List, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 28u val tlvWriter = TlvWriter() tlvWriter.startArray(AnonymousTag) - for (item in value.iterator()) { - item.toTlv(AnonymousTag, tlvWriter) - } - tlvWriter.endArray() + for (item in value.iterator()) { + item.toTlv(AnonymousTag, tlvWriter) + } + tlvWriter.endArray() val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -6051,58 +6566,53 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeListStructOctetStringAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 28u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ListStructOctetStringAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ListStructOctetStringAttributeSubscriptionState.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) { - "Liststructoctetstring attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Liststructoctetstring 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(UnitTestingClusterTestListStructOctet.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(UnitTestingClusterTestListStructOctet.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(ListStructOctetStringAttributeSubscriptionState.Success(decodedValue)) } @@ -6110,57 +6620,68 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(ListStructOctetStringAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readLongOctetStringAttribute(): ByteArray {val ATTRIBUTE_ID: UInt = 29u - suspend fun readLongOctetStringAttribute(): ByteArray { - val ATTRIBUTE_ID: UInt = 29u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Longoctetstring attribute not found in response" } + } + + requireNotNull(attributeData) { + "Longoctetstring attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: ByteArray = tlvReader.getByteArray(AnonymousTag) + return decodedValue } - suspend fun writeLongOctetStringAttribute(value: ByteArray, timedWriteTimeout: Duration? = null) { + suspend fun writeLongOctetStringAttribute( + value: ByteArray, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 29u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -6181,46 +6702,42 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeLongOctetStringAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 29u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ByteArraySubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ByteArraySubscriptionState.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) { - "Longoctetstring attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Longoctetstring attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -6233,57 +6750,68 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(ByteArraySubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readCharStringAttribute(): String {val ATTRIBUTE_ID: UInt = 30u - suspend fun readCharStringAttribute(): String { - val ATTRIBUTE_ID: UInt = 30u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Charstring attribute not found in response" } + } + + requireNotNull(attributeData) { + "Charstring attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: String = tlvReader.getString(AnonymousTag) + return decodedValue } - suspend fun writeCharStringAttribute(value: String, timedWriteTimeout: Duration? = null) { + suspend fun writeCharStringAttribute( + value: String, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 30u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -6304,45 +6832,43 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeCharStringAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 30u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StringSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StringSubscriptionState.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) { "Charstring attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Charstring attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -6354,57 +6880,68 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readLongCharStringAttribute(): String {val ATTRIBUTE_ID: UInt = 31u - suspend fun readLongCharStringAttribute(): String { - val ATTRIBUTE_ID: UInt = 31u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Longcharstring attribute not found in response" } + } + + requireNotNull(attributeData) { + "Longcharstring attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: String = tlvReader.getString(AnonymousTag) + return decodedValue } - suspend fun writeLongCharStringAttribute(value: String, timedWriteTimeout: Duration? = null) { + suspend fun writeLongCharStringAttribute( + value: String, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 31u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -6425,46 +6962,42 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeLongCharStringAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 31u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StringSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StringSubscriptionState.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) { - "Longcharstring attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Longcharstring attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -6477,57 +7010,68 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readEpochUsAttribute(): ULong {val ATTRIBUTE_ID: UInt = 32u - suspend fun readEpochUsAttribute(): ULong { - val ATTRIBUTE_ID: UInt = 32u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Epochus attribute not found in response" } + } + + requireNotNull(attributeData) { + "Epochus attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: ULong = tlvReader.getULong(AnonymousTag) + return decodedValue } - suspend fun writeEpochUsAttribute(value: ULong, timedWriteTimeout: Duration? = null) { + suspend fun writeEpochUsAttribute( + value: ULong, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 32u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -6548,45 +7092,43 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeEpochUsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 32u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ULongSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ULongSubscriptionState.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) { "Epochus attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Epochus attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -6598,57 +7140,68 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(ULongSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readEpochSAttribute(): UInt {val ATTRIBUTE_ID: UInt = 33u - suspend fun readEpochSAttribute(): UInt { - val ATTRIBUTE_ID: UInt = 33u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Epochs attribute not found in response" } + } + + requireNotNull(attributeData) { + "Epochs 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 writeEpochSAttribute(value: UInt, timedWriteTimeout: Duration? = null) { + suspend fun writeEpochSAttribute( + value: UInt, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 33u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -6669,45 +7222,43 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeEpochSAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 33u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Epochs attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Epochs attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -6719,57 +7270,68 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readVendorIdAttribute(): UShort {val ATTRIBUTE_ID: UInt = 34u - suspend fun readVendorIdAttribute(): UShort { - val ATTRIBUTE_ID: UInt = 34u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Vendorid attribute not found in response" } + } + + requireNotNull(attributeData) { + "Vendorid 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 writeVendorIdAttribute(value: UShort, timedWriteTimeout: Duration? = null) { + suspend fun writeVendorIdAttribute( + value: UShort, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 34u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -6790,45 +7352,43 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeVendorIdAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 34u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Vendorid attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Vendorid attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -6840,74 +7400,78 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readListNullablesAndOptionalsStructAttribute(): ListNullablesAndOptionalsStructAttribute {val ATTRIBUTE_ID: UInt = 35u - suspend fun readListNullablesAndOptionalsStructAttribute(): - ListNullablesAndOptionalsStructAttribute { - val ATTRIBUTE_ID: UInt = 35u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { - "Listnullablesandoptionalsstruct attribute not found in response" + } + + requireNotNull(attributeData) { + "Listnullablesandoptionalsstruct 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(UnitTestingClusterNullablesAndOptionalsStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(UnitTestingClusterNullablesAndOptionalsStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + return ListNullablesAndOptionalsStructAttribute(decodedValue) } suspend fun writeListNullablesAndOptionalsStructAttribute( value: List, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 35u val tlvWriter = TlvWriter() tlvWriter.startArray(AnonymousTag) - for (item in value.iterator()) { - item.toTlv(AnonymousTag, tlvWriter) - } - tlvWriter.endArray() + for (item in value.iterator()) { + item.toTlv(AnonymousTag, tlvWriter) + } + tlvWriter.endArray() val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -6928,58 +7492,53 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeListNullablesAndOptionalsStructAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 35u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ListNullablesAndOptionalsStructAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ListNullablesAndOptionalsStructAttributeSubscriptionState.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) { - "Listnullablesandoptionalsstruct attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Listnullablesandoptionalsstruct 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(UnitTestingClusterNullablesAndOptionalsStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(UnitTestingClusterNullablesAndOptionalsStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(ListNullablesAndOptionalsStructAttributeSubscriptionState.Success(decodedValue)) } @@ -6987,57 +7546,68 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(ListNullablesAndOptionalsStructAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readEnumAttrAttribute(): UByte {val ATTRIBUTE_ID: UInt = 36u - suspend fun readEnumAttrAttribute(): UByte { - val ATTRIBUTE_ID: UInt = 36u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Enumattr attribute not found in response" } + } + + requireNotNull(attributeData) { + "Enumattr 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 writeEnumAttrAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeEnumAttrAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 36u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -7058,45 +7628,43 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeEnumAttrAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 36u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Enumattr attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Enumattr attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -7108,61 +7676,68 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readStructAttrAttribute(): StructAttrAttribute {val ATTRIBUTE_ID: UInt = 37u - suspend fun readStructAttrAttribute(): StructAttrAttribute { - val ATTRIBUTE_ID: UInt = 37u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Structattr attribute not found in response" } + } + + requireNotNull(attributeData) { + "Structattr attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UnitTestingClusterSimpleStruct = - UnitTestingClusterSimpleStruct.fromTlv(AnonymousTag, tlvReader) + val decodedValue: UnitTestingClusterSimpleStruct = UnitTestingClusterSimpleStruct.fromTlv(AnonymousTag, tlvReader) + return StructAttrAttribute(decodedValue) } suspend fun writeStructAttrAttribute( value: UnitTestingClusterSimpleStruct, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 37u val tlvWriter = TlvWriter() - value.toTlv(AnonymousTag, tlvWriter) + value.toTlv(AnonymousTag, tlvWriter) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -7183,50 +7758,47 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeStructAttrAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 37u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StructAttrAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StructAttrAttributeSubscriptionState.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) { "Structattr attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Structattr attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UnitTestingClusterSimpleStruct = - UnitTestingClusterSimpleStruct.fromTlv(AnonymousTag, tlvReader) + val decodedValue: UnitTestingClusterSimpleStruct = UnitTestingClusterSimpleStruct.fromTlv(AnonymousTag, tlvReader) emit(StructAttrAttributeSubscriptionState.Success(decodedValue)) } @@ -7234,60 +7806,68 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(StructAttrAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRangeRestrictedInt8uAttribute(): UByte {val ATTRIBUTE_ID: UInt = 38u - suspend fun readRangeRestrictedInt8uAttribute(): UByte { - val ATTRIBUTE_ID: UInt = 38u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rangerestrictedint8u attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rangerestrictedint8u 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 writeRangeRestrictedInt8uAttribute( value: UByte, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 38u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -7308,46 +7888,42 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeRangeRestrictedInt8uAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 38u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Rangerestrictedint8u attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rangerestrictedint8u attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -7360,57 +7936,68 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRangeRestrictedInt8sAttribute(): Byte {val ATTRIBUTE_ID: UInt = 39u - suspend fun readRangeRestrictedInt8sAttribute(): Byte { - val ATTRIBUTE_ID: UInt = 39u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rangerestrictedint8s attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rangerestrictedint8s attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Byte = tlvReader.getByte(AnonymousTag) + return decodedValue } - suspend fun writeRangeRestrictedInt8sAttribute(value: Byte, timedWriteTimeout: Duration? = null) { + suspend fun writeRangeRestrictedInt8sAttribute( + value: Byte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 39u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -7431,46 +8018,42 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeRangeRestrictedInt8sAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 39u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ByteSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ByteSubscriptionState.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) { - "Rangerestrictedint8s attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rangerestrictedint8s attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -7483,60 +8066,68 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(ByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRangeRestrictedInt16uAttribute(): UShort {val ATTRIBUTE_ID: UInt = 40u - suspend fun readRangeRestrictedInt16uAttribute(): UShort { - val ATTRIBUTE_ID: UInt = 40u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rangerestrictedint16u attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rangerestrictedint16u 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 writeRangeRestrictedInt16uAttribute( value: UShort, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 40u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -7557,46 +8148,42 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeRangeRestrictedInt16uAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 40u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Rangerestrictedint16u attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rangerestrictedint16u attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -7609,60 +8196,68 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readRangeRestrictedInt16sAttribute(): Short {val ATTRIBUTE_ID: UInt = 41u - suspend fun readRangeRestrictedInt16sAttribute(): Short { - val ATTRIBUTE_ID: UInt = 41u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Rangerestrictedint16s attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rangerestrictedint16s attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Short = tlvReader.getShort(AnonymousTag) + return decodedValue } suspend fun writeRangeRestrictedInt16sAttribute( value: Short, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 41u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -7683,46 +8278,42 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeRangeRestrictedInt16sAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 41u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ShortSubscriptionState.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) { - "Rangerestrictedint16s attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rangerestrictedint16s attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -7735,71 +8326,78 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readListLongOctetStringAttribute(): ListLongOctetStringAttribute {val ATTRIBUTE_ID: UInt = 42u - suspend fun readListLongOctetStringAttribute(): ListLongOctetStringAttribute { - val ATTRIBUTE_ID: UInt = 42u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Listlongoctetstring attribute not found in response" } + } + + requireNotNull(attributeData) { + "Listlongoctetstring 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.getByteArray(AnonymousTag)) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getByteArray(AnonymousTag)) } + tlvReader.exitContainer() + } + return ListLongOctetStringAttribute(decodedValue) } suspend fun writeListLongOctetStringAttribute( value: List, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 42u val tlvWriter = TlvWriter() tlvWriter.startArray(AnonymousTag) - for (item in value.iterator()) { - tlvWriter.put(AnonymousTag, item) - } - tlvWriter.endArray() + for (item in value.iterator()) { + tlvWriter.put(AnonymousTag, item) + } + tlvWriter.endArray() val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -7820,58 +8418,53 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeListLongOctetStringAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 42u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ListLongOctetStringAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ListLongOctetStringAttributeSubscriptionState.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) { - "Listlongoctetstring attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Listlongoctetstring 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.getByteArray(AnonymousTag)) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getByteArray(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(ListLongOctetStringAttributeSubscriptionState.Success(decodedValue)) } @@ -7879,71 +8472,78 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(ListLongOctetStringAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readListFabricScopedAttribute(): ListFabricScopedAttribute {val ATTRIBUTE_ID: UInt = 43u - suspend fun readListFabricScopedAttribute(): ListFabricScopedAttribute { - val ATTRIBUTE_ID: UInt = 43u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Listfabricscoped attribute not found in response" } + } + + requireNotNull(attributeData) { + "Listfabricscoped 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(UnitTestingClusterTestFabricScoped.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(UnitTestingClusterTestFabricScoped.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + return ListFabricScopedAttribute(decodedValue) } suspend fun writeListFabricScopedAttribute( value: List, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 43u val tlvWriter = TlvWriter() tlvWriter.startArray(AnonymousTag) - for (item in value.iterator()) { - item.toTlv(AnonymousTag, tlvWriter) - } - tlvWriter.endArray() + for (item in value.iterator()) { + item.toTlv(AnonymousTag, tlvWriter) + } + tlvWriter.endArray() val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -7964,58 +8564,53 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeListFabricScopedAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 43u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ListFabricScopedAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ListFabricScopedAttributeSubscriptionState.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) { - "Listfabricscoped attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Listfabricscoped 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(UnitTestingClusterTestFabricScoped.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(UnitTestingClusterTestFabricScoped.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(ListFabricScopedAttributeSubscriptionState.Success(decodedValue)) } @@ -8023,57 +8618,68 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(ListFabricScopedAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readTimedWriteBooleanAttribute(): Boolean {val ATTRIBUTE_ID: UInt = 48u - suspend fun readTimedWriteBooleanAttribute(): Boolean { - val ATTRIBUTE_ID: UInt = 48u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Timedwriteboolean attribute not found in response" } + } + + requireNotNull(attributeData) { + "Timedwriteboolean attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Boolean = tlvReader.getBoolean(AnonymousTag) + return decodedValue } - suspend fun writeTimedWriteBooleanAttribute(value: Boolean, timedWriteTimeout: Duration) { + suspend fun writeTimedWriteBooleanAttribute( + value: Boolean, + timedWriteTimeout: Duration) { val ATTRIBUTE_ID: UInt = 48u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -8094,46 +8700,42 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeTimedWriteBooleanAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 48u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Timedwriteboolean attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Timedwriteboolean attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -8146,60 +8748,68 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readGeneralErrorBooleanAttribute(): Boolean {val ATTRIBUTE_ID: UInt = 49u - suspend fun readGeneralErrorBooleanAttribute(): Boolean { - val ATTRIBUTE_ID: UInt = 49u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Generalerrorboolean attribute not found in response" } + } + + requireNotNull(attributeData) { + "Generalerrorboolean attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Boolean = tlvReader.getBoolean(AnonymousTag) + return decodedValue } suspend fun writeGeneralErrorBooleanAttribute( value: Boolean, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 49u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -8220,46 +8830,42 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeGeneralErrorBooleanAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 49u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Generalerrorboolean attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Generalerrorboolean attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -8272,60 +8878,68 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readClusterErrorBooleanAttribute(): Boolean {val ATTRIBUTE_ID: UInt = 50u - suspend fun readClusterErrorBooleanAttribute(): Boolean { - val ATTRIBUTE_ID: UInt = 50u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Clustererrorboolean attribute not found in response" } + } + + requireNotNull(attributeData) { + "Clustererrorboolean attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Boolean = tlvReader.getBoolean(AnonymousTag) + return decodedValue } suspend fun writeClusterErrorBooleanAttribute( value: Boolean, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 50u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -8346,46 +8960,42 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeClusterErrorBooleanAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 50u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Clustererrorboolean attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Clustererrorboolean attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -8398,57 +9008,68 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readGlobalEnumAttribute(): UByte {val ATTRIBUTE_ID: UInt = 51u - suspend fun readGlobalEnumAttribute(): UByte { - val ATTRIBUTE_ID: UInt = 51u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Globalenum attribute not found in response" } + } + + requireNotNull(attributeData) { + "Globalenum 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 writeGlobalEnumAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeGlobalEnumAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 51u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -8469,45 +9090,43 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeGlobalEnumAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 51u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Globalenum attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Globalenum attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -8519,61 +9138,68 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readGlobalStructAttribute(): GlobalStructAttribute {val ATTRIBUTE_ID: UInt = 52u - suspend fun readGlobalStructAttribute(): GlobalStructAttribute { - val ATTRIBUTE_ID: UInt = 52u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Globalstruct attribute not found in response" } + } + + requireNotNull(attributeData) { + "Globalstruct attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UnitTestingClusterTestGlobalStruct = - UnitTestingClusterTestGlobalStruct.fromTlv(AnonymousTag, tlvReader) + val decodedValue: UnitTestingClusterTestGlobalStruct = UnitTestingClusterTestGlobalStruct.fromTlv(AnonymousTag, tlvReader) + return GlobalStructAttribute(decodedValue) } suspend fun writeGlobalStructAttribute( value: UnitTestingClusterTestGlobalStruct, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 52u val tlvWriter = TlvWriter() - value.toTlv(AnonymousTag, tlvWriter) + value.toTlv(AnonymousTag, tlvWriter) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -8594,50 +9220,47 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeGlobalStructAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 52u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - GlobalStructAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(GlobalStructAttributeSubscriptionState.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) { "Globalstruct attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Globalstruct attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UnitTestingClusterTestGlobalStruct = - UnitTestingClusterTestGlobalStruct.fromTlv(AnonymousTag, tlvReader) + val decodedValue: UnitTestingClusterTestGlobalStruct = UnitTestingClusterTestGlobalStruct.fromTlv(AnonymousTag, tlvReader) emit(GlobalStructAttributeSubscriptionState.Success(decodedValue)) } @@ -8645,62 +9268,72 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(GlobalStructAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readUnsupportedAttribute(): Boolean? {val ATTRIBUTE_ID: UInt = 255u - suspend fun readUnsupportedAttribute(): Boolean? { - val ATTRIBUTE_ID: UInt = 255u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Unsupported attribute not found in response" } + } + + requireNotNull(attributeData) { + "Unsupported 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 - } + val decodedValue: Boolean? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } + return decodedValue } - suspend fun writeUnsupportedAttribute(value: Boolean, timedWriteTimeout: Duration? = null) { + suspend fun writeUnsupportedAttribute( + value: Boolean, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 255u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -8721,118 +9354,128 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeUnsupportedAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 255u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Unsupported attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Unsupported 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 - } + val decodedValue: Boolean? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(BooleanSubscriptionState.Success(it)) } + decodedValue?.let { + emit(BooleanSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNullableBooleanAttribute(): NullableBooleanAttribute {val ATTRIBUTE_ID: UInt = 16384u - suspend fun readNullableBooleanAttribute(): NullableBooleanAttribute { - val ATTRIBUTE_ID: UInt = 16384u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Nullableboolean attribute not found in response" } + } + + requireNotNull(attributeData) { + "Nullableboolean attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Boolean? = - if (!tlvReader.isNull()) { - tlvReader.getBoolean(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Boolean? = if (!tlvReader.isNull()) { + tlvReader.getBoolean(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return NullableBooleanAttribute(decodedValue) } - suspend fun writeNullableBooleanAttribute(value: Boolean, timedWriteTimeout: Duration? = null) { + suspend fun writeNullableBooleanAttribute( + value: Boolean, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16384u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -8853,121 +9496,129 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableBooleanAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16384u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - NullableBooleanAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(NullableBooleanAttributeSubscriptionState.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) { - "Nullableboolean attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Nullableboolean 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.isNull()) { - tlvReader.getBoolean(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Boolean? = if (!tlvReader.isNull()) { + tlvReader.getBoolean(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(NullableBooleanAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(NullableBooleanAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(NullableBooleanAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNullableBitmap8Attribute(): NullableBitmap8Attribute {val ATTRIBUTE_ID: UInt = 16385u - suspend fun readNullableBitmap8Attribute(): NullableBitmap8Attribute { - val ATTRIBUTE_ID: UInt = 16385u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Nullablebitmap8 attribute not found in response" } + } + + requireNotNull(attributeData) { + "Nullablebitmap8 attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return NullableBitmap8Attribute(decodedValue) } - suspend fun writeNullableBitmap8Attribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeNullableBitmap8Attribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16385u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -8988,121 +9639,129 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableBitmap8Attribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16385u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - NullableBitmap8AttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(NullableBitmap8AttributeSubscriptionState.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) { - "Nullablebitmap8 attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Nullablebitmap8 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.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(NullableBitmap8AttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(NullableBitmap8AttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(NullableBitmap8AttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNullableBitmap16Attribute(): NullableBitmap16Attribute {val ATTRIBUTE_ID: UInt = 16386u - suspend fun readNullableBitmap16Attribute(): NullableBitmap16Attribute { - val ATTRIBUTE_ID: UInt = 16386u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Nullablebitmap16 attribute not found in response" } + } + + requireNotNull(attributeData) { + "Nullablebitmap16 attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = - if (!tlvReader.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return NullableBitmap16Attribute(decodedValue) } - suspend fun writeNullableBitmap16Attribute(value: UShort, timedWriteTimeout: Duration? = null) { + suspend fun writeNullableBitmap16Attribute( + value: UShort, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16386u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -9123,121 +9782,129 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableBitmap16Attribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16386u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - NullableBitmap16AttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(NullableBitmap16AttributeSubscriptionState.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) { - "Nullablebitmap16 attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Nullablebitmap16 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.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(NullableBitmap16AttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(NullableBitmap16AttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(NullableBitmap16AttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNullableBitmap32Attribute(): NullableBitmap32Attribute {val ATTRIBUTE_ID: UInt = 16387u - suspend fun readNullableBitmap32Attribute(): NullableBitmap32Attribute { - val ATTRIBUTE_ID: UInt = 16387u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Nullablebitmap32 attribute not found in response" } + } + + requireNotNull(attributeData) { + "Nullablebitmap32 attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - tlvReader.getUInt(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + tlvReader.getUInt(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return NullableBitmap32Attribute(decodedValue) } - suspend fun writeNullableBitmap32Attribute(value: UInt, timedWriteTimeout: Duration? = null) { + suspend fun writeNullableBitmap32Attribute( + value: UInt, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16387u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -9258,121 +9925,129 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableBitmap32Attribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16387u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - NullableBitmap32AttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(NullableBitmap32AttributeSubscriptionState.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) { - "Nullablebitmap32 attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Nullablebitmap32 attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - tlvReader.getUInt(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + tlvReader.getUInt(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(NullableBitmap32AttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(NullableBitmap32AttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(NullableBitmap32AttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNullableBitmap64Attribute(): NullableBitmap64Attribute {val ATTRIBUTE_ID: UInt = 16388u - suspend fun readNullableBitmap64Attribute(): NullableBitmap64Attribute { - val ATTRIBUTE_ID: UInt = 16388u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Nullablebitmap64 attribute not found in response" } + } + + requireNotNull(attributeData) { + "Nullablebitmap64 attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ULong? = - if (!tlvReader.isNull()) { - tlvReader.getULong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ULong? = if (!tlvReader.isNull()) { + tlvReader.getULong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return NullableBitmap64Attribute(decodedValue) } - suspend fun writeNullableBitmap64Attribute(value: ULong, timedWriteTimeout: Duration? = null) { + suspend fun writeNullableBitmap64Attribute( + value: ULong, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16388u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -9393,121 +10068,129 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableBitmap64Attribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16388u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - NullableBitmap64AttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(NullableBitmap64AttributeSubscriptionState.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) { - "Nullablebitmap64 attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Nullablebitmap64 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()) { - tlvReader.getULong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ULong? = if (!tlvReader.isNull()) { + tlvReader.getULong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(NullableBitmap64AttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(NullableBitmap64AttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(NullableBitmap64AttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNullableInt8uAttribute(): NullableInt8uAttribute {val ATTRIBUTE_ID: UInt = 16389u - suspend fun readNullableInt8uAttribute(): NullableInt8uAttribute { - val ATTRIBUTE_ID: UInt = 16389u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Nullableint8u attribute not found in response" } + } + + requireNotNull(attributeData) { + "Nullableint8u attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return NullableInt8uAttribute(decodedValue) } - suspend fun writeNullableInt8uAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeNullableInt8uAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16389u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -9528,119 +10211,129 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableInt8uAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16389u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - NullableInt8uAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(NullableInt8uAttributeSubscriptionState.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) { "Nullableint8u attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Nullableint8u 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.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(NullableInt8uAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(NullableInt8uAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(NullableInt8uAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNullableInt16uAttribute(): NullableInt16uAttribute {val ATTRIBUTE_ID: UInt = 16390u - suspend fun readNullableInt16uAttribute(): NullableInt16uAttribute { - val ATTRIBUTE_ID: UInt = 16390u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Nullableint16u attribute not found in response" } + } + + requireNotNull(attributeData) { + "Nullableint16u attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = - if (!tlvReader.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return NullableInt16uAttribute(decodedValue) } - suspend fun writeNullableInt16uAttribute(value: UShort, timedWriteTimeout: Duration? = null) { + suspend fun writeNullableInt16uAttribute( + value: UShort, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16390u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -9661,121 +10354,129 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableInt16uAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16390u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - NullableInt16uAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(NullableInt16uAttributeSubscriptionState.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) { - "Nullableint16u attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Nullableint16u 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.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(NullableInt16uAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(NullableInt16uAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(NullableInt16uAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNullableInt24uAttribute(): NullableInt24uAttribute {val ATTRIBUTE_ID: UInt = 16391u - suspend fun readNullableInt24uAttribute(): NullableInt24uAttribute { - val ATTRIBUTE_ID: UInt = 16391u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Nullableint24u attribute not found in response" } + } + + requireNotNull(attributeData) { + "Nullableint24u attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - tlvReader.getUInt(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + tlvReader.getUInt(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return NullableInt24uAttribute(decodedValue) } - suspend fun writeNullableInt24uAttribute(value: UInt, timedWriteTimeout: Duration? = null) { + suspend fun writeNullableInt24uAttribute( + value: UInt, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16391u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -9796,121 +10497,129 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableInt24uAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16391u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - NullableInt24uAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(NullableInt24uAttributeSubscriptionState.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) { - "Nullableint24u attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Nullableint24u attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - tlvReader.getUInt(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + tlvReader.getUInt(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(NullableInt24uAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(NullableInt24uAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(NullableInt24uAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNullableInt32uAttribute(): NullableInt32uAttribute {val ATTRIBUTE_ID: UInt = 16392u - suspend fun readNullableInt32uAttribute(): NullableInt32uAttribute { - val ATTRIBUTE_ID: UInt = 16392u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Nullableint32u attribute not found in response" } + } + + requireNotNull(attributeData) { + "Nullableint32u attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - tlvReader.getUInt(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + tlvReader.getUInt(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return NullableInt32uAttribute(decodedValue) } - suspend fun writeNullableInt32uAttribute(value: UInt, timedWriteTimeout: Duration? = null) { + suspend fun writeNullableInt32uAttribute( + value: UInt, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16392u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -9931,121 +10640,129 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableInt32uAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16392u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - NullableInt32uAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(NullableInt32uAttributeSubscriptionState.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) { - "Nullableint32u attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Nullableint32u attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - tlvReader.getUInt(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + tlvReader.getUInt(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(NullableInt32uAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(NullableInt32uAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(NullableInt32uAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNullableInt40uAttribute(): NullableInt40uAttribute {val ATTRIBUTE_ID: UInt = 16393u - suspend fun readNullableInt40uAttribute(): NullableInt40uAttribute { - val ATTRIBUTE_ID: UInt = 16393u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Nullableint40u attribute not found in response" } + } + + requireNotNull(attributeData) { + "Nullableint40u attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ULong? = - if (!tlvReader.isNull()) { - tlvReader.getULong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ULong? = if (!tlvReader.isNull()) { + tlvReader.getULong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return NullableInt40uAttribute(decodedValue) } - suspend fun writeNullableInt40uAttribute(value: ULong, timedWriteTimeout: Duration? = null) { + suspend fun writeNullableInt40uAttribute( + value: ULong, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16393u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -10066,121 +10783,129 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableInt40uAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16393u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - NullableInt40uAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(NullableInt40uAttributeSubscriptionState.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) { - "Nullableint40u attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Nullableint40u 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()) { - tlvReader.getULong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ULong? = if (!tlvReader.isNull()) { + tlvReader.getULong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(NullableInt40uAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(NullableInt40uAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(NullableInt40uAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNullableInt48uAttribute(): NullableInt48uAttribute {val ATTRIBUTE_ID: UInt = 16394u - suspend fun readNullableInt48uAttribute(): NullableInt48uAttribute { - val ATTRIBUTE_ID: UInt = 16394u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Nullableint48u attribute not found in response" } + } + + requireNotNull(attributeData) { + "Nullableint48u attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ULong? = - if (!tlvReader.isNull()) { - tlvReader.getULong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ULong? = if (!tlvReader.isNull()) { + tlvReader.getULong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return NullableInt48uAttribute(decodedValue) } - suspend fun writeNullableInt48uAttribute(value: ULong, timedWriteTimeout: Duration? = null) { + suspend fun writeNullableInt48uAttribute( + value: ULong, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16394u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -10201,121 +10926,129 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableInt48uAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16394u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - NullableInt48uAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(NullableInt48uAttributeSubscriptionState.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) { - "Nullableint48u attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Nullableint48u 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()) { - tlvReader.getULong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ULong? = if (!tlvReader.isNull()) { + tlvReader.getULong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(NullableInt48uAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(NullableInt48uAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(NullableInt48uAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNullableInt56uAttribute(): NullableInt56uAttribute {val ATTRIBUTE_ID: UInt = 16395u - suspend fun readNullableInt56uAttribute(): NullableInt56uAttribute { - val ATTRIBUTE_ID: UInt = 16395u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Nullableint56u attribute not found in response" } + } + + requireNotNull(attributeData) { + "Nullableint56u attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ULong? = - if (!tlvReader.isNull()) { - tlvReader.getULong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ULong? = if (!tlvReader.isNull()) { + tlvReader.getULong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return NullableInt56uAttribute(decodedValue) } - suspend fun writeNullableInt56uAttribute(value: ULong, timedWriteTimeout: Duration? = null) { + suspend fun writeNullableInt56uAttribute( + value: ULong, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16395u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -10336,121 +11069,129 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableInt56uAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16395u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - NullableInt56uAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(NullableInt56uAttributeSubscriptionState.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) { - "Nullableint56u attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Nullableint56u 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()) { - tlvReader.getULong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ULong? = if (!tlvReader.isNull()) { + tlvReader.getULong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(NullableInt56uAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(NullableInt56uAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(NullableInt56uAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNullableInt64uAttribute(): NullableInt64uAttribute {val ATTRIBUTE_ID: UInt = 16396u - suspend fun readNullableInt64uAttribute(): NullableInt64uAttribute { - val ATTRIBUTE_ID: UInt = 16396u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Nullableint64u attribute not found in response" } + } + + requireNotNull(attributeData) { + "Nullableint64u attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ULong? = - if (!tlvReader.isNull()) { - tlvReader.getULong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ULong? = if (!tlvReader.isNull()) { + tlvReader.getULong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return NullableInt64uAttribute(decodedValue) } - suspend fun writeNullableInt64uAttribute(value: ULong, timedWriteTimeout: Duration? = null) { + suspend fun writeNullableInt64uAttribute( + value: ULong, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16396u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -10471,121 +11212,129 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableInt64uAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16396u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - NullableInt64uAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(NullableInt64uAttributeSubscriptionState.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) { - "Nullableint64u attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Nullableint64u 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()) { - tlvReader.getULong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ULong? = if (!tlvReader.isNull()) { + tlvReader.getULong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(NullableInt64uAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(NullableInt64uAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(NullableInt64uAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNullableInt8sAttribute(): NullableInt8sAttribute {val ATTRIBUTE_ID: UInt = 16397u - suspend fun readNullableInt8sAttribute(): NullableInt8sAttribute { - val ATTRIBUTE_ID: UInt = 16397u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Nullableint8s attribute not found in response" } + } + + requireNotNull(attributeData) { + "Nullableint8s attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Byte? = - if (!tlvReader.isNull()) { - tlvReader.getByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Byte? = if (!tlvReader.isNull()) { + tlvReader.getByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return NullableInt8sAttribute(decodedValue) } - suspend fun writeNullableInt8sAttribute(value: Byte, timedWriteTimeout: Duration? = null) { + suspend fun writeNullableInt8sAttribute( + value: Byte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16397u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -10606,119 +11355,129 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableInt8sAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16397u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - NullableInt8sAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(NullableInt8sAttributeSubscriptionState.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) { "Nullableint8s attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Nullableint8s attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Byte? = - if (!tlvReader.isNull()) { - tlvReader.getByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Byte? = if (!tlvReader.isNull()) { + tlvReader.getByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(NullableInt8sAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(NullableInt8sAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(NullableInt8sAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNullableInt16sAttribute(): NullableInt16sAttribute {val ATTRIBUTE_ID: UInt = 16398u - suspend fun readNullableInt16sAttribute(): NullableInt16sAttribute { - val ATTRIBUTE_ID: UInt = 16398u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Nullableint16s attribute not found in response" } + } + + requireNotNull(attributeData) { + "Nullableint16s attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (!tlvReader.isNull()) { - tlvReader.getShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Short? = if (!tlvReader.isNull()) { + tlvReader.getShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return NullableInt16sAttribute(decodedValue) } - suspend fun writeNullableInt16sAttribute(value: Short, timedWriteTimeout: Duration? = null) { + suspend fun writeNullableInt16sAttribute( + value: Short, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16398u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -10739,121 +11498,129 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableInt16sAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16398u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - NullableInt16sAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(NullableInt16sAttributeSubscriptionState.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) { - "Nullableint16s attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Nullableint16s attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (!tlvReader.isNull()) { - tlvReader.getShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Short? = if (!tlvReader.isNull()) { + tlvReader.getShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(NullableInt16sAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(NullableInt16sAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(NullableInt16sAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNullableInt24sAttribute(): NullableInt24sAttribute {val ATTRIBUTE_ID: UInt = 16399u - suspend fun readNullableInt24sAttribute(): NullableInt24sAttribute { - val ATTRIBUTE_ID: UInt = 16399u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Nullableint24s attribute not found in response" } + } + + requireNotNull(attributeData) { + "Nullableint24s attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Int? = - if (!tlvReader.isNull()) { - tlvReader.getInt(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Int? = if (!tlvReader.isNull()) { + tlvReader.getInt(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return NullableInt24sAttribute(decodedValue) } - suspend fun writeNullableInt24sAttribute(value: Int, timedWriteTimeout: Duration? = null) { + suspend fun writeNullableInt24sAttribute( + value: Int, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16399u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -10874,121 +11641,129 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableInt24sAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16399u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - NullableInt24sAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(NullableInt24sAttributeSubscriptionState.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) { - "Nullableint24s attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Nullableint24s attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Int? = - if (!tlvReader.isNull()) { - tlvReader.getInt(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Int? = if (!tlvReader.isNull()) { + tlvReader.getInt(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(NullableInt24sAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(NullableInt24sAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(NullableInt24sAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNullableInt32sAttribute(): NullableInt32sAttribute {val ATTRIBUTE_ID: UInt = 16400u - suspend fun readNullableInt32sAttribute(): NullableInt32sAttribute { - val ATTRIBUTE_ID: UInt = 16400u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Nullableint32s attribute not found in response" } + } + + requireNotNull(attributeData) { + "Nullableint32s attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Int? = - if (!tlvReader.isNull()) { - tlvReader.getInt(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Int? = if (!tlvReader.isNull()) { + tlvReader.getInt(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return NullableInt32sAttribute(decodedValue) } - suspend fun writeNullableInt32sAttribute(value: Int, timedWriteTimeout: Duration? = null) { + suspend fun writeNullableInt32sAttribute( + value: Int, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16400u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -11009,121 +11784,129 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableInt32sAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16400u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - NullableInt32sAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(NullableInt32sAttributeSubscriptionState.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) { - "Nullableint32s attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Nullableint32s attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Int? = - if (!tlvReader.isNull()) { - tlvReader.getInt(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Int? = if (!tlvReader.isNull()) { + tlvReader.getInt(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(NullableInt32sAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(NullableInt32sAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(NullableInt32sAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNullableInt40sAttribute(): NullableInt40sAttribute {val ATTRIBUTE_ID: UInt = 16401u - suspend fun readNullableInt40sAttribute(): NullableInt40sAttribute { - val ATTRIBUTE_ID: UInt = 16401u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Nullableint40s attribute not found in response" } + } + + requireNotNull(attributeData) { + "Nullableint40s attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = - if (!tlvReader.isNull()) { - tlvReader.getLong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Long? = if (!tlvReader.isNull()) { + tlvReader.getLong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return NullableInt40sAttribute(decodedValue) } - suspend fun writeNullableInt40sAttribute(value: Long, timedWriteTimeout: Duration? = null) { + suspend fun writeNullableInt40sAttribute( + value: Long, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16401u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -11144,121 +11927,129 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableInt40sAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16401u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - NullableInt40sAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(NullableInt40sAttributeSubscriptionState.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) { - "Nullableint40s attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Nullableint40s attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = - if (!tlvReader.isNull()) { - tlvReader.getLong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Long? = if (!tlvReader.isNull()) { + tlvReader.getLong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(NullableInt40sAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(NullableInt40sAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(NullableInt40sAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNullableInt48sAttribute(): NullableInt48sAttribute {val ATTRIBUTE_ID: UInt = 16402u - suspend fun readNullableInt48sAttribute(): NullableInt48sAttribute { - val ATTRIBUTE_ID: UInt = 16402u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Nullableint48s attribute not found in response" } + } + + requireNotNull(attributeData) { + "Nullableint48s attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = - if (!tlvReader.isNull()) { - tlvReader.getLong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Long? = if (!tlvReader.isNull()) { + tlvReader.getLong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return NullableInt48sAttribute(decodedValue) } - suspend fun writeNullableInt48sAttribute(value: Long, timedWriteTimeout: Duration? = null) { + suspend fun writeNullableInt48sAttribute( + value: Long, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16402u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -11279,121 +12070,129 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableInt48sAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16402u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - NullableInt48sAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(NullableInt48sAttributeSubscriptionState.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) { - "Nullableint48s attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Nullableint48s attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = - if (!tlvReader.isNull()) { - tlvReader.getLong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Long? = if (!tlvReader.isNull()) { + tlvReader.getLong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(NullableInt48sAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(NullableInt48sAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(NullableInt48sAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNullableInt56sAttribute(): NullableInt56sAttribute {val ATTRIBUTE_ID: UInt = 16403u - suspend fun readNullableInt56sAttribute(): NullableInt56sAttribute { - val ATTRIBUTE_ID: UInt = 16403u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Nullableint56s attribute not found in response" } + } + + requireNotNull(attributeData) { + "Nullableint56s attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = - if (!tlvReader.isNull()) { - tlvReader.getLong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Long? = if (!tlvReader.isNull()) { + tlvReader.getLong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return NullableInt56sAttribute(decodedValue) } - suspend fun writeNullableInt56sAttribute(value: Long, timedWriteTimeout: Duration? = null) { + suspend fun writeNullableInt56sAttribute( + value: Long, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16403u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -11414,121 +12213,129 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableInt56sAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16403u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - NullableInt56sAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(NullableInt56sAttributeSubscriptionState.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) { - "Nullableint56s attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Nullableint56s attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = - if (!tlvReader.isNull()) { - tlvReader.getLong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Long? = if (!tlvReader.isNull()) { + tlvReader.getLong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(NullableInt56sAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(NullableInt56sAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(NullableInt56sAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNullableInt64sAttribute(): NullableInt64sAttribute {val ATTRIBUTE_ID: UInt = 16404u - suspend fun readNullableInt64sAttribute(): NullableInt64sAttribute { - val ATTRIBUTE_ID: UInt = 16404u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Nullableint64s attribute not found in response" } + } + + requireNotNull(attributeData) { + "Nullableint64s attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = - if (!tlvReader.isNull()) { - tlvReader.getLong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Long? = if (!tlvReader.isNull()) { + tlvReader.getLong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return NullableInt64sAttribute(decodedValue) } - suspend fun writeNullableInt64sAttribute(value: Long, timedWriteTimeout: Duration? = null) { + suspend fun writeNullableInt64sAttribute( + value: Long, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16404u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -11549,121 +12356,129 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableInt64sAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16404u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - NullableInt64sAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(NullableInt64sAttributeSubscriptionState.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) { - "Nullableint64s attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Nullableint64s attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = - if (!tlvReader.isNull()) { - tlvReader.getLong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Long? = if (!tlvReader.isNull()) { + tlvReader.getLong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(NullableInt64sAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(NullableInt64sAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(NullableInt64sAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNullableEnum8Attribute(): NullableEnum8Attribute {val ATTRIBUTE_ID: UInt = 16405u - suspend fun readNullableEnum8Attribute(): NullableEnum8Attribute { - val ATTRIBUTE_ID: UInt = 16405u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Nullableenum8 attribute not found in response" } + } + + requireNotNull(attributeData) { + "Nullableenum8 attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return NullableEnum8Attribute(decodedValue) } - suspend fun writeNullableEnum8Attribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeNullableEnum8Attribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16405u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -11684,119 +12499,129 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableEnum8Attribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16405u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - NullableEnum8AttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(NullableEnum8AttributeSubscriptionState.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) { "Nullableenum8 attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Nullableenum8 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.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(NullableEnum8AttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(NullableEnum8AttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(NullableEnum8AttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNullableEnum16Attribute(): NullableEnum16Attribute {val ATTRIBUTE_ID: UInt = 16406u - suspend fun readNullableEnum16Attribute(): NullableEnum16Attribute { - val ATTRIBUTE_ID: UInt = 16406u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Nullableenum16 attribute not found in response" } + } + + requireNotNull(attributeData) { + "Nullableenum16 attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = - if (!tlvReader.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return NullableEnum16Attribute(decodedValue) } - suspend fun writeNullableEnum16Attribute(value: UShort, timedWriteTimeout: Duration? = null) { + suspend fun writeNullableEnum16Attribute( + value: UShort, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16406u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -11817,121 +12642,129 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableEnum16Attribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16406u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - NullableEnum16AttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(NullableEnum16AttributeSubscriptionState.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) { - "Nullableenum16 attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Nullableenum16 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.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(NullableEnum16AttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(NullableEnum16AttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(NullableEnum16AttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNullableFloatSingleAttribute(): NullableFloatSingleAttribute {val ATTRIBUTE_ID: UInt = 16407u - suspend fun readNullableFloatSingleAttribute(): NullableFloatSingleAttribute { - val ATTRIBUTE_ID: UInt = 16407u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Nullablefloatsingle attribute not found in response" } + } + + requireNotNull(attributeData) { + "Nullablefloatsingle attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - tlvReader.getFloat(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Float? = if (!tlvReader.isNull()) { + tlvReader.getFloat(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return NullableFloatSingleAttribute(decodedValue) } - suspend fun writeNullableFloatSingleAttribute(value: Float, timedWriteTimeout: Duration? = null) { + suspend fun writeNullableFloatSingleAttribute( + value: Float, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16407u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -11952,124 +12785,129 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableFloatSingleAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16407u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - NullableFloatSingleAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(NullableFloatSingleAttributeSubscriptionState.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) { - "Nullablefloatsingle attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Nullablefloatsingle attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = - if (!tlvReader.isNull()) { - tlvReader.getFloat(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Float? = if (!tlvReader.isNull()) { + tlvReader.getFloat(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(NullableFloatSingleAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(NullableFloatSingleAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(NullableFloatSingleAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNullableFloatDoubleAttribute(): NullableFloatDoubleAttribute {val ATTRIBUTE_ID: UInt = 16408u - suspend fun readNullableFloatDoubleAttribute(): NullableFloatDoubleAttribute { - val ATTRIBUTE_ID: UInt = 16408u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Nullablefloatdouble attribute not found in response" } + } + + requireNotNull(attributeData) { + "Nullablefloatdouble attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Double? = - if (!tlvReader.isNull()) { - tlvReader.getDouble(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Double? = if (!tlvReader.isNull()) { + tlvReader.getDouble(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return NullableFloatDoubleAttribute(decodedValue) } suspend fun writeNullableFloatDoubleAttribute( value: Double, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16408u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -12090,124 +12928,129 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableFloatDoubleAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16408u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - NullableFloatDoubleAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(NullableFloatDoubleAttributeSubscriptionState.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) { - "Nullablefloatdouble attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Nullablefloatdouble attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Double? = - if (!tlvReader.isNull()) { - tlvReader.getDouble(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Double? = if (!tlvReader.isNull()) { + tlvReader.getDouble(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(NullableFloatDoubleAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(NullableFloatDoubleAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(NullableFloatDoubleAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNullableOctetStringAttribute(): NullableOctetStringAttribute {val ATTRIBUTE_ID: UInt = 16409u - suspend fun readNullableOctetStringAttribute(): NullableOctetStringAttribute { - val ATTRIBUTE_ID: UInt = 16409u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Nullableoctetstring attribute not found in response" } + } + + requireNotNull(attributeData) { + "Nullableoctetstring attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = - if (!tlvReader.isNull()) { - tlvReader.getByteArray(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ByteArray? = if (!tlvReader.isNull()) { + tlvReader.getByteArray(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return NullableOctetStringAttribute(decodedValue) } suspend fun writeNullableOctetStringAttribute( value: ByteArray, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16409u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -12228,121 +13071,129 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableOctetStringAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16409u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - NullableOctetStringAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(NullableOctetStringAttributeSubscriptionState.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) { - "Nullableoctetstring attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Nullableoctetstring attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = - if (!tlvReader.isNull()) { - tlvReader.getByteArray(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ByteArray? = if (!tlvReader.isNull()) { + tlvReader.getByteArray(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(NullableOctetStringAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(NullableOctetStringAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(NullableOctetStringAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNullableCharStringAttribute(): NullableCharStringAttribute {val ATTRIBUTE_ID: UInt = 16414u - suspend fun readNullableCharStringAttribute(): NullableCharStringAttribute { - val ATTRIBUTE_ID: UInt = 16414u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Nullablecharstring attribute not found in response" } + } + + requireNotNull(attributeData) { + "Nullablecharstring attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (!tlvReader.isNull()) { - tlvReader.getString(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: String? = if (!tlvReader.isNull()) { + tlvReader.getString(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return NullableCharStringAttribute(decodedValue) } - suspend fun writeNullableCharStringAttribute(value: String, timedWriteTimeout: Duration? = null) { + suspend fun writeNullableCharStringAttribute( + value: String, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16414u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -12363,121 +13214,129 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableCharStringAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16414u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - NullableCharStringAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(NullableCharStringAttributeSubscriptionState.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) { - "Nullablecharstring attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Nullablecharstring attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (!tlvReader.isNull()) { - tlvReader.getString(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: String? = if (!tlvReader.isNull()) { + tlvReader.getString(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(NullableCharStringAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(NullableCharStringAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(NullableCharStringAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNullableEnumAttrAttribute(): NullableEnumAttrAttribute {val ATTRIBUTE_ID: UInt = 16420u - suspend fun readNullableEnumAttrAttribute(): NullableEnumAttrAttribute { - val ATTRIBUTE_ID: UInt = 16420u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Nullableenumattr attribute not found in response" } + } + + requireNotNull(attributeData) { + "Nullableenumattr attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return NullableEnumAttrAttribute(decodedValue) } - suspend fun writeNullableEnumAttrAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeNullableEnumAttrAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16420u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -12498,124 +13357,129 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableEnumAttrAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16420u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - NullableEnumAttrAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(NullableEnumAttrAttributeSubscriptionState.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) { - "Nullableenumattr attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Nullableenumattr 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.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(NullableEnumAttrAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(NullableEnumAttrAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(NullableEnumAttrAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNullableStructAttribute(): NullableStructAttribute {val ATTRIBUTE_ID: UInt = 16421u - suspend fun readNullableStructAttribute(): NullableStructAttribute { - val ATTRIBUTE_ID: UInt = 16421u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Nullablestruct attribute not found in response" } + } + + requireNotNull(attributeData) { + "Nullablestruct attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UnitTestingClusterSimpleStruct? = - if (!tlvReader.isNull()) { - UnitTestingClusterSimpleStruct.fromTlv(AnonymousTag, tlvReader) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UnitTestingClusterSimpleStruct? = if (!tlvReader.isNull()) { + UnitTestingClusterSimpleStruct.fromTlv(AnonymousTag, tlvReader) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return NullableStructAttribute(decodedValue) } suspend fun writeNullableStructAttribute( value: UnitTestingClusterSimpleStruct, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16421u val tlvWriter = TlvWriter() - value.toTlv(AnonymousTag, tlvWriter) + value.toTlv(AnonymousTag, tlvWriter) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -12636,124 +13500,129 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableStructAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16421u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - NullableStructAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(NullableStructAttributeSubscriptionState.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) { - "Nullablestruct attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Nullablestruct attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UnitTestingClusterSimpleStruct? = - if (!tlvReader.isNull()) { - UnitTestingClusterSimpleStruct.fromTlv(AnonymousTag, tlvReader) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UnitTestingClusterSimpleStruct? = if (!tlvReader.isNull()) { + UnitTestingClusterSimpleStruct.fromTlv(AnonymousTag, tlvReader) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(NullableStructAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(NullableStructAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(NullableStructAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNullableRangeRestrictedInt8uAttribute(): NullableRangeRestrictedInt8uAttribute {val ATTRIBUTE_ID: UInt = 16422u - suspend fun readNullableRangeRestrictedInt8uAttribute(): NullableRangeRestrictedInt8uAttribute { - val ATTRIBUTE_ID: UInt = 16422u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Nullablerangerestrictedint8u attribute not found in response" } + } + + requireNotNull(attributeData) { + "Nullablerangerestrictedint8u attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return NullableRangeRestrictedInt8uAttribute(decodedValue) } suspend fun writeNullableRangeRestrictedInt8uAttribute( value: UByte, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16422u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -12774,126 +13643,129 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableRangeRestrictedInt8uAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16422u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - NullableRangeRestrictedInt8uAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(NullableRangeRestrictedInt8uAttributeSubscriptionState.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) { - "Nullablerangerestrictedint8u attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Nullablerangerestrictedint8u 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.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } decodedValue?.let { emit(NullableRangeRestrictedInt8uAttributeSubscriptionState.Success(it)) } + } SubscriptionState.SubscriptionEstablished -> { emit(NullableRangeRestrictedInt8uAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNullableRangeRestrictedInt8sAttribute(): NullableRangeRestrictedInt8sAttribute {val ATTRIBUTE_ID: UInt = 16423u - suspend fun readNullableRangeRestrictedInt8sAttribute(): NullableRangeRestrictedInt8sAttribute { - val ATTRIBUTE_ID: UInt = 16423u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Nullablerangerestrictedint8s attribute not found in response" } + } + + requireNotNull(attributeData) { + "Nullablerangerestrictedint8s attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Byte? = - if (!tlvReader.isNull()) { - tlvReader.getByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Byte? = if (!tlvReader.isNull()) { + tlvReader.getByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return NullableRangeRestrictedInt8sAttribute(decodedValue) } suspend fun writeNullableRangeRestrictedInt8sAttribute( value: Byte, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16423u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -12914,128 +13786,129 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableRangeRestrictedInt8sAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16423u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - NullableRangeRestrictedInt8sAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(NullableRangeRestrictedInt8sAttributeSubscriptionState.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) { - "Nullablerangerestrictedint8s attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Nullablerangerestrictedint8s attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Byte? = - if (!tlvReader.isNull()) { - tlvReader.getByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Byte? = if (!tlvReader.isNull()) { + tlvReader.getByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } decodedValue?.let { emit(NullableRangeRestrictedInt8sAttributeSubscriptionState.Success(it)) } + } SubscriptionState.SubscriptionEstablished -> { emit(NullableRangeRestrictedInt8sAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNullableRangeRestrictedInt16uAttribute(): NullableRangeRestrictedInt16uAttribute {val ATTRIBUTE_ID: UInt = 16424u - suspend fun readNullableRangeRestrictedInt16uAttribute(): NullableRangeRestrictedInt16uAttribute { - val ATTRIBUTE_ID: UInt = 16424u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { - "Nullablerangerestrictedint16u attribute not found in response" + } + + requireNotNull(attributeData) { + "Nullablerangerestrictedint16u attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = - if (!tlvReader.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return NullableRangeRestrictedInt16uAttribute(decodedValue) } suspend fun writeNullableRangeRestrictedInt16uAttribute( value: UShort, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16424u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -13056,128 +13929,129 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableRangeRestrictedInt16uAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16424u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - NullableRangeRestrictedInt16uAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(NullableRangeRestrictedInt16uAttributeSubscriptionState.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) { - "Nullablerangerestrictedint16u attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Nullablerangerestrictedint16u 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.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } decodedValue?.let { emit(NullableRangeRestrictedInt16uAttributeSubscriptionState.Success(it)) } + } SubscriptionState.SubscriptionEstablished -> { emit(NullableRangeRestrictedInt16uAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNullableRangeRestrictedInt16sAttribute(): NullableRangeRestrictedInt16sAttribute {val ATTRIBUTE_ID: UInt = 16425u - suspend fun readNullableRangeRestrictedInt16sAttribute(): NullableRangeRestrictedInt16sAttribute { - val ATTRIBUTE_ID: UInt = 16425u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { - "Nullablerangerestrictedint16s attribute not found in response" + } + + requireNotNull(attributeData) { + "Nullablerangerestrictedint16s attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (!tlvReader.isNull()) { - tlvReader.getShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Short? = if (!tlvReader.isNull()) { + tlvReader.getShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return NullableRangeRestrictedInt16sAttribute(decodedValue) } suspend fun writeNullableRangeRestrictedInt16sAttribute( value: Short, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16425u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -13198,122 +14072,128 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableRangeRestrictedInt16sAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16425u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - NullableRangeRestrictedInt16sAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(NullableRangeRestrictedInt16sAttributeSubscriptionState.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) { - "Nullablerangerestrictedint16s attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Nullablerangerestrictedint16s attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = - if (!tlvReader.isNull()) { - tlvReader.getShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Short? = if (!tlvReader.isNull()) { + tlvReader.getShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } decodedValue?.let { emit(NullableRangeRestrictedInt16sAttributeSubscriptionState.Success(it)) } + } SubscriptionState.SubscriptionEstablished -> { emit(NullableRangeRestrictedInt16sAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readWriteOnlyInt8uAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 16426u - suspend fun readWriteOnlyInt8uAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 16426u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Writeonlyint8u attribute not found in response" } + } + + requireNotNull(attributeData) { + "Writeonlyint8u 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } - suspend fun writeWriteOnlyInt8uAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeWriteOnlyInt8uAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16426u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -13334,120 +14214,128 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeWriteOnlyInt8uAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16426u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Writeonlyint8u attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Writeonlyint8u 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UByteSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNullableGlobalEnumAttribute(): NullableGlobalEnumAttribute {val ATTRIBUTE_ID: UInt = 16435u - suspend fun readNullableGlobalEnumAttribute(): NullableGlobalEnumAttribute { - val ATTRIBUTE_ID: UInt = 16435u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Nullableglobalenum attribute not found in response" } + } + + requireNotNull(attributeData) { + "Nullableglobalenum attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return NullableGlobalEnumAttribute(decodedValue) } - suspend fun writeNullableGlobalEnumAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeNullableGlobalEnumAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16435u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -13468,124 +14356,129 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableGlobalEnumAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16435u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - NullableGlobalEnumAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(NullableGlobalEnumAttributeSubscriptionState.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) { - "Nullableglobalenum attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Nullableglobalenum 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.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(NullableGlobalEnumAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(NullableGlobalEnumAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(NullableGlobalEnumAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNullableGlobalStructAttribute(): NullableGlobalStructAttribute {val ATTRIBUTE_ID: UInt = 16436u - suspend fun readNullableGlobalStructAttribute(): NullableGlobalStructAttribute { - val ATTRIBUTE_ID: UInt = 16436u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Nullableglobalstruct attribute not found in response" } + } + + requireNotNull(attributeData) { + "Nullableglobalstruct attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UnitTestingClusterTestGlobalStruct? = - if (!tlvReader.isNull()) { - UnitTestingClusterTestGlobalStruct.fromTlv(AnonymousTag, tlvReader) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UnitTestingClusterTestGlobalStruct? = if (!tlvReader.isNull()) { + UnitTestingClusterTestGlobalStruct.fromTlv(AnonymousTag, tlvReader) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return NullableGlobalStructAttribute(decodedValue) } suspend fun writeNullableGlobalStructAttribute( value: UnitTestingClusterTestGlobalStruct, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16436u val tlvWriter = TlvWriter() - value.toTlv(AnonymousTag, tlvWriter) + value.toTlv(AnonymousTag, tlvWriter) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -13606,115 +14499,124 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableGlobalStructAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16436u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - NullableGlobalStructAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(NullableGlobalStructAttributeSubscriptionState.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) { - "Nullableglobalstruct attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Nullableglobalstruct attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UnitTestingClusterTestGlobalStruct? = - if (!tlvReader.isNull()) { - UnitTestingClusterTestGlobalStruct.fromTlv(AnonymousTag, tlvReader) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UnitTestingClusterTestGlobalStruct? = if (!tlvReader.isNull()) { + UnitTestingClusterTestGlobalStruct.fromTlv(AnonymousTag, tlvReader) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { emit(NullableGlobalStructAttributeSubscriptionState.Success(it)) } + decodedValue?.let { + emit(NullableGlobalStructAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(NullableGlobalStructAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readMeiInt8uAttribute(): UByte {val ATTRIBUTE_ID: UInt = 4294070017u - suspend fun readMeiInt8uAttribute(): UByte { - val ATTRIBUTE_ID: UInt = 4294070017u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Meiint8u attribute not found in response" } + } + + requireNotNull(attributeData) { + "Meiint8u 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 writeMeiInt8uAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeMeiInt8uAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 4294070017u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -13735,45 +14637,43 @@ class UnitTestingCluster(private val controller: MatterController, private val e throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeMeiInt8uAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4294070017u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Meiint8u attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Meiint8u attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -13785,96 +14685,97 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65528u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -13882,96 +14783,97 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(GeneratedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65529u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -13979,94 +14881,97 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(AcceptedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt = 65530u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -14074,94 +14979,97 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(EventListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ID: UInt = 65531u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -14169,76 +15077,81 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(AttributeListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u - 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 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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -14250,77 +15163,80 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 65533u - 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 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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -14333,7 +15249,7 @@ class UnitTestingCluster(private val controller: MatterController, private val e emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/UserLabelCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/UserLabelCluster.kt index db94a02ff8ae52..b7fb44b39973dc 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/UserLabelCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/UserLabelCluster.kt @@ -17,141 +17,183 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.UIntSubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState +import matter.controller.UByteSubscriptionState import matter.controller.UShortSubscriptionState +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.cluster.structs.* +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath +import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class UserLabelCluster(private val controller: MatterController, private val endpointId: UShort) { - class LabelListAttribute(val value: List) +class UserLabelCluster(private val controller: MatterController, private val endpointId: UShort) {class LabelListAttribute( + val value: List + ) sealed class LabelListAttributeSubscriptionState { - data class Success(val value: List) : - LabelListAttributeSubscriptionState() - + data class Success( + val value: List + ) : LabelListAttributeSubscriptionState() + data class Error(val exception: Exception) : LabelListAttributeSubscriptionState() - object SubscriptionEstablished : LabelListAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : LabelListAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } - - suspend fun readLabelListAttribute(): LabelListAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } +suspend fun readLabelListAttribute(): LabelListAttribute {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}") - } + 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) { "Labellist attribute not found in response" } + } + + requireNotNull(attributeData) { + "Labellist 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(UserLabelClusterLabelStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(UserLabelClusterLabelStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + return LabelListAttribute(decodedValue) } suspend fun writeLabelListAttribute( value: List, - timedWriteTimeout: Duration? = null, - ) { + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startArray(AnonymousTag) - for (item in value.iterator()) { - item.toTlv(AnonymousTag, tlvWriter) - } - tlvWriter.endArray() + for (item in value.iterator()) { + item.toTlv(AnonymousTag, tlvWriter) + } + tlvWriter.endArray() val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -172,56 +214,53 @@ class UserLabelCluster(private val controller: MatterController, private val end throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeLabelListAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - LabelListAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(LabelListAttributeSubscriptionState.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) { "Labellist attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Labellist 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(UserLabelClusterLabelStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(UserLabelClusterLabelStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(LabelListAttributeSubscriptionState.Success(decodedValue)) } @@ -229,96 +268,97 @@ class UserLabelCluster(private val controller: MatterController, private val end emit(LabelListAttributeSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -326,96 +366,97 @@ class UserLabelCluster(private val controller: MatterController, private val end 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -423,94 +464,97 @@ class UserLabelCluster(private val controller: MatterController, private val end 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -518,94 +562,97 @@ class UserLabelCluster(private val controller: MatterController, private val end 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -613,76 +660,81 @@ class UserLabelCluster(private val controller: MatterController, private val end 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -694,77 +746,80 @@ class UserLabelCluster(private val controller: MatterController, private val end 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -777,7 +832,7 @@ class UserLabelCluster(private val controller: MatterController, private val end emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/ValveConfigurationAndControlCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/ValveConfigurationAndControlCluster.kt index 9c6f8bbec2843c..b4b18cde045376 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/ValveConfigurationAndControlCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/ValveConfigurationAndControlCluster.kt @@ -17,174 +17,229 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.cluster.structs.* +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class ValveConfigurationAndControlCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class OpenDurationAttribute(val value: UInt?) +class ValveConfigurationAndControlCluster(private val controller: MatterController, private val endpointId: UShort) {class OpenDurationAttribute( + val value: UInt? + ) sealed class OpenDurationAttributeSubscriptionState { - data class Success(val value: UInt?) : OpenDurationAttributeSubscriptionState() - + data class Success( + val value: UInt? + ) : OpenDurationAttributeSubscriptionState() + data class Error(val exception: Exception) : OpenDurationAttributeSubscriptionState() - object SubscriptionEstablished : OpenDurationAttributeSubscriptionState() - } - - class DefaultOpenDurationAttribute(val value: UInt?) + object SubscriptionEstablished : OpenDurationAttributeSubscriptionState() + } +class DefaultOpenDurationAttribute( + val value: UInt? + ) sealed class DefaultOpenDurationAttributeSubscriptionState { - data class Success(val value: UInt?) : DefaultOpenDurationAttributeSubscriptionState() - + data class Success( + val value: UInt? + ) : DefaultOpenDurationAttributeSubscriptionState() + data class Error(val exception: Exception) : DefaultOpenDurationAttributeSubscriptionState() - object SubscriptionEstablished : DefaultOpenDurationAttributeSubscriptionState() - } - - class AutoCloseTimeAttribute(val value: ULong?) + object SubscriptionEstablished : DefaultOpenDurationAttributeSubscriptionState() + } +class AutoCloseTimeAttribute( + val value: ULong? + ) sealed class AutoCloseTimeAttributeSubscriptionState { - data class Success(val value: ULong?) : AutoCloseTimeAttributeSubscriptionState() - + data class Success( + val value: ULong? + ) : AutoCloseTimeAttributeSubscriptionState() + data class Error(val exception: Exception) : AutoCloseTimeAttributeSubscriptionState() - object SubscriptionEstablished : AutoCloseTimeAttributeSubscriptionState() - } - - class RemainingDurationAttribute(val value: UInt?) + object SubscriptionEstablished : AutoCloseTimeAttributeSubscriptionState() + } +class RemainingDurationAttribute( + val value: UInt? + ) sealed class RemainingDurationAttributeSubscriptionState { - data class Success(val value: UInt?) : RemainingDurationAttributeSubscriptionState() - + data class Success( + val value: UInt? + ) : RemainingDurationAttributeSubscriptionState() + data class Error(val exception: Exception) : RemainingDurationAttributeSubscriptionState() - object SubscriptionEstablished : RemainingDurationAttributeSubscriptionState() - } - - class CurrentStateAttribute(val value: UByte?) + object SubscriptionEstablished : RemainingDurationAttributeSubscriptionState() + } +class CurrentStateAttribute( + val value: UByte? + ) sealed class CurrentStateAttributeSubscriptionState { - data class Success(val value: UByte?) : CurrentStateAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : CurrentStateAttributeSubscriptionState() + data class Error(val exception: Exception) : CurrentStateAttributeSubscriptionState() - object SubscriptionEstablished : CurrentStateAttributeSubscriptionState() - } - - class TargetStateAttribute(val value: UByte?) + object SubscriptionEstablished : CurrentStateAttributeSubscriptionState() + } +class TargetStateAttribute( + val value: UByte? + ) sealed class TargetStateAttributeSubscriptionState { - data class Success(val value: UByte?) : TargetStateAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : TargetStateAttributeSubscriptionState() + data class Error(val exception: Exception) : TargetStateAttributeSubscriptionState() - object SubscriptionEstablished : TargetStateAttributeSubscriptionState() - } - - class CurrentLevelAttribute(val value: UByte?) + object SubscriptionEstablished : TargetStateAttributeSubscriptionState() + } +class CurrentLevelAttribute( + val value: UByte? + ) sealed class CurrentLevelAttributeSubscriptionState { - data class Success(val value: UByte?) : CurrentLevelAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : CurrentLevelAttributeSubscriptionState() + data class Error(val exception: Exception) : CurrentLevelAttributeSubscriptionState() - object SubscriptionEstablished : CurrentLevelAttributeSubscriptionState() - } - - class TargetLevelAttribute(val value: UByte?) + object SubscriptionEstablished : CurrentLevelAttributeSubscriptionState() + } +class TargetLevelAttribute( + val value: UByte? + ) sealed class TargetLevelAttributeSubscriptionState { - data class Success(val value: UByte?) : TargetLevelAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : TargetLevelAttributeSubscriptionState() + data class Error(val exception: Exception) : TargetLevelAttributeSubscriptionState() - object SubscriptionEstablished : TargetLevelAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : TargetLevelAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun open(openDuration: UInt?, targetLevel: UByte?, timedInvokeTimeout: Duration? = null) { + suspend fun open(openDuration: UInt? + ,targetLevel: UByte? + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_OPEN_DURATION_REQ: Int = 0 - openDuration?.let { tlvWriter.put(ContextSpecificTag(TAG_OPEN_DURATION_REQ), openDuration) } + openDuration?.let { + tlvWriter.put(ContextSpecificTag(TAG_OPEN_DURATION_REQ), openDuration) + } val TAG_TARGET_LEVEL_REQ: Int = 1 - targetLevel?.let { tlvWriter.put(ContextSpecificTag(TAG_TARGET_LEVEL_REQ), targetLevel) } + targetLevel?.let { + tlvWriter.put(ContextSpecificTag(TAG_TARGET_LEVEL_REQ), targetLevel) + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -195,167 +250,183 @@ class ValveConfigurationAndControlCluster( val commandId: UInt = 1u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - - suspend fun readOpenDurationAttribute(): OpenDurationAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readOpenDurationAttribute(): OpenDurationAttribute {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}") - } + 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) { "Openduration attribute not found in response" } + } + + requireNotNull(attributeData) { + "Openduration attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - tlvReader.getUInt(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + tlvReader.getUInt(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return OpenDurationAttribute(decodedValue) } suspend fun subscribeOpenDurationAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - OpenDurationAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(OpenDurationAttributeSubscriptionState.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) { "Openduration attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Openduration attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - tlvReader.getUInt(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(OpenDurationAttributeSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + tlvReader.getUInt(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(OpenDurationAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(OpenDurationAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readDefaultOpenDurationAttribute(): DefaultOpenDurationAttribute { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readDefaultOpenDurationAttribute(): DefaultOpenDurationAttribute {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}") - } + 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) { "Defaultopenduration attribute not found in response" } + } + + requireNotNull(attributeData) { + "Defaultopenduration attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - tlvReader.getUInt(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + tlvReader.getUInt(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return DefaultOpenDurationAttribute(decodedValue) } - suspend fun writeDefaultOpenDurationAttribute(value: UInt, timedWriteTimeout: Duration? = null) { + suspend fun writeDefaultOpenDurationAttribute( + value: UInt, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 1u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -376,704 +447,746 @@ class ValveConfigurationAndControlCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeDefaultOpenDurationAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - DefaultOpenDurationAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(DefaultOpenDurationAttributeSubscriptionState.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) { - "Defaultopenduration attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Defaultopenduration attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - tlvReader.getUInt(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(DefaultOpenDurationAttributeSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + tlvReader.getUInt(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(DefaultOpenDurationAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(DefaultOpenDurationAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readAutoCloseTimeAttribute(): AutoCloseTimeAttribute { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readAutoCloseTimeAttribute(): AutoCloseTimeAttribute {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}") - } + 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) { "Autoclosetime attribute not found in response" } + } + + requireNotNull(attributeData) { + "Autoclosetime 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 - } + val decodedValue: ULong? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return AutoCloseTimeAttribute(decodedValue) } suspend fun subscribeAutoCloseTimeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - AutoCloseTimeAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(AutoCloseTimeAttributeSubscriptionState.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) { "Autoclosetime attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Autoclosetime 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(AutoCloseTimeAttributeSubscriptionState.Success(it)) } + val decodedValue: ULong? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(AutoCloseTimeAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(AutoCloseTimeAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readRemainingDurationAttribute(): RemainingDurationAttribute { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readRemainingDurationAttribute(): RemainingDurationAttribute {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}") - } + 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) { "Remainingduration attribute not found in response" } + } + + requireNotNull(attributeData) { + "Remainingduration attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - tlvReader.getUInt(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + tlvReader.getUInt(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return RemainingDurationAttribute(decodedValue) } suspend fun subscribeRemainingDurationAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - RemainingDurationAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(RemainingDurationAttributeSubscriptionState.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) { - "Remainingduration attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Remainingduration attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - tlvReader.getUInt(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(RemainingDurationAttributeSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + tlvReader.getUInt(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(RemainingDurationAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(RemainingDurationAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readCurrentStateAttribute(): CurrentStateAttribute { - val ATTRIBUTE_ID: UInt = 4u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readCurrentStateAttribute(): CurrentStateAttribute {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}") - } + 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) { "Currentstate attribute not found in response" } + } + + requireNotNull(attributeData) { + "Currentstate attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return CurrentStateAttribute(decodedValue) } suspend fun subscribeCurrentStateAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - CurrentStateAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(CurrentStateAttributeSubscriptionState.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) { "Currentstate attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Currentstate 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.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(CurrentStateAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(CurrentStateAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(CurrentStateAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readTargetStateAttribute(): TargetStateAttribute { - val ATTRIBUTE_ID: UInt = 5u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readTargetStateAttribute(): TargetStateAttribute {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}") - } + 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) { "Targetstate attribute not found in response" } + } + + requireNotNull(attributeData) { + "Targetstate attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return TargetStateAttribute(decodedValue) } suspend fun subscribeTargetStateAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - TargetStateAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(TargetStateAttributeSubscriptionState.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) { "Targetstate attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Targetstate 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.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(TargetStateAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(TargetStateAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(TargetStateAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readCurrentLevelAttribute(): CurrentLevelAttribute { - val ATTRIBUTE_ID: UInt = 6u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readCurrentLevelAttribute(): CurrentLevelAttribute {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}") - } + 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) { "Currentlevel attribute not found in response" } + } + + requireNotNull(attributeData) { + "Currentlevel attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return CurrentLevelAttribute(decodedValue) } suspend fun subscribeCurrentLevelAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - CurrentLevelAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(CurrentLevelAttributeSubscriptionState.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) { "Currentlevel attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Currentlevel 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(CurrentLevelAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(CurrentLevelAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(CurrentLevelAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readTargetLevelAttribute(): TargetLevelAttribute { - val ATTRIBUTE_ID: UInt = 7u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readTargetLevelAttribute(): TargetLevelAttribute {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}") - } + 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) { "Targetlevel attribute not found in response" } + } + + requireNotNull(attributeData) { + "Targetlevel attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return TargetLevelAttribute(decodedValue) } suspend fun subscribeTargetLevelAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - TargetLevelAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(TargetLevelAttributeSubscriptionState.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) { "Targetlevel attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Targetlevel 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(TargetLevelAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(TargetLevelAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(TargetLevelAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readDefaultOpenLevelAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 8u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readDefaultOpenLevelAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 8u + + 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}") - } + 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) { "Defaultopenlevel attribute not found in response" } + } + + requireNotNull(attributeData) { + "Defaultopenlevel 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } - suspend fun writeDefaultOpenLevelAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeDefaultOpenLevelAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 8u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -1094,335 +1207,346 @@ class ValveConfigurationAndControlCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeDefaultOpenLevelAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Defaultopenlevel attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Defaultopenlevel 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)) } + 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 readValveFaultAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 9u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readValveFaultAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 9u + + 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}") - } + 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) { "Valvefault attribute not found in response" } + } + + requireNotNull(attributeData) { + "Valvefault 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeValveFaultAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Valvefault attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Valvefault 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)) } + 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 readLevelStepAttribute(): UByte? { - val ATTRIBUTE_ID: UInt = 10u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readLevelStepAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 10u + + 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}") - } + 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) { "Levelstep attribute not found in response" } + } + + requireNotNull(attributeData) { + "Levelstep 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeLevelStepAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Levelstep attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Levelstep 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)) } + 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 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1430,96 +1554,97 @@ class ValveConfigurationAndControlCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1527,94 +1652,97 @@ class ValveConfigurationAndControlCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1622,94 +1750,97 @@ class ValveConfigurationAndControlCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1717,76 +1848,81 @@ class ValveConfigurationAndControlCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1798,77 +1934,80 @@ class ValveConfigurationAndControlCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1881,7 +2020,7 @@ class ValveConfigurationAndControlCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/WakeOnLanCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/WakeOnLanCluster.kt index 100775120b96aa..18d648654b3557 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/WakeOnLanCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/WakeOnLanCluster.kt @@ -17,337 +17,383 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.ByteArraySubscriptionState import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest -import matter.controller.StringSubscriptionState +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.UIntSubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState +import matter.controller.UByteSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath +import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader +import matter.tlv.TlvWriter -class WakeOnLanCluster(private val controller: MatterController, private val endpointId: UShort) { - class GeneratedCommandListAttribute(val value: List) +class WakeOnLanCluster(private val controller: MatterController, private val endpointId: UShort) {class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } - - suspend fun readMACAddressAttribute(): String? { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } +suspend fun readMACAddressAttribute(): String? {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}") - } + 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) { "Macaddress attribute not found in response" } + } + + requireNotNull(attributeData) { + "Macaddress attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeMACAddressAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StringSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StringSubscriptionState.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) { "Macaddress attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Macaddress attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(StringSubscriptionState.Success(it)) } + val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(StringSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readLinkLocalAddressAttribute(): ByteArray? { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readLinkLocalAddressAttribute(): ByteArray? {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}") - } + 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) { "Linklocaladdress attribute not found in response" } + } + + requireNotNull(attributeData) { + "Linklocaladdress attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByteArray(AnonymousTag) - } else { - null - } + val decodedValue: ByteArray? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByteArray(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeLinkLocalAddressAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ByteArraySubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ByteArraySubscriptionState.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) { - "Linklocaladdress attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Linklocaladdress attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByteArray(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(ByteArraySubscriptionState.Success(it)) } + val decodedValue: ByteArray? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByteArray(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(ByteArraySubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ByteArraySubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -355,96 +401,97 @@ class WakeOnLanCluster(private val controller: MatterController, private val end 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -452,94 +499,97 @@ class WakeOnLanCluster(private val controller: MatterController, private val end 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -547,94 +597,97 @@ class WakeOnLanCluster(private val controller: MatterController, private val end 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -642,76 +695,81 @@ class WakeOnLanCluster(private val controller: MatterController, private val end 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -723,77 +781,80 @@ class WakeOnLanCluster(private val controller: MatterController, private val end 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -806,7 +867,7 @@ class WakeOnLanCluster(private val controller: MatterController, private val end emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/WaterHeaterManagementCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/WaterHeaterManagementCluster.kt index 5f7fb25dd58f77..a54c5d393204d4 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/WaterHeaterManagementCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/WaterHeaterManagementCluster.kt @@ -17,92 +17,117 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse -import matter.controller.LongSubscriptionState import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class WaterHeaterManagementCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class GeneratedCommandListAttribute(val value: List) +class WaterHeaterManagementCluster(private val controller: MatterController, private val endpointId: UShort) {class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun boost( - boostInfo: WaterHeaterManagementClusterWaterHeaterBoostInfoStruct, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun boost(boostInfo: WaterHeaterManagementClusterWaterHeaterBoostInfoStruct + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_BOOST_INFO_REQ: Int = 0 - boostInfo.toTlv(ContextSpecificTag(TAG_BOOST_INFO_REQ), tlvWriter) + boostInfo.toTlv(ContextSpecificTag(TAG_BOOST_INFO_REQ), tlvWriter) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -113,87 +138,92 @@ class WaterHeaterManagementCluster( val commandId: UInt = 1u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - - suspend fun readHeaterTypesAttribute(): 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)) - +suspend fun readHeaterTypesAttribute(): 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}") - } + 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) { "Heatertypes attribute not found in response" } + } + + requireNotNull(attributeData) { + "Heatertypes 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 subscribeHeaterTypesAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Heatertypes attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Heatertypes attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -205,76 +235,81 @@ class WaterHeaterManagementCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readHeatDemandAttribute(): 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)) - +suspend fun readHeatDemandAttribute(): 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}") - } + 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) { "Heatdemand attribute not found in response" } + } + + requireNotNull(attributeData) { + "Heatdemand 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 subscribeHeatDemandAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Heatdemand attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Heatdemand attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -286,353 +321,372 @@ class WaterHeaterManagementCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readTankVolumeAttribute(): 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)) - +suspend fun readTankVolumeAttribute(): 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}") - } + 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) { "Tankvolume attribute not found in response" } + } + + requireNotNull(attributeData) { + "Tankvolume 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeTankVolumeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Tankvolume attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Tankvolume 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)) } + 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 readEstimatedHeatRequiredAttribute(): Long? { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readEstimatedHeatRequiredAttribute(): Long? {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}") - } + 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) { "Estimatedheatrequired attribute not found in response" } + } + + requireNotNull(attributeData) { + "Estimatedheatrequired attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } + val decodedValue: Long? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeEstimatedHeatRequiredAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - LongSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(LongSubscriptionState.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) { - "Estimatedheatrequired attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Estimatedheatrequired attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(LongSubscriptionState.Success(it)) } + val decodedValue: Long? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + + decodedValue?.let { + emit(LongSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(LongSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readTankPercentageAttribute(): 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)) - +suspend fun readTankPercentageAttribute(): 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}") - } + 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) { "Tankpercentage attribute not found in response" } + } + + requireNotNull(attributeData) { + "Tankpercentage 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 - } + val decodedValue: UByte? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeTankPercentageAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Tankpercentage attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Tankpercentage 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)) } + 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 readBoostStateAttribute(): UByte { - val ATTRIBUTE_ID: UInt = 5u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readBoostStateAttribute(): UByte {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}") - } + 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) { "Booststate attribute not found in response" } + } + + requireNotNull(attributeData) { + "Booststate 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 subscribeBoostStateAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Booststate attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Booststate attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -644,96 +698,97 @@ class WaterHeaterManagementCluster( emit(UByteSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -741,96 +796,97 @@ class WaterHeaterManagementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -838,94 +894,97 @@ class WaterHeaterManagementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -933,94 +992,97 @@ class WaterHeaterManagementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1028,76 +1090,81 @@ class WaterHeaterManagementCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1109,77 +1176,80 @@ class WaterHeaterManagementCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1192,7 +1262,7 @@ class WaterHeaterManagementCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/WaterHeaterModeCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/WaterHeaterModeCluster.kt index 27352644935c8a..a651926d7366df 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/WaterHeaterModeCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/WaterHeaterModeCluster.kt @@ -17,127 +17,161 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.cluster.structs.* +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class WaterHeaterModeCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class ChangeToModeResponse(val status: UByte, val statusText: String?) - - class SupportedModesAttribute(val value: List) +class WaterHeaterModeCluster(private val controller: MatterController, private val endpointId: UShort) { + class ChangeToModeResponse( + val status: UByte, + val statusText: String? + ) +class SupportedModesAttribute( + val value: List + ) sealed class SupportedModesAttributeSubscriptionState { - data class Success(val value: List) : - SupportedModesAttributeSubscriptionState() - + data class Success( + val value: List + ) : SupportedModesAttributeSubscriptionState() + data class Error(val exception: Exception) : SupportedModesAttributeSubscriptionState() - object SubscriptionEstablished : SupportedModesAttributeSubscriptionState() - } - - class StartUpModeAttribute(val value: UByte?) + object SubscriptionEstablished : SupportedModesAttributeSubscriptionState() + } +class StartUpModeAttribute( + val value: UByte? + ) sealed class StartUpModeAttributeSubscriptionState { - data class Success(val value: UByte?) : StartUpModeAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : StartUpModeAttributeSubscriptionState() + data class Error(val exception: Exception) : StartUpModeAttributeSubscriptionState() - object SubscriptionEstablished : StartUpModeAttributeSubscriptionState() - } - - class OnModeAttribute(val value: UByte?) + object SubscriptionEstablished : StartUpModeAttributeSubscriptionState() + } +class OnModeAttribute( + val value: UByte? + ) sealed class OnModeAttributeSubscriptionState { - data class Success(val value: UByte?) : OnModeAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : OnModeAttributeSubscriptionState() + data class Error(val exception: Exception) : OnModeAttributeSubscriptionState() - object SubscriptionEstablished : OnModeAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : OnModeAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun changeToMode( - newMode: UByte, - timedInvokeTimeout: Duration? = null, - ): ChangeToModeResponse { + suspend fun changeToMode(newMode: UByte + ,timedInvokeTimeout: Duration? = null): ChangeToModeResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_NEW_MODE_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_NEW_MODE_REQ), newMode) + tlvWriter.put(ContextSpecificTag(TAG_NEW_MODE_REQ), newMode) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -147,130 +181,140 @@ class WaterHeaterModeCluster( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_STATUS_TEXT: Int = 1 var statusText_decoded: String? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_STATUS)) { - status_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_STATUS_TEXT)) { - statusText_decoded = + + if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} + + if (tag == ContextSpecificTag(TAG_STATUS_TEXT)) {statusText_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - } - } else { + tlvReader.getString(tag) + } else { + null + } + }} + + + else { tlvReader.skipElement() } } + + if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } + + + tlvReader.exitContainer() - return ChangeToModeResponse(status_decoded, statusText_decoded) + return ChangeToModeResponse( + status_decoded, + statusText_decoded + ) } - - suspend fun readSupportedModesAttribute(): SupportedModesAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readSupportedModesAttribute(): SupportedModesAttribute {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}") - } + 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) { "Supportedmodes attribute not found in response" } + } + + requireNotNull(attributeData) { + "Supportedmodes 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(WaterHeaterModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(WaterHeaterModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } + return SupportedModesAttribute(decodedValue) } suspend fun subscribeSupportedModesAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - SupportedModesAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(SupportedModesAttributeSubscriptionState.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) { - "Supportedmodes attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Supportedmodes 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(WaterHeaterModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(WaterHeaterModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(SupportedModesAttributeSubscriptionState.Success(decodedValue)) } @@ -278,76 +322,81 @@ class WaterHeaterModeCluster( emit(SupportedModesAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readCurrentModeAttribute(): 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)) - +suspend fun readCurrentModeAttribute(): 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}") - } + 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) { "Currentmode attribute not found in response" } + } + + requireNotNull(attributeData) { + "Currentmode 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 subscribeCurrentModeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Currentmode attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Currentmode attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -359,67 +408,77 @@ class WaterHeaterModeCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readStartUpModeAttribute(): StartUpModeAttribute { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readStartUpModeAttribute(): StartUpModeAttribute {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}") - } + 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) { "Startupmode attribute not found in response" } + } + + requireNotNull(attributeData) { + "Startupmode attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return StartUpModeAttribute(decodedValue) } - suspend fun writeStartUpModeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeStartUpModeAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 2u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -440,127 +499,137 @@ class WaterHeaterModeCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeStartUpModeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - StartUpModeAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(StartUpModeAttributeSubscriptionState.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) { "Startupmode attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Startupmode 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(StartUpModeAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(StartUpModeAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(StartUpModeAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readOnModeAttribute(): OnModeAttribute { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readOnModeAttribute(): OnModeAttribute {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}") - } + 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) { "Onmode attribute not found in response" } + } + + requireNotNull(attributeData) { + "Onmode attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return OnModeAttribute(decodedValue) } - suspend fun writeOnModeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeOnModeAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 3u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -581,156 +650,157 @@ class WaterHeaterModeCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeOnModeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - OnModeAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(OnModeAttributeSubscriptionState.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) { "Onmode attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Onmode 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(OnModeAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(OnModeAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(OnModeAttributeSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -738,96 +808,97 @@ class WaterHeaterModeCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -835,94 +906,97 @@ class WaterHeaterModeCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -930,94 +1004,97 @@ class WaterHeaterModeCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1025,76 +1102,81 @@ class WaterHeaterModeCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1106,77 +1188,80 @@ class WaterHeaterModeCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -1189,7 +1274,7 @@ class WaterHeaterModeCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/WiFiNetworkDiagnosticsCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/WiFiNetworkDiagnosticsCluster.kt index ff7d2ed278ca7f..a863a7bdcbe2f5 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/WiFiNetworkDiagnosticsCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/WiFiNetworkDiagnosticsCluster.kt @@ -17,1591 +17,1727 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.UIntSubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState +import matter.controller.UByteSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class WiFiNetworkDiagnosticsCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class BssidAttribute(val value: ByteArray?) +class WiFiNetworkDiagnosticsCluster(private val controller: MatterController, private val endpointId: UShort) {class BssidAttribute( + val value: ByteArray? + ) sealed class BssidAttributeSubscriptionState { - data class Success(val value: ByteArray?) : BssidAttributeSubscriptionState() - + data class Success( + val value: ByteArray? + ) : BssidAttributeSubscriptionState() + data class Error(val exception: Exception) : BssidAttributeSubscriptionState() - object SubscriptionEstablished : BssidAttributeSubscriptionState() - } - - class SecurityTypeAttribute(val value: UByte?) + object SubscriptionEstablished : BssidAttributeSubscriptionState() + } +class SecurityTypeAttribute( + val value: UByte? + ) sealed class SecurityTypeAttributeSubscriptionState { - data class Success(val value: UByte?) : SecurityTypeAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : SecurityTypeAttributeSubscriptionState() + data class Error(val exception: Exception) : SecurityTypeAttributeSubscriptionState() - object SubscriptionEstablished : SecurityTypeAttributeSubscriptionState() - } - - class WiFiVersionAttribute(val value: UByte?) + object SubscriptionEstablished : SecurityTypeAttributeSubscriptionState() + } +class WiFiVersionAttribute( + val value: UByte? + ) sealed class WiFiVersionAttributeSubscriptionState { - data class Success(val value: UByte?) : WiFiVersionAttributeSubscriptionState() - + data class Success( + val value: UByte? + ) : WiFiVersionAttributeSubscriptionState() + data class Error(val exception: Exception) : WiFiVersionAttributeSubscriptionState() - object SubscriptionEstablished : WiFiVersionAttributeSubscriptionState() - } - - class ChannelNumberAttribute(val value: UShort?) + object SubscriptionEstablished : WiFiVersionAttributeSubscriptionState() + } +class ChannelNumberAttribute( + val value: UShort? + ) sealed class ChannelNumberAttributeSubscriptionState { - data class Success(val value: UShort?) : ChannelNumberAttributeSubscriptionState() - + data class Success( + val value: UShort? + ) : ChannelNumberAttributeSubscriptionState() + data class Error(val exception: Exception) : ChannelNumberAttributeSubscriptionState() - object SubscriptionEstablished : ChannelNumberAttributeSubscriptionState() - } - - class RssiAttribute(val value: Byte?) + object SubscriptionEstablished : ChannelNumberAttributeSubscriptionState() + } +class RssiAttribute( + val value: Byte? + ) sealed class RssiAttributeSubscriptionState { - data class Success(val value: Byte?) : RssiAttributeSubscriptionState() - + data class Success( + val value: Byte? + ) : RssiAttributeSubscriptionState() + data class Error(val exception: Exception) : RssiAttributeSubscriptionState() - object SubscriptionEstablished : RssiAttributeSubscriptionState() - } - - class BeaconLostCountAttribute(val value: UInt?) + object SubscriptionEstablished : RssiAttributeSubscriptionState() + } +class BeaconLostCountAttribute( + val value: UInt? + ) sealed class BeaconLostCountAttributeSubscriptionState { - data class Success(val value: UInt?) : BeaconLostCountAttributeSubscriptionState() - + data class Success( + val value: UInt? + ) : BeaconLostCountAttributeSubscriptionState() + data class Error(val exception: Exception) : BeaconLostCountAttributeSubscriptionState() - object SubscriptionEstablished : BeaconLostCountAttributeSubscriptionState() - } - - class BeaconRxCountAttribute(val value: UInt?) + object SubscriptionEstablished : BeaconLostCountAttributeSubscriptionState() + } +class BeaconRxCountAttribute( + val value: UInt? + ) sealed class BeaconRxCountAttributeSubscriptionState { - data class Success(val value: UInt?) : BeaconRxCountAttributeSubscriptionState() - + data class Success( + val value: UInt? + ) : BeaconRxCountAttributeSubscriptionState() + data class Error(val exception: Exception) : BeaconRxCountAttributeSubscriptionState() - object SubscriptionEstablished : BeaconRxCountAttributeSubscriptionState() - } - - class PacketMulticastRxCountAttribute(val value: UInt?) + object SubscriptionEstablished : BeaconRxCountAttributeSubscriptionState() + } +class PacketMulticastRxCountAttribute( + val value: UInt? + ) sealed class PacketMulticastRxCountAttributeSubscriptionState { - data class Success(val value: UInt?) : PacketMulticastRxCountAttributeSubscriptionState() - + data class Success( + val value: UInt? + ) : PacketMulticastRxCountAttributeSubscriptionState() + data class Error(val exception: Exception) : PacketMulticastRxCountAttributeSubscriptionState() - object SubscriptionEstablished : PacketMulticastRxCountAttributeSubscriptionState() - } - - class PacketMulticastTxCountAttribute(val value: UInt?) + object SubscriptionEstablished : PacketMulticastRxCountAttributeSubscriptionState() + } +class PacketMulticastTxCountAttribute( + val value: UInt? + ) sealed class PacketMulticastTxCountAttributeSubscriptionState { - data class Success(val value: UInt?) : PacketMulticastTxCountAttributeSubscriptionState() - + data class Success( + val value: UInt? + ) : PacketMulticastTxCountAttributeSubscriptionState() + data class Error(val exception: Exception) : PacketMulticastTxCountAttributeSubscriptionState() - object SubscriptionEstablished : PacketMulticastTxCountAttributeSubscriptionState() - } - - class PacketUnicastRxCountAttribute(val value: UInt?) + object SubscriptionEstablished : PacketMulticastTxCountAttributeSubscriptionState() + } +class PacketUnicastRxCountAttribute( + val value: UInt? + ) sealed class PacketUnicastRxCountAttributeSubscriptionState { - data class Success(val value: UInt?) : PacketUnicastRxCountAttributeSubscriptionState() - + data class Success( + val value: UInt? + ) : PacketUnicastRxCountAttributeSubscriptionState() + data class Error(val exception: Exception) : PacketUnicastRxCountAttributeSubscriptionState() - object SubscriptionEstablished : PacketUnicastRxCountAttributeSubscriptionState() - } - - class PacketUnicastTxCountAttribute(val value: UInt?) + object SubscriptionEstablished : PacketUnicastRxCountAttributeSubscriptionState() + } +class PacketUnicastTxCountAttribute( + val value: UInt? + ) sealed class PacketUnicastTxCountAttributeSubscriptionState { - data class Success(val value: UInt?) : PacketUnicastTxCountAttributeSubscriptionState() - + data class Success( + val value: UInt? + ) : PacketUnicastTxCountAttributeSubscriptionState() + data class Error(val exception: Exception) : PacketUnicastTxCountAttributeSubscriptionState() - object SubscriptionEstablished : PacketUnicastTxCountAttributeSubscriptionState() - } - - class CurrentMaxRateAttribute(val value: ULong?) + object SubscriptionEstablished : PacketUnicastTxCountAttributeSubscriptionState() + } +class CurrentMaxRateAttribute( + val value: ULong? + ) sealed class CurrentMaxRateAttributeSubscriptionState { - data class Success(val value: ULong?) : CurrentMaxRateAttributeSubscriptionState() - + data class Success( + val value: ULong? + ) : CurrentMaxRateAttributeSubscriptionState() + data class Error(val exception: Exception) : CurrentMaxRateAttributeSubscriptionState() - object SubscriptionEstablished : CurrentMaxRateAttributeSubscriptionState() - } - - class OverrunCountAttribute(val value: ULong?) + object SubscriptionEstablished : CurrentMaxRateAttributeSubscriptionState() + } +class OverrunCountAttribute( + val value: ULong? + ) sealed class OverrunCountAttributeSubscriptionState { - data class Success(val value: ULong?) : OverrunCountAttributeSubscriptionState() - + data class Success( + val value: ULong? + ) : OverrunCountAttributeSubscriptionState() + data class Error(val exception: Exception) : OverrunCountAttributeSubscriptionState() - object SubscriptionEstablished : OverrunCountAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : OverrunCountAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } suspend fun resetCounts(timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - - suspend fun readBssidAttribute(): BssidAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readBssidAttribute(): BssidAttribute {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}") - } + 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) { "Bssid attribute not found in response" } + } + + requireNotNull(attributeData) { + "Bssid attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = - if (!tlvReader.isNull()) { - tlvReader.getByteArray(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ByteArray? = if (!tlvReader.isNull()) { + tlvReader.getByteArray(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return BssidAttribute(decodedValue) } suspend fun subscribeBssidAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - BssidAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(BssidAttributeSubscriptionState.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) { "Bssid attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Bssid attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = - if (!tlvReader.isNull()) { - tlvReader.getByteArray(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(BssidAttributeSubscriptionState.Success(it)) } + val decodedValue: ByteArray? = if (!tlvReader.isNull()) { + tlvReader.getByteArray(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(BssidAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(BssidAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readSecurityTypeAttribute(): SecurityTypeAttribute { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readSecurityTypeAttribute(): SecurityTypeAttribute {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}") - } + 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) { "Securitytype attribute not found in response" } + } + + requireNotNull(attributeData) { + "Securitytype attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return SecurityTypeAttribute(decodedValue) } suspend fun subscribeSecurityTypeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - SecurityTypeAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(SecurityTypeAttributeSubscriptionState.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) { "Securitytype attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Securitytype 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.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(SecurityTypeAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(SecurityTypeAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(SecurityTypeAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readWiFiVersionAttribute(): WiFiVersionAttribute { - val ATTRIBUTE_ID: UInt = 2u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readWiFiVersionAttribute(): WiFiVersionAttribute {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}") - } + 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) { "Wifiversion attribute not found in response" } + } + + requireNotNull(attributeData) { + "Wifiversion attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return WiFiVersionAttribute(decodedValue) } suspend fun subscribeWiFiVersionAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - WiFiVersionAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(WiFiVersionAttributeSubscriptionState.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) { "Wifiversion attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Wifiversion 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.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(WiFiVersionAttributeSubscriptionState.Success(it)) } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(WiFiVersionAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(WiFiVersionAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readChannelNumberAttribute(): ChannelNumberAttribute { - val ATTRIBUTE_ID: UInt = 3u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readChannelNumberAttribute(): ChannelNumberAttribute {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}") - } + 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) { "Channelnumber attribute not found in response" } + } + + requireNotNull(attributeData) { + "Channelnumber attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = - if (!tlvReader.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return ChannelNumberAttribute(decodedValue) } suspend fun subscribeChannelNumberAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - ChannelNumberAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(ChannelNumberAttributeSubscriptionState.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) { "Channelnumber attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Channelnumber 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.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(ChannelNumberAttributeSubscriptionState.Success(it)) } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(ChannelNumberAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(ChannelNumberAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readRssiAttribute(): RssiAttribute { - val ATTRIBUTE_ID: UInt = 4u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readRssiAttribute(): RssiAttribute {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}") - } + 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) { "Rssi attribute not found in response" } + } + + requireNotNull(attributeData) { + "Rssi attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Byte? = - if (!tlvReader.isNull()) { - tlvReader.getByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Byte? = if (!tlvReader.isNull()) { + tlvReader.getByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return RssiAttribute(decodedValue) } suspend fun subscribeRssiAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - RssiAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(RssiAttributeSubscriptionState.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) { "Rssi attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Rssi attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Byte? = - if (!tlvReader.isNull()) { - tlvReader.getByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(RssiAttributeSubscriptionState.Success(it)) } + val decodedValue: Byte? = if (!tlvReader.isNull()) { + tlvReader.getByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(RssiAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(RssiAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readBeaconLostCountAttribute(): BeaconLostCountAttribute { - val ATTRIBUTE_ID: UInt = 5u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readBeaconLostCountAttribute(): BeaconLostCountAttribute {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}") - } + 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) { "Beaconlostcount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Beaconlostcount attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return BeaconLostCountAttribute(decodedValue) } suspend fun subscribeBeaconLostCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - BeaconLostCountAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(BeaconLostCountAttributeSubscriptionState.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) { - "Beaconlostcount attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Beaconlostcount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(BeaconLostCountAttributeSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(BeaconLostCountAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(BeaconLostCountAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readBeaconRxCountAttribute(): BeaconRxCountAttribute { - val ATTRIBUTE_ID: UInt = 6u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readBeaconRxCountAttribute(): BeaconRxCountAttribute {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}") - } + 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) { "Beaconrxcount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Beaconrxcount attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return BeaconRxCountAttribute(decodedValue) } suspend fun subscribeBeaconRxCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - BeaconRxCountAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(BeaconRxCountAttributeSubscriptionState.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) { "Beaconrxcount attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Beaconrxcount attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(BeaconRxCountAttributeSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(BeaconRxCountAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(BeaconRxCountAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readPacketMulticastRxCountAttribute(): PacketMulticastRxCountAttribute { - val ATTRIBUTE_ID: UInt = 7u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readPacketMulticastRxCountAttribute(): PacketMulticastRxCountAttribute {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}") - } + 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) { "Packetmulticastrxcount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Packetmulticastrxcount attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return PacketMulticastRxCountAttribute(decodedValue) } suspend fun subscribePacketMulticastRxCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - PacketMulticastRxCountAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(PacketMulticastRxCountAttributeSubscriptionState.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) { - "Packetmulticastrxcount attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Packetmulticastrxcount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(PacketMulticastRxCountAttributeSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(PacketMulticastRxCountAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(PacketMulticastRxCountAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readPacketMulticastTxCountAttribute(): PacketMulticastTxCountAttribute { - val ATTRIBUTE_ID: UInt = 8u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readPacketMulticastTxCountAttribute(): PacketMulticastTxCountAttribute {val ATTRIBUTE_ID: UInt = 8u + + 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}") - } + 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) { "Packetmulticasttxcount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Packetmulticasttxcount attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return PacketMulticastTxCountAttribute(decodedValue) } suspend fun subscribePacketMulticastTxCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - PacketMulticastTxCountAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(PacketMulticastTxCountAttributeSubscriptionState.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) { - "Packetmulticasttxcount attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Packetmulticasttxcount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(PacketMulticastTxCountAttributeSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(PacketMulticastTxCountAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(PacketMulticastTxCountAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readPacketUnicastRxCountAttribute(): PacketUnicastRxCountAttribute { - val ATTRIBUTE_ID: UInt = 9u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readPacketUnicastRxCountAttribute(): PacketUnicastRxCountAttribute {val ATTRIBUTE_ID: UInt = 9u + + 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}") - } + 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) { "Packetunicastrxcount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Packetunicastrxcount attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return PacketUnicastRxCountAttribute(decodedValue) } suspend fun subscribePacketUnicastRxCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - PacketUnicastRxCountAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(PacketUnicastRxCountAttributeSubscriptionState.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) { - "Packetunicastrxcount attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Packetunicastrxcount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(PacketUnicastRxCountAttributeSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(PacketUnicastRxCountAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(PacketUnicastRxCountAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readPacketUnicastTxCountAttribute(): PacketUnicastTxCountAttribute { - val ATTRIBUTE_ID: UInt = 10u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readPacketUnicastTxCountAttribute(): PacketUnicastTxCountAttribute {val ATTRIBUTE_ID: UInt = 10u + + 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}") - } + 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) { "Packetunicasttxcount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Packetunicasttxcount attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return PacketUnicastTxCountAttribute(decodedValue) } suspend fun subscribePacketUnicastTxCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - PacketUnicastTxCountAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(PacketUnicastTxCountAttributeSubscriptionState.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) { - "Packetunicasttxcount attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Packetunicasttxcount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(PacketUnicastTxCountAttributeSubscriptionState.Success(it)) } + val decodedValue: UInt? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(PacketUnicastTxCountAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(PacketUnicastTxCountAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readCurrentMaxRateAttribute(): CurrentMaxRateAttribute { - val ATTRIBUTE_ID: UInt = 11u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readCurrentMaxRateAttribute(): CurrentMaxRateAttribute {val ATTRIBUTE_ID: UInt = 11u + + 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}") - } + 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) { "Currentmaxrate attribute not found in response" } + } + + requireNotNull(attributeData) { + "Currentmaxrate 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 - } + val decodedValue: ULong? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return CurrentMaxRateAttribute(decodedValue) } suspend fun subscribeCurrentMaxRateAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 11u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - CurrentMaxRateAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(CurrentMaxRateAttributeSubscriptionState.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) { - "Currentmaxrate attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Currentmaxrate 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(CurrentMaxRateAttributeSubscriptionState.Success(it)) } + val decodedValue: ULong? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(CurrentMaxRateAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(CurrentMaxRateAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readOverrunCountAttribute(): OverrunCountAttribute { - val ATTRIBUTE_ID: UInt = 12u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readOverrunCountAttribute(): OverrunCountAttribute {val ATTRIBUTE_ID: UInt = 12u + + 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}") - } + 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) { "Overruncount attribute not found in response" } + } + + requireNotNull(attributeData) { + "Overruncount 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 - } + val decodedValue: ULong? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return OverrunCountAttribute(decodedValue) } suspend fun subscribeOverrunCountAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 12u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - OverrunCountAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(OverrunCountAttributeSubscriptionState.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) { "Overruncount attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Overruncount 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(OverrunCountAttributeSubscriptionState.Success(it)) } + val decodedValue: ULong? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(OverrunCountAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(OverrunCountAttributeSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1609,96 +1745,97 @@ class WiFiNetworkDiagnosticsCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1706,94 +1843,97 @@ class WiFiNetworkDiagnosticsCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1801,94 +1941,97 @@ class WiFiNetworkDiagnosticsCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1896,76 +2039,81 @@ class WiFiNetworkDiagnosticsCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -1977,77 +2125,80 @@ class WiFiNetworkDiagnosticsCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -2060,7 +2211,7 @@ class WiFiNetworkDiagnosticsCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/WiFiNetworkManagementCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/WiFiNetworkManagementCluster.kt index 48efb1cea1f4b2..4b65842446ee0e 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/WiFiNetworkManagementCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/WiFiNetworkManagementCluster.kt @@ -17,108 +17,143 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.UIntSubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState +import matter.controller.UByteSubscriptionState import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.WriteRequest +import matter.controller.WriteRequests +import matter.controller.WriteResponse +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class WiFiNetworkManagementCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class NetworkPassphraseResponse(val passphrase: ByteArray) - - class SsidAttribute(val value: ByteArray?) +class WiFiNetworkManagementCluster(private val controller: MatterController, private val endpointId: UShort) { + class NetworkPassphraseResponse( + val passphrase: ByteArray + ) +class SsidAttribute( + val value: ByteArray? + ) sealed class SsidAttributeSubscriptionState { - data class Success(val value: ByteArray?) : SsidAttributeSubscriptionState() - + data class Success( + val value: ByteArray? + ) : SsidAttributeSubscriptionState() + data class Error(val exception: Exception) : SsidAttributeSubscriptionState() - object SubscriptionEstablished : SsidAttributeSubscriptionState() - } - - class PassphraseSurrogateAttribute(val value: ULong?) + object SubscriptionEstablished : SsidAttributeSubscriptionState() + } +class PassphraseSurrogateAttribute( + val value: ULong? + ) sealed class PassphraseSurrogateAttributeSubscriptionState { - data class Success(val value: ULong?) : PassphraseSurrogateAttributeSubscriptionState() - + data class Success( + val value: ULong? + ) : PassphraseSurrogateAttributeSubscriptionState() + data class Error(val exception: Exception) : PassphraseSurrogateAttributeSubscriptionState() - object SubscriptionEstablished : PassphraseSurrogateAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + object SubscriptionEstablished : PassphraseSurrogateAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun networkPassphraseRequest( - timedInvokeTimeout: Duration? = null - ): NetworkPassphraseResponse { + suspend fun networkPassphraseRequest(timedInvokeTimeout: Duration? = null): NetworkPassphraseResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -128,301 +163,320 @@ class WiFiNetworkManagementCluster( tlvReader.enterStructure(AnonymousTag) val TAG_PASSPHRASE: Int = 0 var passphrase_decoded: ByteArray? = null + while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - if (tag == ContextSpecificTag(TAG_PASSPHRASE)) { - passphrase_decoded = tlvReader.getByteArray(tag) - } else { + + if (tag == ContextSpecificTag(TAG_PASSPHRASE)) {passphrase_decoded = tlvReader.getByteArray(tag)} + + + else { tlvReader.skipElement() } } + + if (passphrase_decoded == null) { - throw IllegalStateException("passphrase not found in TLV") + throw IllegalStateException("passphrase not found in TLV") } + tlvReader.exitContainer() - return NetworkPassphraseResponse(passphrase_decoded) + return NetworkPassphraseResponse( + passphrase_decoded + ) } - - suspend fun readSsidAttribute(): SsidAttribute { - val ATTRIBUTE_ID: UInt = 0u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readSsidAttribute(): SsidAttribute {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}") - } + 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) { "Ssid attribute not found in response" } + } + + requireNotNull(attributeData) { + "Ssid attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = - if (!tlvReader.isNull()) { - tlvReader.getByteArray(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ByteArray? = if (!tlvReader.isNull()) { + tlvReader.getByteArray(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return SsidAttribute(decodedValue) } suspend fun subscribeSsidAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - SsidAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(SsidAttributeSubscriptionState.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) { "Ssid attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Ssid attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = - if (!tlvReader.isNull()) { - tlvReader.getByteArray(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(SsidAttributeSubscriptionState.Success(it)) } + val decodedValue: ByteArray? = if (!tlvReader.isNull()) { + tlvReader.getByteArray(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(SsidAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(SsidAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } - - suspend fun readPassphraseSurrogateAttribute(): PassphraseSurrogateAttribute { - val ATTRIBUTE_ID: UInt = 1u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - +suspend fun readPassphraseSurrogateAttribute(): PassphraseSurrogateAttribute {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}") - } + 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) { "Passphrasesurrogate attribute not found in response" } + } + + requireNotNull(attributeData) { + "Passphrasesurrogate attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ULong? = - if (!tlvReader.isNull()) { - tlvReader.getULong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ULong? = if (!tlvReader.isNull()) { + tlvReader.getULong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + return PassphraseSurrogateAttribute(decodedValue) } suspend fun subscribePassphraseSurrogateAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - PassphraseSurrogateAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(PassphraseSurrogateAttributeSubscriptionState.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) { - "Passphrasesurrogate attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Passphrasesurrogate 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()) { - tlvReader.getULong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(PassphraseSurrogateAttributeSubscriptionState.Success(it)) } + val decodedValue: ULong? = if (!tlvReader.isNull()) { + tlvReader.getULong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(PassphraseSurrogateAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(PassphraseSurrogateAttributeSubscriptionState.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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -430,96 +484,97 @@ class WiFiNetworkManagementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -527,94 +582,97 @@ class WiFiNetworkManagementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -622,94 +680,97 @@ class WiFiNetworkManagementCluster( 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)) - +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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -717,76 +778,81 @@ class WiFiNetworkManagementCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -798,77 +864,80 @@ class WiFiNetworkManagementCluster( 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)) - +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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -881,7 +950,7 @@ class WiFiNetworkManagementCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/WindowCoveringCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/WindowCoveringCluster.kt index 6c0b93c6a67575..d47645e5b75dca 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/WindowCoveringCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/WindowCoveringCluster.kt @@ -17,180 +17,217 @@ package matter.controller.cluster.clusters -import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadData import matter.controller.ReadRequest +import matter.controller.ReadData +import matter.controller.ReadFailure +import matter.controller.ReadResponse import matter.controller.SubscribeRequest import matter.controller.SubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.ShortSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.LongSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.CharSubscriptionState +import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState import matter.controller.UShortSubscriptionState +import matter.controller.UIntSubscriptionState +import matter.controller.ULongSubscriptionState +import matter.controller.StringSubscriptionState +import matter.controller.ByteArraySubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.cluster.structs.* +import matter.controller.AttributeWriteError +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.model.AttributePath import matter.controller.model.CommandPath +import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class WindowCoveringCluster( - private val controller: MatterController, - private val endpointId: UShort, -) { - class CurrentPositionLiftAttribute(val value: UShort?) +class WindowCoveringCluster(private val controller: MatterController, private val endpointId: UShort) {class CurrentPositionLiftAttribute( + val value: UShort? + ) sealed class CurrentPositionLiftAttributeSubscriptionState { - data class Success(val value: UShort?) : CurrentPositionLiftAttributeSubscriptionState() - + data class Success( + val value: UShort? + ) : CurrentPositionLiftAttributeSubscriptionState() + data class Error(val exception: Exception) : CurrentPositionLiftAttributeSubscriptionState() - object SubscriptionEstablished : CurrentPositionLiftAttributeSubscriptionState() - } - - class CurrentPositionTiltAttribute(val value: UShort?) + object SubscriptionEstablished : CurrentPositionLiftAttributeSubscriptionState() + } +class CurrentPositionTiltAttribute( + val value: UShort? + ) sealed class CurrentPositionTiltAttributeSubscriptionState { - data class Success(val value: UShort?) : CurrentPositionTiltAttributeSubscriptionState() - + data class Success( + val value: UShort? + ) : CurrentPositionTiltAttributeSubscriptionState() + data class Error(val exception: Exception) : CurrentPositionTiltAttributeSubscriptionState() - object SubscriptionEstablished : CurrentPositionTiltAttributeSubscriptionState() - } - - class CurrentPositionLiftPercentageAttribute(val value: UByte?) + object SubscriptionEstablished : CurrentPositionTiltAttributeSubscriptionState() + } +class CurrentPositionLiftPercentageAttribute( + val value: UByte? + ) sealed class CurrentPositionLiftPercentageAttributeSubscriptionState { - data class Success(val value: UByte?) : - CurrentPositionLiftPercentageAttributeSubscriptionState() - - data class Error(val exception: Exception) : - CurrentPositionLiftPercentageAttributeSubscriptionState() - - object SubscriptionEstablished : CurrentPositionLiftPercentageAttributeSubscriptionState() - } - - class CurrentPositionTiltPercentageAttribute(val value: UByte?) + data class Success( + val value: UByte? + ) : CurrentPositionLiftPercentageAttributeSubscriptionState() + + data class Error(val exception: Exception) : CurrentPositionLiftPercentageAttributeSubscriptionState() + + object SubscriptionEstablished : CurrentPositionLiftPercentageAttributeSubscriptionState() + } +class CurrentPositionTiltPercentageAttribute( + val value: UByte? + ) sealed class CurrentPositionTiltPercentageAttributeSubscriptionState { - data class Success(val value: UByte?) : - CurrentPositionTiltPercentageAttributeSubscriptionState() - - data class Error(val exception: Exception) : - CurrentPositionTiltPercentageAttributeSubscriptionState() - - object SubscriptionEstablished : CurrentPositionTiltPercentageAttributeSubscriptionState() - } - - class TargetPositionLiftPercent100thsAttribute(val value: UShort?) + data class Success( + val value: UByte? + ) : CurrentPositionTiltPercentageAttributeSubscriptionState() + + data class Error(val exception: Exception) : CurrentPositionTiltPercentageAttributeSubscriptionState() + + object SubscriptionEstablished : CurrentPositionTiltPercentageAttributeSubscriptionState() + } +class TargetPositionLiftPercent100thsAttribute( + val value: UShort? + ) sealed class TargetPositionLiftPercent100thsAttributeSubscriptionState { - data class Success(val value: UShort?) : - TargetPositionLiftPercent100thsAttributeSubscriptionState() - - data class Error(val exception: Exception) : - TargetPositionLiftPercent100thsAttributeSubscriptionState() - - object SubscriptionEstablished : TargetPositionLiftPercent100thsAttributeSubscriptionState() - } - - class TargetPositionTiltPercent100thsAttribute(val value: UShort?) + data class Success( + val value: UShort? + ) : TargetPositionLiftPercent100thsAttributeSubscriptionState() + + data class Error(val exception: Exception) : TargetPositionLiftPercent100thsAttributeSubscriptionState() + + object SubscriptionEstablished : TargetPositionLiftPercent100thsAttributeSubscriptionState() + } +class TargetPositionTiltPercent100thsAttribute( + val value: UShort? + ) sealed class TargetPositionTiltPercent100thsAttributeSubscriptionState { - data class Success(val value: UShort?) : - TargetPositionTiltPercent100thsAttributeSubscriptionState() - - data class Error(val exception: Exception) : - TargetPositionTiltPercent100thsAttributeSubscriptionState() - - object SubscriptionEstablished : TargetPositionTiltPercent100thsAttributeSubscriptionState() - } - - class CurrentPositionLiftPercent100thsAttribute(val value: UShort?) + data class Success( + val value: UShort? + ) : TargetPositionTiltPercent100thsAttributeSubscriptionState() + + data class Error(val exception: Exception) : TargetPositionTiltPercent100thsAttributeSubscriptionState() + + object SubscriptionEstablished : TargetPositionTiltPercent100thsAttributeSubscriptionState() + } +class CurrentPositionLiftPercent100thsAttribute( + val value: UShort? + ) sealed class CurrentPositionLiftPercent100thsAttributeSubscriptionState { - data class Success(val value: UShort?) : - CurrentPositionLiftPercent100thsAttributeSubscriptionState() - - data class Error(val exception: Exception) : - CurrentPositionLiftPercent100thsAttributeSubscriptionState() - - object SubscriptionEstablished : CurrentPositionLiftPercent100thsAttributeSubscriptionState() - } - - class CurrentPositionTiltPercent100thsAttribute(val value: UShort?) + data class Success( + val value: UShort? + ) : CurrentPositionLiftPercent100thsAttributeSubscriptionState() + + data class Error(val exception: Exception) : CurrentPositionLiftPercent100thsAttributeSubscriptionState() + + object SubscriptionEstablished : CurrentPositionLiftPercent100thsAttributeSubscriptionState() + } +class CurrentPositionTiltPercent100thsAttribute( + val value: UShort? + ) sealed class CurrentPositionTiltPercent100thsAttributeSubscriptionState { - data class Success(val value: UShort?) : - CurrentPositionTiltPercent100thsAttributeSubscriptionState() - - data class Error(val exception: Exception) : - CurrentPositionTiltPercent100thsAttributeSubscriptionState() - - object SubscriptionEstablished : CurrentPositionTiltPercent100thsAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) + data class Success( + val value: UShort? + ) : CurrentPositionTiltPercent100thsAttributeSubscriptionState() + + data class Error(val exception: Exception) : CurrentPositionTiltPercent100thsAttributeSubscriptionState() + + object SubscriptionEstablished : CurrentPositionTiltPercent100thsAttributeSubscriptionState() + } +class GeneratedCommandListAttribute( + val value: List + ) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } +class AcceptedCommandListAttribute( + val value: List + ) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } +class EventListAttribute( + val value: List + ) sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - + data class Success( + val value: List + ) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } +class AttributeListAttribute( + val value: List + ) sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - + data class Success( + val value: List + ) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } suspend fun upOrOpen(timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -201,14 +238,14 @@ class WindowCoveringCluster( val commandId: UInt = 1u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) @@ -219,177 +256,180 @@ class WindowCoveringCluster( val commandId: UInt = 2u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun goToLiftValue(liftValue: UShort, timedInvokeTimeout: Duration? = null) { + suspend fun goToLiftValue(liftValue: UShort + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 4u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_LIFT_VALUE_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_LIFT_VALUE_REQ), liftValue) + tlvWriter.put(ContextSpecificTag(TAG_LIFT_VALUE_REQ), liftValue) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun goToLiftPercentage( - liftPercent100thsValue: UShort, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun goToLiftPercentage(liftPercent100thsValue: UShort + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 5u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_LIFT_PERCENT100THS_VALUE_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_LIFT_PERCENT100THS_VALUE_REQ), liftPercent100thsValue) + tlvWriter.put(ContextSpecificTag(TAG_LIFT_PERCENT100THS_VALUE_REQ), liftPercent100thsValue) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun goToTiltValue(tiltValue: UShort, timedInvokeTimeout: Duration? = null) { + suspend fun goToTiltValue(tiltValue: UShort + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 7u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_TILT_VALUE_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_TILT_VALUE_REQ), tiltValue) + tlvWriter.put(ContextSpecificTag(TAG_TILT_VALUE_REQ), tiltValue) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun goToTiltPercentage( - tiltPercent100thsValue: UShort, - timedInvokeTimeout: Duration? = null, - ) { + suspend fun goToTiltPercentage(tiltPercent100thsValue: UShort + ,timedInvokeTimeout: Duration? = null) { val commandId: UInt = 8u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_TILT_PERCENT100THS_VALUE_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_TILT_PERCENT100THS_VALUE_REQ), tiltPercent100thsValue) + tlvWriter.put(ContextSpecificTag(TAG_TILT_PERCENT100THS_VALUE_REQ), tiltPercent100thsValue) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout, + timedRequest = timedInvokeTimeout ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } +suspend fun readTypeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 0u - suspend fun readTypeAttribute(): 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 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}") - } + 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) { "Type attribute not found in response" } + } + + requireNotNull(attributeData) { + "Type 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 subscribeTypeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Type attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Type attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -401,654 +441,683 @@ class WindowCoveringCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readPhysicalClosedLimitLiftAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 1u - suspend fun readPhysicalClosedLimitLiftAttribute(): UShort? { - 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 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}") - } + 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) { "Physicalclosedlimitlift attribute not found in response" } + } + + requireNotNull(attributeData) { + "Physicalclosedlimitlift 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribePhysicalClosedLimitLiftAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Physicalclosedlimitlift attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Physicalclosedlimitlift 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readPhysicalClosedLimitTiltAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2u - suspend fun readPhysicalClosedLimitTiltAttribute(): 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 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}") - } + 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) { "Physicalclosedlimittilt attribute not found in response" } + } + + requireNotNull(attributeData) { + "Physicalclosedlimittilt 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribePhysicalClosedLimitTiltAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Physicalclosedlimittilt attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Physicalclosedlimittilt 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readCurrentPositionLiftAttribute(): CurrentPositionLiftAttribute {val ATTRIBUTE_ID: UInt = 3u - suspend fun readCurrentPositionLiftAttribute(): CurrentPositionLiftAttribute { - 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 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}") - } + 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) { "Currentpositionlift attribute not found in response" } + } + + requireNotNull(attributeData) { + "Currentpositionlift attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return CurrentPositionLiftAttribute(decodedValue) } suspend fun subscribeCurrentPositionLiftAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - CurrentPositionLiftAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(CurrentPositionLiftAttributeSubscriptionState.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) { - "Currentpositionlift attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Currentpositionlift 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(CurrentPositionLiftAttributeSubscriptionState.Success(it)) } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(CurrentPositionLiftAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(CurrentPositionLiftAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readCurrentPositionTiltAttribute(): CurrentPositionTiltAttribute {val ATTRIBUTE_ID: UInt = 4u - suspend fun readCurrentPositionTiltAttribute(): CurrentPositionTiltAttribute { - 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 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}") - } + 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) { "Currentpositiontilt attribute not found in response" } + } + + requireNotNull(attributeData) { + "Currentpositiontilt attribute not found in response" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return CurrentPositionTiltAttribute(decodedValue) } suspend fun subscribeCurrentPositionTiltAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - CurrentPositionTiltAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(CurrentPositionTiltAttributeSubscriptionState.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) { - "Currentpositiontilt attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Currentpositiontilt 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(CurrentPositionTiltAttributeSubscriptionState.Success(it)) } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { + emit(CurrentPositionTiltAttributeSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(CurrentPositionTiltAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNumberOfActuationsLiftAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 5u - suspend fun readNumberOfActuationsLiftAttribute(): UShort? { - 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 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}") - } + 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) { "Numberofactuationslift attribute not found in response" } + } + + requireNotNull(attributeData) { + "Numberofactuationslift 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeNumberOfActuationsLiftAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Numberofactuationslift attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Numberofactuationslift 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readNumberOfActuationsTiltAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 6u - suspend fun readNumberOfActuationsTiltAttribute(): 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 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}") - } + 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) { "Numberofactuationstilt attribute not found in response" } + } + + requireNotNull(attributeData) { + "Numberofactuationstilt 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeNumberOfActuationsTiltAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Numberofactuationstilt attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Numberofactuationstilt 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readConfigStatusAttribute(): UByte {val ATTRIBUTE_ID: UInt = 7u - suspend fun readConfigStatusAttribute(): UByte { - 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 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}") - } + 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) { "Configstatus attribute not found in response" } + } + + requireNotNull(attributeData) { + "Configstatus 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 subscribeConfigStatusAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Configstatus attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Configstatus attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -1060,291 +1129,294 @@ class WindowCoveringCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readCurrentPositionLiftPercentageAttribute(): CurrentPositionLiftPercentageAttribute {val ATTRIBUTE_ID: UInt = 8u - suspend fun readCurrentPositionLiftPercentageAttribute(): CurrentPositionLiftPercentageAttribute { - val ATTRIBUTE_ID: UInt = 8u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { - "Currentpositionliftpercentage attribute not found in response" + } + + requireNotNull(attributeData) { + "Currentpositionliftpercentage attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return CurrentPositionLiftPercentageAttribute(decodedValue) } suspend fun subscribeCurrentPositionLiftPercentageAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - CurrentPositionLiftPercentageAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(CurrentPositionLiftPercentageAttributeSubscriptionState.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) { - "Currentpositionliftpercentage attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Currentpositionliftpercentage 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } decodedValue?.let { emit(CurrentPositionLiftPercentageAttributeSubscriptionState.Success(it)) } + } SubscriptionState.SubscriptionEstablished -> { emit(CurrentPositionLiftPercentageAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readCurrentPositionTiltPercentageAttribute(): CurrentPositionTiltPercentageAttribute {val ATTRIBUTE_ID: UInt = 9u - suspend fun readCurrentPositionTiltPercentageAttribute(): CurrentPositionTiltPercentageAttribute { - val ATTRIBUTE_ID: UInt = 9u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { - "Currentpositiontiltpercentage attribute not found in response" + } + + requireNotNull(attributeData) { + "Currentpositiontiltpercentage attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return CurrentPositionTiltPercentageAttribute(decodedValue) } suspend fun subscribeCurrentPositionTiltPercentageAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - CurrentPositionTiltPercentageAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(CurrentPositionTiltPercentageAttributeSubscriptionState.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) { - "Currentpositiontiltpercentage attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Currentpositiontiltpercentage 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } decodedValue?.let { emit(CurrentPositionTiltPercentageAttributeSubscriptionState.Success(it)) } + } SubscriptionState.SubscriptionEstablished -> { emit(CurrentPositionTiltPercentageAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readOperationalStatusAttribute(): UByte {val ATTRIBUTE_ID: UInt = 10u - suspend fun readOperationalStatusAttribute(): UByte { - val ATTRIBUTE_ID: UInt = 10u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Operationalstatus attribute not found in response" } + } + + requireNotNull(attributeData) { + "Operationalstatus 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 subscribeOperationalStatusAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Operationalstatus attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Operationalstatus attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -1357,293 +1429,294 @@ class WindowCoveringCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readTargetPositionLiftPercent100thsAttribute(): TargetPositionLiftPercent100thsAttribute {val ATTRIBUTE_ID: UInt = 11u - suspend fun readTargetPositionLiftPercent100thsAttribute(): - TargetPositionLiftPercent100thsAttribute { - val ATTRIBUTE_ID: UInt = 11u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { - "Targetpositionliftpercent100ths attribute not found in response" + } + + requireNotNull(attributeData) { + "Targetpositionliftpercent100ths attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return TargetPositionLiftPercent100thsAttribute(decodedValue) } suspend fun subscribeTargetPositionLiftPercent100thsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 11u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - TargetPositionLiftPercent100thsAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(TargetPositionLiftPercent100thsAttributeSubscriptionState.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) { - "Targetpositionliftpercent100ths attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Targetpositionliftpercent100ths 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } decodedValue?.let { emit(TargetPositionLiftPercent100thsAttributeSubscriptionState.Success(it)) } + } SubscriptionState.SubscriptionEstablished -> { emit(TargetPositionLiftPercent100thsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readTargetPositionTiltPercent100thsAttribute(): TargetPositionTiltPercent100thsAttribute {val ATTRIBUTE_ID: UInt = 12u - suspend fun readTargetPositionTiltPercent100thsAttribute(): - TargetPositionTiltPercent100thsAttribute { - val ATTRIBUTE_ID: UInt = 12u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { + "Targetpositiontiltpercent100ths attribute not found in response" + } - requireNotNull(attributeData) { - "Targetpositiontiltpercent100ths attribute not found in response" + // Decode the TLV data into the appropriate type + val tlvReader = TlvReader(attributeData.data) + val decodedValue: UShort? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null } - // Decode the TLV data into the appropriate type - val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } return TargetPositionTiltPercent100thsAttribute(decodedValue) } suspend fun subscribeTargetPositionTiltPercent100thsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 12u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - TargetPositionTiltPercent100thsAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(TargetPositionTiltPercent100thsAttributeSubscriptionState.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) { - "Targetpositiontiltpercent100ths attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Targetpositiontiltpercent100ths 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } decodedValue?.let { emit(TargetPositionTiltPercent100thsAttributeSubscriptionState.Success(it)) } + } SubscriptionState.SubscriptionEstablished -> { emit(TargetPositionTiltPercent100thsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readEndProductTypeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 13u - suspend fun readEndProductTypeAttribute(): UByte { - val ATTRIBUTE_ID: UInt = 13u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Endproducttype attribute not found in response" } + } + + requireNotNull(attributeData) { + "Endproducttype 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 subscribeEndProductTypeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 13u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Endproducttype attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Endproducttype attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -1656,645 +1729,670 @@ class WindowCoveringCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readCurrentPositionLiftPercent100thsAttribute(): CurrentPositionLiftPercent100thsAttribute {val ATTRIBUTE_ID: UInt = 14u - suspend fun readCurrentPositionLiftPercent100thsAttribute(): - CurrentPositionLiftPercent100thsAttribute { - val ATTRIBUTE_ID: UInt = 14u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { - "Currentpositionliftpercent100ths attribute not found in response" + } + + requireNotNull(attributeData) { + "Currentpositionliftpercent100ths attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return CurrentPositionLiftPercent100thsAttribute(decodedValue) } suspend fun subscribeCurrentPositionLiftPercent100thsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 14u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - CurrentPositionLiftPercent100thsAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(CurrentPositionLiftPercent100thsAttributeSubscriptionState.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) { - "Currentpositionliftpercent100ths attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Currentpositionliftpercent100ths 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } decodedValue?.let { emit(CurrentPositionLiftPercent100thsAttributeSubscriptionState.Success(it)) } + } SubscriptionState.SubscriptionEstablished -> { emit(CurrentPositionLiftPercent100thsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readCurrentPositionTiltPercent100thsAttribute(): CurrentPositionTiltPercent100thsAttribute {val ATTRIBUTE_ID: UInt = 15u - suspend fun readCurrentPositionTiltPercent100thsAttribute(): - CurrentPositionTiltPercent100thsAttribute { - val ATTRIBUTE_ID: UInt = 15u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { - "Currentpositiontiltpercent100ths attribute not found in response" + } + + requireNotNull(attributeData) { + "Currentpositiontiltpercent100ths attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + return CurrentPositionTiltPercent100thsAttribute(decodedValue) } suspend fun subscribeCurrentPositionTiltPercent100thsAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 15u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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( - CurrentPositionTiltPercent100thsAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) + emit(CurrentPositionTiltPercent100thsAttributeSubscriptionState.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) { - "Currentpositiontiltpercent100ths attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Currentpositiontiltpercent100ths 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } decodedValue?.let { emit(CurrentPositionTiltPercent100thsAttributeSubscriptionState.Success(it)) } + } SubscriptionState.SubscriptionEstablished -> { emit(CurrentPositionTiltPercent100thsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readInstalledOpenLimitLiftAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 16u - suspend fun readInstalledOpenLimitLiftAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 16u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Installedopenlimitlift attribute not found in response" } + } + + requireNotNull(attributeData) { + "Installedopenlimitlift 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeInstalledOpenLimitLiftAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 16u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Installedopenlimitlift attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Installedopenlimitlift 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readInstalledClosedLimitLiftAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 17u - suspend fun readInstalledClosedLimitLiftAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 17u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Installedclosedlimitlift attribute not found in response" } + } + + requireNotNull(attributeData) { + "Installedclosedlimitlift 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeInstalledClosedLimitLiftAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 17u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Installedclosedlimitlift attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Installedclosedlimitlift 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readInstalledOpenLimitTiltAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 18u - suspend fun readInstalledOpenLimitTiltAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 18u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Installedopenlimittilt attribute not found in response" } + } + + requireNotNull(attributeData) { + "Installedopenlimittilt 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeInstalledOpenLimitTiltAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 18u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Installedopenlimittilt attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Installedopenlimittilt 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readInstalledClosedLimitTiltAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 19u - suspend fun readInstalledClosedLimitTiltAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 19u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Installedclosedlimittilt attribute not found in response" } + } + + requireNotNull(attributeData) { + "Installedclosedlimittilt 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeInstalledClosedLimitTiltAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 19u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { - "Installedclosedlimittilt attribute not found in Node State update" + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Installedclosedlimittilt 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readModeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 23u - suspend fun readModeAttribute(): UByte { - val ATTRIBUTE_ID: UInt = 23u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Mode attribute not found in response" } + } + + requireNotNull(attributeData) { + "Mode 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 writeModeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { + suspend fun writeModeAttribute( + value: UByte, + timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 23u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = - listOf( - WriteRequest( - attributePath = - AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), - tlvPayload = tlvWriter.getEncoded(), - ) - ), - timedRequest = timedWriteTimeout, + requests = listOf( + WriteRequest( + attributePath = AttributePath( + endpointId, + clusterId = CLUSTER_ID, + attributeId = ATTRIBUTE_ID + ), + tlvPayload = tlvWriter.getEncoded() + ) + ), + timedRequest = timedWriteTimeout ) val response: WriteResponse = controller.write(writeRequests) @@ -2315,45 +2413,43 @@ class WindowCoveringCluster( throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeModeAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 23u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Mode attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Mode attribute not found in Node State update" + } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -2365,187 +2461,194 @@ class WindowCoveringCluster( emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readSafetyStatusAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 26u - suspend fun readSafetyStatusAttribute(): UShort? { - val ATTRIBUTE_ID: UInt = 26u - - val attributePath = - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - - val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + 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}") - } + 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) { "Safetystatus attribute not found in response" } + } + + requireNotNull(attributeData) { + "Safetystatus 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + return decodedValue } suspend fun subscribeSafetyStatusAttribute( minInterval: Int, - maxInterval: Int, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 26u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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) { "Safetystatus attribute not found in Node State update" } + subscriptionState.updateState.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { + "Safetystatus 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 - } + val decodedValue: UShort? = if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } + decodedValue?.let { + emit(UShortSubscriptionState.Success(it)) + } + } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65528u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -2553,96 +2656,97 @@ class WindowCoveringCluster( emit(GeneratedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65529u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -2650,94 +2754,97 @@ class WindowCoveringCluster( emit(AcceptedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt = 65530u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -2745,94 +2852,97 @@ class WindowCoveringCluster( emit(EventListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ID: UInt = 65531u - 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 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}") - } + 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" } + } + + 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() + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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() - } + val decodedValue: List = buildList { + tlvReader.enterArray(AnonymousTag) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -2840,76 +2950,81 @@ class WindowCoveringCluster( emit(AttributeListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u - 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 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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" } + 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) @@ -2921,77 +3036,80 @@ class WindowCoveringCluster( emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } +suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 65533u - 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 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}") - } + 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" } + } + + 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, + maxInterval: Int ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + 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()), - ) + 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}" - ) - ) - ) + 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" + 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 @@ -3004,7 +3122,7 @@ class WindowCoveringCluster( emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/AccessControlClusterAccessControlEntryChangedEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/AccessControlClusterAccessControlEntryChangedEvent.kt index 2ac4b28ebebcb9..2fdbf26e1294da 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/AccessControlClusterAccessControlEntryChangedEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/AccessControlClusterAccessControlEntryChangedEvent.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -27,7 +29,7 @@ class AccessControlClusterAccessControlEntryChangedEvent( val adminPasscodeID: UShort?, val changeType: UByte, val latestValue: matter.controller.cluster.structs.AccessControlClusterAccessControlEntryStruct?, - val fabricIndex: UByte, + val fabricIndex: UByte ) { override fun toString(): String = buildString { append("AccessControlClusterAccessControlEntryChangedEvent {\n") @@ -70,47 +72,32 @@ class AccessControlClusterAccessControlEntryChangedEvent( private const val TAG_LATEST_VALUE = 4 private const val TAG_FABRIC_INDEX = 254 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): AccessControlClusterAccessControlEntryChangedEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : AccessControlClusterAccessControlEntryChangedEvent { tlvReader.enterStructure(tlvTag) - val adminNodeID = - if (!tlvReader.isNull()) { - tlvReader.getULong(ContextSpecificTag(TAG_ADMIN_NODE_ID)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_ADMIN_NODE_ID)) - null - } - val adminPasscodeID = - if (!tlvReader.isNull()) { - tlvReader.getUShort(ContextSpecificTag(TAG_ADMIN_PASSCODE_ID)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_ADMIN_PASSCODE_ID)) - null - } + val adminNodeID = if (!tlvReader.isNull()) { + tlvReader.getULong(ContextSpecificTag(TAG_ADMIN_NODE_ID)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_ADMIN_NODE_ID)) + null + } + val adminPasscodeID = if (!tlvReader.isNull()) { + tlvReader.getUShort(ContextSpecificTag(TAG_ADMIN_PASSCODE_ID)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_ADMIN_PASSCODE_ID)) + null + } val changeType = tlvReader.getUByte(ContextSpecificTag(TAG_CHANGE_TYPE)) - val latestValue = - if (!tlvReader.isNull()) { - matter.controller.cluster.structs.AccessControlClusterAccessControlEntryStruct.fromTlv( - ContextSpecificTag(TAG_LATEST_VALUE), - tlvReader, - ) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_LATEST_VALUE)) - null - } + val latestValue = if (!tlvReader.isNull()) { + matter.controller.cluster.structs.AccessControlClusterAccessControlEntryStruct.fromTlv(ContextSpecificTag(TAG_LATEST_VALUE), tlvReader) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_LATEST_VALUE)) + null + } val fabricIndex = tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) - + tlvReader.exitContainer() - return AccessControlClusterAccessControlEntryChangedEvent( - adminNodeID, - adminPasscodeID, - changeType, - latestValue, - fabricIndex, - ) + return AccessControlClusterAccessControlEntryChangedEvent(adminNodeID, adminPasscodeID, changeType, latestValue, fabricIndex) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/AccessControlClusterAccessControlExtensionChangedEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/AccessControlClusterAccessControlExtensionChangedEvent.kt index 668ee86be2e380..b99c69451dc1c4 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/AccessControlClusterAccessControlExtensionChangedEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/AccessControlClusterAccessControlExtensionChangedEvent.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,9 +28,8 @@ class AccessControlClusterAccessControlExtensionChangedEvent( val adminNodeID: ULong?, val adminPasscodeID: UShort?, val changeType: UByte, - val latestValue: - matter.controller.cluster.structs.AccessControlClusterAccessControlExtensionStruct?, - val fabricIndex: UByte, + val latestValue: matter.controller.cluster.structs.AccessControlClusterAccessControlExtensionStruct?, + val fabricIndex: UByte ) { override fun toString(): String = buildString { append("AccessControlClusterAccessControlExtensionChangedEvent {\n") @@ -71,45 +72,32 @@ class AccessControlClusterAccessControlExtensionChangedEvent( private const val TAG_LATEST_VALUE = 4 private const val TAG_FABRIC_INDEX = 254 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): AccessControlClusterAccessControlExtensionChangedEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : AccessControlClusterAccessControlExtensionChangedEvent { tlvReader.enterStructure(tlvTag) - val adminNodeID = - if (!tlvReader.isNull()) { - tlvReader.getULong(ContextSpecificTag(TAG_ADMIN_NODE_ID)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_ADMIN_NODE_ID)) - null - } - val adminPasscodeID = - if (!tlvReader.isNull()) { - tlvReader.getUShort(ContextSpecificTag(TAG_ADMIN_PASSCODE_ID)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_ADMIN_PASSCODE_ID)) - null - } + val adminNodeID = if (!tlvReader.isNull()) { + tlvReader.getULong(ContextSpecificTag(TAG_ADMIN_NODE_ID)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_ADMIN_NODE_ID)) + null + } + val adminPasscodeID = if (!tlvReader.isNull()) { + tlvReader.getUShort(ContextSpecificTag(TAG_ADMIN_PASSCODE_ID)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_ADMIN_PASSCODE_ID)) + null + } val changeType = tlvReader.getUByte(ContextSpecificTag(TAG_CHANGE_TYPE)) - val latestValue = - if (!tlvReader.isNull()) { - matter.controller.cluster.structs.AccessControlClusterAccessControlExtensionStruct - .fromTlv(ContextSpecificTag(TAG_LATEST_VALUE), tlvReader) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_LATEST_VALUE)) - null - } + val latestValue = if (!tlvReader.isNull()) { + matter.controller.cluster.structs.AccessControlClusterAccessControlExtensionStruct.fromTlv(ContextSpecificTag(TAG_LATEST_VALUE), tlvReader) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_LATEST_VALUE)) + null + } val fabricIndex = tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) - + tlvReader.exitContainer() - return AccessControlClusterAccessControlExtensionChangedEvent( - adminNodeID, - adminPasscodeID, - changeType, - latestValue, - fabricIndex, - ) + return AccessControlClusterAccessControlExtensionChangedEvent(adminNodeID, adminPasscodeID, changeType, latestValue, fabricIndex) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/AccessControlClusterAccessRestrictionEntryChangedEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/AccessControlClusterAccessRestrictionEntryChangedEvent.kt index 8a272f8854ae12..19b74788bb9582 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/AccessControlClusterAccessRestrictionEntryChangedEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/AccessControlClusterAccessRestrictionEntryChangedEvent.kt @@ -16,13 +16,17 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional 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 AccessControlClusterAccessRestrictionEntryChangedEvent(val fabricIndex: UByte) { +class AccessControlClusterAccessRestrictionEntryChangedEvent( + val fabricIndex: UByte +) { override fun toString(): String = buildString { append("AccessControlClusterAccessRestrictionEntryChangedEvent {\n") append("\tfabricIndex : $fabricIndex\n") @@ -40,13 +44,10 @@ class AccessControlClusterAccessRestrictionEntryChangedEvent(val fabricIndex: UB companion object { private const val TAG_FABRIC_INDEX = 254 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): AccessControlClusterAccessRestrictionEntryChangedEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : AccessControlClusterAccessRestrictionEntryChangedEvent { tlvReader.enterStructure(tlvTag) val fabricIndex = tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) - + tlvReader.exitContainer() return AccessControlClusterAccessRestrictionEntryChangedEvent(fabricIndex) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/AccessControlClusterFabricRestrictionReviewUpdateEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/AccessControlClusterFabricRestrictionReviewUpdateEvent.kt index 6bf03e6afc8c13..fae7081a36d9db 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/AccessControlClusterFabricRestrictionReviewUpdateEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/AccessControlClusterFabricRestrictionReviewUpdateEvent.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +28,7 @@ class AccessControlClusterFabricRestrictionReviewUpdateEvent( val token: ULong, val instruction: String?, val redirectURL: String?, - val fabricIndex: UByte, + val fabricIndex: UByte ) { override fun toString(): String = buildString { append("AccessControlClusterFabricRestrictionReviewUpdateEvent {\n") @@ -62,36 +64,26 @@ class AccessControlClusterFabricRestrictionReviewUpdateEvent( private const val TAG_REDIRECT_URL = 2 private const val TAG_FABRIC_INDEX = 254 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): AccessControlClusterFabricRestrictionReviewUpdateEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : AccessControlClusterFabricRestrictionReviewUpdateEvent { tlvReader.enterStructure(tlvTag) val token = tlvReader.getULong(ContextSpecificTag(TAG_TOKEN)) - val instruction = - if (!tlvReader.isNull()) { - tlvReader.getString(ContextSpecificTag(TAG_INSTRUCTION)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_INSTRUCTION)) - null - } - val redirectURL = - if (!tlvReader.isNull()) { - tlvReader.getString(ContextSpecificTag(TAG_REDIRECT_URL)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_REDIRECT_URL)) - null - } + val instruction = if (!tlvReader.isNull()) { + tlvReader.getString(ContextSpecificTag(TAG_INSTRUCTION)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_INSTRUCTION)) + null + } + val redirectURL = if (!tlvReader.isNull()) { + tlvReader.getString(ContextSpecificTag(TAG_REDIRECT_URL)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_REDIRECT_URL)) + null + } val fabricIndex = tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) - + tlvReader.exitContainer() - return AccessControlClusterFabricRestrictionReviewUpdateEvent( - token, - instruction, - redirectURL, - fabricIndex, - ) + return AccessControlClusterFabricRestrictionReviewUpdateEvent(token, instruction, redirectURL, fabricIndex) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/AccountLoginClusterLoggedOutEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/AccountLoginClusterLoggedOutEvent.kt index 81e55baf4fe4f7..4adc0b113c8e01 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/AccountLoginClusterLoggedOutEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/AccountLoginClusterLoggedOutEvent.kt @@ -18,12 +18,15 @@ package matter.controller.cluster.eventstructs import java.util.Optional 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 AccountLoginClusterLoggedOutEvent(val node: Optional) { +class AccountLoginClusterLoggedOutEvent( + val node: Optional +) { override fun toString(): String = buildString { append("AccountLoginClusterLoggedOutEvent {\n") append("\tnode : $node\n") @@ -44,15 +47,14 @@ class AccountLoginClusterLoggedOutEvent(val node: Optional) { companion object { private const val TAG_NODE = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): AccountLoginClusterLoggedOutEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : AccountLoginClusterLoggedOutEvent { tlvReader.enterStructure(tlvTag) - val node = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_NODE))) { - Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_NODE))) - } else { - Optional.empty() - } - + val node = if (tlvReader.isNextTag(ContextSpecificTag(TAG_NODE))) { + Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_NODE))) + } else { + Optional.empty() + } + tlvReader.exitContainer() return AccountLoginClusterLoggedOutEvent(node) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ActionsClusterActionFailedEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ActionsClusterActionFailedEvent.kt index a1fe90125f5e61..014d77c3f2ecc7 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ActionsClusterActionFailedEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ActionsClusterActionFailedEvent.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +28,7 @@ class ActionsClusterActionFailedEvent( val actionID: UShort, val invokeID: UInt, val newState: UByte, - val error: UByte, + val error: UByte ) { override fun toString(): String = buildString { append("ActionsClusterActionFailedEvent {\n") @@ -54,13 +56,13 @@ class ActionsClusterActionFailedEvent( private const val TAG_NEW_STATE = 2 private const val TAG_ERROR = 3 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ActionsClusterActionFailedEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : ActionsClusterActionFailedEvent { tlvReader.enterStructure(tlvTag) val actionID = tlvReader.getUShort(ContextSpecificTag(TAG_ACTION_ID)) val invokeID = tlvReader.getUInt(ContextSpecificTag(TAG_INVOKE_ID)) val newState = tlvReader.getUByte(ContextSpecificTag(TAG_NEW_STATE)) val error = tlvReader.getUByte(ContextSpecificTag(TAG_ERROR)) - + tlvReader.exitContainer() return ActionsClusterActionFailedEvent(actionID, invokeID, newState, error) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ActionsClusterStateChangedEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ActionsClusterStateChangedEvent.kt index 8fdefb84b1b3ba..c4d49cc015a6e5 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ActionsClusterStateChangedEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ActionsClusterStateChangedEvent.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -25,7 +27,7 @@ import matter.tlv.TlvWriter class ActionsClusterStateChangedEvent( val actionID: UShort, val invokeID: UInt, - val newState: UByte, + val newState: UByte ) { override fun toString(): String = buildString { append("ActionsClusterStateChangedEvent {\n") @@ -50,12 +52,12 @@ class ActionsClusterStateChangedEvent( private const val TAG_INVOKE_ID = 1 private const val TAG_NEW_STATE = 2 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ActionsClusterStateChangedEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : ActionsClusterStateChangedEvent { tlvReader.enterStructure(tlvTag) val actionID = tlvReader.getUShort(ContextSpecificTag(TAG_ACTION_ID)) val invokeID = tlvReader.getUInt(ContextSpecificTag(TAG_INVOKE_ID)) val newState = tlvReader.getUByte(ContextSpecificTag(TAG_NEW_STATE)) - + tlvReader.exitContainer() return ActionsClusterStateChangedEvent(actionID, invokeID, newState) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BasicInformationClusterLeaveEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BasicInformationClusterLeaveEvent.kt index ea0e7e1e1004c4..2b909a62b20b6f 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BasicInformationClusterLeaveEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BasicInformationClusterLeaveEvent.kt @@ -16,13 +16,17 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional 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 BasicInformationClusterLeaveEvent(val fabricIndex: UByte) { +class BasicInformationClusterLeaveEvent( + val fabricIndex: UByte +) { override fun toString(): String = buildString { append("BasicInformationClusterLeaveEvent {\n") append("\tfabricIndex : $fabricIndex\n") @@ -40,10 +44,10 @@ class BasicInformationClusterLeaveEvent(val fabricIndex: UByte) { companion object { private const val TAG_FABRIC_INDEX = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): BasicInformationClusterLeaveEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : BasicInformationClusterLeaveEvent { tlvReader.enterStructure(tlvTag) val fabricIndex = tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) - + tlvReader.exitContainer() return BasicInformationClusterLeaveEvent(fabricIndex) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BasicInformationClusterReachableChangedEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BasicInformationClusterReachableChangedEvent.kt index a6924b859aa024..4bacfa94d86ef9 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BasicInformationClusterReachableChangedEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BasicInformationClusterReachableChangedEvent.kt @@ -16,13 +16,17 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional 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 BasicInformationClusterReachableChangedEvent(val reachableNewValue: Boolean) { +class BasicInformationClusterReachableChangedEvent( + val reachableNewValue: Boolean +) { override fun toString(): String = buildString { append("BasicInformationClusterReachableChangedEvent {\n") append("\treachableNewValue : $reachableNewValue\n") @@ -40,10 +44,10 @@ class BasicInformationClusterReachableChangedEvent(val reachableNewValue: Boolea companion object { private const val TAG_REACHABLE_NEW_VALUE = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): BasicInformationClusterReachableChangedEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : BasicInformationClusterReachableChangedEvent { tlvReader.enterStructure(tlvTag) val reachableNewValue = tlvReader.getBoolean(ContextSpecificTag(TAG_REACHABLE_NEW_VALUE)) - + tlvReader.exitContainer() return BasicInformationClusterReachableChangedEvent(reachableNewValue) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BasicInformationClusterStartUpEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BasicInformationClusterStartUpEvent.kt index fff1d76a1fa86e..949ae5f92688a0 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BasicInformationClusterStartUpEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BasicInformationClusterStartUpEvent.kt @@ -16,13 +16,17 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional 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 BasicInformationClusterStartUpEvent(val softwareVersion: UInt) { +class BasicInformationClusterStartUpEvent( + val softwareVersion: UInt +) { override fun toString(): String = buildString { append("BasicInformationClusterStartUpEvent {\n") append("\tsoftwareVersion : $softwareVersion\n") @@ -40,10 +44,10 @@ class BasicInformationClusterStartUpEvent(val softwareVersion: UInt) { companion object { private const val TAG_SOFTWARE_VERSION = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): BasicInformationClusterStartUpEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : BasicInformationClusterStartUpEvent { tlvReader.enterStructure(tlvTag) val softwareVersion = tlvReader.getUInt(ContextSpecificTag(TAG_SOFTWARE_VERSION)) - + tlvReader.exitContainer() return BasicInformationClusterStartUpEvent(softwareVersion) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BooleanStateClusterStateChangeEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BooleanStateClusterStateChangeEvent.kt index 82db9ecdb2a8f4..50b4494eebdc0d 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BooleanStateClusterStateChangeEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BooleanStateClusterStateChangeEvent.kt @@ -16,13 +16,17 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional 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 BooleanStateClusterStateChangeEvent(val stateValue: Boolean) { +class BooleanStateClusterStateChangeEvent( + val stateValue: Boolean +) { override fun toString(): String = buildString { append("BooleanStateClusterStateChangeEvent {\n") append("\tstateValue : $stateValue\n") @@ -40,10 +44,10 @@ class BooleanStateClusterStateChangeEvent(val stateValue: Boolean) { companion object { private const val TAG_STATE_VALUE = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): BooleanStateClusterStateChangeEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : BooleanStateClusterStateChangeEvent { tlvReader.enterStructure(tlvTag) val stateValue = tlvReader.getBoolean(ContextSpecificTag(TAG_STATE_VALUE)) - + tlvReader.exitContainer() return BooleanStateClusterStateChangeEvent(stateValue) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BooleanStateConfigurationClusterAlarmsStateChangedEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BooleanStateConfigurationClusterAlarmsStateChangedEvent.kt index 0a221d724b4cc1..14d64045516493 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BooleanStateConfigurationClusterAlarmsStateChangedEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BooleanStateConfigurationClusterAlarmsStateChangedEvent.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.eventstructs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -25,7 +26,7 @@ import matter.tlv.TlvWriter class BooleanStateConfigurationClusterAlarmsStateChangedEvent( val alarmsActive: UByte, - val alarmsSuppressed: Optional, + val alarmsSuppressed: Optional ) { override fun toString(): String = buildString { append("BooleanStateConfigurationClusterAlarmsStateChangedEvent {\n") @@ -50,19 +51,15 @@ class BooleanStateConfigurationClusterAlarmsStateChangedEvent( private const val TAG_ALARMS_ACTIVE = 0 private const val TAG_ALARMS_SUPPRESSED = 1 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): BooleanStateConfigurationClusterAlarmsStateChangedEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : BooleanStateConfigurationClusterAlarmsStateChangedEvent { tlvReader.enterStructure(tlvTag) val alarmsActive = tlvReader.getUByte(ContextSpecificTag(TAG_ALARMS_ACTIVE)) - val alarmsSuppressed = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_ALARMS_SUPPRESSED))) { - Optional.of(tlvReader.getUByte(ContextSpecificTag(TAG_ALARMS_SUPPRESSED))) - } else { - Optional.empty() - } - + val alarmsSuppressed = if (tlvReader.isNextTag(ContextSpecificTag(TAG_ALARMS_SUPPRESSED))) { + Optional.of(tlvReader.getUByte(ContextSpecificTag(TAG_ALARMS_SUPPRESSED))) + } else { + Optional.empty() + } + tlvReader.exitContainer() return BooleanStateConfigurationClusterAlarmsStateChangedEvent(alarmsActive, alarmsSuppressed) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BooleanStateConfigurationClusterSensorFaultEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BooleanStateConfigurationClusterSensorFaultEvent.kt index cce18515d5a10a..750d449968ba98 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BooleanStateConfigurationClusterSensorFaultEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BooleanStateConfigurationClusterSensorFaultEvent.kt @@ -16,13 +16,17 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional 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 BooleanStateConfigurationClusterSensorFaultEvent(val sensorFault: UShort) { +class BooleanStateConfigurationClusterSensorFaultEvent( + val sensorFault: UShort +) { override fun toString(): String = buildString { append("BooleanStateConfigurationClusterSensorFaultEvent {\n") append("\tsensorFault : $sensorFault\n") @@ -40,13 +44,10 @@ class BooleanStateConfigurationClusterSensorFaultEvent(val sensorFault: UShort) companion object { private const val TAG_SENSOR_FAULT = 0 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): BooleanStateConfigurationClusterSensorFaultEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : BooleanStateConfigurationClusterSensorFaultEvent { tlvReader.enterStructure(tlvTag) val sensorFault = tlvReader.getUShort(ContextSpecificTag(TAG_SENSOR_FAULT)) - + tlvReader.exitContainer() return BooleanStateConfigurationClusterSensorFaultEvent(sensorFault) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BridgedDeviceBasicInformationClusterActiveChangedEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BridgedDeviceBasicInformationClusterActiveChangedEvent.kt index 7713cb0faf07b3..cbfb8d7b65dc40 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BridgedDeviceBasicInformationClusterActiveChangedEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BridgedDeviceBasicInformationClusterActiveChangedEvent.kt @@ -16,13 +16,17 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional 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 BridgedDeviceBasicInformationClusterActiveChangedEvent(val promisedActiveDuration: UInt) { +class BridgedDeviceBasicInformationClusterActiveChangedEvent( + val promisedActiveDuration: UInt +) { override fun toString(): String = buildString { append("BridgedDeviceBasicInformationClusterActiveChangedEvent {\n") append("\tpromisedActiveDuration : $promisedActiveDuration\n") @@ -40,14 +44,10 @@ class BridgedDeviceBasicInformationClusterActiveChangedEvent(val promisedActiveD companion object { private const val TAG_PROMISED_ACTIVE_DURATION = 0 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): BridgedDeviceBasicInformationClusterActiveChangedEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : BridgedDeviceBasicInformationClusterActiveChangedEvent { tlvReader.enterStructure(tlvTag) - val promisedActiveDuration = - tlvReader.getUInt(ContextSpecificTag(TAG_PROMISED_ACTIVE_DURATION)) - + val promisedActiveDuration = tlvReader.getUInt(ContextSpecificTag(TAG_PROMISED_ACTIVE_DURATION)) + tlvReader.exitContainer() return BridgedDeviceBasicInformationClusterActiveChangedEvent(promisedActiveDuration) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BridgedDeviceBasicInformationClusterReachableChangedEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BridgedDeviceBasicInformationClusterReachableChangedEvent.kt index bd259a290a3bde..5bd65929e12bdc 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BridgedDeviceBasicInformationClusterReachableChangedEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BridgedDeviceBasicInformationClusterReachableChangedEvent.kt @@ -16,13 +16,17 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional 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 BridgedDeviceBasicInformationClusterReachableChangedEvent(val reachableNewValue: Boolean) { +class BridgedDeviceBasicInformationClusterReachableChangedEvent( + val reachableNewValue: Boolean +) { override fun toString(): String = buildString { append("BridgedDeviceBasicInformationClusterReachableChangedEvent {\n") append("\treachableNewValue : $reachableNewValue\n") @@ -40,13 +44,10 @@ class BridgedDeviceBasicInformationClusterReachableChangedEvent(val reachableNew companion object { private const val TAG_REACHABLE_NEW_VALUE = 0 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): BridgedDeviceBasicInformationClusterReachableChangedEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : BridgedDeviceBasicInformationClusterReachableChangedEvent { tlvReader.enterStructure(tlvTag) val reachableNewValue = tlvReader.getBoolean(ContextSpecificTag(TAG_REACHABLE_NEW_VALUE)) - + tlvReader.exitContainer() return BridgedDeviceBasicInformationClusterReachableChangedEvent(reachableNewValue) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BridgedDeviceBasicInformationClusterStartUpEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BridgedDeviceBasicInformationClusterStartUpEvent.kt index 41e4f4e2d0003d..67aa89e3788154 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BridgedDeviceBasicInformationClusterStartUpEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BridgedDeviceBasicInformationClusterStartUpEvent.kt @@ -16,13 +16,17 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional 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 BridgedDeviceBasicInformationClusterStartUpEvent(val softwareVersion: UInt) { +class BridgedDeviceBasicInformationClusterStartUpEvent( + val softwareVersion: UInt +) { override fun toString(): String = buildString { append("BridgedDeviceBasicInformationClusterStartUpEvent {\n") append("\tsoftwareVersion : $softwareVersion\n") @@ -40,13 +44,10 @@ class BridgedDeviceBasicInformationClusterStartUpEvent(val softwareVersion: UInt companion object { private const val TAG_SOFTWARE_VERSION = 0 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): BridgedDeviceBasicInformationClusterStartUpEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : BridgedDeviceBasicInformationClusterStartUpEvent { tlvReader.enterStructure(tlvTag) val softwareVersion = tlvReader.getUInt(ContextSpecificTag(TAG_SOFTWARE_VERSION)) - + tlvReader.exitContainer() return BridgedDeviceBasicInformationClusterStartUpEvent(softwareVersion) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/CommissionerControlClusterCommissioningRequestResultEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/CommissionerControlClusterCommissioningRequestResultEvent.kt index c8947776269773..d7df65fa518b14 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/CommissionerControlClusterCommissioningRequestResultEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/CommissionerControlClusterCommissioningRequestResultEvent.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +28,7 @@ class CommissionerControlClusterCommissioningRequestResultEvent( val requestId: ULong, val clientNodeId: ULong, val statusCode: UByte, - val fabricIndex: UByte, + val fabricIndex: UByte ) { override fun toString(): String = buildString { append("CommissionerControlClusterCommissioningRequestResultEvent {\n") @@ -54,24 +56,16 @@ class CommissionerControlClusterCommissioningRequestResultEvent( private const val TAG_STATUS_CODE = 2 private const val TAG_FABRIC_INDEX = 254 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): CommissionerControlClusterCommissioningRequestResultEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : CommissionerControlClusterCommissioningRequestResultEvent { tlvReader.enterStructure(tlvTag) val requestId = tlvReader.getULong(ContextSpecificTag(TAG_REQUEST_ID)) val clientNodeId = tlvReader.getULong(ContextSpecificTag(TAG_CLIENT_NODE_ID)) val statusCode = tlvReader.getUByte(ContextSpecificTag(TAG_STATUS_CODE)) val fabricIndex = tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) - + tlvReader.exitContainer() - return CommissionerControlClusterCommissioningRequestResultEvent( - requestId, - clientNodeId, - statusCode, - fabricIndex, - ) + return CommissionerControlClusterCommissioningRequestResultEvent(requestId, clientNodeId, statusCode, fabricIndex) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DemandResponseLoadControlClusterLoadControlEventStatusChangeEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DemandResponseLoadControlClusterLoadControlEventStatusChangeEvent.kt index d5e263249bd4c4..0132fbc3c34698 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DemandResponseLoadControlClusterLoadControlEventStatusChangeEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DemandResponseLoadControlClusterLoadControlEventStatusChangeEvent.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.eventstructs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -29,26 +30,11 @@ class DemandResponseLoadControlClusterLoadControlEventStatusChangeEvent( val status: UByte, val criticality: UByte, val control: UShort, - val temperatureControl: - Optional< - matter.controller.cluster.structs.DemandResponseLoadControlClusterTemperatureControlStruct - >?, - val averageLoadControl: - Optional< - matter.controller.cluster.structs.DemandResponseLoadControlClusterAverageLoadControlStruct - >?, - val dutyCycleControl: - Optional< - matter.controller.cluster.structs.DemandResponseLoadControlClusterDutyCycleControlStruct - >?, - val powerSavingsControl: - Optional< - matter.controller.cluster.structs.DemandResponseLoadControlClusterPowerSavingsControlStruct - >?, - val heatingSourceControl: - Optional< - matter.controller.cluster.structs.DemandResponseLoadControlClusterHeatingSourceControlStruct - >?, + val temperatureControl: Optional?, + val averageLoadControl: Optional?, + val dutyCycleControl: Optional?, + val powerSavingsControl: Optional?, + val heatingSourceControl: Optional? ) { override fun toString(): String = buildString { append("DemandResponseLoadControlClusterLoadControlEventStatusChangeEvent {\n") @@ -79,41 +65,41 @@ class DemandResponseLoadControlClusterLoadControlEventStatusChangeEvent( put(ContextSpecificTag(TAG_CONTROL), control) if (temperatureControl != null) { if (temperatureControl.isPresent) { - val opttemperatureControl = temperatureControl.get() - opttemperatureControl.toTlv(ContextSpecificTag(TAG_TEMPERATURE_CONTROL), this) - } + val opttemperatureControl = temperatureControl.get() + opttemperatureControl.toTlv(ContextSpecificTag(TAG_TEMPERATURE_CONTROL), this) + } } else { putNull(ContextSpecificTag(TAG_TEMPERATURE_CONTROL)) } if (averageLoadControl != null) { if (averageLoadControl.isPresent) { - val optaverageLoadControl = averageLoadControl.get() - optaverageLoadControl.toTlv(ContextSpecificTag(TAG_AVERAGE_LOAD_CONTROL), this) - } + val optaverageLoadControl = averageLoadControl.get() + optaverageLoadControl.toTlv(ContextSpecificTag(TAG_AVERAGE_LOAD_CONTROL), this) + } } else { putNull(ContextSpecificTag(TAG_AVERAGE_LOAD_CONTROL)) } if (dutyCycleControl != null) { if (dutyCycleControl.isPresent) { - val optdutyCycleControl = dutyCycleControl.get() - optdutyCycleControl.toTlv(ContextSpecificTag(TAG_DUTY_CYCLE_CONTROL), this) - } + val optdutyCycleControl = dutyCycleControl.get() + optdutyCycleControl.toTlv(ContextSpecificTag(TAG_DUTY_CYCLE_CONTROL), this) + } } else { putNull(ContextSpecificTag(TAG_DUTY_CYCLE_CONTROL)) } if (powerSavingsControl != null) { if (powerSavingsControl.isPresent) { - val optpowerSavingsControl = powerSavingsControl.get() - optpowerSavingsControl.toTlv(ContextSpecificTag(TAG_POWER_SAVINGS_CONTROL), this) - } + val optpowerSavingsControl = powerSavingsControl.get() + optpowerSavingsControl.toTlv(ContextSpecificTag(TAG_POWER_SAVINGS_CONTROL), this) + } } else { putNull(ContextSpecificTag(TAG_POWER_SAVINGS_CONTROL)) } if (heatingSourceControl != null) { if (heatingSourceControl.isPresent) { - val optheatingSourceControl = heatingSourceControl.get() - optheatingSourceControl.toTlv(ContextSpecificTag(TAG_HEATING_SOURCE_CONTROL), this) - } + val optheatingSourceControl = heatingSourceControl.get() + optheatingSourceControl.toTlv(ContextSpecificTag(TAG_HEATING_SOURCE_CONTROL), this) + } } else { putNull(ContextSpecificTag(TAG_HEATING_SOURCE_CONTROL)) } @@ -133,112 +119,72 @@ class DemandResponseLoadControlClusterLoadControlEventStatusChangeEvent( private const val TAG_POWER_SAVINGS_CONTROL = 8 private const val TAG_HEATING_SOURCE_CONTROL = 9 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): DemandResponseLoadControlClusterLoadControlEventStatusChangeEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : DemandResponseLoadControlClusterLoadControlEventStatusChangeEvent { tlvReader.enterStructure(tlvTag) val eventID = tlvReader.getByteArray(ContextSpecificTag(TAG_EVENT_ID)) - val transitionIndex = - if (!tlvReader.isNull()) { - tlvReader.getUByte(ContextSpecificTag(TAG_TRANSITION_INDEX)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_TRANSITION_INDEX)) - null - } + val transitionIndex = if (!tlvReader.isNull()) { + tlvReader.getUByte(ContextSpecificTag(TAG_TRANSITION_INDEX)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_TRANSITION_INDEX)) + null + } val status = tlvReader.getUByte(ContextSpecificTag(TAG_STATUS)) val criticality = tlvReader.getUByte(ContextSpecificTag(TAG_CRITICALITY)) val control = tlvReader.getUShort(ContextSpecificTag(TAG_CONTROL)) - val temperatureControl = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_TEMPERATURE_CONTROL))) { - Optional.of( - matter.controller.cluster.structs - .DemandResponseLoadControlClusterTemperatureControlStruct - .fromTlv(ContextSpecificTag(TAG_TEMPERATURE_CONTROL), tlvReader) - ) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_TEMPERATURE_CONTROL)) - null - } - val averageLoadControl = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_AVERAGE_LOAD_CONTROL))) { - Optional.of( - matter.controller.cluster.structs - .DemandResponseLoadControlClusterAverageLoadControlStruct - .fromTlv(ContextSpecificTag(TAG_AVERAGE_LOAD_CONTROL), tlvReader) - ) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_AVERAGE_LOAD_CONTROL)) - null - } - val dutyCycleControl = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_DUTY_CYCLE_CONTROL))) { - Optional.of( - matter.controller.cluster.structs - .DemandResponseLoadControlClusterDutyCycleControlStruct - .fromTlv(ContextSpecificTag(TAG_DUTY_CYCLE_CONTROL), tlvReader) - ) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_DUTY_CYCLE_CONTROL)) - null - } - val powerSavingsControl = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_POWER_SAVINGS_CONTROL))) { - Optional.of( - matter.controller.cluster.structs - .DemandResponseLoadControlClusterPowerSavingsControlStruct - .fromTlv(ContextSpecificTag(TAG_POWER_SAVINGS_CONTROL), tlvReader) - ) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_POWER_SAVINGS_CONTROL)) - null - } - val heatingSourceControl = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_HEATING_SOURCE_CONTROL))) { - Optional.of( - matter.controller.cluster.structs - .DemandResponseLoadControlClusterHeatingSourceControlStruct - .fromTlv(ContextSpecificTag(TAG_HEATING_SOURCE_CONTROL), tlvReader) - ) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_HEATING_SOURCE_CONTROL)) - null - } - + val temperatureControl = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_TEMPERATURE_CONTROL))) { + Optional.of(matter.controller.cluster.structs.DemandResponseLoadControlClusterTemperatureControlStruct.fromTlv(ContextSpecificTag(TAG_TEMPERATURE_CONTROL), tlvReader)) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_TEMPERATURE_CONTROL)) + null + } + val averageLoadControl = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_AVERAGE_LOAD_CONTROL))) { + Optional.of(matter.controller.cluster.structs.DemandResponseLoadControlClusterAverageLoadControlStruct.fromTlv(ContextSpecificTag(TAG_AVERAGE_LOAD_CONTROL), tlvReader)) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_AVERAGE_LOAD_CONTROL)) + null + } + val dutyCycleControl = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_DUTY_CYCLE_CONTROL))) { + Optional.of(matter.controller.cluster.structs.DemandResponseLoadControlClusterDutyCycleControlStruct.fromTlv(ContextSpecificTag(TAG_DUTY_CYCLE_CONTROL), tlvReader)) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_DUTY_CYCLE_CONTROL)) + null + } + val powerSavingsControl = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_POWER_SAVINGS_CONTROL))) { + Optional.of(matter.controller.cluster.structs.DemandResponseLoadControlClusterPowerSavingsControlStruct.fromTlv(ContextSpecificTag(TAG_POWER_SAVINGS_CONTROL), tlvReader)) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_POWER_SAVINGS_CONTROL)) + null + } + val heatingSourceControl = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_HEATING_SOURCE_CONTROL))) { + Optional.of(matter.controller.cluster.structs.DemandResponseLoadControlClusterHeatingSourceControlStruct.fromTlv(ContextSpecificTag(TAG_HEATING_SOURCE_CONTROL), tlvReader)) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_HEATING_SOURCE_CONTROL)) + null + } + tlvReader.exitContainer() - return DemandResponseLoadControlClusterLoadControlEventStatusChangeEvent( - eventID, - transitionIndex, - status, - criticality, - control, - temperatureControl, - averageLoadControl, - dutyCycleControl, - powerSavingsControl, - heatingSourceControl, - ) + return DemandResponseLoadControlClusterLoadControlEventStatusChangeEvent(eventID, transitionIndex, status, criticality, control, temperatureControl, averageLoadControl, dutyCycleControl, powerSavingsControl, heatingSourceControl) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DeviceEnergyManagementClusterPowerAdjustEndEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DeviceEnergyManagementClusterPowerAdjustEndEvent.kt index 556666715883df..e05ca8e86ba704 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DeviceEnergyManagementClusterPowerAdjustEndEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DeviceEnergyManagementClusterPowerAdjustEndEvent.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -25,7 +27,7 @@ import matter.tlv.TlvWriter class DeviceEnergyManagementClusterPowerAdjustEndEvent( val cause: UByte, val duration: UInt, - val energyUse: Long, + val energyUse: Long ) { override fun toString(): String = buildString { append("DeviceEnergyManagementClusterPowerAdjustEndEvent {\n") @@ -50,15 +52,12 @@ class DeviceEnergyManagementClusterPowerAdjustEndEvent( private const val TAG_DURATION = 1 private const val TAG_ENERGY_USE = 2 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): DeviceEnergyManagementClusterPowerAdjustEndEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : DeviceEnergyManagementClusterPowerAdjustEndEvent { tlvReader.enterStructure(tlvTag) val cause = tlvReader.getUByte(ContextSpecificTag(TAG_CAUSE)) val duration = tlvReader.getUInt(ContextSpecificTag(TAG_DURATION)) val energyUse = tlvReader.getLong(ContextSpecificTag(TAG_ENERGY_USE)) - + tlvReader.exitContainer() return DeviceEnergyManagementClusterPowerAdjustEndEvent(cause, duration, energyUse) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DeviceEnergyManagementClusterResumedEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DeviceEnergyManagementClusterResumedEvent.kt index db5219f72dba0e..8d103f74e33de4 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DeviceEnergyManagementClusterResumedEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DeviceEnergyManagementClusterResumedEvent.kt @@ -16,13 +16,17 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional 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 DeviceEnergyManagementClusterResumedEvent(val cause: UByte) { +class DeviceEnergyManagementClusterResumedEvent( + val cause: UByte +) { override fun toString(): String = buildString { append("DeviceEnergyManagementClusterResumedEvent {\n") append("\tcause : $cause\n") @@ -40,10 +44,10 @@ class DeviceEnergyManagementClusterResumedEvent(val cause: UByte) { companion object { private const val TAG_CAUSE = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): DeviceEnergyManagementClusterResumedEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : DeviceEnergyManagementClusterResumedEvent { tlvReader.enterStructure(tlvTag) val cause = tlvReader.getUByte(ContextSpecificTag(TAG_CAUSE)) - + tlvReader.exitContainer() return DeviceEnergyManagementClusterResumedEvent(cause) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DishwasherAlarmClusterNotifyEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DishwasherAlarmClusterNotifyEvent.kt index a9ad126e50db5d..e17f43ed147ae0 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DishwasherAlarmClusterNotifyEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DishwasherAlarmClusterNotifyEvent.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +28,7 @@ class DishwasherAlarmClusterNotifyEvent( val active: UInt, val inactive: UInt, val state: UInt, - val mask: UInt, + val mask: UInt ) { override fun toString(): String = buildString { append("DishwasherAlarmClusterNotifyEvent {\n") @@ -54,13 +56,13 @@ class DishwasherAlarmClusterNotifyEvent( private const val TAG_STATE = 2 private const val TAG_MASK = 3 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): DishwasherAlarmClusterNotifyEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : DishwasherAlarmClusterNotifyEvent { tlvReader.enterStructure(tlvTag) val active = tlvReader.getUInt(ContextSpecificTag(TAG_ACTIVE)) val inactive = tlvReader.getUInt(ContextSpecificTag(TAG_INACTIVE)) val state = tlvReader.getUInt(ContextSpecificTag(TAG_STATE)) val mask = tlvReader.getUInt(ContextSpecificTag(TAG_MASK)) - + tlvReader.exitContainer() return DishwasherAlarmClusterNotifyEvent(active, inactive, state, mask) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DoorLockClusterDoorLockAlarmEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DoorLockClusterDoorLockAlarmEvent.kt index 233130a2371a2e..a04df8246a437e 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DoorLockClusterDoorLockAlarmEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DoorLockClusterDoorLockAlarmEvent.kt @@ -16,13 +16,17 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional 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 DoorLockClusterDoorLockAlarmEvent(val alarmCode: UByte) { +class DoorLockClusterDoorLockAlarmEvent( + val alarmCode: UByte +) { override fun toString(): String = buildString { append("DoorLockClusterDoorLockAlarmEvent {\n") append("\talarmCode : $alarmCode\n") @@ -40,10 +44,10 @@ class DoorLockClusterDoorLockAlarmEvent(val alarmCode: UByte) { companion object { private const val TAG_ALARM_CODE = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): DoorLockClusterDoorLockAlarmEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : DoorLockClusterDoorLockAlarmEvent { tlvReader.enterStructure(tlvTag) val alarmCode = tlvReader.getUByte(ContextSpecificTag(TAG_ALARM_CODE)) - + tlvReader.exitContainer() return DoorLockClusterDoorLockAlarmEvent(alarmCode) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DoorLockClusterDoorStateChangeEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DoorLockClusterDoorStateChangeEvent.kt index 92d04f6662dffe..c0dd0441ac3010 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DoorLockClusterDoorStateChangeEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DoorLockClusterDoorStateChangeEvent.kt @@ -16,13 +16,17 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional 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 DoorLockClusterDoorStateChangeEvent(val doorState: UByte) { +class DoorLockClusterDoorStateChangeEvent( + val doorState: UByte +) { override fun toString(): String = buildString { append("DoorLockClusterDoorStateChangeEvent {\n") append("\tdoorState : $doorState\n") @@ -40,10 +44,10 @@ class DoorLockClusterDoorStateChangeEvent(val doorState: UByte) { companion object { private const val TAG_DOOR_STATE = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): DoorLockClusterDoorStateChangeEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : DoorLockClusterDoorStateChangeEvent { tlvReader.enterStructure(tlvTag) val doorState = tlvReader.getUByte(ContextSpecificTag(TAG_DOOR_STATE)) - + tlvReader.exitContainer() return DoorLockClusterDoorStateChangeEvent(doorState) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DoorLockClusterLockOperationErrorEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DoorLockClusterLockOperationErrorEvent.kt index 4208a2059d32d2..af031bad313f8f 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DoorLockClusterLockOperationErrorEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DoorLockClusterLockOperationErrorEvent.kt @@ -31,8 +31,7 @@ class DoorLockClusterLockOperationErrorEvent( val userIndex: UShort?, val fabricIndex: UByte?, val sourceNode: ULong?, - val credentials: - Optional>?, + val credentials: Optional>? ) { override fun toString(): String = buildString { append("DoorLockClusterLockOperationErrorEvent {\n") @@ -69,13 +68,13 @@ class DoorLockClusterLockOperationErrorEvent( } if (credentials != null) { if (credentials.isPresent) { - val optcredentials = credentials.get() - startArray(ContextSpecificTag(TAG_CREDENTIALS)) - for (item in optcredentials.iterator()) { - item.toTlv(AnonymousTag, this) - } - endArray() - } + val optcredentials = credentials.get() + startArray(ContextSpecificTag(TAG_CREDENTIALS)) + for (item in optcredentials.iterator()) { + item.toTlv(AnonymousTag, this) + } + endArray() + } } else { putNull(ContextSpecificTag(TAG_CREDENTIALS)) } @@ -92,68 +91,49 @@ class DoorLockClusterLockOperationErrorEvent( private const val TAG_SOURCE_NODE = 5 private const val TAG_CREDENTIALS = 6 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): DoorLockClusterLockOperationErrorEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : DoorLockClusterLockOperationErrorEvent { tlvReader.enterStructure(tlvTag) val lockOperationType = tlvReader.getUByte(ContextSpecificTag(TAG_LOCK_OPERATION_TYPE)) val operationSource = tlvReader.getUByte(ContextSpecificTag(TAG_OPERATION_SOURCE)) val operationError = tlvReader.getUByte(ContextSpecificTag(TAG_OPERATION_ERROR)) - val userIndex = - if (!tlvReader.isNull()) { - tlvReader.getUShort(ContextSpecificTag(TAG_USER_INDEX)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_USER_INDEX)) - null - } - val fabricIndex = - if (!tlvReader.isNull()) { - tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_FABRIC_INDEX)) - null - } - val sourceNode = - if (!tlvReader.isNull()) { - tlvReader.getULong(ContextSpecificTag(TAG_SOURCE_NODE)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_SOURCE_NODE)) - null - } - val credentials = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_CREDENTIALS))) { - Optional.of( - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_CREDENTIALS)) - while (!tlvReader.isEndOfContainer()) { - this.add( - matter.controller.cluster.structs.DoorLockClusterCredentialStruct.fromTlv( - AnonymousTag, - tlvReader, - ) - ) - } - tlvReader.exitContainer() - } - ) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_CREDENTIALS)) - null + val userIndex = if (!tlvReader.isNull()) { + tlvReader.getUShort(ContextSpecificTag(TAG_USER_INDEX)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_USER_INDEX)) + null + } + val fabricIndex = if (!tlvReader.isNull()) { + tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_FABRIC_INDEX)) + null + } + val sourceNode = if (!tlvReader.isNull()) { + tlvReader.getULong(ContextSpecificTag(TAG_SOURCE_NODE)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_SOURCE_NODE)) + null + } + val credentials = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_CREDENTIALS))) { + Optional.of(buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_CREDENTIALS)) + while(!tlvReader.isEndOfContainer()) { + this.add(matter.controller.cluster.structs.DoorLockClusterCredentialStruct.fromTlv(AnonymousTag, tlvReader)) } - + tlvReader.exitContainer() + }) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_CREDENTIALS)) + null + } + tlvReader.exitContainer() - return DoorLockClusterLockOperationErrorEvent( - lockOperationType, - operationSource, - operationError, - userIndex, - fabricIndex, - sourceNode, - credentials, - ) + return DoorLockClusterLockOperationErrorEvent(lockOperationType, operationSource, operationError, userIndex, fabricIndex, sourceNode, credentials) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DoorLockClusterLockOperationEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DoorLockClusterLockOperationEvent.kt index c5cf52060b6dff..d47734e612adc8 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DoorLockClusterLockOperationEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DoorLockClusterLockOperationEvent.kt @@ -30,8 +30,7 @@ class DoorLockClusterLockOperationEvent( val userIndex: UShort?, val fabricIndex: UByte?, val sourceNode: ULong?, - val credentials: - Optional>?, + val credentials: Optional>? ) { override fun toString(): String = buildString { append("DoorLockClusterLockOperationEvent {\n") @@ -66,13 +65,13 @@ class DoorLockClusterLockOperationEvent( } if (credentials != null) { if (credentials.isPresent) { - val optcredentials = credentials.get() - startArray(ContextSpecificTag(TAG_CREDENTIALS)) - for (item in optcredentials.iterator()) { - item.toTlv(AnonymousTag, this) - } - endArray() - } + val optcredentials = credentials.get() + startArray(ContextSpecificTag(TAG_CREDENTIALS)) + for (item in optcredentials.iterator()) { + item.toTlv(AnonymousTag, this) + } + endArray() + } } else { putNull(ContextSpecificTag(TAG_CREDENTIALS)) } @@ -88,66 +87,48 @@ class DoorLockClusterLockOperationEvent( private const val TAG_SOURCE_NODE = 4 private const val TAG_CREDENTIALS = 5 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): DoorLockClusterLockOperationEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : DoorLockClusterLockOperationEvent { tlvReader.enterStructure(tlvTag) val lockOperationType = tlvReader.getUByte(ContextSpecificTag(TAG_LOCK_OPERATION_TYPE)) val operationSource = tlvReader.getUByte(ContextSpecificTag(TAG_OPERATION_SOURCE)) - val userIndex = - if (!tlvReader.isNull()) { - tlvReader.getUShort(ContextSpecificTag(TAG_USER_INDEX)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_USER_INDEX)) - null - } - val fabricIndex = - if (!tlvReader.isNull()) { - tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_FABRIC_INDEX)) - null - } - val sourceNode = - if (!tlvReader.isNull()) { - tlvReader.getULong(ContextSpecificTag(TAG_SOURCE_NODE)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_SOURCE_NODE)) - null - } - val credentials = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_CREDENTIALS))) { - Optional.of( - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_CREDENTIALS)) - while (!tlvReader.isEndOfContainer()) { - this.add( - matter.controller.cluster.structs.DoorLockClusterCredentialStruct.fromTlv( - AnonymousTag, - tlvReader, - ) - ) - } - tlvReader.exitContainer() - } - ) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_CREDENTIALS)) - null + val userIndex = if (!tlvReader.isNull()) { + tlvReader.getUShort(ContextSpecificTag(TAG_USER_INDEX)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_USER_INDEX)) + null + } + val fabricIndex = if (!tlvReader.isNull()) { + tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_FABRIC_INDEX)) + null + } + val sourceNode = if (!tlvReader.isNull()) { + tlvReader.getULong(ContextSpecificTag(TAG_SOURCE_NODE)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_SOURCE_NODE)) + null + } + val credentials = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_CREDENTIALS))) { + Optional.of(buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_CREDENTIALS)) + while(!tlvReader.isEndOfContainer()) { + this.add(matter.controller.cluster.structs.DoorLockClusterCredentialStruct.fromTlv(AnonymousTag, tlvReader)) } - + tlvReader.exitContainer() + }) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_CREDENTIALS)) + null + } + tlvReader.exitContainer() - return DoorLockClusterLockOperationEvent( - lockOperationType, - operationSource, - userIndex, - fabricIndex, - sourceNode, - credentials, - ) + return DoorLockClusterLockOperationEvent(lockOperationType, operationSource, userIndex, fabricIndex, sourceNode, credentials) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DoorLockClusterLockUserChangeEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DoorLockClusterLockUserChangeEvent.kt index cd0ab80f8a2b92..bb39257e80cd71 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DoorLockClusterLockUserChangeEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DoorLockClusterLockUserChangeEvent.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -29,7 +31,7 @@ class DoorLockClusterLockUserChangeEvent( val userIndex: UShort?, val fabricIndex: UByte?, val sourceNode: ULong?, - val dataIndex: UShort?, + val dataIndex: UShort? ) { override fun toString(): String = buildString { append("DoorLockClusterLockUserChangeEvent {\n") @@ -82,51 +84,39 @@ class DoorLockClusterLockUserChangeEvent( private const val TAG_SOURCE_NODE = 5 private const val TAG_DATA_INDEX = 6 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): DoorLockClusterLockUserChangeEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : DoorLockClusterLockUserChangeEvent { tlvReader.enterStructure(tlvTag) val lockDataType = tlvReader.getUByte(ContextSpecificTag(TAG_LOCK_DATA_TYPE)) val dataOperationType = tlvReader.getUByte(ContextSpecificTag(TAG_DATA_OPERATION_TYPE)) val operationSource = tlvReader.getUByte(ContextSpecificTag(TAG_OPERATION_SOURCE)) - val userIndex = - if (!tlvReader.isNull()) { - tlvReader.getUShort(ContextSpecificTag(TAG_USER_INDEX)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_USER_INDEX)) - null - } - val fabricIndex = - if (!tlvReader.isNull()) { - tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_FABRIC_INDEX)) - null - } - val sourceNode = - if (!tlvReader.isNull()) { - tlvReader.getULong(ContextSpecificTag(TAG_SOURCE_NODE)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_SOURCE_NODE)) - null - } - val dataIndex = - if (!tlvReader.isNull()) { - tlvReader.getUShort(ContextSpecificTag(TAG_DATA_INDEX)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_DATA_INDEX)) - null - } - + val userIndex = if (!tlvReader.isNull()) { + tlvReader.getUShort(ContextSpecificTag(TAG_USER_INDEX)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_USER_INDEX)) + null + } + val fabricIndex = if (!tlvReader.isNull()) { + tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_FABRIC_INDEX)) + null + } + val sourceNode = if (!tlvReader.isNull()) { + tlvReader.getULong(ContextSpecificTag(TAG_SOURCE_NODE)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_SOURCE_NODE)) + null + } + val dataIndex = if (!tlvReader.isNull()) { + tlvReader.getUShort(ContextSpecificTag(TAG_DATA_INDEX)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_DATA_INDEX)) + null + } + tlvReader.exitContainer() - return DoorLockClusterLockUserChangeEvent( - lockDataType, - dataOperationType, - operationSource, - userIndex, - fabricIndex, - sourceNode, - dataIndex, - ) + return DoorLockClusterLockUserChangeEvent(lockDataType, dataOperationType, operationSource, userIndex, fabricIndex, sourceNode, dataIndex) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ElectricalEnergyMeasurementClusterCumulativeEnergyMeasuredEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ElectricalEnergyMeasurementClusterCumulativeEnergyMeasuredEvent.kt index bf30d118921aa6..8fecbdd04a6da1 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ElectricalEnergyMeasurementClusterCumulativeEnergyMeasuredEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ElectricalEnergyMeasurementClusterCumulativeEnergyMeasuredEvent.kt @@ -18,20 +18,15 @@ package matter.controller.cluster.eventstructs import java.util.Optional 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 ElectricalEnergyMeasurementClusterCumulativeEnergyMeasuredEvent( - val energyImported: - Optional< - matter.controller.cluster.structs.ElectricalEnergyMeasurementClusterEnergyMeasurementStruct - >, - val energyExported: - Optional< - matter.controller.cluster.structs.ElectricalEnergyMeasurementClusterEnergyMeasurementStruct - >, + val energyImported: Optional, + val energyExported: Optional ) { override fun toString(): String = buildString { append("ElectricalEnergyMeasurementClusterCumulativeEnergyMeasuredEvent {\n") @@ -59,38 +54,22 @@ class ElectricalEnergyMeasurementClusterCumulativeEnergyMeasuredEvent( private const val TAG_ENERGY_IMPORTED = 0 private const val TAG_ENERGY_EXPORTED = 1 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): ElectricalEnergyMeasurementClusterCumulativeEnergyMeasuredEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : ElectricalEnergyMeasurementClusterCumulativeEnergyMeasuredEvent { tlvReader.enterStructure(tlvTag) - val energyImported = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_ENERGY_IMPORTED))) { - Optional.of( - matter.controller.cluster.structs - .ElectricalEnergyMeasurementClusterEnergyMeasurementStruct - .fromTlv(ContextSpecificTag(TAG_ENERGY_IMPORTED), tlvReader) - ) - } else { - Optional.empty() - } - val energyExported = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_ENERGY_EXPORTED))) { - Optional.of( - matter.controller.cluster.structs - .ElectricalEnergyMeasurementClusterEnergyMeasurementStruct - .fromTlv(ContextSpecificTag(TAG_ENERGY_EXPORTED), tlvReader) - ) - } else { - Optional.empty() - } - + val energyImported = if (tlvReader.isNextTag(ContextSpecificTag(TAG_ENERGY_IMPORTED))) { + Optional.of(matter.controller.cluster.structs.ElectricalEnergyMeasurementClusterEnergyMeasurementStruct.fromTlv(ContextSpecificTag(TAG_ENERGY_IMPORTED), tlvReader)) + } else { + Optional.empty() + } + val energyExported = if (tlvReader.isNextTag(ContextSpecificTag(TAG_ENERGY_EXPORTED))) { + Optional.of(matter.controller.cluster.structs.ElectricalEnergyMeasurementClusterEnergyMeasurementStruct.fromTlv(ContextSpecificTag(TAG_ENERGY_EXPORTED), tlvReader)) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return ElectricalEnergyMeasurementClusterCumulativeEnergyMeasuredEvent( - energyImported, - energyExported, - ) + return ElectricalEnergyMeasurementClusterCumulativeEnergyMeasuredEvent(energyImported, energyExported) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ElectricalEnergyMeasurementClusterPeriodicEnergyMeasuredEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ElectricalEnergyMeasurementClusterPeriodicEnergyMeasuredEvent.kt index 0654435bfd6fb9..65f3e9e1dc1ba1 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ElectricalEnergyMeasurementClusterPeriodicEnergyMeasuredEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ElectricalEnergyMeasurementClusterPeriodicEnergyMeasuredEvent.kt @@ -18,20 +18,15 @@ package matter.controller.cluster.eventstructs import java.util.Optional 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 ElectricalEnergyMeasurementClusterPeriodicEnergyMeasuredEvent( - val energyImported: - Optional< - matter.controller.cluster.structs.ElectricalEnergyMeasurementClusterEnergyMeasurementStruct - >, - val energyExported: - Optional< - matter.controller.cluster.structs.ElectricalEnergyMeasurementClusterEnergyMeasurementStruct - >, + val energyImported: Optional, + val energyExported: Optional ) { override fun toString(): String = buildString { append("ElectricalEnergyMeasurementClusterPeriodicEnergyMeasuredEvent {\n") @@ -59,38 +54,22 @@ class ElectricalEnergyMeasurementClusterPeriodicEnergyMeasuredEvent( private const val TAG_ENERGY_IMPORTED = 0 private const val TAG_ENERGY_EXPORTED = 1 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): ElectricalEnergyMeasurementClusterPeriodicEnergyMeasuredEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : ElectricalEnergyMeasurementClusterPeriodicEnergyMeasuredEvent { tlvReader.enterStructure(tlvTag) - val energyImported = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_ENERGY_IMPORTED))) { - Optional.of( - matter.controller.cluster.structs - .ElectricalEnergyMeasurementClusterEnergyMeasurementStruct - .fromTlv(ContextSpecificTag(TAG_ENERGY_IMPORTED), tlvReader) - ) - } else { - Optional.empty() - } - val energyExported = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_ENERGY_EXPORTED))) { - Optional.of( - matter.controller.cluster.structs - .ElectricalEnergyMeasurementClusterEnergyMeasurementStruct - .fromTlv(ContextSpecificTag(TAG_ENERGY_EXPORTED), tlvReader) - ) - } else { - Optional.empty() - } - + val energyImported = if (tlvReader.isNextTag(ContextSpecificTag(TAG_ENERGY_IMPORTED))) { + Optional.of(matter.controller.cluster.structs.ElectricalEnergyMeasurementClusterEnergyMeasurementStruct.fromTlv(ContextSpecificTag(TAG_ENERGY_IMPORTED), tlvReader)) + } else { + Optional.empty() + } + val energyExported = if (tlvReader.isNextTag(ContextSpecificTag(TAG_ENERGY_EXPORTED))) { + Optional.of(matter.controller.cluster.structs.ElectricalEnergyMeasurementClusterEnergyMeasurementStruct.fromTlv(ContextSpecificTag(TAG_ENERGY_EXPORTED), tlvReader)) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return ElectricalEnergyMeasurementClusterPeriodicEnergyMeasuredEvent( - energyImported, - energyExported, - ) + return ElectricalEnergyMeasurementClusterPeriodicEnergyMeasuredEvent(energyImported, energyExported) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ElectricalPowerMeasurementClusterMeasurementPeriodRangesEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ElectricalPowerMeasurementClusterMeasurementPeriodRangesEvent.kt index 6688cc9a769ef5..78baf664f250c1 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ElectricalPowerMeasurementClusterMeasurementPeriodRangesEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ElectricalPowerMeasurementClusterMeasurementPeriodRangesEvent.kt @@ -16,6 +16,7 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -24,8 +25,7 @@ import matter.tlv.TlvReader import matter.tlv.TlvWriter class ElectricalPowerMeasurementClusterMeasurementPeriodRangesEvent( - val ranges: - List + val ranges: List ) { override fun toString(): String = buildString { append("ElectricalPowerMeasurementClusterMeasurementPeriodRangesEvent {\n") @@ -48,26 +48,16 @@ class ElectricalPowerMeasurementClusterMeasurementPeriodRangesEvent( companion object { private const val TAG_RANGES = 0 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): ElectricalPowerMeasurementClusterMeasurementPeriodRangesEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : ElectricalPowerMeasurementClusterMeasurementPeriodRangesEvent { tlvReader.enterStructure(tlvTag) - val ranges = - buildList< - matter.controller.cluster.structs.ElectricalPowerMeasurementClusterMeasurementRangeStruct - > { - tlvReader.enterArray(ContextSpecificTag(TAG_RANGES)) - while (!tlvReader.isEndOfContainer()) { - this.add( - matter.controller.cluster.structs - .ElectricalPowerMeasurementClusterMeasurementRangeStruct - .fromTlv(AnonymousTag, tlvReader) - ) - } - tlvReader.exitContainer() + val ranges = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_RANGES)) + while(!tlvReader.isEndOfContainer()) { + this.add(matter.controller.cluster.structs.ElectricalPowerMeasurementClusterMeasurementRangeStruct.fromTlv(AnonymousTag, tlvReader)) } - + tlvReader.exitContainer() + } + tlvReader.exitContainer() return ElectricalPowerMeasurementClusterMeasurementPeriodRangesEvent(ranges) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/EnergyEvseClusterEVConnectedEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/EnergyEvseClusterEVConnectedEvent.kt index 672690fcdac70f..28180727bc065e 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/EnergyEvseClusterEVConnectedEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/EnergyEvseClusterEVConnectedEvent.kt @@ -16,13 +16,17 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional 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 EnergyEvseClusterEVConnectedEvent(val sessionID: UInt) { +class EnergyEvseClusterEVConnectedEvent( + val sessionID: UInt +) { override fun toString(): String = buildString { append("EnergyEvseClusterEVConnectedEvent {\n") append("\tsessionID : $sessionID\n") @@ -40,10 +44,10 @@ class EnergyEvseClusterEVConnectedEvent(val sessionID: UInt) { companion object { private const val TAG_SESSION_ID = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): EnergyEvseClusterEVConnectedEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : EnergyEvseClusterEVConnectedEvent { tlvReader.enterStructure(tlvTag) val sessionID = tlvReader.getUInt(ContextSpecificTag(TAG_SESSION_ID)) - + tlvReader.exitContainer() return EnergyEvseClusterEVConnectedEvent(sessionID) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/EnergyEvseClusterEVNotDetectedEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/EnergyEvseClusterEVNotDetectedEvent.kt index 7f033f40a6c888..17358072f4cf41 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/EnergyEvseClusterEVNotDetectedEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/EnergyEvseClusterEVNotDetectedEvent.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.eventstructs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -28,7 +29,7 @@ class EnergyEvseClusterEVNotDetectedEvent( val state: UByte, val sessionDuration: UInt, val sessionEnergyCharged: Long, - val sessionEnergyDischarged: Optional, + val sessionEnergyDischarged: Optional ) { override fun toString(): String = buildString { append("EnergyEvseClusterEVNotDetectedEvent {\n") @@ -62,28 +63,21 @@ class EnergyEvseClusterEVNotDetectedEvent( private const val TAG_SESSION_ENERGY_CHARGED = 3 private const val TAG_SESSION_ENERGY_DISCHARGED = 4 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): EnergyEvseClusterEVNotDetectedEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : EnergyEvseClusterEVNotDetectedEvent { tlvReader.enterStructure(tlvTag) val sessionID = tlvReader.getUInt(ContextSpecificTag(TAG_SESSION_ID)) val state = tlvReader.getUByte(ContextSpecificTag(TAG_STATE)) val sessionDuration = tlvReader.getUInt(ContextSpecificTag(TAG_SESSION_DURATION)) val sessionEnergyCharged = tlvReader.getLong(ContextSpecificTag(TAG_SESSION_ENERGY_CHARGED)) - val sessionEnergyDischarged = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_SESSION_ENERGY_DISCHARGED))) { - Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_SESSION_ENERGY_DISCHARGED))) - } else { - Optional.empty() - } - + val sessionEnergyDischarged = if (tlvReader.isNextTag(ContextSpecificTag(TAG_SESSION_ENERGY_DISCHARGED))) { + Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_SESSION_ENERGY_DISCHARGED))) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return EnergyEvseClusterEVNotDetectedEvent( - sessionID, - state, - sessionDuration, - sessionEnergyCharged, - sessionEnergyDischarged, - ) + return EnergyEvseClusterEVNotDetectedEvent(sessionID, state, sessionDuration, sessionEnergyCharged, sessionEnergyDischarged) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/EnergyEvseClusterEnergyTransferStartedEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/EnergyEvseClusterEnergyTransferStartedEvent.kt index d6ca275c22f47a..f6131547f3fdf8 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/EnergyEvseClusterEnergyTransferStartedEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/EnergyEvseClusterEnergyTransferStartedEvent.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.eventstructs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -27,7 +28,7 @@ class EnergyEvseClusterEnergyTransferStartedEvent( val sessionID: UInt, val state: UByte, val maximumCurrent: Long, - val maximumDischargeCurrent: Optional, + val maximumDischargeCurrent: Optional ) { override fun toString(): String = buildString { append("EnergyEvseClusterEnergyTransferStartedEvent {\n") @@ -58,26 +59,20 @@ class EnergyEvseClusterEnergyTransferStartedEvent( private const val TAG_MAXIMUM_CURRENT = 2 private const val TAG_MAXIMUM_DISCHARGE_CURRENT = 3 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): EnergyEvseClusterEnergyTransferStartedEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : EnergyEvseClusterEnergyTransferStartedEvent { tlvReader.enterStructure(tlvTag) val sessionID = tlvReader.getUInt(ContextSpecificTag(TAG_SESSION_ID)) val state = tlvReader.getUByte(ContextSpecificTag(TAG_STATE)) val maximumCurrent = tlvReader.getLong(ContextSpecificTag(TAG_MAXIMUM_CURRENT)) - val maximumDischargeCurrent = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_MAXIMUM_DISCHARGE_CURRENT))) { - Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_MAXIMUM_DISCHARGE_CURRENT))) - } else { - Optional.empty() - } - + val maximumDischargeCurrent = if (tlvReader.isNextTag(ContextSpecificTag(TAG_MAXIMUM_DISCHARGE_CURRENT))) { + Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_MAXIMUM_DISCHARGE_CURRENT))) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return EnergyEvseClusterEnergyTransferStartedEvent( - sessionID, - state, - maximumCurrent, - maximumDischargeCurrent, - ) + return EnergyEvseClusterEnergyTransferStartedEvent(sessionID, state, maximumCurrent, maximumDischargeCurrent) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/EnergyEvseClusterEnergyTransferStoppedEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/EnergyEvseClusterEnergyTransferStoppedEvent.kt index 1dea5f56e6e64d..1eec2bb9109e86 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/EnergyEvseClusterEnergyTransferStoppedEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/EnergyEvseClusterEnergyTransferStoppedEvent.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.eventstructs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -28,7 +29,7 @@ class EnergyEvseClusterEnergyTransferStoppedEvent( val state: UByte, val reason: UByte, val energyTransferred: Long, - val energyDischarged: Optional, + val energyDischarged: Optional ) { override fun toString(): String = buildString { append("EnergyEvseClusterEnergyTransferStoppedEvent {\n") @@ -62,28 +63,21 @@ class EnergyEvseClusterEnergyTransferStoppedEvent( private const val TAG_ENERGY_TRANSFERRED = 4 private const val TAG_ENERGY_DISCHARGED = 5 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): EnergyEvseClusterEnergyTransferStoppedEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : EnergyEvseClusterEnergyTransferStoppedEvent { tlvReader.enterStructure(tlvTag) val sessionID = tlvReader.getUInt(ContextSpecificTag(TAG_SESSION_ID)) val state = tlvReader.getUByte(ContextSpecificTag(TAG_STATE)) val reason = tlvReader.getUByte(ContextSpecificTag(TAG_REASON)) val energyTransferred = tlvReader.getLong(ContextSpecificTag(TAG_ENERGY_TRANSFERRED)) - val energyDischarged = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_ENERGY_DISCHARGED))) { - Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_ENERGY_DISCHARGED))) - } else { - Optional.empty() - } - + val energyDischarged = if (tlvReader.isNextTag(ContextSpecificTag(TAG_ENERGY_DISCHARGED))) { + Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_ENERGY_DISCHARGED))) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return EnergyEvseClusterEnergyTransferStoppedEvent( - sessionID, - state, - reason, - energyTransferred, - energyDischarged, - ) + return EnergyEvseClusterEnergyTransferStoppedEvent(sessionID, state, reason, energyTransferred, energyDischarged) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/EnergyEvseClusterFaultEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/EnergyEvseClusterFaultEvent.kt index 02800fa6ed6733..08842a5b4616a3 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/EnergyEvseClusterFaultEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/EnergyEvseClusterFaultEvent.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +28,7 @@ class EnergyEvseClusterFaultEvent( val sessionID: UInt?, val state: UByte, val faultStatePreviousState: UByte, - val faultStateCurrentState: UByte, + val faultStateCurrentState: UByte ) { override fun toString(): String = buildString { append("EnergyEvseClusterFaultEvent {\n") @@ -58,29 +60,21 @@ class EnergyEvseClusterFaultEvent( private const val TAG_FAULT_STATE_PREVIOUS_STATE = 2 private const val TAG_FAULT_STATE_CURRENT_STATE = 4 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): EnergyEvseClusterFaultEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : EnergyEvseClusterFaultEvent { tlvReader.enterStructure(tlvTag) - val sessionID = - if (!tlvReader.isNull()) { - tlvReader.getUInt(ContextSpecificTag(TAG_SESSION_ID)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_SESSION_ID)) - null - } + val sessionID = if (!tlvReader.isNull()) { + tlvReader.getUInt(ContextSpecificTag(TAG_SESSION_ID)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_SESSION_ID)) + null + } val state = tlvReader.getUByte(ContextSpecificTag(TAG_STATE)) - val faultStatePreviousState = - tlvReader.getUByte(ContextSpecificTag(TAG_FAULT_STATE_PREVIOUS_STATE)) - val faultStateCurrentState = - tlvReader.getUByte(ContextSpecificTag(TAG_FAULT_STATE_CURRENT_STATE)) - + val faultStatePreviousState = tlvReader.getUByte(ContextSpecificTag(TAG_FAULT_STATE_PREVIOUS_STATE)) + val faultStateCurrentState = tlvReader.getUByte(ContextSpecificTag(TAG_FAULT_STATE_CURRENT_STATE)) + tlvReader.exitContainer() - return EnergyEvseClusterFaultEvent( - sessionID, - state, - faultStatePreviousState, - faultStateCurrentState, - ) + return EnergyEvseClusterFaultEvent(sessionID, state, faultStatePreviousState, faultStateCurrentState) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/EnergyEvseClusterRFIDEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/EnergyEvseClusterRFIDEvent.kt index cf0fe503e13bd8..6db4c1a10ed59f 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/EnergyEvseClusterRFIDEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/EnergyEvseClusterRFIDEvent.kt @@ -16,13 +16,17 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional 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 EnergyEvseClusterRFIDEvent(val uid: ByteArray) { +class EnergyEvseClusterRFIDEvent( + val uid: ByteArray +) { override fun toString(): String = buildString { append("EnergyEvseClusterRFIDEvent {\n") append("\tuid : $uid\n") @@ -40,10 +44,10 @@ class EnergyEvseClusterRFIDEvent(val uid: ByteArray) { companion object { private const val TAG_UID = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): EnergyEvseClusterRFIDEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : EnergyEvseClusterRFIDEvent { tlvReader.enterStructure(tlvTag) val uid = tlvReader.getByteArray(ContextSpecificTag(TAG_UID)) - + tlvReader.exitContainer() return EnergyEvseClusterRFIDEvent(uid) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/GeneralDiagnosticsClusterBootReasonEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/GeneralDiagnosticsClusterBootReasonEvent.kt index 8d13675dece145..5d6ee591cdf22d 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/GeneralDiagnosticsClusterBootReasonEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/GeneralDiagnosticsClusterBootReasonEvent.kt @@ -16,13 +16,17 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional 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 GeneralDiagnosticsClusterBootReasonEvent(val bootReason: UByte) { +class GeneralDiagnosticsClusterBootReasonEvent( + val bootReason: UByte +) { override fun toString(): String = buildString { append("GeneralDiagnosticsClusterBootReasonEvent {\n") append("\tbootReason : $bootReason\n") @@ -40,10 +44,10 @@ class GeneralDiagnosticsClusterBootReasonEvent(val bootReason: UByte) { companion object { private const val TAG_BOOT_REASON = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): GeneralDiagnosticsClusterBootReasonEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : GeneralDiagnosticsClusterBootReasonEvent { tlvReader.enterStructure(tlvTag) val bootReason = tlvReader.getUByte(ContextSpecificTag(TAG_BOOT_REASON)) - + tlvReader.exitContainer() return GeneralDiagnosticsClusterBootReasonEvent(bootReason) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/GeneralDiagnosticsClusterHardwareFaultChangeEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/GeneralDiagnosticsClusterHardwareFaultChangeEvent.kt index 0f97ac10d53617..415b83a66b74ba 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/GeneralDiagnosticsClusterHardwareFaultChangeEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/GeneralDiagnosticsClusterHardwareFaultChangeEvent.kt @@ -16,6 +16,7 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -25,7 +26,7 @@ import matter.tlv.TlvWriter class GeneralDiagnosticsClusterHardwareFaultChangeEvent( val current: List, - val previous: List, + val previous: List ) { override fun toString(): String = buildString { append("GeneralDiagnosticsClusterHardwareFaultChangeEvent {\n") @@ -55,28 +56,23 @@ class GeneralDiagnosticsClusterHardwareFaultChangeEvent( private const val TAG_CURRENT = 0 private const val TAG_PREVIOUS = 1 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): GeneralDiagnosticsClusterHardwareFaultChangeEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : GeneralDiagnosticsClusterHardwareFaultChangeEvent { tlvReader.enterStructure(tlvTag) - val current = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_CURRENT)) - while (!tlvReader.isEndOfContainer()) { - this.add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() + val current = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_CURRENT)) + while(!tlvReader.isEndOfContainer()) { + this.add(tlvReader.getUByte(AnonymousTag)) } - val previous = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_PREVIOUS)) - while (!tlvReader.isEndOfContainer()) { - this.add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() + tlvReader.exitContainer() + } + val previous = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_PREVIOUS)) + while(!tlvReader.isEndOfContainer()) { + this.add(tlvReader.getUByte(AnonymousTag)) } - + tlvReader.exitContainer() + } + tlvReader.exitContainer() return GeneralDiagnosticsClusterHardwareFaultChangeEvent(current, previous) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/GeneralDiagnosticsClusterNetworkFaultChangeEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/GeneralDiagnosticsClusterNetworkFaultChangeEvent.kt index c20ffadb2b321f..e5ae628b6edfc1 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/GeneralDiagnosticsClusterNetworkFaultChangeEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/GeneralDiagnosticsClusterNetworkFaultChangeEvent.kt @@ -16,6 +16,7 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -25,7 +26,7 @@ import matter.tlv.TlvWriter class GeneralDiagnosticsClusterNetworkFaultChangeEvent( val current: List, - val previous: List, + val previous: List ) { override fun toString(): String = buildString { append("GeneralDiagnosticsClusterNetworkFaultChangeEvent {\n") @@ -55,28 +56,23 @@ class GeneralDiagnosticsClusterNetworkFaultChangeEvent( private const val TAG_CURRENT = 0 private const val TAG_PREVIOUS = 1 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): GeneralDiagnosticsClusterNetworkFaultChangeEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : GeneralDiagnosticsClusterNetworkFaultChangeEvent { tlvReader.enterStructure(tlvTag) - val current = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_CURRENT)) - while (!tlvReader.isEndOfContainer()) { - this.add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() + val current = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_CURRENT)) + while(!tlvReader.isEndOfContainer()) { + this.add(tlvReader.getUByte(AnonymousTag)) } - val previous = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_PREVIOUS)) - while (!tlvReader.isEndOfContainer()) { - this.add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() + tlvReader.exitContainer() + } + val previous = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_PREVIOUS)) + while(!tlvReader.isEndOfContainer()) { + this.add(tlvReader.getUByte(AnonymousTag)) } - + tlvReader.exitContainer() + } + tlvReader.exitContainer() return GeneralDiagnosticsClusterNetworkFaultChangeEvent(current, previous) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/GeneralDiagnosticsClusterRadioFaultChangeEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/GeneralDiagnosticsClusterRadioFaultChangeEvent.kt index eaa89f70e7c8c6..9ebbfae718bb68 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/GeneralDiagnosticsClusterRadioFaultChangeEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/GeneralDiagnosticsClusterRadioFaultChangeEvent.kt @@ -16,6 +16,7 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -25,7 +26,7 @@ import matter.tlv.TlvWriter class GeneralDiagnosticsClusterRadioFaultChangeEvent( val current: List, - val previous: List, + val previous: List ) { override fun toString(): String = buildString { append("GeneralDiagnosticsClusterRadioFaultChangeEvent {\n") @@ -55,25 +56,23 @@ class GeneralDiagnosticsClusterRadioFaultChangeEvent( private const val TAG_CURRENT = 0 private const val TAG_PREVIOUS = 1 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): GeneralDiagnosticsClusterRadioFaultChangeEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : GeneralDiagnosticsClusterRadioFaultChangeEvent { tlvReader.enterStructure(tlvTag) - val current = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_CURRENT)) - while (!tlvReader.isEndOfContainer()) { - this.add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() + val current = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_CURRENT)) + while(!tlvReader.isEndOfContainer()) { + this.add(tlvReader.getUByte(AnonymousTag)) } - val previous = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_PREVIOUS)) - while (!tlvReader.isEndOfContainer()) { - this.add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() + tlvReader.exitContainer() + } + val previous = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_PREVIOUS)) + while(!tlvReader.isEndOfContainer()) { + this.add(tlvReader.getUByte(AnonymousTag)) } - + tlvReader.exitContainer() + } + tlvReader.exitContainer() return GeneralDiagnosticsClusterRadioFaultChangeEvent(current, previous) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/MediaPlaybackClusterStateChangedEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/MediaPlaybackClusterStateChangedEvent.kt index 58b861020c85b3..d7b7eb6f0d01d5 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/MediaPlaybackClusterStateChangedEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/MediaPlaybackClusterStateChangedEvent.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.eventstructs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -32,7 +33,7 @@ class MediaPlaybackClusterStateChangedEvent( val seekRangeEnd: ULong, val seekRangeStart: ULong, val data: Optional, - val audioAdvanceUnmuted: Boolean, + val audioAdvanceUnmuted: Boolean ) { override fun toString(): String = buildString { append("MediaPlaybackClusterStateChangedEvent {\n") @@ -78,40 +79,25 @@ class MediaPlaybackClusterStateChangedEvent( private const val TAG_DATA = 7 private const val TAG_AUDIO_ADVANCE_UNMUTED = 8 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): MediaPlaybackClusterStateChangedEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : MediaPlaybackClusterStateChangedEvent { tlvReader.enterStructure(tlvTag) val currentState = tlvReader.getUByte(ContextSpecificTag(TAG_CURRENT_STATE)) val startTime = tlvReader.getULong(ContextSpecificTag(TAG_START_TIME)) val duration = tlvReader.getULong(ContextSpecificTag(TAG_DURATION)) - val sampledPosition = - matter.controller.cluster.structs.MediaPlaybackClusterPlaybackPositionStruct.fromTlv( - ContextSpecificTag(TAG_SAMPLED_POSITION), - tlvReader, - ) + val sampledPosition = matter.controller.cluster.structs.MediaPlaybackClusterPlaybackPositionStruct.fromTlv(ContextSpecificTag(TAG_SAMPLED_POSITION), tlvReader) val playbackSpeed = tlvReader.getFloat(ContextSpecificTag(TAG_PLAYBACK_SPEED)) val seekRangeEnd = tlvReader.getULong(ContextSpecificTag(TAG_SEEK_RANGE_END)) val seekRangeStart = tlvReader.getULong(ContextSpecificTag(TAG_SEEK_RANGE_START)) - val data = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_DATA))) { - Optional.of(tlvReader.getByteArray(ContextSpecificTag(TAG_DATA))) - } else { - Optional.empty() - } + val data = if (tlvReader.isNextTag(ContextSpecificTag(TAG_DATA))) { + Optional.of(tlvReader.getByteArray(ContextSpecificTag(TAG_DATA))) + } else { + Optional.empty() + } val audioAdvanceUnmuted = tlvReader.getBoolean(ContextSpecificTag(TAG_AUDIO_ADVANCE_UNMUTED)) - + tlvReader.exitContainer() - return MediaPlaybackClusterStateChangedEvent( - currentState, - startTime, - duration, - sampledPosition, - playbackSpeed, - seekRangeEnd, - seekRangeStart, - data, - audioAdvanceUnmuted, - ) + return MediaPlaybackClusterStateChangedEvent(currentState, startTime, duration, sampledPosition, playbackSpeed, seekRangeEnd, seekRangeStart, data, audioAdvanceUnmuted) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/MessagesClusterMessageCompleteEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/MessagesClusterMessageCompleteEvent.kt index 9255c6a84b3e93..1349a714e327c3 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/MessagesClusterMessageCompleteEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/MessagesClusterMessageCompleteEvent.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.eventstructs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -27,7 +28,7 @@ class MessagesClusterMessageCompleteEvent( val messageID: ByteArray, val responseID: Optional?, val reply: Optional?, - val futureMessagesPreference: UByte?, + val futureMessagesPreference: UByte? ) { override fun toString(): String = buildString { append("MessagesClusterMessageCompleteEvent {\n") @@ -44,17 +45,17 @@ class MessagesClusterMessageCompleteEvent( put(ContextSpecificTag(TAG_MESSAGE_ID), messageID) if (responseID != null) { if (responseID.isPresent) { - val optresponseID = responseID.get() - put(ContextSpecificTag(TAG_RESPONSE_ID), optresponseID) - } + val optresponseID = responseID.get() + put(ContextSpecificTag(TAG_RESPONSE_ID), optresponseID) + } } else { putNull(ContextSpecificTag(TAG_RESPONSE_ID)) } if (reply != null) { if (reply.isPresent) { - val optreply = reply.get() - put(ContextSpecificTag(TAG_REPLY), optreply) - } + val optreply = reply.get() + put(ContextSpecificTag(TAG_REPLY), optreply) + } } else { putNull(ContextSpecificTag(TAG_REPLY)) } @@ -73,47 +74,39 @@ class MessagesClusterMessageCompleteEvent( private const val TAG_REPLY = 2 private const val TAG_FUTURE_MESSAGES_PREFERENCE = 3 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): MessagesClusterMessageCompleteEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : MessagesClusterMessageCompleteEvent { tlvReader.enterStructure(tlvTag) val messageID = tlvReader.getByteArray(ContextSpecificTag(TAG_MESSAGE_ID)) - val responseID = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_RESPONSE_ID))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_RESPONSE_ID))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_RESPONSE_ID)) - null - } - val reply = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_REPLY))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_REPLY))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_REPLY)) - null - } - val futureMessagesPreference = - if (!tlvReader.isNull()) { - tlvReader.getUByte(ContextSpecificTag(TAG_FUTURE_MESSAGES_PREFERENCE)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_FUTURE_MESSAGES_PREFERENCE)) - null - } - + val responseID = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_RESPONSE_ID))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_RESPONSE_ID))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_RESPONSE_ID)) + null + } + val reply = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_REPLY))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_REPLY))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_REPLY)) + null + } + val futureMessagesPreference = if (!tlvReader.isNull()) { + tlvReader.getUByte(ContextSpecificTag(TAG_FUTURE_MESSAGES_PREFERENCE)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_FUTURE_MESSAGES_PREFERENCE)) + null + } + tlvReader.exitContainer() - return MessagesClusterMessageCompleteEvent( - messageID, - responseID, - reply, - futureMessagesPreference, - ) + return MessagesClusterMessageCompleteEvent(messageID, responseID, reply, futureMessagesPreference) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/MessagesClusterMessagePresentedEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/MessagesClusterMessagePresentedEvent.kt index eb92978ebc2d27..9526fcd47f5fc4 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/MessagesClusterMessagePresentedEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/MessagesClusterMessagePresentedEvent.kt @@ -16,13 +16,17 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional 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 MessagesClusterMessagePresentedEvent(val messageID: ByteArray) { +class MessagesClusterMessagePresentedEvent( + val messageID: ByteArray +) { override fun toString(): String = buildString { append("MessagesClusterMessagePresentedEvent {\n") append("\tmessageID : $messageID\n") @@ -40,10 +44,10 @@ class MessagesClusterMessagePresentedEvent(val messageID: ByteArray) { companion object { private const val TAG_MESSAGE_ID = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): MessagesClusterMessagePresentedEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : MessagesClusterMessagePresentedEvent { tlvReader.enterStructure(tlvTag) val messageID = tlvReader.getByteArray(ContextSpecificTag(TAG_MESSAGE_ID)) - + tlvReader.exitContainer() return MessagesClusterMessagePresentedEvent(messageID) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/MessagesClusterMessageQueuedEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/MessagesClusterMessageQueuedEvent.kt index 5f0e2b0b3c46fe..b7481a30e837c7 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/MessagesClusterMessageQueuedEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/MessagesClusterMessageQueuedEvent.kt @@ -16,13 +16,17 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional 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 MessagesClusterMessageQueuedEvent(val messageID: ByteArray) { +class MessagesClusterMessageQueuedEvent( + val messageID: ByteArray +) { override fun toString(): String = buildString { append("MessagesClusterMessageQueuedEvent {\n") append("\tmessageID : $messageID\n") @@ -40,10 +44,10 @@ class MessagesClusterMessageQueuedEvent(val messageID: ByteArray) { companion object { private const val TAG_MESSAGE_ID = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): MessagesClusterMessageQueuedEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : MessagesClusterMessageQueuedEvent { tlvReader.enterStructure(tlvTag) val messageID = tlvReader.getByteArray(ContextSpecificTag(TAG_MESSAGE_ID)) - + tlvReader.exitContainer() return MessagesClusterMessageQueuedEvent(messageID) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OperationalStateClusterOperationCompletionEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OperationalStateClusterOperationCompletionEvent.kt index b056da59644a7f..e5a17a96700fca 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OperationalStateClusterOperationCompletionEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OperationalStateClusterOperationCompletionEvent.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.eventstructs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +27,7 @@ import matter.tlv.TlvWriter class OperationalStateClusterOperationCompletionEvent( val completionErrorCode: UByte, val totalOperationalTime: Optional?, - val pausedTime: Optional?, + val pausedTime: Optional? ) { override fun toString(): String = buildString { append("OperationalStateClusterOperationCompletionEvent {\n") @@ -42,17 +43,17 @@ class OperationalStateClusterOperationCompletionEvent( put(ContextSpecificTag(TAG_COMPLETION_ERROR_CODE), completionErrorCode) if (totalOperationalTime != null) { if (totalOperationalTime.isPresent) { - val opttotalOperationalTime = totalOperationalTime.get() - put(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME), opttotalOperationalTime) - } + val opttotalOperationalTime = totalOperationalTime.get() + put(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME), opttotalOperationalTime) + } } else { putNull(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME)) } if (pausedTime != null) { if (pausedTime.isPresent) { - val optpausedTime = pausedTime.get() - put(ContextSpecificTag(TAG_PAUSED_TIME), optpausedTime) - } + val optpausedTime = pausedTime.get() + put(ContextSpecificTag(TAG_PAUSED_TIME), optpausedTime) + } } else { putNull(ContextSpecificTag(TAG_PAUSED_TIME)) } @@ -65,42 +66,33 @@ class OperationalStateClusterOperationCompletionEvent( private const val TAG_TOTAL_OPERATIONAL_TIME = 1 private const val TAG_PAUSED_TIME = 2 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): OperationalStateClusterOperationCompletionEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : OperationalStateClusterOperationCompletionEvent { tlvReader.enterStructure(tlvTag) val completionErrorCode = tlvReader.getUByte(ContextSpecificTag(TAG_COMPLETION_ERROR_CODE)) - val totalOperationalTime = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME)) - null - } - val pausedTime = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_PAUSED_TIME))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_PAUSED_TIME))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_PAUSED_TIME)) - null - } - + val totalOperationalTime = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME)) + null + } + val pausedTime = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_PAUSED_TIME))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_PAUSED_TIME))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_PAUSED_TIME)) + null + } + tlvReader.exitContainer() - return OperationalStateClusterOperationCompletionEvent( - completionErrorCode, - totalOperationalTime, - pausedTime, - ) + return OperationalStateClusterOperationCompletionEvent(completionErrorCode, totalOperationalTime, pausedTime) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OperationalStateClusterOperationalErrorEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OperationalStateClusterOperationalErrorEvent.kt index b2101fbfd5c5d9..10bd2f4144b114 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OperationalStateClusterOperationalErrorEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OperationalStateClusterOperationalErrorEvent.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -42,14 +44,10 @@ class OperationalStateClusterOperationalErrorEvent( companion object { private const val TAG_ERROR_STATE = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): OperationalStateClusterOperationalErrorEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : OperationalStateClusterOperationalErrorEvent { tlvReader.enterStructure(tlvTag) - val errorState = - matter.controller.cluster.structs.OperationalStateClusterErrorStateStruct.fromTlv( - ContextSpecificTag(TAG_ERROR_STATE), - tlvReader, - ) - + val errorState = matter.controller.cluster.structs.OperationalStateClusterErrorStateStruct.fromTlv(ContextSpecificTag(TAG_ERROR_STATE), tlvReader) + tlvReader.exitContainer() return OperationalStateClusterOperationalErrorEvent(errorState) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OtaSoftwareUpdateRequestorClusterDownloadErrorEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OtaSoftwareUpdateRequestorClusterDownloadErrorEvent.kt index a336ae37ddff83..3cdebe626405a4 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OtaSoftwareUpdateRequestorClusterDownloadErrorEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OtaSoftwareUpdateRequestorClusterDownloadErrorEvent.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +28,7 @@ class OtaSoftwareUpdateRequestorClusterDownloadErrorEvent( val softwareVersion: UInt, val bytesDownloaded: ULong, val progressPercent: UByte?, - val platformCode: Long?, + val platformCode: Long? ) { override fun toString(): String = buildString { append("OtaSoftwareUpdateRequestorClusterDownloadErrorEvent {\n") @@ -62,36 +64,26 @@ class OtaSoftwareUpdateRequestorClusterDownloadErrorEvent( private const val TAG_PROGRESS_PERCENT = 2 private const val TAG_PLATFORM_CODE = 3 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): OtaSoftwareUpdateRequestorClusterDownloadErrorEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : OtaSoftwareUpdateRequestorClusterDownloadErrorEvent { tlvReader.enterStructure(tlvTag) val softwareVersion = tlvReader.getUInt(ContextSpecificTag(TAG_SOFTWARE_VERSION)) val bytesDownloaded = tlvReader.getULong(ContextSpecificTag(TAG_BYTES_DOWNLOADED)) - val progressPercent = - if (!tlvReader.isNull()) { - tlvReader.getUByte(ContextSpecificTag(TAG_PROGRESS_PERCENT)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_PROGRESS_PERCENT)) - null - } - val platformCode = - if (!tlvReader.isNull()) { - tlvReader.getLong(ContextSpecificTag(TAG_PLATFORM_CODE)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_PLATFORM_CODE)) - null - } - + val progressPercent = if (!tlvReader.isNull()) { + tlvReader.getUByte(ContextSpecificTag(TAG_PROGRESS_PERCENT)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_PROGRESS_PERCENT)) + null + } + val platformCode = if (!tlvReader.isNull()) { + tlvReader.getLong(ContextSpecificTag(TAG_PLATFORM_CODE)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_PLATFORM_CODE)) + null + } + tlvReader.exitContainer() - return OtaSoftwareUpdateRequestorClusterDownloadErrorEvent( - softwareVersion, - bytesDownloaded, - progressPercent, - platformCode, - ) + return OtaSoftwareUpdateRequestorClusterDownloadErrorEvent(softwareVersion, bytesDownloaded, progressPercent, platformCode) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OtaSoftwareUpdateRequestorClusterStateTransitionEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OtaSoftwareUpdateRequestorClusterStateTransitionEvent.kt index 5c94d6a9e91ded..cacab69022c9c7 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OtaSoftwareUpdateRequestorClusterStateTransitionEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OtaSoftwareUpdateRequestorClusterStateTransitionEvent.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +28,7 @@ class OtaSoftwareUpdateRequestorClusterStateTransitionEvent( val previousState: UByte, val newState: UByte, val reason: UByte, - val targetSoftwareVersion: UInt?, + val targetSoftwareVersion: UInt? ) { override fun toString(): String = buildString { append("OtaSoftwareUpdateRequestorClusterStateTransitionEvent {\n") @@ -58,30 +60,21 @@ class OtaSoftwareUpdateRequestorClusterStateTransitionEvent( private const val TAG_REASON = 2 private const val TAG_TARGET_SOFTWARE_VERSION = 3 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): OtaSoftwareUpdateRequestorClusterStateTransitionEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : OtaSoftwareUpdateRequestorClusterStateTransitionEvent { tlvReader.enterStructure(tlvTag) val previousState = tlvReader.getUByte(ContextSpecificTag(TAG_PREVIOUS_STATE)) val newState = tlvReader.getUByte(ContextSpecificTag(TAG_NEW_STATE)) val reason = tlvReader.getUByte(ContextSpecificTag(TAG_REASON)) - val targetSoftwareVersion = - if (!tlvReader.isNull()) { - tlvReader.getUInt(ContextSpecificTag(TAG_TARGET_SOFTWARE_VERSION)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_TARGET_SOFTWARE_VERSION)) - null - } - + val targetSoftwareVersion = if (!tlvReader.isNull()) { + tlvReader.getUInt(ContextSpecificTag(TAG_TARGET_SOFTWARE_VERSION)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_TARGET_SOFTWARE_VERSION)) + null + } + tlvReader.exitContainer() - return OtaSoftwareUpdateRequestorClusterStateTransitionEvent( - previousState, - newState, - reason, - targetSoftwareVersion, - ) + return OtaSoftwareUpdateRequestorClusterStateTransitionEvent(previousState, newState, reason, targetSoftwareVersion) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OtaSoftwareUpdateRequestorClusterVersionAppliedEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OtaSoftwareUpdateRequestorClusterVersionAppliedEvent.kt index bc361f53a5b2a3..b4cca73ec9cca2 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OtaSoftwareUpdateRequestorClusterVersionAppliedEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OtaSoftwareUpdateRequestorClusterVersionAppliedEvent.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -24,7 +26,7 @@ import matter.tlv.TlvWriter class OtaSoftwareUpdateRequestorClusterVersionAppliedEvent( val softwareVersion: UInt, - val productID: UShort, + val productID: UShort ) { override fun toString(): String = buildString { append("OtaSoftwareUpdateRequestorClusterVersionAppliedEvent {\n") @@ -46,14 +48,11 @@ class OtaSoftwareUpdateRequestorClusterVersionAppliedEvent( private const val TAG_SOFTWARE_VERSION = 0 private const val TAG_PRODUCT_ID = 1 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): OtaSoftwareUpdateRequestorClusterVersionAppliedEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : OtaSoftwareUpdateRequestorClusterVersionAppliedEvent { tlvReader.enterStructure(tlvTag) val softwareVersion = tlvReader.getUInt(ContextSpecificTag(TAG_SOFTWARE_VERSION)) val productID = tlvReader.getUShort(ContextSpecificTag(TAG_PRODUCT_ID)) - + tlvReader.exitContainer() return OtaSoftwareUpdateRequestorClusterVersionAppliedEvent(softwareVersion, productID) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OvenCavityOperationalStateClusterOperationCompletionEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OvenCavityOperationalStateClusterOperationCompletionEvent.kt index bceab29e1e313d..c2f767d8be59a5 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OvenCavityOperationalStateClusterOperationCompletionEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OvenCavityOperationalStateClusterOperationCompletionEvent.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.eventstructs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +27,7 @@ import matter.tlv.TlvWriter class OvenCavityOperationalStateClusterOperationCompletionEvent( val completionErrorCode: UByte, val totalOperationalTime: Optional?, - val pausedTime: Optional?, + val pausedTime: Optional? ) { override fun toString(): String = buildString { append("OvenCavityOperationalStateClusterOperationCompletionEvent {\n") @@ -42,17 +43,17 @@ class OvenCavityOperationalStateClusterOperationCompletionEvent( put(ContextSpecificTag(TAG_COMPLETION_ERROR_CODE), completionErrorCode) if (totalOperationalTime != null) { if (totalOperationalTime.isPresent) { - val opttotalOperationalTime = totalOperationalTime.get() - put(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME), opttotalOperationalTime) - } + val opttotalOperationalTime = totalOperationalTime.get() + put(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME), opttotalOperationalTime) + } } else { putNull(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME)) } if (pausedTime != null) { if (pausedTime.isPresent) { - val optpausedTime = pausedTime.get() - put(ContextSpecificTag(TAG_PAUSED_TIME), optpausedTime) - } + val optpausedTime = pausedTime.get() + put(ContextSpecificTag(TAG_PAUSED_TIME), optpausedTime) + } } else { putNull(ContextSpecificTag(TAG_PAUSED_TIME)) } @@ -65,42 +66,33 @@ class OvenCavityOperationalStateClusterOperationCompletionEvent( private const val TAG_TOTAL_OPERATIONAL_TIME = 1 private const val TAG_PAUSED_TIME = 2 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): OvenCavityOperationalStateClusterOperationCompletionEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : OvenCavityOperationalStateClusterOperationCompletionEvent { tlvReader.enterStructure(tlvTag) val completionErrorCode = tlvReader.getUByte(ContextSpecificTag(TAG_COMPLETION_ERROR_CODE)) - val totalOperationalTime = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME)) - null - } - val pausedTime = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_PAUSED_TIME))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_PAUSED_TIME))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_PAUSED_TIME)) - null - } - + val totalOperationalTime = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME)) + null + } + val pausedTime = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_PAUSED_TIME))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_PAUSED_TIME))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_PAUSED_TIME)) + null + } + tlvReader.exitContainer() - return OvenCavityOperationalStateClusterOperationCompletionEvent( - completionErrorCode, - totalOperationalTime, - pausedTime, - ) + return OvenCavityOperationalStateClusterOperationCompletionEvent(completionErrorCode, totalOperationalTime, pausedTime) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OvenCavityOperationalStateClusterOperationalErrorEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OvenCavityOperationalStateClusterOperationalErrorEvent.kt index 32cbc2f431b862..ee5fe0b442932f 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OvenCavityOperationalStateClusterOperationalErrorEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OvenCavityOperationalStateClusterOperationalErrorEvent.kt @@ -16,15 +16,16 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional 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 OvenCavityOperationalStateClusterOperationalErrorEvent( - val errorState: - matter.controller.cluster.structs.OvenCavityOperationalStateClusterErrorStateStruct + val errorState: matter.controller.cluster.structs.OvenCavityOperationalStateClusterErrorStateStruct ) { override fun toString(): String = buildString { append("OvenCavityOperationalStateClusterOperationalErrorEvent {\n") @@ -43,17 +44,10 @@ class OvenCavityOperationalStateClusterOperationalErrorEvent( companion object { private const val TAG_ERROR_STATE = 0 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): OvenCavityOperationalStateClusterOperationalErrorEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : OvenCavityOperationalStateClusterOperationalErrorEvent { tlvReader.enterStructure(tlvTag) - val errorState = - matter.controller.cluster.structs.OvenCavityOperationalStateClusterErrorStateStruct.fromTlv( - ContextSpecificTag(TAG_ERROR_STATE), - tlvReader, - ) - + val errorState = matter.controller.cluster.structs.OvenCavityOperationalStateClusterErrorStateStruct.fromTlv(ContextSpecificTag(TAG_ERROR_STATE), tlvReader) + tlvReader.exitContainer() return OvenCavityOperationalStateClusterOperationalErrorEvent(errorState) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/PowerSourceClusterBatChargeFaultChangeEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/PowerSourceClusterBatChargeFaultChangeEvent.kt index 2290f97774eb1b..6669a84bd6ec2e 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/PowerSourceClusterBatChargeFaultChangeEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/PowerSourceClusterBatChargeFaultChangeEvent.kt @@ -16,6 +16,7 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -25,7 +26,7 @@ import matter.tlv.TlvWriter class PowerSourceClusterBatChargeFaultChangeEvent( val current: List, - val previous: List, + val previous: List ) { override fun toString(): String = buildString { append("PowerSourceClusterBatChargeFaultChangeEvent {\n") @@ -55,25 +56,23 @@ class PowerSourceClusterBatChargeFaultChangeEvent( private const val TAG_CURRENT = 0 private const val TAG_PREVIOUS = 1 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): PowerSourceClusterBatChargeFaultChangeEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : PowerSourceClusterBatChargeFaultChangeEvent { tlvReader.enterStructure(tlvTag) - val current = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_CURRENT)) - while (!tlvReader.isEndOfContainer()) { - this.add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() + val current = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_CURRENT)) + while(!tlvReader.isEndOfContainer()) { + this.add(tlvReader.getUByte(AnonymousTag)) } - val previous = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_PREVIOUS)) - while (!tlvReader.isEndOfContainer()) { - this.add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() + tlvReader.exitContainer() + } + val previous = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_PREVIOUS)) + while(!tlvReader.isEndOfContainer()) { + this.add(tlvReader.getUByte(AnonymousTag)) } - + tlvReader.exitContainer() + } + tlvReader.exitContainer() return PowerSourceClusterBatChargeFaultChangeEvent(current, previous) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/PowerSourceClusterBatFaultChangeEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/PowerSourceClusterBatFaultChangeEvent.kt index 7aa1a81b862fd5..50752bc8ce3d78 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/PowerSourceClusterBatFaultChangeEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/PowerSourceClusterBatFaultChangeEvent.kt @@ -16,6 +16,7 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -23,7 +24,10 @@ import matter.tlv.Tag import matter.tlv.TlvReader import matter.tlv.TlvWriter -class PowerSourceClusterBatFaultChangeEvent(val current: List, val previous: List) { +class PowerSourceClusterBatFaultChangeEvent( + val current: List, + val previous: List +) { override fun toString(): String = buildString { append("PowerSourceClusterBatFaultChangeEvent {\n") append("\tcurrent : $current\n") @@ -52,25 +56,23 @@ class PowerSourceClusterBatFaultChangeEvent(val current: List, val previo private const val TAG_CURRENT = 0 private const val TAG_PREVIOUS = 1 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): PowerSourceClusterBatFaultChangeEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : PowerSourceClusterBatFaultChangeEvent { tlvReader.enterStructure(tlvTag) - val current = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_CURRENT)) - while (!tlvReader.isEndOfContainer()) { - this.add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() + val current = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_CURRENT)) + while(!tlvReader.isEndOfContainer()) { + this.add(tlvReader.getUByte(AnonymousTag)) } - val previous = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_PREVIOUS)) - while (!tlvReader.isEndOfContainer()) { - this.add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() + tlvReader.exitContainer() + } + val previous = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_PREVIOUS)) + while(!tlvReader.isEndOfContainer()) { + this.add(tlvReader.getUByte(AnonymousTag)) } - + tlvReader.exitContainer() + } + tlvReader.exitContainer() return PowerSourceClusterBatFaultChangeEvent(current, previous) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/PowerSourceClusterWiredFaultChangeEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/PowerSourceClusterWiredFaultChangeEvent.kt index 5dc6444f06cd51..9f125a71de6a58 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/PowerSourceClusterWiredFaultChangeEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/PowerSourceClusterWiredFaultChangeEvent.kt @@ -16,6 +16,7 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -23,7 +24,10 @@ import matter.tlv.Tag import matter.tlv.TlvReader import matter.tlv.TlvWriter -class PowerSourceClusterWiredFaultChangeEvent(val current: List, val previous: List) { +class PowerSourceClusterWiredFaultChangeEvent( + val current: List, + val previous: List +) { override fun toString(): String = buildString { append("PowerSourceClusterWiredFaultChangeEvent {\n") append("\tcurrent : $current\n") @@ -52,25 +56,23 @@ class PowerSourceClusterWiredFaultChangeEvent(val current: List, val prev private const val TAG_CURRENT = 0 private const val TAG_PREVIOUS = 1 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): PowerSourceClusterWiredFaultChangeEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : PowerSourceClusterWiredFaultChangeEvent { tlvReader.enterStructure(tlvTag) - val current = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_CURRENT)) - while (!tlvReader.isEndOfContainer()) { - this.add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() + val current = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_CURRENT)) + while(!tlvReader.isEndOfContainer()) { + this.add(tlvReader.getUByte(AnonymousTag)) } - val previous = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_PREVIOUS)) - while (!tlvReader.isEndOfContainer()) { - this.add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() + tlvReader.exitContainer() + } + val previous = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_PREVIOUS)) + while(!tlvReader.isEndOfContainer()) { + this.add(tlvReader.getUByte(AnonymousTag)) } - + tlvReader.exitContainer() + } + tlvReader.exitContainer() return PowerSourceClusterWiredFaultChangeEvent(current, previous) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/RefrigeratorAlarmClusterNotifyEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/RefrigeratorAlarmClusterNotifyEvent.kt index 7d32c11c70554e..75df72186f31ce 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/RefrigeratorAlarmClusterNotifyEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/RefrigeratorAlarmClusterNotifyEvent.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +28,7 @@ class RefrigeratorAlarmClusterNotifyEvent( val active: UInt, val inactive: UInt, val state: UInt, - val mask: UInt, + val mask: UInt ) { override fun toString(): String = buildString { append("RefrigeratorAlarmClusterNotifyEvent {\n") @@ -54,13 +56,13 @@ class RefrigeratorAlarmClusterNotifyEvent( private const val TAG_STATE = 2 private const val TAG_MASK = 3 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): RefrigeratorAlarmClusterNotifyEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : RefrigeratorAlarmClusterNotifyEvent { tlvReader.enterStructure(tlvTag) val active = tlvReader.getUInt(ContextSpecificTag(TAG_ACTIVE)) val inactive = tlvReader.getUInt(ContextSpecificTag(TAG_INACTIVE)) val state = tlvReader.getUInt(ContextSpecificTag(TAG_STATE)) val mask = tlvReader.getUInt(ContextSpecificTag(TAG_MASK)) - + tlvReader.exitContainer() return RefrigeratorAlarmClusterNotifyEvent(active, inactive, state, mask) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/RvcOperationalStateClusterOperationCompletionEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/RvcOperationalStateClusterOperationCompletionEvent.kt index 4ecfe3b4266ee3..82db20e092df34 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/RvcOperationalStateClusterOperationCompletionEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/RvcOperationalStateClusterOperationCompletionEvent.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.eventstructs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +27,7 @@ import matter.tlv.TlvWriter class RvcOperationalStateClusterOperationCompletionEvent( val completionErrorCode: UByte, val totalOperationalTime: Optional?, - val pausedTime: Optional?, + val pausedTime: Optional? ) { override fun toString(): String = buildString { append("RvcOperationalStateClusterOperationCompletionEvent {\n") @@ -42,17 +43,17 @@ class RvcOperationalStateClusterOperationCompletionEvent( put(ContextSpecificTag(TAG_COMPLETION_ERROR_CODE), completionErrorCode) if (totalOperationalTime != null) { if (totalOperationalTime.isPresent) { - val opttotalOperationalTime = totalOperationalTime.get() - put(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME), opttotalOperationalTime) - } + val opttotalOperationalTime = totalOperationalTime.get() + put(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME), opttotalOperationalTime) + } } else { putNull(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME)) } if (pausedTime != null) { if (pausedTime.isPresent) { - val optpausedTime = pausedTime.get() - put(ContextSpecificTag(TAG_PAUSED_TIME), optpausedTime) - } + val optpausedTime = pausedTime.get() + put(ContextSpecificTag(TAG_PAUSED_TIME), optpausedTime) + } } else { putNull(ContextSpecificTag(TAG_PAUSED_TIME)) } @@ -65,42 +66,33 @@ class RvcOperationalStateClusterOperationCompletionEvent( private const val TAG_TOTAL_OPERATIONAL_TIME = 1 private const val TAG_PAUSED_TIME = 2 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): RvcOperationalStateClusterOperationCompletionEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : RvcOperationalStateClusterOperationCompletionEvent { tlvReader.enterStructure(tlvTag) val completionErrorCode = tlvReader.getUByte(ContextSpecificTag(TAG_COMPLETION_ERROR_CODE)) - val totalOperationalTime = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME)) - null - } - val pausedTime = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_PAUSED_TIME))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_PAUSED_TIME))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_PAUSED_TIME)) - null - } - + val totalOperationalTime = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME)) + null + } + val pausedTime = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_PAUSED_TIME))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_PAUSED_TIME))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_PAUSED_TIME)) + null + } + tlvReader.exitContainer() - return RvcOperationalStateClusterOperationCompletionEvent( - completionErrorCode, - totalOperationalTime, - pausedTime, - ) + return RvcOperationalStateClusterOperationCompletionEvent(completionErrorCode, totalOperationalTime, pausedTime) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/RvcOperationalStateClusterOperationalErrorEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/RvcOperationalStateClusterOperationalErrorEvent.kt index ad1c620ea96f4b..092b9234e3b44d 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/RvcOperationalStateClusterOperationalErrorEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/RvcOperationalStateClusterOperationalErrorEvent.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -42,17 +44,10 @@ class RvcOperationalStateClusterOperationalErrorEvent( companion object { private const val TAG_ERROR_STATE = 0 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): RvcOperationalStateClusterOperationalErrorEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : RvcOperationalStateClusterOperationalErrorEvent { tlvReader.enterStructure(tlvTag) - val errorState = - matter.controller.cluster.structs.RvcOperationalStateClusterErrorStateStruct.fromTlv( - ContextSpecificTag(TAG_ERROR_STATE), - tlvReader, - ) - + val errorState = matter.controller.cluster.structs.RvcOperationalStateClusterErrorStateStruct.fromTlv(ContextSpecificTag(TAG_ERROR_STATE), tlvReader) + tlvReader.exitContainer() return RvcOperationalStateClusterOperationalErrorEvent(errorState) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SampleMeiClusterPingCountEventEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SampleMeiClusterPingCountEventEvent.kt index 5570ba7a3af4a3..e6853817f212a1 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SampleMeiClusterPingCountEventEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SampleMeiClusterPingCountEventEvent.kt @@ -16,13 +16,18 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional 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 SampleMeiClusterPingCountEventEvent(val count: UInt, val fabricIndex: UByte) { +class SampleMeiClusterPingCountEventEvent( + val count: UInt, + val fabricIndex: UByte +) { override fun toString(): String = buildString { append("SampleMeiClusterPingCountEventEvent {\n") append("\tcount : $count\n") @@ -43,11 +48,11 @@ class SampleMeiClusterPingCountEventEvent(val count: UInt, val fabricIndex: UByt private const val TAG_COUNT = 1 private const val TAG_FABRIC_INDEX = 254 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): SampleMeiClusterPingCountEventEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : SampleMeiClusterPingCountEventEvent { tlvReader.enterStructure(tlvTag) val count = tlvReader.getUInt(ContextSpecificTag(TAG_COUNT)) val fabricIndex = tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) - + tlvReader.exitContainer() return SampleMeiClusterPingCountEventEvent(count, fabricIndex) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SmokeCoAlarmClusterCOAlarmEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SmokeCoAlarmClusterCOAlarmEvent.kt index 52c7a19053aacb..ab23f8de4499fc 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SmokeCoAlarmClusterCOAlarmEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SmokeCoAlarmClusterCOAlarmEvent.kt @@ -16,13 +16,17 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional 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 SmokeCoAlarmClusterCOAlarmEvent(val alarmSeverityLevel: UByte) { +class SmokeCoAlarmClusterCOAlarmEvent( + val alarmSeverityLevel: UByte +) { override fun toString(): String = buildString { append("SmokeCoAlarmClusterCOAlarmEvent {\n") append("\talarmSeverityLevel : $alarmSeverityLevel\n") @@ -40,10 +44,10 @@ class SmokeCoAlarmClusterCOAlarmEvent(val alarmSeverityLevel: UByte) { companion object { private const val TAG_ALARM_SEVERITY_LEVEL = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): SmokeCoAlarmClusterCOAlarmEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : SmokeCoAlarmClusterCOAlarmEvent { tlvReader.enterStructure(tlvTag) val alarmSeverityLevel = tlvReader.getUByte(ContextSpecificTag(TAG_ALARM_SEVERITY_LEVEL)) - + tlvReader.exitContainer() return SmokeCoAlarmClusterCOAlarmEvent(alarmSeverityLevel) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SmokeCoAlarmClusterInterconnectCOAlarmEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SmokeCoAlarmClusterInterconnectCOAlarmEvent.kt index 80c6a860b1ccc0..3ccd697a30d045 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SmokeCoAlarmClusterInterconnectCOAlarmEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SmokeCoAlarmClusterInterconnectCOAlarmEvent.kt @@ -16,13 +16,17 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional 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 SmokeCoAlarmClusterInterconnectCOAlarmEvent(val alarmSeverityLevel: UByte) { +class SmokeCoAlarmClusterInterconnectCOAlarmEvent( + val alarmSeverityLevel: UByte +) { override fun toString(): String = buildString { append("SmokeCoAlarmClusterInterconnectCOAlarmEvent {\n") append("\talarmSeverityLevel : $alarmSeverityLevel\n") @@ -40,10 +44,10 @@ class SmokeCoAlarmClusterInterconnectCOAlarmEvent(val alarmSeverityLevel: UByte) companion object { private const val TAG_ALARM_SEVERITY_LEVEL = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): SmokeCoAlarmClusterInterconnectCOAlarmEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : SmokeCoAlarmClusterInterconnectCOAlarmEvent { tlvReader.enterStructure(tlvTag) val alarmSeverityLevel = tlvReader.getUByte(ContextSpecificTag(TAG_ALARM_SEVERITY_LEVEL)) - + tlvReader.exitContainer() return SmokeCoAlarmClusterInterconnectCOAlarmEvent(alarmSeverityLevel) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SmokeCoAlarmClusterInterconnectSmokeAlarmEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SmokeCoAlarmClusterInterconnectSmokeAlarmEvent.kt index 2a3f3f2d05c730..3edfa2543f5b3f 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SmokeCoAlarmClusterInterconnectSmokeAlarmEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SmokeCoAlarmClusterInterconnectSmokeAlarmEvent.kt @@ -16,13 +16,17 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional 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 SmokeCoAlarmClusterInterconnectSmokeAlarmEvent(val alarmSeverityLevel: UByte) { +class SmokeCoAlarmClusterInterconnectSmokeAlarmEvent( + val alarmSeverityLevel: UByte +) { override fun toString(): String = buildString { append("SmokeCoAlarmClusterInterconnectSmokeAlarmEvent {\n") append("\talarmSeverityLevel : $alarmSeverityLevel\n") @@ -40,10 +44,10 @@ class SmokeCoAlarmClusterInterconnectSmokeAlarmEvent(val alarmSeverityLevel: UBy companion object { private const val TAG_ALARM_SEVERITY_LEVEL = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): SmokeCoAlarmClusterInterconnectSmokeAlarmEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : SmokeCoAlarmClusterInterconnectSmokeAlarmEvent { tlvReader.enterStructure(tlvTag) val alarmSeverityLevel = tlvReader.getUByte(ContextSpecificTag(TAG_ALARM_SEVERITY_LEVEL)) - + tlvReader.exitContainer() return SmokeCoAlarmClusterInterconnectSmokeAlarmEvent(alarmSeverityLevel) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SmokeCoAlarmClusterLowBatteryEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SmokeCoAlarmClusterLowBatteryEvent.kt index 3930c40935d0ef..42579fecbdda42 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SmokeCoAlarmClusterLowBatteryEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SmokeCoAlarmClusterLowBatteryEvent.kt @@ -16,13 +16,17 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional 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 SmokeCoAlarmClusterLowBatteryEvent(val alarmSeverityLevel: UByte) { +class SmokeCoAlarmClusterLowBatteryEvent( + val alarmSeverityLevel: UByte +) { override fun toString(): String = buildString { append("SmokeCoAlarmClusterLowBatteryEvent {\n") append("\talarmSeverityLevel : $alarmSeverityLevel\n") @@ -40,10 +44,10 @@ class SmokeCoAlarmClusterLowBatteryEvent(val alarmSeverityLevel: UByte) { companion object { private const val TAG_ALARM_SEVERITY_LEVEL = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): SmokeCoAlarmClusterLowBatteryEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : SmokeCoAlarmClusterLowBatteryEvent { tlvReader.enterStructure(tlvTag) val alarmSeverityLevel = tlvReader.getUByte(ContextSpecificTag(TAG_ALARM_SEVERITY_LEVEL)) - + tlvReader.exitContainer() return SmokeCoAlarmClusterLowBatteryEvent(alarmSeverityLevel) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SmokeCoAlarmClusterSmokeAlarmEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SmokeCoAlarmClusterSmokeAlarmEvent.kt index 934c42da5479a2..25a54c367090c2 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SmokeCoAlarmClusterSmokeAlarmEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SmokeCoAlarmClusterSmokeAlarmEvent.kt @@ -16,13 +16,17 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional 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 SmokeCoAlarmClusterSmokeAlarmEvent(val alarmSeverityLevel: UByte) { +class SmokeCoAlarmClusterSmokeAlarmEvent( + val alarmSeverityLevel: UByte +) { override fun toString(): String = buildString { append("SmokeCoAlarmClusterSmokeAlarmEvent {\n") append("\talarmSeverityLevel : $alarmSeverityLevel\n") @@ -40,10 +44,10 @@ class SmokeCoAlarmClusterSmokeAlarmEvent(val alarmSeverityLevel: UByte) { companion object { private const val TAG_ALARM_SEVERITY_LEVEL = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): SmokeCoAlarmClusterSmokeAlarmEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : SmokeCoAlarmClusterSmokeAlarmEvent { tlvReader.enterStructure(tlvTag) val alarmSeverityLevel = tlvReader.getUByte(ContextSpecificTag(TAG_ALARM_SEVERITY_LEVEL)) - + tlvReader.exitContainer() return SmokeCoAlarmClusterSmokeAlarmEvent(alarmSeverityLevel) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SoftwareDiagnosticsClusterSoftwareFaultEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SoftwareDiagnosticsClusterSoftwareFaultEvent.kt index 13a984acfd4da5..5d78915d64828a 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SoftwareDiagnosticsClusterSoftwareFaultEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SoftwareDiagnosticsClusterSoftwareFaultEvent.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.eventstructs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +27,7 @@ import matter.tlv.TlvWriter class SoftwareDiagnosticsClusterSoftwareFaultEvent( val id: ULong, val name: Optional, - val faultRecording: Optional, + val faultRecording: Optional ) { override fun toString(): String = buildString { append("SoftwareDiagnosticsClusterSoftwareFaultEvent {\n") @@ -57,22 +58,20 @@ class SoftwareDiagnosticsClusterSoftwareFaultEvent( private const val TAG_NAME = 1 private const val TAG_FAULT_RECORDING = 2 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): SoftwareDiagnosticsClusterSoftwareFaultEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : SoftwareDiagnosticsClusterSoftwareFaultEvent { tlvReader.enterStructure(tlvTag) val id = tlvReader.getULong(ContextSpecificTag(TAG_ID)) - val name = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_NAME))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_NAME))) - } else { - Optional.empty() - } - val faultRecording = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_FAULT_RECORDING))) { - Optional.of(tlvReader.getByteArray(ContextSpecificTag(TAG_FAULT_RECORDING))) - } else { - Optional.empty() - } - + val name = if (tlvReader.isNextTag(ContextSpecificTag(TAG_NAME))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_NAME))) + } else { + Optional.empty() + } + val faultRecording = if (tlvReader.isNextTag(ContextSpecificTag(TAG_FAULT_RECORDING))) { + Optional.of(tlvReader.getByteArray(ContextSpecificTag(TAG_FAULT_RECORDING))) + } else { + Optional.empty() + } + tlvReader.exitContainer() return SoftwareDiagnosticsClusterSoftwareFaultEvent(id, name, faultRecording) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterInitialPressEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterInitialPressEvent.kt index f7a74f79826494..eef9c3864807ea 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterInitialPressEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterInitialPressEvent.kt @@ -16,13 +16,17 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional 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 SwitchClusterInitialPressEvent(val newPosition: UByte) { +class SwitchClusterInitialPressEvent( + val newPosition: UByte +) { override fun toString(): String = buildString { append("SwitchClusterInitialPressEvent {\n") append("\tnewPosition : $newPosition\n") @@ -40,10 +44,10 @@ class SwitchClusterInitialPressEvent(val newPosition: UByte) { companion object { private const val TAG_NEW_POSITION = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): SwitchClusterInitialPressEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : SwitchClusterInitialPressEvent { tlvReader.enterStructure(tlvTag) val newPosition = tlvReader.getUByte(ContextSpecificTag(TAG_NEW_POSITION)) - + tlvReader.exitContainer() return SwitchClusterInitialPressEvent(newPosition) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterLongPressEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterLongPressEvent.kt index bacc49c76bbc53..42cd9c501135bc 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterLongPressEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterLongPressEvent.kt @@ -16,13 +16,17 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional 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 SwitchClusterLongPressEvent(val newPosition: UByte) { +class SwitchClusterLongPressEvent( + val newPosition: UByte +) { override fun toString(): String = buildString { append("SwitchClusterLongPressEvent {\n") append("\tnewPosition : $newPosition\n") @@ -40,10 +44,10 @@ class SwitchClusterLongPressEvent(val newPosition: UByte) { companion object { private const val TAG_NEW_POSITION = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): SwitchClusterLongPressEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : SwitchClusterLongPressEvent { tlvReader.enterStructure(tlvTag) val newPosition = tlvReader.getUByte(ContextSpecificTag(TAG_NEW_POSITION)) - + tlvReader.exitContainer() return SwitchClusterLongPressEvent(newPosition) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterLongReleaseEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterLongReleaseEvent.kt index cbd0166269542b..8de4860fe1f299 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterLongReleaseEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterLongReleaseEvent.kt @@ -16,13 +16,17 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional 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 SwitchClusterLongReleaseEvent(val previousPosition: UByte) { +class SwitchClusterLongReleaseEvent( + val previousPosition: UByte +) { override fun toString(): String = buildString { append("SwitchClusterLongReleaseEvent {\n") append("\tpreviousPosition : $previousPosition\n") @@ -40,10 +44,10 @@ class SwitchClusterLongReleaseEvent(val previousPosition: UByte) { companion object { private const val TAG_PREVIOUS_POSITION = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): SwitchClusterLongReleaseEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : SwitchClusterLongReleaseEvent { tlvReader.enterStructure(tlvTag) val previousPosition = tlvReader.getUByte(ContextSpecificTag(TAG_PREVIOUS_POSITION)) - + tlvReader.exitContainer() return SwitchClusterLongReleaseEvent(previousPosition) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterMultiPressCompleteEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterMultiPressCompleteEvent.kt index 584fa5bf06323b..49d9b22f9b45ff 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterMultiPressCompleteEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterMultiPressCompleteEvent.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -24,7 +26,7 @@ import matter.tlv.TlvWriter class SwitchClusterMultiPressCompleteEvent( val previousPosition: UByte, - val totalNumberOfPressesCounted: UByte, + val totalNumberOfPressesCounted: UByte ) { override fun toString(): String = buildString { append("SwitchClusterMultiPressCompleteEvent {\n") @@ -46,12 +48,11 @@ class SwitchClusterMultiPressCompleteEvent( private const val TAG_PREVIOUS_POSITION = 0 private const val TAG_TOTAL_NUMBER_OF_PRESSES_COUNTED = 1 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): SwitchClusterMultiPressCompleteEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : SwitchClusterMultiPressCompleteEvent { tlvReader.enterStructure(tlvTag) val previousPosition = tlvReader.getUByte(ContextSpecificTag(TAG_PREVIOUS_POSITION)) - val totalNumberOfPressesCounted = - tlvReader.getUByte(ContextSpecificTag(TAG_TOTAL_NUMBER_OF_PRESSES_COUNTED)) - + val totalNumberOfPressesCounted = tlvReader.getUByte(ContextSpecificTag(TAG_TOTAL_NUMBER_OF_PRESSES_COUNTED)) + tlvReader.exitContainer() return SwitchClusterMultiPressCompleteEvent(previousPosition, totalNumberOfPressesCounted) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterMultiPressOngoingEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterMultiPressOngoingEvent.kt index 5b621da3f813a0..104be8f4fb63ee 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterMultiPressOngoingEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterMultiPressOngoingEvent.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -24,7 +26,7 @@ import matter.tlv.TlvWriter class SwitchClusterMultiPressOngoingEvent( val newPosition: UByte, - val currentNumberOfPressesCounted: UByte, + val currentNumberOfPressesCounted: UByte ) { override fun toString(): String = buildString { append("SwitchClusterMultiPressOngoingEvent {\n") @@ -46,12 +48,11 @@ class SwitchClusterMultiPressOngoingEvent( private const val TAG_NEW_POSITION = 0 private const val TAG_CURRENT_NUMBER_OF_PRESSES_COUNTED = 1 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): SwitchClusterMultiPressOngoingEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : SwitchClusterMultiPressOngoingEvent { tlvReader.enterStructure(tlvTag) val newPosition = tlvReader.getUByte(ContextSpecificTag(TAG_NEW_POSITION)) - val currentNumberOfPressesCounted = - tlvReader.getUByte(ContextSpecificTag(TAG_CURRENT_NUMBER_OF_PRESSES_COUNTED)) - + val currentNumberOfPressesCounted = tlvReader.getUByte(ContextSpecificTag(TAG_CURRENT_NUMBER_OF_PRESSES_COUNTED)) + tlvReader.exitContainer() return SwitchClusterMultiPressOngoingEvent(newPosition, currentNumberOfPressesCounted) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterShortReleaseEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterShortReleaseEvent.kt index c08c0e63f8b5e1..156c253a485af1 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterShortReleaseEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterShortReleaseEvent.kt @@ -16,13 +16,17 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional 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 SwitchClusterShortReleaseEvent(val previousPosition: UByte) { +class SwitchClusterShortReleaseEvent( + val previousPosition: UByte +) { override fun toString(): String = buildString { append("SwitchClusterShortReleaseEvent {\n") append("\tpreviousPosition : $previousPosition\n") @@ -40,10 +44,10 @@ class SwitchClusterShortReleaseEvent(val previousPosition: UByte) { companion object { private const val TAG_PREVIOUS_POSITION = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): SwitchClusterShortReleaseEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : SwitchClusterShortReleaseEvent { tlvReader.enterStructure(tlvTag) val previousPosition = tlvReader.getUByte(ContextSpecificTag(TAG_PREVIOUS_POSITION)) - + tlvReader.exitContainer() return SwitchClusterShortReleaseEvent(previousPosition) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterSwitchLatchedEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterSwitchLatchedEvent.kt index 4aae22fb446979..f08eaeee96a617 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterSwitchLatchedEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterSwitchLatchedEvent.kt @@ -16,13 +16,17 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional 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 SwitchClusterSwitchLatchedEvent(val newPosition: UByte) { +class SwitchClusterSwitchLatchedEvent( + val newPosition: UByte +) { override fun toString(): String = buildString { append("SwitchClusterSwitchLatchedEvent {\n") append("\tnewPosition : $newPosition\n") @@ -40,10 +44,10 @@ class SwitchClusterSwitchLatchedEvent(val newPosition: UByte) { companion object { private const val TAG_NEW_POSITION = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): SwitchClusterSwitchLatchedEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : SwitchClusterSwitchLatchedEvent { tlvReader.enterStructure(tlvTag) val newPosition = tlvReader.getUByte(ContextSpecificTag(TAG_NEW_POSITION)) - + tlvReader.exitContainer() return SwitchClusterSwitchLatchedEvent(newPosition) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/TargetNavigatorClusterTargetUpdatedEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/TargetNavigatorClusterTargetUpdatedEvent.kt index 7e585378937cee..86a03eb5080eba 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/TargetNavigatorClusterTargetUpdatedEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/TargetNavigatorClusterTargetUpdatedEvent.kt @@ -16,6 +16,7 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -26,7 +27,7 @@ import matter.tlv.TlvWriter class TargetNavigatorClusterTargetUpdatedEvent( val targetList: List, val currentTarget: UByte, - val data: ByteArray, + val data: ByteArray ) { override fun toString(): String = buildString { append("TargetNavigatorClusterTargetUpdatedEvent {\n") @@ -55,24 +56,18 @@ class TargetNavigatorClusterTargetUpdatedEvent( private const val TAG_CURRENT_TARGET = 1 private const val TAG_DATA = 2 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): TargetNavigatorClusterTargetUpdatedEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : TargetNavigatorClusterTargetUpdatedEvent { tlvReader.enterStructure(tlvTag) - val targetList = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_TARGET_LIST)) - while (!tlvReader.isEndOfContainer()) { - this.add( - matter.controller.cluster.structs.TargetNavigatorClusterTargetInfoStruct.fromTlv( - AnonymousTag, - tlvReader, - ) - ) - } - tlvReader.exitContainer() + val targetList = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_TARGET_LIST)) + while(!tlvReader.isEndOfContainer()) { + this.add(matter.controller.cluster.structs.TargetNavigatorClusterTargetInfoStruct.fromTlv(AnonymousTag, tlvReader)) } + tlvReader.exitContainer() + } val currentTarget = tlvReader.getUByte(ContextSpecificTag(TAG_CURRENT_TARGET)) val data = tlvReader.getByteArray(ContextSpecificTag(TAG_DATA)) - + tlvReader.exitContainer() return TargetNavigatorClusterTargetUpdatedEvent(targetList, currentTarget, data) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ThreadNetworkDiagnosticsClusterConnectionStatusEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ThreadNetworkDiagnosticsClusterConnectionStatusEvent.kt index cc872ec9049acc..823b3eb003da4a 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ThreadNetworkDiagnosticsClusterConnectionStatusEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ThreadNetworkDiagnosticsClusterConnectionStatusEvent.kt @@ -16,13 +16,17 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional 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 ThreadNetworkDiagnosticsClusterConnectionStatusEvent(val connectionStatus: UByte) { +class ThreadNetworkDiagnosticsClusterConnectionStatusEvent( + val connectionStatus: UByte +) { override fun toString(): String = buildString { append("ThreadNetworkDiagnosticsClusterConnectionStatusEvent {\n") append("\tconnectionStatus : $connectionStatus\n") @@ -40,13 +44,10 @@ class ThreadNetworkDiagnosticsClusterConnectionStatusEvent(val connectionStatus: companion object { private const val TAG_CONNECTION_STATUS = 0 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): ThreadNetworkDiagnosticsClusterConnectionStatusEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : ThreadNetworkDiagnosticsClusterConnectionStatusEvent { tlvReader.enterStructure(tlvTag) val connectionStatus = tlvReader.getUByte(ContextSpecificTag(TAG_CONNECTION_STATUS)) - + tlvReader.exitContainer() return ThreadNetworkDiagnosticsClusterConnectionStatusEvent(connectionStatus) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ThreadNetworkDiagnosticsClusterNetworkFaultChangeEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ThreadNetworkDiagnosticsClusterNetworkFaultChangeEvent.kt index e81f3bedbfc279..01a5989a931f38 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ThreadNetworkDiagnosticsClusterNetworkFaultChangeEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ThreadNetworkDiagnosticsClusterNetworkFaultChangeEvent.kt @@ -16,6 +16,7 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -25,7 +26,7 @@ import matter.tlv.TlvWriter class ThreadNetworkDiagnosticsClusterNetworkFaultChangeEvent( val current: List, - val previous: List, + val previous: List ) { override fun toString(): String = buildString { append("ThreadNetworkDiagnosticsClusterNetworkFaultChangeEvent {\n") @@ -55,28 +56,23 @@ class ThreadNetworkDiagnosticsClusterNetworkFaultChangeEvent( private const val TAG_CURRENT = 0 private const val TAG_PREVIOUS = 1 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): ThreadNetworkDiagnosticsClusterNetworkFaultChangeEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : ThreadNetworkDiagnosticsClusterNetworkFaultChangeEvent { tlvReader.enterStructure(tlvTag) - val current = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_CURRENT)) - while (!tlvReader.isEndOfContainer()) { - this.add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() + val current = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_CURRENT)) + while(!tlvReader.isEndOfContainer()) { + this.add(tlvReader.getUByte(AnonymousTag)) } - val previous = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_PREVIOUS)) - while (!tlvReader.isEndOfContainer()) { - this.add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() + tlvReader.exitContainer() + } + val previous = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_PREVIOUS)) + while(!tlvReader.isEndOfContainer()) { + this.add(tlvReader.getUByte(AnonymousTag)) } - + tlvReader.exitContainer() + } + tlvReader.exitContainer() return ThreadNetworkDiagnosticsClusterNetworkFaultChangeEvent(current, previous) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/TimeSynchronizationClusterDSTStatusEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/TimeSynchronizationClusterDSTStatusEvent.kt index 53a976552ca1a1..7178725bc96112 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/TimeSynchronizationClusterDSTStatusEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/TimeSynchronizationClusterDSTStatusEvent.kt @@ -16,13 +16,17 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional 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 TimeSynchronizationClusterDSTStatusEvent(val DSTOffsetActive: Boolean) { +class TimeSynchronizationClusterDSTStatusEvent( + val DSTOffsetActive: Boolean +) { override fun toString(): String = buildString { append("TimeSynchronizationClusterDSTStatusEvent {\n") append("\tDSTOffsetActive : $DSTOffsetActive\n") @@ -40,10 +44,10 @@ class TimeSynchronizationClusterDSTStatusEvent(val DSTOffsetActive: Boolean) { companion object { private const val TAG_DST_OFFSET_ACTIVE = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): TimeSynchronizationClusterDSTStatusEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : TimeSynchronizationClusterDSTStatusEvent { tlvReader.enterStructure(tlvTag) val DSTOffsetActive = tlvReader.getBoolean(ContextSpecificTag(TAG_DST_OFFSET_ACTIVE)) - + tlvReader.exitContainer() return TimeSynchronizationClusterDSTStatusEvent(DSTOffsetActive) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/TimeSynchronizationClusterTimeZoneStatusEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/TimeSynchronizationClusterTimeZoneStatusEvent.kt index 0ef92440535c0a..0a12d142db0443 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/TimeSynchronizationClusterTimeZoneStatusEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/TimeSynchronizationClusterTimeZoneStatusEvent.kt @@ -18,12 +18,16 @@ package matter.controller.cluster.eventstructs import java.util.Optional 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 TimeSynchronizationClusterTimeZoneStatusEvent(val offset: Int, val name: Optional) { +class TimeSynchronizationClusterTimeZoneStatusEvent( + val offset: Int, + val name: Optional +) { override fun toString(): String = buildString { append("TimeSynchronizationClusterTimeZoneStatusEvent {\n") append("\toffset : $offset\n") @@ -47,16 +51,15 @@ class TimeSynchronizationClusterTimeZoneStatusEvent(val offset: Int, val name: O private const val TAG_OFFSET = 0 private const val TAG_NAME = 1 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): TimeSynchronizationClusterTimeZoneStatusEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : TimeSynchronizationClusterTimeZoneStatusEvent { tlvReader.enterStructure(tlvTag) val offset = tlvReader.getInt(ContextSpecificTag(TAG_OFFSET)) - val name = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_NAME))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_NAME))) - } else { - Optional.empty() - } - + val name = if (tlvReader.isNextTag(ContextSpecificTag(TAG_NAME))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_NAME))) + } else { + Optional.empty() + } + tlvReader.exitContainer() return TimeSynchronizationClusterTimeZoneStatusEvent(offset, name) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/UnitTestingClusterTestDifferentVendorMeiEventEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/UnitTestingClusterTestDifferentVendorMeiEventEvent.kt index f5119e3ee0b406..add97526607d6d 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/UnitTestingClusterTestDifferentVendorMeiEventEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/UnitTestingClusterTestDifferentVendorMeiEventEvent.kt @@ -16,13 +16,17 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional 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 UnitTestingClusterTestDifferentVendorMeiEventEvent(val arg1: UByte) { +class UnitTestingClusterTestDifferentVendorMeiEventEvent( + val arg1: UByte +) { override fun toString(): String = buildString { append("UnitTestingClusterTestDifferentVendorMeiEventEvent {\n") append("\targ1 : $arg1\n") @@ -40,13 +44,10 @@ class UnitTestingClusterTestDifferentVendorMeiEventEvent(val arg1: UByte) { companion object { private const val TAG_ARG1 = 1 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): UnitTestingClusterTestDifferentVendorMeiEventEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : UnitTestingClusterTestDifferentVendorMeiEventEvent { tlvReader.enterStructure(tlvTag) val arg1 = tlvReader.getUByte(ContextSpecificTag(TAG_ARG1)) - + tlvReader.exitContainer() return UnitTestingClusterTestDifferentVendorMeiEventEvent(arg1) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/UnitTestingClusterTestEventEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/UnitTestingClusterTestEventEvent.kt index 3d3fb3827695dc..2294e08b8377db 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/UnitTestingClusterTestEventEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/UnitTestingClusterTestEventEvent.kt @@ -16,6 +16,7 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -29,7 +30,7 @@ class UnitTestingClusterTestEventEvent( val arg3: Boolean, val arg4: matter.controller.cluster.structs.UnitTestingClusterSimpleStruct, val arg5: List, - val arg6: List, + val arg6: List ) { override fun toString(): String = buildString { append("UnitTestingClusterTestEventEvent {\n") @@ -71,38 +72,27 @@ class UnitTestingClusterTestEventEvent( private const val TAG_ARG5 = 5 private const val TAG_ARG6 = 6 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): UnitTestingClusterTestEventEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : UnitTestingClusterTestEventEvent { tlvReader.enterStructure(tlvTag) val arg1 = tlvReader.getUByte(ContextSpecificTag(TAG_ARG1)) val arg2 = tlvReader.getUByte(ContextSpecificTag(TAG_ARG2)) val arg3 = tlvReader.getBoolean(ContextSpecificTag(TAG_ARG3)) - val arg4 = - matter.controller.cluster.structs.UnitTestingClusterSimpleStruct.fromTlv( - ContextSpecificTag(TAG_ARG4), - tlvReader, - ) - val arg5 = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_ARG5)) - while (!tlvReader.isEndOfContainer()) { - this.add( - matter.controller.cluster.structs.UnitTestingClusterSimpleStruct.fromTlv( - AnonymousTag, - tlvReader, - ) - ) - } - tlvReader.exitContainer() + val arg4 = matter.controller.cluster.structs.UnitTestingClusterSimpleStruct.fromTlv(ContextSpecificTag(TAG_ARG4), tlvReader) + val arg5 = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_ARG5)) + while(!tlvReader.isEndOfContainer()) { + this.add(matter.controller.cluster.structs.UnitTestingClusterSimpleStruct.fromTlv(AnonymousTag, tlvReader)) } - val arg6 = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_ARG6)) - while (!tlvReader.isEndOfContainer()) { - this.add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() + tlvReader.exitContainer() + } + val arg6 = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_ARG6)) + while(!tlvReader.isEndOfContainer()) { + this.add(tlvReader.getUByte(AnonymousTag)) } - + tlvReader.exitContainer() + } + tlvReader.exitContainer() return UnitTestingClusterTestEventEvent(arg1, arg2, arg3, arg4, arg5, arg6) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/UnitTestingClusterTestFabricScopedEventEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/UnitTestingClusterTestFabricScopedEventEvent.kt index b0ac8683c99209..a52b06cd5cbd96 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/UnitTestingClusterTestFabricScopedEventEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/UnitTestingClusterTestFabricScopedEventEvent.kt @@ -16,13 +16,17 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional 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 UnitTestingClusterTestFabricScopedEventEvent(val fabricIndex: UByte) { +class UnitTestingClusterTestFabricScopedEventEvent( + val fabricIndex: UByte +) { override fun toString(): String = buildString { append("UnitTestingClusterTestFabricScopedEventEvent {\n") append("\tfabricIndex : $fabricIndex\n") @@ -40,10 +44,10 @@ class UnitTestingClusterTestFabricScopedEventEvent(val fabricIndex: UByte) { companion object { private const val TAG_FABRIC_INDEX = 254 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): UnitTestingClusterTestFabricScopedEventEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : UnitTestingClusterTestFabricScopedEventEvent { tlvReader.enterStructure(tlvTag) val fabricIndex = tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) - + tlvReader.exitContainer() return UnitTestingClusterTestFabricScopedEventEvent(fabricIndex) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ValveConfigurationAndControlClusterValveFaultEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ValveConfigurationAndControlClusterValveFaultEvent.kt index a19524d74e9c9e..a740d0e35331fe 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ValveConfigurationAndControlClusterValveFaultEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ValveConfigurationAndControlClusterValveFaultEvent.kt @@ -16,13 +16,17 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional 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 ValveConfigurationAndControlClusterValveFaultEvent(val valveFault: UShort) { +class ValveConfigurationAndControlClusterValveFaultEvent( + val valveFault: UShort +) { override fun toString(): String = buildString { append("ValveConfigurationAndControlClusterValveFaultEvent {\n") append("\tvalveFault : $valveFault\n") @@ -40,13 +44,10 @@ class ValveConfigurationAndControlClusterValveFaultEvent(val valveFault: UShort) companion object { private const val TAG_VALVE_FAULT = 0 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): ValveConfigurationAndControlClusterValveFaultEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : ValveConfigurationAndControlClusterValveFaultEvent { tlvReader.enterStructure(tlvTag) val valveFault = tlvReader.getUShort(ContextSpecificTag(TAG_VALVE_FAULT)) - + tlvReader.exitContainer() return ValveConfigurationAndControlClusterValveFaultEvent(valveFault) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ValveConfigurationAndControlClusterValveStateChangedEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ValveConfigurationAndControlClusterValveStateChangedEvent.kt index 332e4e19342ebf..2331135586801c 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ValveConfigurationAndControlClusterValveStateChangedEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ValveConfigurationAndControlClusterValveStateChangedEvent.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.eventstructs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -25,7 +26,7 @@ import matter.tlv.TlvWriter class ValveConfigurationAndControlClusterValveStateChangedEvent( val valveState: UByte, - val valveLevel: Optional, + val valveLevel: Optional ) { override fun toString(): String = buildString { append("ValveConfigurationAndControlClusterValveStateChangedEvent {\n") @@ -50,19 +51,15 @@ class ValveConfigurationAndControlClusterValveStateChangedEvent( private const val TAG_VALVE_STATE = 0 private const val TAG_VALVE_LEVEL = 1 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): ValveConfigurationAndControlClusterValveStateChangedEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : ValveConfigurationAndControlClusterValveStateChangedEvent { tlvReader.enterStructure(tlvTag) val valveState = tlvReader.getUByte(ContextSpecificTag(TAG_VALVE_STATE)) - val valveLevel = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_VALVE_LEVEL))) { - Optional.of(tlvReader.getUByte(ContextSpecificTag(TAG_VALVE_LEVEL))) - } else { - Optional.empty() - } - + val valveLevel = if (tlvReader.isNextTag(ContextSpecificTag(TAG_VALVE_LEVEL))) { + Optional.of(tlvReader.getUByte(ContextSpecificTag(TAG_VALVE_LEVEL))) + } else { + Optional.empty() + } + tlvReader.exitContainer() return ValveConfigurationAndControlClusterValveStateChangedEvent(valveState, valveLevel) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/WaterHeaterManagementClusterBoostStartedEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/WaterHeaterManagementClusterBoostStartedEvent.kt index 44e51796c1fa50..192b9e9c6421c9 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/WaterHeaterManagementClusterBoostStartedEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/WaterHeaterManagementClusterBoostStartedEvent.kt @@ -16,15 +16,16 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional 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 WaterHeaterManagementClusterBoostStartedEvent( - val boostInfo: - matter.controller.cluster.structs.WaterHeaterManagementClusterWaterHeaterBoostInfoStruct + val boostInfo: matter.controller.cluster.structs.WaterHeaterManagementClusterWaterHeaterBoostInfoStruct ) { override fun toString(): String = buildString { append("WaterHeaterManagementClusterBoostStartedEvent {\n") @@ -43,12 +44,10 @@ class WaterHeaterManagementClusterBoostStartedEvent( companion object { private const val TAG_BOOST_INFO = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): WaterHeaterManagementClusterBoostStartedEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : WaterHeaterManagementClusterBoostStartedEvent { tlvReader.enterStructure(tlvTag) - val boostInfo = - matter.controller.cluster.structs.WaterHeaterManagementClusterWaterHeaterBoostInfoStruct - .fromTlv(ContextSpecificTag(TAG_BOOST_INFO), tlvReader) - + val boostInfo = matter.controller.cluster.structs.WaterHeaterManagementClusterWaterHeaterBoostInfoStruct.fromTlv(ContextSpecificTag(TAG_BOOST_INFO), tlvReader) + tlvReader.exitContainer() return WaterHeaterManagementClusterBoostStartedEvent(boostInfo) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/WiFiNetworkDiagnosticsClusterAssociationFailureEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/WiFiNetworkDiagnosticsClusterAssociationFailureEvent.kt index 64f5392aa4fb50..fddf6cdad7a8a6 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/WiFiNetworkDiagnosticsClusterAssociationFailureEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/WiFiNetworkDiagnosticsClusterAssociationFailureEvent.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -24,7 +26,7 @@ import matter.tlv.TlvWriter class WiFiNetworkDiagnosticsClusterAssociationFailureEvent( val associationFailureCause: UByte, - val status: UShort, + val status: UShort ) { override fun toString(): String = buildString { append("WiFiNetworkDiagnosticsClusterAssociationFailureEvent {\n") @@ -46,15 +48,11 @@ class WiFiNetworkDiagnosticsClusterAssociationFailureEvent( private const val TAG_ASSOCIATION_FAILURE_CAUSE = 0 private const val TAG_STATUS = 1 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): WiFiNetworkDiagnosticsClusterAssociationFailureEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : WiFiNetworkDiagnosticsClusterAssociationFailureEvent { tlvReader.enterStructure(tlvTag) - val associationFailureCause = - tlvReader.getUByte(ContextSpecificTag(TAG_ASSOCIATION_FAILURE_CAUSE)) + val associationFailureCause = tlvReader.getUByte(ContextSpecificTag(TAG_ASSOCIATION_FAILURE_CAUSE)) val status = tlvReader.getUShort(ContextSpecificTag(TAG_STATUS)) - + tlvReader.exitContainer() return WiFiNetworkDiagnosticsClusterAssociationFailureEvent(associationFailureCause, status) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/WiFiNetworkDiagnosticsClusterConnectionStatusEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/WiFiNetworkDiagnosticsClusterConnectionStatusEvent.kt index 122e44de1dc246..0e668adcf859dd 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/WiFiNetworkDiagnosticsClusterConnectionStatusEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/WiFiNetworkDiagnosticsClusterConnectionStatusEvent.kt @@ -16,13 +16,17 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional 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 WiFiNetworkDiagnosticsClusterConnectionStatusEvent(val connectionStatus: UByte) { +class WiFiNetworkDiagnosticsClusterConnectionStatusEvent( + val connectionStatus: UByte +) { override fun toString(): String = buildString { append("WiFiNetworkDiagnosticsClusterConnectionStatusEvent {\n") append("\tconnectionStatus : $connectionStatus\n") @@ -40,13 +44,10 @@ class WiFiNetworkDiagnosticsClusterConnectionStatusEvent(val connectionStatus: U companion object { private const val TAG_CONNECTION_STATUS = 0 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): WiFiNetworkDiagnosticsClusterConnectionStatusEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : WiFiNetworkDiagnosticsClusterConnectionStatusEvent { tlvReader.enterStructure(tlvTag) val connectionStatus = tlvReader.getUByte(ContextSpecificTag(TAG_CONNECTION_STATUS)) - + tlvReader.exitContainer() return WiFiNetworkDiagnosticsClusterConnectionStatusEvent(connectionStatus) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/WiFiNetworkDiagnosticsClusterDisconnectionEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/WiFiNetworkDiagnosticsClusterDisconnectionEvent.kt index baff7be3fea8cb..40a4bf1d3cc947 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/WiFiNetworkDiagnosticsClusterDisconnectionEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/WiFiNetworkDiagnosticsClusterDisconnectionEvent.kt @@ -16,13 +16,17 @@ */ package matter.controller.cluster.eventstructs +import java.util.Optional 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 WiFiNetworkDiagnosticsClusterDisconnectionEvent(val reasonCode: UShort) { +class WiFiNetworkDiagnosticsClusterDisconnectionEvent( + val reasonCode: UShort +) { override fun toString(): String = buildString { append("WiFiNetworkDiagnosticsClusterDisconnectionEvent {\n") append("\treasonCode : $reasonCode\n") @@ -40,13 +44,10 @@ class WiFiNetworkDiagnosticsClusterDisconnectionEvent(val reasonCode: UShort) { companion object { private const val TAG_REASON_CODE = 0 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): WiFiNetworkDiagnosticsClusterDisconnectionEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : WiFiNetworkDiagnosticsClusterDisconnectionEvent { tlvReader.enterStructure(tlvTag) val reasonCode = tlvReader.getUShort(ContextSpecificTag(TAG_REASON_CODE)) - + tlvReader.exitContainer() return WiFiNetworkDiagnosticsClusterDisconnectionEvent(reasonCode) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/AccessControlClusterAccessControlEntryStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/AccessControlClusterAccessControlEntryStruct.kt index e452c201c3c824..bd703215de0a5b 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/AccessControlClusterAccessControlEntryStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/AccessControlClusterAccessControlEntryStruct.kt @@ -16,6 +16,7 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -28,7 +29,7 @@ class AccessControlClusterAccessControlEntryStruct( val authMode: UByte, val subjects: List?, val targets: List?, - val fabricIndex: UByte, + val fabricIndex: UByte ) { override fun toString(): String = buildString { append("AccessControlClusterAccessControlEntryStruct {\n") @@ -47,19 +48,19 @@ class AccessControlClusterAccessControlEntryStruct( put(ContextSpecificTag(TAG_AUTH_MODE), authMode) if (subjects != null) { startArray(ContextSpecificTag(TAG_SUBJECTS)) - for (item in subjects.iterator()) { - put(AnonymousTag, item) - } - endArray() + for (item in subjects.iterator()) { + put(AnonymousTag, item) + } + endArray() } else { putNull(ContextSpecificTag(TAG_SUBJECTS)) } if (targets != null) { startArray(ContextSpecificTag(TAG_TARGETS)) - for (item in targets.iterator()) { - item.toTlv(AnonymousTag, this) - } - endArray() + for (item in targets.iterator()) { + item.toTlv(AnonymousTag, this) + } + endArray() } else { putNull(ContextSpecificTag(TAG_TARGETS)) } @@ -79,43 +80,35 @@ class AccessControlClusterAccessControlEntryStruct( tlvReader.enterStructure(tlvTag) val privilege = tlvReader.getUByte(ContextSpecificTag(TAG_PRIVILEGE)) val authMode = tlvReader.getUByte(ContextSpecificTag(TAG_AUTH_MODE)) - val subjects = - if (!tlvReader.isNull()) { - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_SUBJECTS)) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getULong(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_SUBJECTS)) - null - } - val targets = - if (!tlvReader.isNull()) { - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_TARGETS)) - while (!tlvReader.isEndOfContainer()) { - add(AccessControlClusterAccessControlTargetStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_TARGETS)) - null - } + val subjects = if (!tlvReader.isNull()) { + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_SUBJECTS)) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getULong(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_SUBJECTS)) + null + } + val targets = if (!tlvReader.isNull()) { + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_TARGETS)) + while(!tlvReader.isEndOfContainer()) { + add(AccessControlClusterAccessControlTargetStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_TARGETS)) + null + } val fabricIndex = tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) - + tlvReader.exitContainer() - return AccessControlClusterAccessControlEntryStruct( - privilege, - authMode, - subjects, - targets, - fabricIndex, - ) + return AccessControlClusterAccessControlEntryStruct(privilege, authMode, subjects, targets, fabricIndex) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/AccessControlClusterAccessControlExtensionStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/AccessControlClusterAccessControlExtensionStruct.kt index 34abd2cb66e907..8ffb7a94a61ed1 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/AccessControlClusterAccessControlExtensionStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/AccessControlClusterAccessControlExtensionStruct.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -24,7 +26,7 @@ import matter.tlv.TlvWriter class AccessControlClusterAccessControlExtensionStruct( val data: ByteArray, - val fabricIndex: UByte, + val fabricIndex: UByte ) { override fun toString(): String = buildString { append("AccessControlClusterAccessControlExtensionStruct {\n") @@ -46,14 +48,11 @@ class AccessControlClusterAccessControlExtensionStruct( private const val TAG_DATA = 1 private const val TAG_FABRIC_INDEX = 254 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): AccessControlClusterAccessControlExtensionStruct { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): AccessControlClusterAccessControlExtensionStruct { tlvReader.enterStructure(tlvTag) val data = tlvReader.getByteArray(ContextSpecificTag(TAG_DATA)) val fabricIndex = tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) - + tlvReader.exitContainer() return AccessControlClusterAccessControlExtensionStruct(data, fabricIndex) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/AccessControlClusterAccessControlTargetStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/AccessControlClusterAccessControlTargetStruct.kt index 518b2ec671cb28..dc275d27e5f803 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/AccessControlClusterAccessControlTargetStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/AccessControlClusterAccessControlTargetStruct.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -25,7 +27,7 @@ import matter.tlv.TlvWriter class AccessControlClusterAccessControlTargetStruct( val cluster: UInt?, val endpoint: UShort?, - val deviceType: UInt?, + val deviceType: UInt? ) { override fun toString(): String = buildString { append("AccessControlClusterAccessControlTargetStruct {\n") @@ -64,28 +66,25 @@ class AccessControlClusterAccessControlTargetStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): AccessControlClusterAccessControlTargetStruct { tlvReader.enterStructure(tlvTag) - val cluster = - if (!tlvReader.isNull()) { - tlvReader.getUInt(ContextSpecificTag(TAG_CLUSTER)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_CLUSTER)) - null - } - val endpoint = - if (!tlvReader.isNull()) { - tlvReader.getUShort(ContextSpecificTag(TAG_ENDPOINT)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_ENDPOINT)) - null - } - val deviceType = - if (!tlvReader.isNull()) { - tlvReader.getUInt(ContextSpecificTag(TAG_DEVICE_TYPE)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_DEVICE_TYPE)) - null - } - + val cluster = if (!tlvReader.isNull()) { + tlvReader.getUInt(ContextSpecificTag(TAG_CLUSTER)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_CLUSTER)) + null + } + val endpoint = if (!tlvReader.isNull()) { + tlvReader.getUShort(ContextSpecificTag(TAG_ENDPOINT)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_ENDPOINT)) + null + } + val deviceType = if (!tlvReader.isNull()) { + tlvReader.getUInt(ContextSpecificTag(TAG_DEVICE_TYPE)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_DEVICE_TYPE)) + null + } + tlvReader.exitContainer() return AccessControlClusterAccessControlTargetStruct(cluster, endpoint, deviceType) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/AccessControlClusterAccessRestrictionEntryStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/AccessControlClusterAccessRestrictionEntryStruct.kt index 6750b4fc80c401..c2cd26aba3ca98 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/AccessControlClusterAccessRestrictionEntryStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/AccessControlClusterAccessRestrictionEntryStruct.kt @@ -16,6 +16,7 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -27,7 +28,7 @@ class AccessControlClusterAccessRestrictionEntryStruct( val endpoint: UShort, val cluster: UInt, val restrictions: List, - val fabricIndex: UByte, + val fabricIndex: UByte ) { override fun toString(): String = buildString { append("AccessControlClusterAccessRestrictionEntryStruct {\n") @@ -59,31 +60,22 @@ class AccessControlClusterAccessRestrictionEntryStruct( private const val TAG_RESTRICTIONS = 2 private const val TAG_FABRIC_INDEX = 254 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): AccessControlClusterAccessRestrictionEntryStruct { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): AccessControlClusterAccessRestrictionEntryStruct { tlvReader.enterStructure(tlvTag) val endpoint = tlvReader.getUShort(ContextSpecificTag(TAG_ENDPOINT)) val cluster = tlvReader.getUInt(ContextSpecificTag(TAG_CLUSTER)) - val restrictions = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_RESTRICTIONS)) - while (!tlvReader.isEndOfContainer()) { - add(AccessControlClusterAccessRestrictionStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val restrictions = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_RESTRICTIONS)) + while(!tlvReader.isEndOfContainer()) { + add(AccessControlClusterAccessRestrictionStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } val fabricIndex = tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) - + tlvReader.exitContainer() - return AccessControlClusterAccessRestrictionEntryStruct( - endpoint, - cluster, - restrictions, - fabricIndex, - ) + return AccessControlClusterAccessRestrictionEntryStruct(endpoint, cluster, restrictions, fabricIndex) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/AccessControlClusterAccessRestrictionStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/AccessControlClusterAccessRestrictionStruct.kt index 16452c2baa2919..dae6259cbc6217 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/AccessControlClusterAccessRestrictionStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/AccessControlClusterAccessRestrictionStruct.kt @@ -16,13 +16,18 @@ */ package matter.controller.cluster.structs +import java.util.Optional 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 AccessControlClusterAccessRestrictionStruct(val type: UByte, val id: UInt?) { +class AccessControlClusterAccessRestrictionStruct( + val type: UByte, + val id: UInt? +) { override fun toString(): String = buildString { append("AccessControlClusterAccessRestrictionStruct {\n") append("\ttype : $type\n") @@ -50,14 +55,13 @@ class AccessControlClusterAccessRestrictionStruct(val type: UByte, val id: UInt? fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): AccessControlClusterAccessRestrictionStruct { tlvReader.enterStructure(tlvTag) val type = tlvReader.getUByte(ContextSpecificTag(TAG_TYPE)) - val id = - if (!tlvReader.isNull()) { - tlvReader.getUInt(ContextSpecificTag(TAG_ID)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_ID)) - null - } - + val id = if (!tlvReader.isNull()) { + tlvReader.getUInt(ContextSpecificTag(TAG_ID)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_ID)) + null + } + tlvReader.exitContainer() return AccessControlClusterAccessRestrictionStruct(type, id) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/AccessControlClusterCommissioningAccessRestrictionEntryStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/AccessControlClusterCommissioningAccessRestrictionEntryStruct.kt index c2c9582400272a..c24ffa1c6cdbe8 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/AccessControlClusterCommissioningAccessRestrictionEntryStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/AccessControlClusterCommissioningAccessRestrictionEntryStruct.kt @@ -16,6 +16,7 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -26,7 +27,7 @@ import matter.tlv.TlvWriter class AccessControlClusterCommissioningAccessRestrictionEntryStruct( val endpoint: UShort, val cluster: UInt, - val restrictions: List, + val restrictions: List ) { override fun toString(): String = buildString { append("AccessControlClusterCommissioningAccessRestrictionEntryStruct {\n") @@ -55,29 +56,21 @@ class AccessControlClusterCommissioningAccessRestrictionEntryStruct( private const val TAG_CLUSTER = 1 private const val TAG_RESTRICTIONS = 2 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): AccessControlClusterCommissioningAccessRestrictionEntryStruct { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): AccessControlClusterCommissioningAccessRestrictionEntryStruct { tlvReader.enterStructure(tlvTag) val endpoint = tlvReader.getUShort(ContextSpecificTag(TAG_ENDPOINT)) val cluster = tlvReader.getUInt(ContextSpecificTag(TAG_CLUSTER)) - val restrictions = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_RESTRICTIONS)) - while (!tlvReader.isEndOfContainer()) { - add(AccessControlClusterAccessRestrictionStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - + val restrictions = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_RESTRICTIONS)) + while(!tlvReader.isEndOfContainer()) { + add(AccessControlClusterAccessRestrictionStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + tlvReader.exitContainer() - return AccessControlClusterCommissioningAccessRestrictionEntryStruct( - endpoint, - cluster, - restrictions, - ) + return AccessControlClusterCommissioningAccessRestrictionEntryStruct(endpoint, cluster, restrictions) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ActionsClusterActionStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ActionsClusterActionStruct.kt index 080da76540c4a6..965cedd6ace042 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ActionsClusterActionStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ActionsClusterActionStruct.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -28,7 +30,7 @@ class ActionsClusterActionStruct( val type: UByte, val endpointListID: UShort, val supportedCommands: UShort, - val state: UByte, + val state: UByte ) { override fun toString(): String = buildString { append("ActionsClusterActionStruct {\n") @@ -70,17 +72,10 @@ class ActionsClusterActionStruct( val endpointListID = tlvReader.getUShort(ContextSpecificTag(TAG_ENDPOINT_LIST_ID)) val supportedCommands = tlvReader.getUShort(ContextSpecificTag(TAG_SUPPORTED_COMMANDS)) val state = tlvReader.getUByte(ContextSpecificTag(TAG_STATE)) - + tlvReader.exitContainer() - return ActionsClusterActionStruct( - actionID, - name, - type, - endpointListID, - supportedCommands, - state, - ) + return ActionsClusterActionStruct(actionID, name, type, endpointListID, supportedCommands, state) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ActionsClusterEndpointListStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ActionsClusterEndpointListStruct.kt index 3c4603e164076d..df60e68d39bae8 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ActionsClusterEndpointListStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ActionsClusterEndpointListStruct.kt @@ -16,6 +16,7 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -27,7 +28,7 @@ class ActionsClusterEndpointListStruct( val endpointListID: UShort, val name: String, val type: UByte, - val endpoints: List, + val endpoints: List ) { override fun toString(): String = buildString { append("ActionsClusterEndpointListStruct {\n") @@ -64,15 +65,14 @@ class ActionsClusterEndpointListStruct( val endpointListID = tlvReader.getUShort(ContextSpecificTag(TAG_ENDPOINT_LIST_ID)) val name = tlvReader.getString(ContextSpecificTag(TAG_NAME)) val type = tlvReader.getUByte(ContextSpecificTag(TAG_TYPE)) - val endpoints = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_ENDPOINTS)) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getUShort(AnonymousTag)) - } - tlvReader.exitContainer() - } - + val endpoints = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_ENDPOINTS)) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUShort(AnonymousTag)) + } + tlvReader.exitContainer() + } + tlvReader.exitContainer() return ActionsClusterEndpointListStruct(endpointListID, name, type, endpoints) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ActivatedCarbonFilterMonitoringClusterReplacementProductStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ActivatedCarbonFilterMonitoringClusterReplacementProductStruct.kt index 20c989ddc5a368..c43c172f39ad4a 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ActivatedCarbonFilterMonitoringClusterReplacementProductStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ActivatedCarbonFilterMonitoringClusterReplacementProductStruct.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -24,7 +26,7 @@ import matter.tlv.TlvWriter class ActivatedCarbonFilterMonitoringClusterReplacementProductStruct( val productIdentifierType: UByte, - val productIdentifierValue: String, + val productIdentifierValue: String ) { override fun toString(): String = buildString { append("ActivatedCarbonFilterMonitoringClusterReplacementProductStruct {\n") @@ -46,22 +48,14 @@ class ActivatedCarbonFilterMonitoringClusterReplacementProductStruct( private const val TAG_PRODUCT_IDENTIFIER_TYPE = 0 private const val TAG_PRODUCT_IDENTIFIER_VALUE = 1 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): ActivatedCarbonFilterMonitoringClusterReplacementProductStruct { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ActivatedCarbonFilterMonitoringClusterReplacementProductStruct { tlvReader.enterStructure(tlvTag) - val productIdentifierType = - tlvReader.getUByte(ContextSpecificTag(TAG_PRODUCT_IDENTIFIER_TYPE)) - val productIdentifierValue = - tlvReader.getString(ContextSpecificTag(TAG_PRODUCT_IDENTIFIER_VALUE)) - + val productIdentifierType = tlvReader.getUByte(ContextSpecificTag(TAG_PRODUCT_IDENTIFIER_TYPE)) + val productIdentifierValue = tlvReader.getString(ContextSpecificTag(TAG_PRODUCT_IDENTIFIER_VALUE)) + tlvReader.exitContainer() - return ActivatedCarbonFilterMonitoringClusterReplacementProductStruct( - productIdentifierType, - productIdentifierValue, - ) + return ActivatedCarbonFilterMonitoringClusterReplacementProductStruct(productIdentifierType, productIdentifierValue) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ApplicationBasicClusterApplicationStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ApplicationBasicClusterApplicationStruct.kt index be4a1e7984e307..32845e1a63817a 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ApplicationBasicClusterApplicationStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ApplicationBasicClusterApplicationStruct.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -24,7 +26,7 @@ import matter.tlv.TlvWriter class ApplicationBasicClusterApplicationStruct( val catalogVendorID: UShort, - val applicationID: String, + val applicationID: String ) { override fun toString(): String = buildString { append("ApplicationBasicClusterApplicationStruct {\n") @@ -50,7 +52,7 @@ class ApplicationBasicClusterApplicationStruct( tlvReader.enterStructure(tlvTag) val catalogVendorID = tlvReader.getUShort(ContextSpecificTag(TAG_CATALOG_VENDOR_ID)) val applicationID = tlvReader.getString(ContextSpecificTag(TAG_APPLICATION_ID)) - + tlvReader.exitContainer() return ApplicationBasicClusterApplicationStruct(catalogVendorID, applicationID) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ApplicationLauncherClusterApplicationEPStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ApplicationLauncherClusterApplicationEPStruct.kt index 8e6b905d8aa91c..eeca3b79254426 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ApplicationLauncherClusterApplicationEPStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ApplicationLauncherClusterApplicationEPStruct.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -25,7 +26,7 @@ import matter.tlv.TlvWriter class ApplicationLauncherClusterApplicationEPStruct( val application: ApplicationLauncherClusterApplicationStruct, - val endpoint: Optional, + val endpoint: Optional ) { override fun toString(): String = buildString { append("ApplicationLauncherClusterApplicationEPStruct {\n") @@ -52,18 +53,13 @@ class ApplicationLauncherClusterApplicationEPStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ApplicationLauncherClusterApplicationEPStruct { tlvReader.enterStructure(tlvTag) - val application = - ApplicationLauncherClusterApplicationStruct.fromTlv( - ContextSpecificTag(TAG_APPLICATION), - tlvReader, - ) - val endpoint = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_ENDPOINT))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_ENDPOINT))) - } else { - Optional.empty() - } - + val application = ApplicationLauncherClusterApplicationStruct.fromTlv(ContextSpecificTag(TAG_APPLICATION), tlvReader) + val endpoint = if (tlvReader.isNextTag(ContextSpecificTag(TAG_ENDPOINT))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_ENDPOINT))) + } else { + Optional.empty() + } + tlvReader.exitContainer() return ApplicationLauncherClusterApplicationEPStruct(application, endpoint) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ApplicationLauncherClusterApplicationStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ApplicationLauncherClusterApplicationStruct.kt index ea921ee690d16c..0427e6d5bd22b8 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ApplicationLauncherClusterApplicationStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ApplicationLauncherClusterApplicationStruct.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -24,7 +26,7 @@ import matter.tlv.TlvWriter class ApplicationLauncherClusterApplicationStruct( val catalogVendorID: UShort, - val applicationID: String, + val applicationID: String ) { override fun toString(): String = buildString { append("ApplicationLauncherClusterApplicationStruct {\n") @@ -50,7 +52,7 @@ class ApplicationLauncherClusterApplicationStruct( tlvReader.enterStructure(tlvTag) val catalogVendorID = tlvReader.getUShort(ContextSpecificTag(TAG_CATALOG_VENDOR_ID)) val applicationID = tlvReader.getString(ContextSpecificTag(TAG_APPLICATION_ID)) - + tlvReader.exitContainer() return ApplicationLauncherClusterApplicationStruct(catalogVendorID, applicationID) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/AudioOutputClusterOutputInfoStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/AudioOutputClusterOutputInfoStruct.kt index e37c78ff74d38c..2a48b0b450bf4a 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/AudioOutputClusterOutputInfoStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/AudioOutputClusterOutputInfoStruct.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -25,7 +27,7 @@ import matter.tlv.TlvWriter class AudioOutputClusterOutputInfoStruct( val index: UByte, val outputType: UByte, - val name: String, + val name: String ) { override fun toString(): String = buildString { append("AudioOutputClusterOutputInfoStruct {\n") @@ -55,7 +57,7 @@ class AudioOutputClusterOutputInfoStruct( val index = tlvReader.getUByte(ContextSpecificTag(TAG_INDEX)) val outputType = tlvReader.getUByte(ContextSpecificTag(TAG_OUTPUT_TYPE)) val name = tlvReader.getString(ContextSpecificTag(TAG_NAME)) - + tlvReader.exitContainer() return AudioOutputClusterOutputInfoStruct(index, outputType, name) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/BasicInformationClusterCapabilityMinimaStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/BasicInformationClusterCapabilityMinimaStruct.kt index 74a5a0bb98be93..aa977b5fdb8578 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/BasicInformationClusterCapabilityMinimaStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/BasicInformationClusterCapabilityMinimaStruct.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -24,7 +26,7 @@ import matter.tlv.TlvWriter class BasicInformationClusterCapabilityMinimaStruct( val caseSessionsPerFabric: UShort, - val subscriptionsPerFabric: UShort, + val subscriptionsPerFabric: UShort ) { override fun toString(): String = buildString { append("BasicInformationClusterCapabilityMinimaStruct {\n") @@ -48,17 +50,12 @@ class BasicInformationClusterCapabilityMinimaStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): BasicInformationClusterCapabilityMinimaStruct { tlvReader.enterStructure(tlvTag) - val caseSessionsPerFabric = - tlvReader.getUShort(ContextSpecificTag(TAG_CASE_SESSIONS_PER_FABRIC)) - val subscriptionsPerFabric = - tlvReader.getUShort(ContextSpecificTag(TAG_SUBSCRIPTIONS_PER_FABRIC)) - + val caseSessionsPerFabric = tlvReader.getUShort(ContextSpecificTag(TAG_CASE_SESSIONS_PER_FABRIC)) + val subscriptionsPerFabric = tlvReader.getUShort(ContextSpecificTag(TAG_SUBSCRIPTIONS_PER_FABRIC)) + tlvReader.exitContainer() - return BasicInformationClusterCapabilityMinimaStruct( - caseSessionsPerFabric, - subscriptionsPerFabric, - ) + return BasicInformationClusterCapabilityMinimaStruct(caseSessionsPerFabric, subscriptionsPerFabric) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/BasicInformationClusterProductAppearanceStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/BasicInformationClusterProductAppearanceStruct.kt index 56583564b0c687..d5cc1315e520cd 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/BasicInformationClusterProductAppearanceStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/BasicInformationClusterProductAppearanceStruct.kt @@ -16,13 +16,18 @@ */ package matter.controller.cluster.structs +import java.util.Optional 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 BasicInformationClusterProductAppearanceStruct(val finish: UByte, val primaryColor: UByte?) { +class BasicInformationClusterProductAppearanceStruct( + val finish: UByte, + val primaryColor: UByte? +) { override fun toString(): String = buildString { append("BasicInformationClusterProductAppearanceStruct {\n") append("\tfinish : $finish\n") @@ -50,14 +55,13 @@ class BasicInformationClusterProductAppearanceStruct(val finish: UByte, val prim fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): BasicInformationClusterProductAppearanceStruct { tlvReader.enterStructure(tlvTag) val finish = tlvReader.getUByte(ContextSpecificTag(TAG_FINISH)) - val primaryColor = - if (!tlvReader.isNull()) { - tlvReader.getUByte(ContextSpecificTag(TAG_PRIMARY_COLOR)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_PRIMARY_COLOR)) - null - } - + val primaryColor = if (!tlvReader.isNull()) { + tlvReader.getUByte(ContextSpecificTag(TAG_PRIMARY_COLOR)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_PRIMARY_COLOR)) + null + } + tlvReader.exitContainer() return BasicInformationClusterProductAppearanceStruct(finish, primaryColor) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/BindingClusterTargetStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/BindingClusterTargetStruct.kt index e4e3d8027767ca..1a382bd10ab5a0 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/BindingClusterTargetStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/BindingClusterTargetStruct.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -28,7 +29,7 @@ class BindingClusterTargetStruct( val group: Optional, val endpoint: Optional, val cluster: Optional, - val fabricIndex: UByte, + val fabricIndex: UByte ) { override fun toString(): String = buildString { append("BindingClusterTargetStruct {\n") @@ -73,32 +74,28 @@ class BindingClusterTargetStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): BindingClusterTargetStruct { tlvReader.enterStructure(tlvTag) - val node = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_NODE))) { - Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_NODE))) - } else { - Optional.empty() - } - val group = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_GROUP))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_GROUP))) - } else { - Optional.empty() - } - val endpoint = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_ENDPOINT))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_ENDPOINT))) - } else { - Optional.empty() - } - val cluster = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_CLUSTER))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_CLUSTER))) - } else { - Optional.empty() - } + val node = if (tlvReader.isNextTag(ContextSpecificTag(TAG_NODE))) { + Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_NODE))) + } else { + Optional.empty() + } + val group = if (tlvReader.isNextTag(ContextSpecificTag(TAG_GROUP))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_GROUP))) + } else { + Optional.empty() + } + val endpoint = if (tlvReader.isNextTag(ContextSpecificTag(TAG_ENDPOINT))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_ENDPOINT))) + } else { + Optional.empty() + } + val cluster = if (tlvReader.isNextTag(ContextSpecificTag(TAG_CLUSTER))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_CLUSTER))) + } else { + Optional.empty() + } val fabricIndex = tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) - + tlvReader.exitContainer() return BindingClusterTargetStruct(node, group, endpoint, cluster, fabricIndex) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/BridgedDeviceBasicInformationClusterProductAppearanceStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/BridgedDeviceBasicInformationClusterProductAppearanceStruct.kt index d1b8b79bc3f553..9e9eabc793ef94 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/BridgedDeviceBasicInformationClusterProductAppearanceStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/BridgedDeviceBasicInformationClusterProductAppearanceStruct.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -24,7 +26,7 @@ import matter.tlv.TlvWriter class BridgedDeviceBasicInformationClusterProductAppearanceStruct( val finish: UByte, - val primaryColor: UByte?, + val primaryColor: UByte? ) { override fun toString(): String = buildString { append("BridgedDeviceBasicInformationClusterProductAppearanceStruct {\n") @@ -50,20 +52,16 @@ class BridgedDeviceBasicInformationClusterProductAppearanceStruct( private const val TAG_FINISH = 0 private const val TAG_PRIMARY_COLOR = 1 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): BridgedDeviceBasicInformationClusterProductAppearanceStruct { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): BridgedDeviceBasicInformationClusterProductAppearanceStruct { tlvReader.enterStructure(tlvTag) val finish = tlvReader.getUByte(ContextSpecificTag(TAG_FINISH)) - val primaryColor = - if (!tlvReader.isNull()) { - tlvReader.getUByte(ContextSpecificTag(TAG_PRIMARY_COLOR)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_PRIMARY_COLOR)) - null - } - + val primaryColor = if (!tlvReader.isNull()) { + tlvReader.getUByte(ContextSpecificTag(TAG_PRIMARY_COLOR)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_PRIMARY_COLOR)) + null + } + tlvReader.exitContainer() return BridgedDeviceBasicInformationClusterProductAppearanceStruct(finish, primaryColor) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterAdditionalInfoStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterAdditionalInfoStruct.kt index cd2eacc749cb0d..9c504e9f434b18 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterAdditionalInfoStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterAdditionalInfoStruct.kt @@ -16,13 +16,18 @@ */ package matter.controller.cluster.structs +import java.util.Optional 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 ChannelClusterAdditionalInfoStruct(val name: String, val value: String) { +class ChannelClusterAdditionalInfoStruct( + val name: String, + val value: String +) { override fun toString(): String = buildString { append("ChannelClusterAdditionalInfoStruct {\n") append("\tname : $name\n") @@ -47,7 +52,7 @@ class ChannelClusterAdditionalInfoStruct(val name: String, val value: String) { tlvReader.enterStructure(tlvTag) val name = tlvReader.getString(ContextSpecificTag(TAG_NAME)) val value = tlvReader.getString(ContextSpecificTag(TAG_VALUE)) - + tlvReader.exitContainer() return ChannelClusterAdditionalInfoStruct(name, value) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterChannelInfoStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterChannelInfoStruct.kt index 13b805080c391b..914bcad0e6cc7f 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterChannelInfoStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterChannelInfoStruct.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -30,7 +31,7 @@ class ChannelClusterChannelInfoStruct( val callSign: Optional, val affiliateCallSign: Optional, val identifier: Optional, - val type: Optional, + val type: Optional ) { override fun toString(): String = buildString { append("ChannelClusterChannelInfoStruct {\n") @@ -86,48 +87,35 @@ class ChannelClusterChannelInfoStruct( tlvReader.enterStructure(tlvTag) val majorNumber = tlvReader.getUShort(ContextSpecificTag(TAG_MAJOR_NUMBER)) val minorNumber = tlvReader.getUShort(ContextSpecificTag(TAG_MINOR_NUMBER)) - val name = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_NAME))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_NAME))) - } else { - Optional.empty() - } - val callSign = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_CALL_SIGN))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_CALL_SIGN))) - } else { - Optional.empty() - } - val affiliateCallSign = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_AFFILIATE_CALL_SIGN))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_AFFILIATE_CALL_SIGN))) - } else { - Optional.empty() - } - val identifier = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_IDENTIFIER))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_IDENTIFIER))) - } else { - Optional.empty() - } - val type = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_TYPE))) { - Optional.of(tlvReader.getUByte(ContextSpecificTag(TAG_TYPE))) - } else { - Optional.empty() - } - + val name = if (tlvReader.isNextTag(ContextSpecificTag(TAG_NAME))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_NAME))) + } else { + Optional.empty() + } + val callSign = if (tlvReader.isNextTag(ContextSpecificTag(TAG_CALL_SIGN))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_CALL_SIGN))) + } else { + Optional.empty() + } + val affiliateCallSign = if (tlvReader.isNextTag(ContextSpecificTag(TAG_AFFILIATE_CALL_SIGN))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_AFFILIATE_CALL_SIGN))) + } else { + Optional.empty() + } + val identifier = if (tlvReader.isNextTag(ContextSpecificTag(TAG_IDENTIFIER))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_IDENTIFIER))) + } else { + Optional.empty() + } + val type = if (tlvReader.isNextTag(ContextSpecificTag(TAG_TYPE))) { + Optional.of(tlvReader.getUByte(ContextSpecificTag(TAG_TYPE))) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return ChannelClusterChannelInfoStruct( - majorNumber, - minorNumber, - name, - callSign, - affiliateCallSign, - identifier, - type, - ) + return ChannelClusterChannelInfoStruct(majorNumber, minorNumber, name, callSign, affiliateCallSign, identifier, type) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterChannelPagingStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterChannelPagingStruct.kt index e84410d09dd64d..f3b7c7d5f51755 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterChannelPagingStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterChannelPagingStruct.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -25,7 +26,7 @@ import matter.tlv.TlvWriter class ChannelClusterChannelPagingStruct( val previousToken: Optional?, - val nextToken: Optional?, + val nextToken: Optional? ) { override fun toString(): String = buildString { append("ChannelClusterChannelPagingStruct {\n") @@ -39,17 +40,17 @@ class ChannelClusterChannelPagingStruct( startStructure(tlvTag) if (previousToken != null) { if (previousToken.isPresent) { - val optpreviousToken = previousToken.get() - optpreviousToken.toTlv(ContextSpecificTag(TAG_PREVIOUS_TOKEN), this) - } + val optpreviousToken = previousToken.get() + optpreviousToken.toTlv(ContextSpecificTag(TAG_PREVIOUS_TOKEN), this) + } } else { putNull(ContextSpecificTag(TAG_PREVIOUS_TOKEN)) } if (nextToken != null) { if (nextToken.isPresent) { - val optnextToken = nextToken.get() - optnextToken.toTlv(ContextSpecificTag(TAG_NEXT_TOKEN), this) - } + val optnextToken = nextToken.get() + optnextToken.toTlv(ContextSpecificTag(TAG_NEXT_TOKEN), this) + } } else { putNull(ContextSpecificTag(TAG_NEXT_TOKEN)) } @@ -63,36 +64,27 @@ class ChannelClusterChannelPagingStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ChannelClusterChannelPagingStruct { tlvReader.enterStructure(tlvTag) - val previousToken = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_PREVIOUS_TOKEN))) { - Optional.of( - ChannelClusterPageTokenStruct.fromTlv( - ContextSpecificTag(TAG_PREVIOUS_TOKEN), - tlvReader, - ) - ) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_PREVIOUS_TOKEN)) - null - } - val nextToken = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_NEXT_TOKEN))) { - Optional.of( - ChannelClusterPageTokenStruct.fromTlv(ContextSpecificTag(TAG_NEXT_TOKEN), tlvReader) - ) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_NEXT_TOKEN)) - null - } - + val previousToken = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_PREVIOUS_TOKEN))) { + Optional.of(ChannelClusterPageTokenStruct.fromTlv(ContextSpecificTag(TAG_PREVIOUS_TOKEN), tlvReader)) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_PREVIOUS_TOKEN)) + null + } + val nextToken = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_NEXT_TOKEN))) { + Optional.of(ChannelClusterPageTokenStruct.fromTlv(ContextSpecificTag(TAG_NEXT_TOKEN), tlvReader)) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_NEXT_TOKEN)) + null + } + tlvReader.exitContainer() return ChannelClusterChannelPagingStruct(previousToken, nextToken) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterLineupInfoStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterLineupInfoStruct.kt index 9863a0515c0070..21eb682b010a20 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterLineupInfoStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterLineupInfoStruct.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -27,7 +28,7 @@ class ChannelClusterLineupInfoStruct( val operatorName: String, val lineupName: Optional, val postalCode: Optional, - val lineupInfoType: UByte, + val lineupInfoType: UByte ) { override fun toString(): String = buildString { append("ChannelClusterLineupInfoStruct {\n") @@ -64,20 +65,18 @@ class ChannelClusterLineupInfoStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ChannelClusterLineupInfoStruct { tlvReader.enterStructure(tlvTag) val operatorName = tlvReader.getString(ContextSpecificTag(TAG_OPERATOR_NAME)) - val lineupName = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_LINEUP_NAME))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_LINEUP_NAME))) - } else { - Optional.empty() - } - val postalCode = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_POSTAL_CODE))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_POSTAL_CODE))) - } else { - Optional.empty() - } + val lineupName = if (tlvReader.isNextTag(ContextSpecificTag(TAG_LINEUP_NAME))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_LINEUP_NAME))) + } else { + Optional.empty() + } + val postalCode = if (tlvReader.isNextTag(ContextSpecificTag(TAG_POSTAL_CODE))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_POSTAL_CODE))) + } else { + Optional.empty() + } val lineupInfoType = tlvReader.getUByte(ContextSpecificTag(TAG_LINEUP_INFO_TYPE)) - + tlvReader.exitContainer() return ChannelClusterLineupInfoStruct(operatorName, lineupName, postalCode, lineupInfoType) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterPageTokenStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterPageTokenStruct.kt index f42ecb1d1219f3..963a7c2beb5ffa 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterPageTokenStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterPageTokenStruct.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +27,7 @@ import matter.tlv.TlvWriter class ChannelClusterPageTokenStruct( val limit: Optional, val after: Optional, - val before: Optional, + val before: Optional ) { override fun toString(): String = buildString { append("ChannelClusterPageTokenStruct {\n") @@ -62,25 +63,22 @@ class ChannelClusterPageTokenStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ChannelClusterPageTokenStruct { tlvReader.enterStructure(tlvTag) - val limit = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_LIMIT))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_LIMIT))) - } else { - Optional.empty() - } - val after = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_AFTER))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_AFTER))) - } else { - Optional.empty() - } - val before = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_BEFORE))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_BEFORE))) - } else { - Optional.empty() - } - + val limit = if (tlvReader.isNextTag(ContextSpecificTag(TAG_LIMIT))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_LIMIT))) + } else { + Optional.empty() + } + val after = if (tlvReader.isNextTag(ContextSpecificTag(TAG_AFTER))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_AFTER))) + } else { + Optional.empty() + } + val before = if (tlvReader.isNextTag(ContextSpecificTag(TAG_BEFORE))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_BEFORE))) + } else { + Optional.empty() + } + tlvReader.exitContainer() return ChannelClusterPageTokenStruct(limit, after, before) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterProgramCastStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterProgramCastStruct.kt index 45b0a22100ef25..54568f0b775970 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterProgramCastStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterProgramCastStruct.kt @@ -16,13 +16,18 @@ */ package matter.controller.cluster.structs +import java.util.Optional 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 ChannelClusterProgramCastStruct(val name: String, val role: String) { +class ChannelClusterProgramCastStruct( + val name: String, + val role: String +) { override fun toString(): String = buildString { append("ChannelClusterProgramCastStruct {\n") append("\tname : $name\n") @@ -47,7 +52,7 @@ class ChannelClusterProgramCastStruct(val name: String, val role: String) { tlvReader.enterStructure(tlvTag) val name = tlvReader.getString(ContextSpecificTag(TAG_NAME)) val role = tlvReader.getString(ContextSpecificTag(TAG_ROLE)) - + tlvReader.exitContainer() return ChannelClusterProgramCastStruct(name, role) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterProgramCategoryStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterProgramCategoryStruct.kt index 6e89f24cd39e25..3ffaea537244dc 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterProgramCategoryStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterProgramCategoryStruct.kt @@ -18,12 +18,16 @@ package matter.controller.cluster.structs import java.util.Optional 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 ChannelClusterProgramCategoryStruct(val category: String, val subCategory: Optional) { +class ChannelClusterProgramCategoryStruct( + val category: String, + val subCategory: Optional +) { override fun toString(): String = buildString { append("ChannelClusterProgramCategoryStruct {\n") append("\tcategory : $category\n") @@ -50,13 +54,12 @@ class ChannelClusterProgramCategoryStruct(val category: String, val subCategory: fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ChannelClusterProgramCategoryStruct { tlvReader.enterStructure(tlvTag) val category = tlvReader.getString(ContextSpecificTag(TAG_CATEGORY)) - val subCategory = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_SUB_CATEGORY))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_SUB_CATEGORY))) - } else { - Optional.empty() - } - + val subCategory = if (tlvReader.isNextTag(ContextSpecificTag(TAG_SUB_CATEGORY))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_SUB_CATEGORY))) + } else { + Optional.empty() + } + tlvReader.exitContainer() return ChannelClusterProgramCategoryStruct(category, subCategory) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterProgramStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterProgramStruct.kt index c8dfd42de67a1c..6b0bf99a15529b 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterProgramStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterProgramStruct.kt @@ -43,7 +43,7 @@ class ChannelClusterProgramStruct( val seriesInfo: Optional?, val categoryList: Optional>, val castList: Optional>, - val externalIDList: Optional>, + val externalIDList: Optional> ) { override fun toString(): String = buildString { append("ChannelClusterProgramStruct {\n") @@ -88,18 +88,18 @@ class ChannelClusterProgramStruct( if (audioLanguages.isPresent) { val optaudioLanguages = audioLanguages.get() startArray(ContextSpecificTag(TAG_AUDIO_LANGUAGES)) - for (item in optaudioLanguages.iterator()) { - put(AnonymousTag, item) - } - endArray() + for (item in optaudioLanguages.iterator()) { + put(AnonymousTag, item) + } + endArray() } if (ratings.isPresent) { val optratings = ratings.get() startArray(ContextSpecificTag(TAG_RATINGS)) - for (item in optratings.iterator()) { - put(AnonymousTag, item) - } - endArray() + for (item in optratings.iterator()) { + put(AnonymousTag, item) + } + endArray() } if (thumbnailUrl.isPresent) { val optthumbnailUrl = thumbnailUrl.get() @@ -127,35 +127,35 @@ class ChannelClusterProgramStruct( } if (seriesInfo != null) { if (seriesInfo.isPresent) { - val optseriesInfo = seriesInfo.get() - optseriesInfo.toTlv(ContextSpecificTag(TAG_SERIES_INFO), this) - } + val optseriesInfo = seriesInfo.get() + optseriesInfo.toTlv(ContextSpecificTag(TAG_SERIES_INFO), this) + } } else { putNull(ContextSpecificTag(TAG_SERIES_INFO)) } if (categoryList.isPresent) { val optcategoryList = categoryList.get() startArray(ContextSpecificTag(TAG_CATEGORY_LIST)) - for (item in optcategoryList.iterator()) { - item.toTlv(AnonymousTag, this) - } - endArray() + for (item in optcategoryList.iterator()) { + item.toTlv(AnonymousTag, this) + } + endArray() } if (castList.isPresent) { val optcastList = castList.get() startArray(ContextSpecificTag(TAG_CAST_LIST)) - for (item in optcastList.iterator()) { - item.toTlv(AnonymousTag, this) - } - endArray() + for (item in optcastList.iterator()) { + item.toTlv(AnonymousTag, this) + } + endArray() } if (externalIDList.isPresent) { val optexternalIDList = externalIDList.get() startArray(ContextSpecificTag(TAG_EXTERNAL_ID_LIST)) - for (item in optexternalIDList.iterator()) { - item.toTlv(AnonymousTag, this) - } - endArray() + for (item in optexternalIDList.iterator()) { + item.toTlv(AnonymousTag, this) + } + endArray() } endStructure() } @@ -185,166 +185,119 @@ class ChannelClusterProgramStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ChannelClusterProgramStruct { tlvReader.enterStructure(tlvTag) val identifier = tlvReader.getString(ContextSpecificTag(TAG_IDENTIFIER)) - val channel = - ChannelClusterChannelInfoStruct.fromTlv(ContextSpecificTag(TAG_CHANNEL), tlvReader) + val channel = ChannelClusterChannelInfoStruct.fromTlv(ContextSpecificTag(TAG_CHANNEL), tlvReader) val startTime = tlvReader.getUInt(ContextSpecificTag(TAG_START_TIME)) val endTime = tlvReader.getUInt(ContextSpecificTag(TAG_END_TIME)) val title = tlvReader.getString(ContextSpecificTag(TAG_TITLE)) - val subtitle = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_SUBTITLE))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_SUBTITLE))) - } else { - Optional.empty() - } - val description = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_DESCRIPTION))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_DESCRIPTION))) - } else { - Optional.empty() - } - val audioLanguages = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_AUDIO_LANGUAGES))) { - Optional.of( - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_AUDIO_LANGUAGES)) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getString(AnonymousTag)) - } - tlvReader.exitContainer() - } - ) - } else { - Optional.empty() - } - val ratings = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_RATINGS))) { - Optional.of( - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_RATINGS)) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getString(AnonymousTag)) - } - tlvReader.exitContainer() - } - ) - } else { - Optional.empty() - } - val thumbnailUrl = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_THUMBNAIL_URL))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_THUMBNAIL_URL))) - } else { - Optional.empty() - } - val posterArtUrl = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_POSTER_ART_URL))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_POSTER_ART_URL))) - } else { - Optional.empty() - } - val dvbiUrl = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_DVBI_URL))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_DVBI_URL))) - } else { - Optional.empty() - } - val releaseDate = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_RELEASE_DATE))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_RELEASE_DATE))) - } else { - Optional.empty() - } - val parentalGuidanceText = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_PARENTAL_GUIDANCE_TEXT))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_PARENTAL_GUIDANCE_TEXT))) - } else { - Optional.empty() - } - val recordingFlag = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_RECORDING_FLAG))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_RECORDING_FLAG))) - } else { - Optional.empty() - } - val seriesInfo = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_SERIES_INFO))) { - Optional.of( - ChannelClusterSeriesInfoStruct.fromTlv(ContextSpecificTag(TAG_SERIES_INFO), tlvReader) - ) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_SERIES_INFO)) - null - } - val categoryList = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_CATEGORY_LIST))) { - Optional.of( - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_CATEGORY_LIST)) - while (!tlvReader.isEndOfContainer()) { - add(ChannelClusterProgramCategoryStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - ) - } else { - Optional.empty() - } - val castList = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_CAST_LIST))) { - Optional.of( - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_CAST_LIST)) - while (!tlvReader.isEndOfContainer()) { - add(ChannelClusterProgramCastStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - ) - } else { - Optional.empty() - } - val externalIDList = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_EXTERNAL_ID_LIST))) { - Optional.of( - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_EXTERNAL_ID_LIST)) - while (!tlvReader.isEndOfContainer()) { - add(ChannelClusterProgramCastStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - ) - } else { - Optional.empty() - } - + val subtitle = if (tlvReader.isNextTag(ContextSpecificTag(TAG_SUBTITLE))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_SUBTITLE))) + } else { + Optional.empty() + } + val description = if (tlvReader.isNextTag(ContextSpecificTag(TAG_DESCRIPTION))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_DESCRIPTION))) + } else { + Optional.empty() + } + val audioLanguages = if (tlvReader.isNextTag(ContextSpecificTag(TAG_AUDIO_LANGUAGES))) { + Optional.of(buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_AUDIO_LANGUAGES)) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getString(AnonymousTag)) + } + tlvReader.exitContainer() + }) + } else { + Optional.empty() + } + val ratings = if (tlvReader.isNextTag(ContextSpecificTag(TAG_RATINGS))) { + Optional.of(buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_RATINGS)) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getString(AnonymousTag)) + } + tlvReader.exitContainer() + }) + } else { + Optional.empty() + } + val thumbnailUrl = if (tlvReader.isNextTag(ContextSpecificTag(TAG_THUMBNAIL_URL))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_THUMBNAIL_URL))) + } else { + Optional.empty() + } + val posterArtUrl = if (tlvReader.isNextTag(ContextSpecificTag(TAG_POSTER_ART_URL))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_POSTER_ART_URL))) + } else { + Optional.empty() + } + val dvbiUrl = if (tlvReader.isNextTag(ContextSpecificTag(TAG_DVBI_URL))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_DVBI_URL))) + } else { + Optional.empty() + } + val releaseDate = if (tlvReader.isNextTag(ContextSpecificTag(TAG_RELEASE_DATE))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_RELEASE_DATE))) + } else { + Optional.empty() + } + val parentalGuidanceText = if (tlvReader.isNextTag(ContextSpecificTag(TAG_PARENTAL_GUIDANCE_TEXT))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_PARENTAL_GUIDANCE_TEXT))) + } else { + Optional.empty() + } + val recordingFlag = if (tlvReader.isNextTag(ContextSpecificTag(TAG_RECORDING_FLAG))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_RECORDING_FLAG))) + } else { + Optional.empty() + } + val seriesInfo = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_SERIES_INFO))) { + Optional.of(ChannelClusterSeriesInfoStruct.fromTlv(ContextSpecificTag(TAG_SERIES_INFO), tlvReader)) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_SERIES_INFO)) + null + } + val categoryList = if (tlvReader.isNextTag(ContextSpecificTag(TAG_CATEGORY_LIST))) { + Optional.of(buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_CATEGORY_LIST)) + while(!tlvReader.isEndOfContainer()) { + add(ChannelClusterProgramCategoryStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + }) + } else { + Optional.empty() + } + val castList = if (tlvReader.isNextTag(ContextSpecificTag(TAG_CAST_LIST))) { + Optional.of(buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_CAST_LIST)) + while(!tlvReader.isEndOfContainer()) { + add(ChannelClusterProgramCastStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + }) + } else { + Optional.empty() + } + val externalIDList = if (tlvReader.isNextTag(ContextSpecificTag(TAG_EXTERNAL_ID_LIST))) { + Optional.of(buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_EXTERNAL_ID_LIST)) + while(!tlvReader.isEndOfContainer()) { + add(ChannelClusterProgramCastStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + }) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return ChannelClusterProgramStruct( - identifier, - channel, - startTime, - endTime, - title, - subtitle, - description, - audioLanguages, - ratings, - thumbnailUrl, - posterArtUrl, - dvbiUrl, - releaseDate, - parentalGuidanceText, - recordingFlag, - seriesInfo, - categoryList, - castList, - externalIDList, - ) + return ChannelClusterProgramStruct(identifier, channel, startTime, endTime, title, subtitle, description, audioLanguages, ratings, thumbnailUrl, posterArtUrl, dvbiUrl, releaseDate, parentalGuidanceText, recordingFlag, seriesInfo, categoryList, castList, externalIDList) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterSeriesInfoStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterSeriesInfoStruct.kt index 9e3928a48de8a5..c0445d55460703 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterSeriesInfoStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterSeriesInfoStruct.kt @@ -16,13 +16,18 @@ */ package matter.controller.cluster.structs +import java.util.Optional 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 ChannelClusterSeriesInfoStruct(val season: String, val episode: String) { +class ChannelClusterSeriesInfoStruct( + val season: String, + val episode: String +) { override fun toString(): String = buildString { append("ChannelClusterSeriesInfoStruct {\n") append("\tseason : $season\n") @@ -47,7 +52,7 @@ class ChannelClusterSeriesInfoStruct(val season: String, val episode: String) { tlvReader.enterStructure(tlvTag) val season = tlvReader.getString(ContextSpecificTag(TAG_SEASON)) val episode = tlvReader.getString(ContextSpecificTag(TAG_EPISODE)) - + tlvReader.exitContainer() return ChannelClusterSeriesInfoStruct(season, episode) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ContentControlClusterRatingNameStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ContentControlClusterRatingNameStruct.kt index fd405633efdf9f..fe5058eb533a87 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ContentControlClusterRatingNameStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ContentControlClusterRatingNameStruct.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -25,7 +26,7 @@ import matter.tlv.TlvWriter class ContentControlClusterRatingNameStruct( val ratingName: String, - val ratingNameDesc: Optional, + val ratingNameDesc: Optional ) { override fun toString(): String = buildString { append("ContentControlClusterRatingNameStruct {\n") @@ -53,13 +54,12 @@ class ContentControlClusterRatingNameStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ContentControlClusterRatingNameStruct { tlvReader.enterStructure(tlvTag) val ratingName = tlvReader.getString(ContextSpecificTag(TAG_RATING_NAME)) - val ratingNameDesc = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_RATING_NAME_DESC))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_RATING_NAME_DESC))) - } else { - Optional.empty() - } - + val ratingNameDesc = if (tlvReader.isNextTag(ContextSpecificTag(TAG_RATING_NAME_DESC))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_RATING_NAME_DESC))) + } else { + Optional.empty() + } + tlvReader.exitContainer() return ContentControlClusterRatingNameStruct(ratingName, ratingNameDesc) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterAdditionalInfoStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterAdditionalInfoStruct.kt index af51becfe86381..504997933652c9 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterAdditionalInfoStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterAdditionalInfoStruct.kt @@ -16,13 +16,18 @@ */ package matter.controller.cluster.structs +import java.util.Optional 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 ContentLauncherClusterAdditionalInfoStruct(val name: String, val value: String) { +class ContentLauncherClusterAdditionalInfoStruct( + val name: String, + val value: String +) { override fun toString(): String = buildString { append("ContentLauncherClusterAdditionalInfoStruct {\n") append("\tname : $name\n") @@ -47,7 +52,7 @@ class ContentLauncherClusterAdditionalInfoStruct(val name: String, val value: St tlvReader.enterStructure(tlvTag) val name = tlvReader.getString(ContextSpecificTag(TAG_NAME)) val value = tlvReader.getString(ContextSpecificTag(TAG_VALUE)) - + tlvReader.exitContainer() return ContentLauncherClusterAdditionalInfoStruct(name, value) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterBrandingInformationStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterBrandingInformationStruct.kt index fa9e391b5af70e..e94826e1eb40d8 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterBrandingInformationStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterBrandingInformationStruct.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -29,7 +30,7 @@ class ContentLauncherClusterBrandingInformationStruct( val logo: Optional, val progressBar: Optional, val splash: Optional, - val waterMark: Optional, + val waterMark: Optional ) { override fun toString(): String = buildString { append("ContentLauncherClusterBrandingInformationStruct {\n") @@ -78,78 +79,38 @@ class ContentLauncherClusterBrandingInformationStruct( private const val TAG_SPLASH = 4 private const val TAG_WATER_MARK = 5 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): ContentLauncherClusterBrandingInformationStruct { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ContentLauncherClusterBrandingInformationStruct { tlvReader.enterStructure(tlvTag) val providerName = tlvReader.getString(ContextSpecificTag(TAG_PROVIDER_NAME)) - val background = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_BACKGROUND))) { - Optional.of( - ContentLauncherClusterStyleInformationStruct.fromTlv( - ContextSpecificTag(TAG_BACKGROUND), - tlvReader, - ) - ) - } else { - Optional.empty() - } - val logo = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_LOGO))) { - Optional.of( - ContentLauncherClusterStyleInformationStruct.fromTlv( - ContextSpecificTag(TAG_LOGO), - tlvReader, - ) - ) - } else { - Optional.empty() - } - val progressBar = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_PROGRESS_BAR))) { - Optional.of( - ContentLauncherClusterStyleInformationStruct.fromTlv( - ContextSpecificTag(TAG_PROGRESS_BAR), - tlvReader, - ) - ) - } else { - Optional.empty() - } - val splash = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_SPLASH))) { - Optional.of( - ContentLauncherClusterStyleInformationStruct.fromTlv( - ContextSpecificTag(TAG_SPLASH), - tlvReader, - ) - ) - } else { - Optional.empty() - } - val waterMark = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_WATER_MARK))) { - Optional.of( - ContentLauncherClusterStyleInformationStruct.fromTlv( - ContextSpecificTag(TAG_WATER_MARK), - tlvReader, - ) - ) - } else { - Optional.empty() - } - + val background = if (tlvReader.isNextTag(ContextSpecificTag(TAG_BACKGROUND))) { + Optional.of(ContentLauncherClusterStyleInformationStruct.fromTlv(ContextSpecificTag(TAG_BACKGROUND), tlvReader)) + } else { + Optional.empty() + } + val logo = if (tlvReader.isNextTag(ContextSpecificTag(TAG_LOGO))) { + Optional.of(ContentLauncherClusterStyleInformationStruct.fromTlv(ContextSpecificTag(TAG_LOGO), tlvReader)) + } else { + Optional.empty() + } + val progressBar = if (tlvReader.isNextTag(ContextSpecificTag(TAG_PROGRESS_BAR))) { + Optional.of(ContentLauncherClusterStyleInformationStruct.fromTlv(ContextSpecificTag(TAG_PROGRESS_BAR), tlvReader)) + } else { + Optional.empty() + } + val splash = if (tlvReader.isNextTag(ContextSpecificTag(TAG_SPLASH))) { + Optional.of(ContentLauncherClusterStyleInformationStruct.fromTlv(ContextSpecificTag(TAG_SPLASH), tlvReader)) + } else { + Optional.empty() + } + val waterMark = if (tlvReader.isNextTag(ContextSpecificTag(TAG_WATER_MARK))) { + Optional.of(ContentLauncherClusterStyleInformationStruct.fromTlv(ContextSpecificTag(TAG_WATER_MARK), tlvReader)) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return ContentLauncherClusterBrandingInformationStruct( - providerName, - background, - logo, - progressBar, - splash, - waterMark, - ) + return ContentLauncherClusterBrandingInformationStruct(providerName, background, logo, progressBar, splash, waterMark) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterContentSearchStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterContentSearchStruct.kt index 1fe0fc71463ee6..052e4f66723755 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterContentSearchStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterContentSearchStruct.kt @@ -16,6 +16,7 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -49,15 +50,14 @@ class ContentLauncherClusterContentSearchStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ContentLauncherClusterContentSearchStruct { tlvReader.enterStructure(tlvTag) - val parameterList = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_PARAMETER_LIST)) - while (!tlvReader.isEndOfContainer()) { - add(ContentLauncherClusterParameterStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - + val parameterList = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_PARAMETER_LIST)) + while(!tlvReader.isEndOfContainer()) { + add(ContentLauncherClusterParameterStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + tlvReader.exitContainer() return ContentLauncherClusterContentSearchStruct(parameterList) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterDimensionStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterDimensionStruct.kt index d9d100400566e8..5870e4079531e8 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterDimensionStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterDimensionStruct.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -25,7 +27,7 @@ import matter.tlv.TlvWriter class ContentLauncherClusterDimensionStruct( val width: Double, val height: Double, - val metric: UByte, + val metric: UByte ) { override fun toString(): String = buildString { append("ContentLauncherClusterDimensionStruct {\n") @@ -55,7 +57,7 @@ class ContentLauncherClusterDimensionStruct( val width = tlvReader.getDouble(ContextSpecificTag(TAG_WIDTH)) val height = tlvReader.getDouble(ContextSpecificTag(TAG_HEIGHT)) val metric = tlvReader.getUByte(ContextSpecificTag(TAG_METRIC)) - + tlvReader.exitContainer() return ContentLauncherClusterDimensionStruct(width, height, metric) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterParameterStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterParameterStruct.kt index 1785ef89c54840..03f542ae56835a 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterParameterStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterParameterStruct.kt @@ -27,7 +27,7 @@ import matter.tlv.TlvWriter class ContentLauncherClusterParameterStruct( val type: UByte, val value: String, - val externalIDList: Optional>, + val externalIDList: Optional> ) { override fun toString(): String = buildString { append("ContentLauncherClusterParameterStruct {\n") @@ -45,10 +45,10 @@ class ContentLauncherClusterParameterStruct( if (externalIDList.isPresent) { val optexternalIDList = externalIDList.get() startArray(ContextSpecificTag(TAG_EXTERNAL_ID_LIST)) - for (item in optexternalIDList.iterator()) { - item.toTlv(AnonymousTag, this) - } - endArray() + for (item in optexternalIDList.iterator()) { + item.toTlv(AnonymousTag, this) + } + endArray() } endStructure() } @@ -63,21 +63,18 @@ class ContentLauncherClusterParameterStruct( tlvReader.enterStructure(tlvTag) val type = tlvReader.getUByte(ContextSpecificTag(TAG_TYPE)) val value = tlvReader.getString(ContextSpecificTag(TAG_VALUE)) - val externalIDList = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_EXTERNAL_ID_LIST))) { - Optional.of( - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_EXTERNAL_ID_LIST)) - while (!tlvReader.isEndOfContainer()) { - add(ContentLauncherClusterAdditionalInfoStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - ) - } else { - Optional.empty() - } - + val externalIDList = if (tlvReader.isNextTag(ContextSpecificTag(TAG_EXTERNAL_ID_LIST))) { + Optional.of(buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_EXTERNAL_ID_LIST)) + while(!tlvReader.isEndOfContainer()) { + add(ContentLauncherClusterAdditionalInfoStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + }) + } else { + Optional.empty() + } + tlvReader.exitContainer() return ContentLauncherClusterParameterStruct(type, value, externalIDList) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterPlaybackPreferencesStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterPlaybackPreferencesStruct.kt index aa71bc1d9895a6..adba8615ee2d73 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterPlaybackPreferencesStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterPlaybackPreferencesStruct.kt @@ -27,7 +27,7 @@ import matter.tlv.TlvWriter class ContentLauncherClusterPlaybackPreferencesStruct( val playbackPosition: ULong, val textTrack: ContentLauncherClusterTrackPreferenceStruct, - val audioTracks: Optional>, + val audioTracks: Optional> ) { override fun toString(): String = buildString { append("ContentLauncherClusterPlaybackPreferencesStruct {\n") @@ -45,10 +45,10 @@ class ContentLauncherClusterPlaybackPreferencesStruct( if (audioTracks.isPresent) { val optaudioTracks = audioTracks.get() startArray(ContextSpecificTag(TAG_AUDIO_TRACKS)) - for (item in optaudioTracks.iterator()) { - item.toTlv(AnonymousTag, this) - } - endArray() + for (item in optaudioTracks.iterator()) { + item.toTlv(AnonymousTag, this) + } + endArray() } endStructure() } @@ -59,39 +59,25 @@ class ContentLauncherClusterPlaybackPreferencesStruct( private const val TAG_TEXT_TRACK = 1 private const val TAG_AUDIO_TRACKS = 2 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): ContentLauncherClusterPlaybackPreferencesStruct { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ContentLauncherClusterPlaybackPreferencesStruct { tlvReader.enterStructure(tlvTag) val playbackPosition = tlvReader.getULong(ContextSpecificTag(TAG_PLAYBACK_POSITION)) - val textTrack = - ContentLauncherClusterTrackPreferenceStruct.fromTlv( - ContextSpecificTag(TAG_TEXT_TRACK), - tlvReader, - ) - val audioTracks = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_AUDIO_TRACKS))) { - Optional.of( - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_AUDIO_TRACKS)) - while (!tlvReader.isEndOfContainer()) { - add(ContentLauncherClusterTrackPreferenceStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - ) - } else { - Optional.empty() - } - + val textTrack = ContentLauncherClusterTrackPreferenceStruct.fromTlv(ContextSpecificTag(TAG_TEXT_TRACK), tlvReader) + val audioTracks = if (tlvReader.isNextTag(ContextSpecificTag(TAG_AUDIO_TRACKS))) { + Optional.of(buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_AUDIO_TRACKS)) + while(!tlvReader.isEndOfContainer()) { + add(ContentLauncherClusterTrackPreferenceStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + }) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return ContentLauncherClusterPlaybackPreferencesStruct( - playbackPosition, - textTrack, - audioTracks, - ) + return ContentLauncherClusterPlaybackPreferencesStruct(playbackPosition, textTrack, audioTracks) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterStyleInformationStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterStyleInformationStruct.kt index b1a5ea8bfe0a70..192719b95e2400 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterStyleInformationStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterStyleInformationStruct.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +27,7 @@ import matter.tlv.TlvWriter class ContentLauncherClusterStyleInformationStruct( val imageURL: Optional, val color: Optional, - val size: Optional, + val size: Optional ) { override fun toString(): String = buildString { append("ContentLauncherClusterStyleInformationStruct {\n") @@ -62,27 +63,22 @@ class ContentLauncherClusterStyleInformationStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ContentLauncherClusterStyleInformationStruct { tlvReader.enterStructure(tlvTag) - val imageURL = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_IMAGE_URL))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_IMAGE_URL))) - } else { - Optional.empty() - } - val color = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_COLOR))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_COLOR))) - } else { - Optional.empty() - } - val size = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_SIZE))) { - Optional.of( - ContentLauncherClusterDimensionStruct.fromTlv(ContextSpecificTag(TAG_SIZE), tlvReader) - ) - } else { - Optional.empty() - } - + val imageURL = if (tlvReader.isNextTag(ContextSpecificTag(TAG_IMAGE_URL))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_IMAGE_URL))) + } else { + Optional.empty() + } + val color = if (tlvReader.isNextTag(ContextSpecificTag(TAG_COLOR))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_COLOR))) + } else { + Optional.empty() + } + val size = if (tlvReader.isNextTag(ContextSpecificTag(TAG_SIZE))) { + Optional.of(ContentLauncherClusterDimensionStruct.fromTlv(ContextSpecificTag(TAG_SIZE), tlvReader)) + } else { + Optional.empty() + } + tlvReader.exitContainer() return ContentLauncherClusterStyleInformationStruct(imageURL, color, size) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterTrackPreferenceStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterTrackPreferenceStruct.kt index 1e0b96a553e125..47dadc45c6f0b3 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterTrackPreferenceStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterTrackPreferenceStruct.kt @@ -27,7 +27,7 @@ import matter.tlv.TlvWriter class ContentLauncherClusterTrackPreferenceStruct( val languageCode: String, val characteristics: Optional>, - val audioOutputIndex: UByte, + val audioOutputIndex: UByte ) { override fun toString(): String = buildString { append("ContentLauncherClusterTrackPreferenceStruct {\n") @@ -44,10 +44,10 @@ class ContentLauncherClusterTrackPreferenceStruct( if (characteristics.isPresent) { val optcharacteristics = characteristics.get() startArray(ContextSpecificTag(TAG_CHARACTERISTICS)) - for (item in optcharacteristics.iterator()) { - put(AnonymousTag, item) - } - endArray() + for (item in optcharacteristics.iterator()) { + put(AnonymousTag, item) + } + endArray() } put(ContextSpecificTag(TAG_AUDIO_OUTPUT_INDEX), audioOutputIndex) endStructure() @@ -62,29 +62,22 @@ class ContentLauncherClusterTrackPreferenceStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ContentLauncherClusterTrackPreferenceStruct { tlvReader.enterStructure(tlvTag) val languageCode = tlvReader.getString(ContextSpecificTag(TAG_LANGUAGE_CODE)) - val characteristics = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_CHARACTERISTICS))) { - Optional.of( - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_CHARACTERISTICS)) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } - ) - } else { - Optional.empty() - } + val characteristics = if (tlvReader.isNextTag(ContextSpecificTag(TAG_CHARACTERISTICS))) { + Optional.of(buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_CHARACTERISTICS)) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + }) + } else { + Optional.empty() + } val audioOutputIndex = tlvReader.getUByte(ContextSpecificTag(TAG_AUDIO_OUTPUT_INDEX)) - + tlvReader.exitContainer() - return ContentLauncherClusterTrackPreferenceStruct( - languageCode, - characteristics, - audioOutputIndex, - ) + return ContentLauncherClusterTrackPreferenceStruct(languageCode, characteristics, audioOutputIndex) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterAverageLoadControlStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterAverageLoadControlStruct.kt index c59c3b96d2a63b..5a055dd4270923 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterAverageLoadControlStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterAverageLoadControlStruct.kt @@ -16,13 +16,17 @@ */ package matter.controller.cluster.structs +import java.util.Optional 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 DemandResponseLoadControlClusterAverageLoadControlStruct(val loadAdjustment: Byte) { +class DemandResponseLoadControlClusterAverageLoadControlStruct( + val loadAdjustment: Byte +) { override fun toString(): String = buildString { append("DemandResponseLoadControlClusterAverageLoadControlStruct {\n") append("\tloadAdjustment : $loadAdjustment\n") @@ -40,13 +44,10 @@ class DemandResponseLoadControlClusterAverageLoadControlStruct(val loadAdjustmen companion object { private const val TAG_LOAD_ADJUSTMENT = 0 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): DemandResponseLoadControlClusterAverageLoadControlStruct { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): DemandResponseLoadControlClusterAverageLoadControlStruct { tlvReader.enterStructure(tlvTag) val loadAdjustment = tlvReader.getByte(ContextSpecificTag(TAG_LOAD_ADJUSTMENT)) - + tlvReader.exitContainer() return DemandResponseLoadControlClusterAverageLoadControlStruct(loadAdjustment) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterDutyCycleControlStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterDutyCycleControlStruct.kt index db86b004c9ae35..9573a4e3ff11fa 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterDutyCycleControlStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterDutyCycleControlStruct.kt @@ -16,13 +16,17 @@ */ package matter.controller.cluster.structs +import java.util.Optional 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 DemandResponseLoadControlClusterDutyCycleControlStruct(val dutyCycle: UByte) { +class DemandResponseLoadControlClusterDutyCycleControlStruct( + val dutyCycle: UByte +) { override fun toString(): String = buildString { append("DemandResponseLoadControlClusterDutyCycleControlStruct {\n") append("\tdutyCycle : $dutyCycle\n") @@ -40,13 +44,10 @@ class DemandResponseLoadControlClusterDutyCycleControlStruct(val dutyCycle: UByt companion object { private const val TAG_DUTY_CYCLE = 0 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): DemandResponseLoadControlClusterDutyCycleControlStruct { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): DemandResponseLoadControlClusterDutyCycleControlStruct { tlvReader.enterStructure(tlvTag) val dutyCycle = tlvReader.getUByte(ContextSpecificTag(TAG_DUTY_CYCLE)) - + tlvReader.exitContainer() return DemandResponseLoadControlClusterDutyCycleControlStruct(dutyCycle) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterHeatingSourceControlStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterHeatingSourceControlStruct.kt index 0624700d6ddd5a..ed90e36f3a637e 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterHeatingSourceControlStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterHeatingSourceControlStruct.kt @@ -16,13 +16,17 @@ */ package matter.controller.cluster.structs +import java.util.Optional 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 DemandResponseLoadControlClusterHeatingSourceControlStruct(val heatingSource: UByte) { +class DemandResponseLoadControlClusterHeatingSourceControlStruct( + val heatingSource: UByte +) { override fun toString(): String = buildString { append("DemandResponseLoadControlClusterHeatingSourceControlStruct {\n") append("\theatingSource : $heatingSource\n") @@ -40,13 +44,10 @@ class DemandResponseLoadControlClusterHeatingSourceControlStruct(val heatingSour companion object { private const val TAG_HEATING_SOURCE = 0 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): DemandResponseLoadControlClusterHeatingSourceControlStruct { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): DemandResponseLoadControlClusterHeatingSourceControlStruct { tlvReader.enterStructure(tlvTag) val heatingSource = tlvReader.getUByte(ContextSpecificTag(TAG_HEATING_SOURCE)) - + tlvReader.exitContainer() return DemandResponseLoadControlClusterHeatingSourceControlStruct(heatingSource) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterLoadControlEventStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterLoadControlEventStruct.kt index e17da92ffddf7e..b0c75402f1f006 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterLoadControlEventStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterLoadControlEventStruct.kt @@ -32,7 +32,7 @@ class DemandResponseLoadControlClusterLoadControlEventStruct( val enrollmentGroup: Optional, val criticality: UByte, val startTime: UInt?, - val transitions: List, + val transitions: List ) { override fun toString(): String = buildString { append("DemandResponseLoadControlClusterLoadControlEventStruct {\n") @@ -87,61 +87,40 @@ class DemandResponseLoadControlClusterLoadControlEventStruct( private const val TAG_START_TIME = 6 private const val TAG_TRANSITIONS = 7 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): DemandResponseLoadControlClusterLoadControlEventStruct { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): DemandResponseLoadControlClusterLoadControlEventStruct { tlvReader.enterStructure(tlvTag) val eventID = tlvReader.getByteArray(ContextSpecificTag(TAG_EVENT_ID)) - val programID = - if (!tlvReader.isNull()) { - tlvReader.getByteArray(ContextSpecificTag(TAG_PROGRAM_ID)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_PROGRAM_ID)) - null - } + val programID = if (!tlvReader.isNull()) { + tlvReader.getByteArray(ContextSpecificTag(TAG_PROGRAM_ID)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_PROGRAM_ID)) + null + } val control = tlvReader.getUShort(ContextSpecificTag(TAG_CONTROL)) val deviceClass = tlvReader.getUInt(ContextSpecificTag(TAG_DEVICE_CLASS)) - val enrollmentGroup = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_ENROLLMENT_GROUP))) { - Optional.of(tlvReader.getUByte(ContextSpecificTag(TAG_ENROLLMENT_GROUP))) - } else { - Optional.empty() - } + val enrollmentGroup = if (tlvReader.isNextTag(ContextSpecificTag(TAG_ENROLLMENT_GROUP))) { + Optional.of(tlvReader.getUByte(ContextSpecificTag(TAG_ENROLLMENT_GROUP))) + } else { + Optional.empty() + } val criticality = tlvReader.getUByte(ContextSpecificTag(TAG_CRITICALITY)) - val startTime = - if (!tlvReader.isNull()) { - tlvReader.getUInt(ContextSpecificTag(TAG_START_TIME)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_START_TIME)) - null - } - val transitions = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_TRANSITIONS)) - while (!tlvReader.isEndOfContainer()) { - add( - DemandResponseLoadControlClusterLoadControlEventTransitionStruct.fromTlv( - AnonymousTag, - tlvReader, - ) - ) - } - tlvReader.exitContainer() - } - + val startTime = if (!tlvReader.isNull()) { + tlvReader.getUInt(ContextSpecificTag(TAG_START_TIME)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_START_TIME)) + null + } + val transitions = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_TRANSITIONS)) + while(!tlvReader.isEndOfContainer()) { + add(DemandResponseLoadControlClusterLoadControlEventTransitionStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + tlvReader.exitContainer() - return DemandResponseLoadControlClusterLoadControlEventStruct( - eventID, - programID, - control, - deviceClass, - enrollmentGroup, - criticality, - startTime, - transitions, - ) + return DemandResponseLoadControlClusterLoadControlEventStruct(eventID, programID, control, deviceClass, enrollmentGroup, criticality, startTime, transitions) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterLoadControlEventTransitionStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterLoadControlEventTransitionStruct.kt index cf7f5f337061db..8b11bb21f1b0a0 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterLoadControlEventTransitionStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterLoadControlEventTransitionStruct.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -30,7 +31,7 @@ class DemandResponseLoadControlClusterLoadControlEventTransitionStruct( val averageLoadControl: Optional, val dutyCycleControl: Optional, val powerSavingsControl: Optional, - val heatingSourceControl: Optional, + val heatingSourceControl: Optional ) { override fun toString(): String = buildString { append("DemandResponseLoadControlClusterLoadControlEventTransitionStruct {\n") @@ -82,80 +83,39 @@ class DemandResponseLoadControlClusterLoadControlEventTransitionStruct( private const val TAG_POWER_SAVINGS_CONTROL = 5 private const val TAG_HEATING_SOURCE_CONTROL = 6 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): DemandResponseLoadControlClusterLoadControlEventTransitionStruct { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): DemandResponseLoadControlClusterLoadControlEventTransitionStruct { tlvReader.enterStructure(tlvTag) val duration = tlvReader.getUShort(ContextSpecificTag(TAG_DURATION)) val control = tlvReader.getUShort(ContextSpecificTag(TAG_CONTROL)) - val temperatureControl = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_TEMPERATURE_CONTROL))) { - Optional.of( - DemandResponseLoadControlClusterTemperatureControlStruct.fromTlv( - ContextSpecificTag(TAG_TEMPERATURE_CONTROL), - tlvReader, - ) - ) - } else { - Optional.empty() - } - val averageLoadControl = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_AVERAGE_LOAD_CONTROL))) { - Optional.of( - DemandResponseLoadControlClusterAverageLoadControlStruct.fromTlv( - ContextSpecificTag(TAG_AVERAGE_LOAD_CONTROL), - tlvReader, - ) - ) - } else { - Optional.empty() - } - val dutyCycleControl = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_DUTY_CYCLE_CONTROL))) { - Optional.of( - DemandResponseLoadControlClusterDutyCycleControlStruct.fromTlv( - ContextSpecificTag(TAG_DUTY_CYCLE_CONTROL), - tlvReader, - ) - ) - } else { - Optional.empty() - } - val powerSavingsControl = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_POWER_SAVINGS_CONTROL))) { - Optional.of( - DemandResponseLoadControlClusterPowerSavingsControlStruct.fromTlv( - ContextSpecificTag(TAG_POWER_SAVINGS_CONTROL), - tlvReader, - ) - ) - } else { - Optional.empty() - } - val heatingSourceControl = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_HEATING_SOURCE_CONTROL))) { - Optional.of( - DemandResponseLoadControlClusterHeatingSourceControlStruct.fromTlv( - ContextSpecificTag(TAG_HEATING_SOURCE_CONTROL), - tlvReader, - ) - ) - } else { - Optional.empty() - } - + val temperatureControl = if (tlvReader.isNextTag(ContextSpecificTag(TAG_TEMPERATURE_CONTROL))) { + Optional.of(DemandResponseLoadControlClusterTemperatureControlStruct.fromTlv(ContextSpecificTag(TAG_TEMPERATURE_CONTROL), tlvReader)) + } else { + Optional.empty() + } + val averageLoadControl = if (tlvReader.isNextTag(ContextSpecificTag(TAG_AVERAGE_LOAD_CONTROL))) { + Optional.of(DemandResponseLoadControlClusterAverageLoadControlStruct.fromTlv(ContextSpecificTag(TAG_AVERAGE_LOAD_CONTROL), tlvReader)) + } else { + Optional.empty() + } + val dutyCycleControl = if (tlvReader.isNextTag(ContextSpecificTag(TAG_DUTY_CYCLE_CONTROL))) { + Optional.of(DemandResponseLoadControlClusterDutyCycleControlStruct.fromTlv(ContextSpecificTag(TAG_DUTY_CYCLE_CONTROL), tlvReader)) + } else { + Optional.empty() + } + val powerSavingsControl = if (tlvReader.isNextTag(ContextSpecificTag(TAG_POWER_SAVINGS_CONTROL))) { + Optional.of(DemandResponseLoadControlClusterPowerSavingsControlStruct.fromTlv(ContextSpecificTag(TAG_POWER_SAVINGS_CONTROL), tlvReader)) + } else { + Optional.empty() + } + val heatingSourceControl = if (tlvReader.isNextTag(ContextSpecificTag(TAG_HEATING_SOURCE_CONTROL))) { + Optional.of(DemandResponseLoadControlClusterHeatingSourceControlStruct.fromTlv(ContextSpecificTag(TAG_HEATING_SOURCE_CONTROL), tlvReader)) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return DemandResponseLoadControlClusterLoadControlEventTransitionStruct( - duration, - control, - temperatureControl, - averageLoadControl, - dutyCycleControl, - powerSavingsControl, - heatingSourceControl, - ) + return DemandResponseLoadControlClusterLoadControlEventTransitionStruct(duration, control, temperatureControl, averageLoadControl, dutyCycleControl, powerSavingsControl, heatingSourceControl) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterLoadControlProgramStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterLoadControlProgramStruct.kt index e22ed84158307e..32b997de3d68cc 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterLoadControlProgramStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterLoadControlProgramStruct.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -27,7 +29,7 @@ class DemandResponseLoadControlClusterLoadControlProgramStruct( val name: String, val enrollmentGroup: UByte?, val randomStartMinutes: UByte?, - val randomDurationMinutes: UByte?, + val randomDurationMinutes: UByte? ) { override fun toString(): String = buildString { append("DemandResponseLoadControlClusterLoadControlProgramStruct {\n") @@ -70,44 +72,32 @@ class DemandResponseLoadControlClusterLoadControlProgramStruct( private const val TAG_RANDOM_START_MINUTES = 3 private const val TAG_RANDOM_DURATION_MINUTES = 4 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): DemandResponseLoadControlClusterLoadControlProgramStruct { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): DemandResponseLoadControlClusterLoadControlProgramStruct { tlvReader.enterStructure(tlvTag) val programID = tlvReader.getByteArray(ContextSpecificTag(TAG_PROGRAM_ID)) val name = tlvReader.getString(ContextSpecificTag(TAG_NAME)) - val enrollmentGroup = - if (!tlvReader.isNull()) { - tlvReader.getUByte(ContextSpecificTag(TAG_ENROLLMENT_GROUP)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_ENROLLMENT_GROUP)) - null - } - val randomStartMinutes = - if (!tlvReader.isNull()) { - tlvReader.getUByte(ContextSpecificTag(TAG_RANDOM_START_MINUTES)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_RANDOM_START_MINUTES)) - null - } - val randomDurationMinutes = - if (!tlvReader.isNull()) { - tlvReader.getUByte(ContextSpecificTag(TAG_RANDOM_DURATION_MINUTES)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_RANDOM_DURATION_MINUTES)) - null - } - + val enrollmentGroup = if (!tlvReader.isNull()) { + tlvReader.getUByte(ContextSpecificTag(TAG_ENROLLMENT_GROUP)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_ENROLLMENT_GROUP)) + null + } + val randomStartMinutes = if (!tlvReader.isNull()) { + tlvReader.getUByte(ContextSpecificTag(TAG_RANDOM_START_MINUTES)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_RANDOM_START_MINUTES)) + null + } + val randomDurationMinutes = if (!tlvReader.isNull()) { + tlvReader.getUByte(ContextSpecificTag(TAG_RANDOM_DURATION_MINUTES)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_RANDOM_DURATION_MINUTES)) + null + } + tlvReader.exitContainer() - return DemandResponseLoadControlClusterLoadControlProgramStruct( - programID, - name, - enrollmentGroup, - randomStartMinutes, - randomDurationMinutes, - ) + return DemandResponseLoadControlClusterLoadControlProgramStruct(programID, name, enrollmentGroup, randomStartMinutes, randomDurationMinutes) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterPowerSavingsControlStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterPowerSavingsControlStruct.kt index 86fa69fc99fb1b..08d7bc21262e2e 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterPowerSavingsControlStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterPowerSavingsControlStruct.kt @@ -16,13 +16,17 @@ */ package matter.controller.cluster.structs +import java.util.Optional 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 DemandResponseLoadControlClusterPowerSavingsControlStruct(val powerSavings: UByte) { +class DemandResponseLoadControlClusterPowerSavingsControlStruct( + val powerSavings: UByte +) { override fun toString(): String = buildString { append("DemandResponseLoadControlClusterPowerSavingsControlStruct {\n") append("\tpowerSavings : $powerSavings\n") @@ -40,13 +44,10 @@ class DemandResponseLoadControlClusterPowerSavingsControlStruct(val powerSavings companion object { private const val TAG_POWER_SAVINGS = 0 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): DemandResponseLoadControlClusterPowerSavingsControlStruct { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): DemandResponseLoadControlClusterPowerSavingsControlStruct { tlvReader.enterStructure(tlvTag) val powerSavings = tlvReader.getUByte(ContextSpecificTag(TAG_POWER_SAVINGS)) - + tlvReader.exitContainer() return DemandResponseLoadControlClusterPowerSavingsControlStruct(powerSavings) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterTemperatureControlStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterTemperatureControlStruct.kt index 099dfb3628e747..d6bd0cd2524906 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterTemperatureControlStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterTemperatureControlStruct.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -27,7 +28,7 @@ class DemandResponseLoadControlClusterTemperatureControlStruct( val coolingTempOffset: Optional?, val heatingtTempOffset: Optional?, val coolingTempSetpoint: Optional?, - val heatingTempSetpoint: Optional?, + val heatingTempSetpoint: Optional? ) { override fun toString(): String = buildString { append("DemandResponseLoadControlClusterTemperatureControlStruct {\n") @@ -43,33 +44,33 @@ class DemandResponseLoadControlClusterTemperatureControlStruct( startStructure(tlvTag) if (coolingTempOffset != null) { if (coolingTempOffset.isPresent) { - val optcoolingTempOffset = coolingTempOffset.get() - put(ContextSpecificTag(TAG_COOLING_TEMP_OFFSET), optcoolingTempOffset) - } + val optcoolingTempOffset = coolingTempOffset.get() + put(ContextSpecificTag(TAG_COOLING_TEMP_OFFSET), optcoolingTempOffset) + } } else { putNull(ContextSpecificTag(TAG_COOLING_TEMP_OFFSET)) } if (heatingtTempOffset != null) { if (heatingtTempOffset.isPresent) { - val optheatingtTempOffset = heatingtTempOffset.get() - put(ContextSpecificTag(TAG_HEATINGT_TEMP_OFFSET), optheatingtTempOffset) - } + val optheatingtTempOffset = heatingtTempOffset.get() + put(ContextSpecificTag(TAG_HEATINGT_TEMP_OFFSET), optheatingtTempOffset) + } } else { putNull(ContextSpecificTag(TAG_HEATINGT_TEMP_OFFSET)) } if (coolingTempSetpoint != null) { if (coolingTempSetpoint.isPresent) { - val optcoolingTempSetpoint = coolingTempSetpoint.get() - put(ContextSpecificTag(TAG_COOLING_TEMP_SETPOINT), optcoolingTempSetpoint) - } + val optcoolingTempSetpoint = coolingTempSetpoint.get() + put(ContextSpecificTag(TAG_COOLING_TEMP_SETPOINT), optcoolingTempSetpoint) + } } else { putNull(ContextSpecificTag(TAG_COOLING_TEMP_SETPOINT)) } if (heatingTempSetpoint != null) { if (heatingTempSetpoint.isPresent) { - val optheatingTempSetpoint = heatingTempSetpoint.get() - put(ContextSpecificTag(TAG_HEATING_TEMP_SETPOINT), optheatingTempSetpoint) - } + val optheatingTempSetpoint = heatingTempSetpoint.get() + put(ContextSpecificTag(TAG_HEATING_TEMP_SETPOINT), optheatingTempSetpoint) + } } else { putNull(ContextSpecificTag(TAG_HEATING_TEMP_SETPOINT)) } @@ -83,64 +84,52 @@ class DemandResponseLoadControlClusterTemperatureControlStruct( private const val TAG_COOLING_TEMP_SETPOINT = 2 private const val TAG_HEATING_TEMP_SETPOINT = 3 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): DemandResponseLoadControlClusterTemperatureControlStruct { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): DemandResponseLoadControlClusterTemperatureControlStruct { tlvReader.enterStructure(tlvTag) - val coolingTempOffset = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_COOLING_TEMP_OFFSET))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_COOLING_TEMP_OFFSET))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_COOLING_TEMP_OFFSET)) - null - } - val heatingtTempOffset = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_HEATINGT_TEMP_OFFSET))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_HEATINGT_TEMP_OFFSET))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_HEATINGT_TEMP_OFFSET)) - null - } - val coolingTempSetpoint = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_COOLING_TEMP_SETPOINT))) { - Optional.of(tlvReader.getShort(ContextSpecificTag(TAG_COOLING_TEMP_SETPOINT))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_COOLING_TEMP_SETPOINT)) - null - } - val heatingTempSetpoint = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_HEATING_TEMP_SETPOINT))) { - Optional.of(tlvReader.getShort(ContextSpecificTag(TAG_HEATING_TEMP_SETPOINT))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_HEATING_TEMP_SETPOINT)) - null - } - + val coolingTempOffset = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_COOLING_TEMP_OFFSET))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_COOLING_TEMP_OFFSET))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_COOLING_TEMP_OFFSET)) + null + } + val heatingtTempOffset = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_HEATINGT_TEMP_OFFSET))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_HEATINGT_TEMP_OFFSET))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_HEATINGT_TEMP_OFFSET)) + null + } + val coolingTempSetpoint = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_COOLING_TEMP_SETPOINT))) { + Optional.of(tlvReader.getShort(ContextSpecificTag(TAG_COOLING_TEMP_SETPOINT))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_COOLING_TEMP_SETPOINT)) + null + } + val heatingTempSetpoint = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_HEATING_TEMP_SETPOINT))) { + Optional.of(tlvReader.getShort(ContextSpecificTag(TAG_HEATING_TEMP_SETPOINT))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_HEATING_TEMP_SETPOINT)) + null + } + tlvReader.exitContainer() - return DemandResponseLoadControlClusterTemperatureControlStruct( - coolingTempOffset, - heatingtTempOffset, - coolingTempSetpoint, - heatingTempSetpoint, - ) + return DemandResponseLoadControlClusterTemperatureControlStruct(coolingTempOffset, heatingtTempOffset, coolingTempSetpoint, heatingTempSetpoint) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/DescriptorClusterDeviceTypeStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/DescriptorClusterDeviceTypeStruct.kt index c8cc82e04d50eb..3b1d50b42659e8 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/DescriptorClusterDeviceTypeStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/DescriptorClusterDeviceTypeStruct.kt @@ -16,13 +16,18 @@ */ package matter.controller.cluster.structs +import java.util.Optional 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 DescriptorClusterDeviceTypeStruct(val deviceType: UInt, val revision: UShort) { +class DescriptorClusterDeviceTypeStruct( + val deviceType: UInt, + val revision: UShort +) { override fun toString(): String = buildString { append("DescriptorClusterDeviceTypeStruct {\n") append("\tdeviceType : $deviceType\n") @@ -47,7 +52,7 @@ class DescriptorClusterDeviceTypeStruct(val deviceType: UInt, val revision: USho tlvReader.enterStructure(tlvTag) val deviceType = tlvReader.getUInt(ContextSpecificTag(TAG_DEVICE_TYPE)) val revision = tlvReader.getUShort(ContextSpecificTag(TAG_REVISION)) - + tlvReader.exitContainer() return DescriptorClusterDeviceTypeStruct(deviceType, revision) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/DescriptorClusterSemanticTagStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/DescriptorClusterSemanticTagStruct.kt index f0206f14fa26cc..784537e96506e8 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/DescriptorClusterSemanticTagStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/DescriptorClusterSemanticTagStruct.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -27,7 +28,7 @@ class DescriptorClusterSemanticTagStruct( val mfgCode: UShort?, val namespaceID: UByte, val tag: UByte, - val label: Optional?, + val label: Optional? ) { override fun toString(): String = buildString { append("DescriptorClusterSemanticTagStruct {\n") @@ -50,9 +51,9 @@ class DescriptorClusterSemanticTagStruct( put(ContextSpecificTag(TAG_TAG), tag) if (label != null) { if (label.isPresent) { - val optlabel = label.get() - put(ContextSpecificTag(TAG_LABEL), optlabel) - } + val optlabel = label.get() + put(ContextSpecificTag(TAG_LABEL), optlabel) + } } else { putNull(ContextSpecificTag(TAG_LABEL)) } @@ -68,27 +69,25 @@ class DescriptorClusterSemanticTagStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): DescriptorClusterSemanticTagStruct { tlvReader.enterStructure(tlvTag) - val mfgCode = - if (!tlvReader.isNull()) { - tlvReader.getUShort(ContextSpecificTag(TAG_MFG_CODE)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_MFG_CODE)) - null - } + val mfgCode = if (!tlvReader.isNull()) { + tlvReader.getUShort(ContextSpecificTag(TAG_MFG_CODE)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_MFG_CODE)) + null + } val namespaceID = tlvReader.getUByte(ContextSpecificTag(TAG_NAMESPACE_ID)) val tag = tlvReader.getUByte(ContextSpecificTag(TAG_TAG)) - val label = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_LABEL))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_LABEL))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_LABEL)) - null - } - + val label = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_LABEL))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_LABEL))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_LABEL)) + null + } + tlvReader.exitContainer() return DescriptorClusterSemanticTagStruct(mfgCode, namespaceID, tag, label) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterConstraintsStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterConstraintsStruct.kt index f0f18cebb2e1e0..0972701ad34688 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterConstraintsStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterConstraintsStruct.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -28,7 +29,7 @@ class DeviceEnergyManagementClusterConstraintsStruct( val duration: UInt, val nominalPower: Optional, val maximumEnergy: Optional, - val loadControl: Optional, + val loadControl: Optional ) { override fun toString(): String = buildString { append("DeviceEnergyManagementClusterConstraintsStruct {\n") @@ -72,34 +73,25 @@ class DeviceEnergyManagementClusterConstraintsStruct( tlvReader.enterStructure(tlvTag) val startTime = tlvReader.getUInt(ContextSpecificTag(TAG_START_TIME)) val duration = tlvReader.getUInt(ContextSpecificTag(TAG_DURATION)) - val nominalPower = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_NOMINAL_POWER))) { - Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_NOMINAL_POWER))) - } else { - Optional.empty() - } - val maximumEnergy = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_MAXIMUM_ENERGY))) { - Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_MAXIMUM_ENERGY))) - } else { - Optional.empty() - } - val loadControl = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_LOAD_CONTROL))) { - Optional.of(tlvReader.getByte(ContextSpecificTag(TAG_LOAD_CONTROL))) - } else { - Optional.empty() - } - + val nominalPower = if (tlvReader.isNextTag(ContextSpecificTag(TAG_NOMINAL_POWER))) { + Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_NOMINAL_POWER))) + } else { + Optional.empty() + } + val maximumEnergy = if (tlvReader.isNextTag(ContextSpecificTag(TAG_MAXIMUM_ENERGY))) { + Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_MAXIMUM_ENERGY))) + } else { + Optional.empty() + } + val loadControl = if (tlvReader.isNextTag(ContextSpecificTag(TAG_LOAD_CONTROL))) { + Optional.of(tlvReader.getByte(ContextSpecificTag(TAG_LOAD_CONTROL))) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return DeviceEnergyManagementClusterConstraintsStruct( - startTime, - duration, - nominalPower, - maximumEnergy, - loadControl, - ) + return DeviceEnergyManagementClusterConstraintsStruct(startTime, duration, nominalPower, maximumEnergy, loadControl) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterCostStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterCostStruct.kt index 71a113c9fd2b43..f75628b28ac4f9 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterCostStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterCostStruct.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -27,7 +28,7 @@ class DeviceEnergyManagementClusterCostStruct( val costType: UByte, val value: Int, val decimalPoints: UByte, - val currency: Optional, + val currency: Optional ) { override fun toString(): String = buildString { append("DeviceEnergyManagementClusterCostStruct {\n") @@ -63,13 +64,12 @@ class DeviceEnergyManagementClusterCostStruct( val costType = tlvReader.getUByte(ContextSpecificTag(TAG_COST_TYPE)) val value = tlvReader.getInt(ContextSpecificTag(TAG_VALUE)) val decimalPoints = tlvReader.getUByte(ContextSpecificTag(TAG_DECIMAL_POINTS)) - val currency = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_CURRENCY))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_CURRENCY))) - } else { - Optional.empty() - } - + val currency = if (tlvReader.isNextTag(ContextSpecificTag(TAG_CURRENCY))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_CURRENCY))) + } else { + Optional.empty() + } + tlvReader.exitContainer() return DeviceEnergyManagementClusterCostStruct(costType, value, decimalPoints, currency) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterForecastStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterForecastStruct.kt index d10b032374dade..050a8c6ae1d424 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterForecastStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterForecastStruct.kt @@ -33,7 +33,7 @@ class DeviceEnergyManagementClusterForecastStruct( val latestEndTime: Optional, val isPausable: Boolean, val slots: List, - val forecastUpdateReason: UByte, + val forecastUpdateReason: UByte ) { override fun toString(): String = buildString { append("DeviceEnergyManagementClusterForecastStruct {\n") @@ -62,9 +62,9 @@ class DeviceEnergyManagementClusterForecastStruct( put(ContextSpecificTag(TAG_END_TIME), endTime) if (earliestStartTime != null) { if (earliestStartTime.isPresent) { - val optearliestStartTime = earliestStartTime.get() - put(ContextSpecificTag(TAG_EARLIEST_START_TIME), optearliestStartTime) - } + val optearliestStartTime = earliestStartTime.get() + put(ContextSpecificTag(TAG_EARLIEST_START_TIME), optearliestStartTime) + } } else { putNull(ContextSpecificTag(TAG_EARLIEST_START_TIME)) } @@ -97,56 +97,42 @@ class DeviceEnergyManagementClusterForecastStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): DeviceEnergyManagementClusterForecastStruct { tlvReader.enterStructure(tlvTag) val forecastID = tlvReader.getUInt(ContextSpecificTag(TAG_FORECAST_ID)) - val activeSlotNumber = - if (!tlvReader.isNull()) { - tlvReader.getUShort(ContextSpecificTag(TAG_ACTIVE_SLOT_NUMBER)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_ACTIVE_SLOT_NUMBER)) - null - } + val activeSlotNumber = if (!tlvReader.isNull()) { + tlvReader.getUShort(ContextSpecificTag(TAG_ACTIVE_SLOT_NUMBER)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_ACTIVE_SLOT_NUMBER)) + null + } val startTime = tlvReader.getUInt(ContextSpecificTag(TAG_START_TIME)) val endTime = tlvReader.getUInt(ContextSpecificTag(TAG_END_TIME)) - val earliestStartTime = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_EARLIEST_START_TIME))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_EARLIEST_START_TIME))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_EARLIEST_START_TIME)) - null - } - val latestEndTime = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_LATEST_END_TIME))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_LATEST_END_TIME))) - } else { - Optional.empty() - } + val earliestStartTime = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_EARLIEST_START_TIME))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_EARLIEST_START_TIME))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_EARLIEST_START_TIME)) + null + } + val latestEndTime = if (tlvReader.isNextTag(ContextSpecificTag(TAG_LATEST_END_TIME))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_LATEST_END_TIME))) + } else { + Optional.empty() + } val isPausable = tlvReader.getBoolean(ContextSpecificTag(TAG_IS_PAUSABLE)) - val slots = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_SLOTS)) - while (!tlvReader.isEndOfContainer()) { - add(DeviceEnergyManagementClusterSlotStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val slots = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_SLOTS)) + while(!tlvReader.isEndOfContainer()) { + add(DeviceEnergyManagementClusterSlotStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } val forecastUpdateReason = tlvReader.getUByte(ContextSpecificTag(TAG_FORECAST_UPDATE_REASON)) - + tlvReader.exitContainer() - return DeviceEnergyManagementClusterForecastStruct( - forecastID, - activeSlotNumber, - startTime, - endTime, - earliestStartTime, - latestEndTime, - isPausable, - slots, - forecastUpdateReason, - ) + return DeviceEnergyManagementClusterForecastStruct(forecastID, activeSlotNumber, startTime, endTime, earliestStartTime, latestEndTime, isPausable, slots, forecastUpdateReason) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterPowerAdjustCapabilityStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterPowerAdjustCapabilityStruct.kt index 0c1409014d254b..188f6bffef9f73 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterPowerAdjustCapabilityStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterPowerAdjustCapabilityStruct.kt @@ -16,6 +16,7 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -25,7 +26,7 @@ import matter.tlv.TlvWriter class DeviceEnergyManagementClusterPowerAdjustCapabilityStruct( val powerAdjustCapability: List?, - val cause: UByte, + val cause: UByte ) { override fun toString(): String = buildString { append("DeviceEnergyManagementClusterPowerAdjustCapabilityStruct {\n") @@ -39,10 +40,10 @@ class DeviceEnergyManagementClusterPowerAdjustCapabilityStruct( startStructure(tlvTag) if (powerAdjustCapability != null) { startArray(ContextSpecificTag(TAG_POWER_ADJUST_CAPABILITY)) - for (item in powerAdjustCapability.iterator()) { - item.toTlv(AnonymousTag, this) - } - endArray() + for (item in powerAdjustCapability.iterator()) { + item.toTlv(AnonymousTag, this) + } + endArray() } else { putNull(ContextSpecificTag(TAG_POWER_ADJUST_CAPABILITY)) } @@ -55,26 +56,22 @@ class DeviceEnergyManagementClusterPowerAdjustCapabilityStruct( private const val TAG_POWER_ADJUST_CAPABILITY = 0 private const val TAG_CAUSE = 1 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): DeviceEnergyManagementClusterPowerAdjustCapabilityStruct { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): DeviceEnergyManagementClusterPowerAdjustCapabilityStruct { tlvReader.enterStructure(tlvTag) - val powerAdjustCapability = - if (!tlvReader.isNull()) { - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_POWER_ADJUST_CAPABILITY)) - while (!tlvReader.isEndOfContainer()) { - add(DeviceEnergyManagementClusterPowerAdjustStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_POWER_ADJUST_CAPABILITY)) - null - } + val powerAdjustCapability = if (!tlvReader.isNull()) { + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_POWER_ADJUST_CAPABILITY)) + while(!tlvReader.isEndOfContainer()) { + add(DeviceEnergyManagementClusterPowerAdjustStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_POWER_ADJUST_CAPABILITY)) + null + } val cause = tlvReader.getUByte(ContextSpecificTag(TAG_CAUSE)) - + tlvReader.exitContainer() return DeviceEnergyManagementClusterPowerAdjustCapabilityStruct(powerAdjustCapability, cause) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterPowerAdjustStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterPowerAdjustStruct.kt index c7a29be35ead97..f03165bcf17f94 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterPowerAdjustStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterPowerAdjustStruct.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +28,7 @@ class DeviceEnergyManagementClusterPowerAdjustStruct( val minPower: Long, val maxPower: Long, val minDuration: UInt, - val maxDuration: UInt, + val maxDuration: UInt ) { override fun toString(): String = buildString { append("DeviceEnergyManagementClusterPowerAdjustStruct {\n") @@ -60,15 +62,10 @@ class DeviceEnergyManagementClusterPowerAdjustStruct( val maxPower = tlvReader.getLong(ContextSpecificTag(TAG_MAX_POWER)) val minDuration = tlvReader.getUInt(ContextSpecificTag(TAG_MIN_DURATION)) val maxDuration = tlvReader.getUInt(ContextSpecificTag(TAG_MAX_DURATION)) - + tlvReader.exitContainer() - return DeviceEnergyManagementClusterPowerAdjustStruct( - minPower, - maxPower, - minDuration, - maxDuration, - ) + return DeviceEnergyManagementClusterPowerAdjustStruct(minPower, maxPower, minDuration, maxDuration) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterSlotAdjustmentStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterSlotAdjustmentStruct.kt index 34dc8ddf4b2864..5be69214a8dfd4 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterSlotAdjustmentStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterSlotAdjustmentStruct.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +27,7 @@ import matter.tlv.TlvWriter class DeviceEnergyManagementClusterSlotAdjustmentStruct( val slotIndex: UByte, val nominalPower: Optional, - val duration: UInt, + val duration: UInt ) { override fun toString(): String = buildString { append("DeviceEnergyManagementClusterSlotAdjustmentStruct {\n") @@ -54,20 +55,16 @@ class DeviceEnergyManagementClusterSlotAdjustmentStruct( private const val TAG_NOMINAL_POWER = 1 private const val TAG_DURATION = 2 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): DeviceEnergyManagementClusterSlotAdjustmentStruct { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): DeviceEnergyManagementClusterSlotAdjustmentStruct { tlvReader.enterStructure(tlvTag) val slotIndex = tlvReader.getUByte(ContextSpecificTag(TAG_SLOT_INDEX)) - val nominalPower = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_NOMINAL_POWER))) { - Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_NOMINAL_POWER))) - } else { - Optional.empty() - } + val nominalPower = if (tlvReader.isNextTag(ContextSpecificTag(TAG_NOMINAL_POWER))) { + Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_NOMINAL_POWER))) + } else { + Optional.empty() + } val duration = tlvReader.getUInt(ContextSpecificTag(TAG_DURATION)) - + tlvReader.exitContainer() return DeviceEnergyManagementClusterSlotAdjustmentStruct(slotIndex, nominalPower, duration) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterSlotStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterSlotStruct.kt index d1babaf255c322..2d723d6c772bdc 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterSlotStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterSlotStruct.kt @@ -42,7 +42,7 @@ class DeviceEnergyManagementClusterSlotStruct( val minPowerAdjustment: Optional, val maxPowerAdjustment: Optional, val minDurationAdjustment: Optional, - val maxDurationAdjustment: Optional, + val maxDurationAdjustment: Optional ) { override fun toString(): String = buildString { append("DeviceEnergyManagementClusterSlotStruct {\n") @@ -110,10 +110,10 @@ class DeviceEnergyManagementClusterSlotStruct( if (costs.isPresent) { val optcosts = costs.get() startArray(ContextSpecificTag(TAG_COSTS)) - for (item in optcosts.iterator()) { - item.toTlv(AnonymousTag, this) - } - endArray() + for (item in optcosts.iterator()) { + item.toTlv(AnonymousTag, this) + } + endArray() } if (minPowerAdjustment.isPresent) { val optminPowerAdjustment = minPowerAdjustment.get() @@ -162,115 +162,81 @@ class DeviceEnergyManagementClusterSlotStruct( val defaultDuration = tlvReader.getUInt(ContextSpecificTag(TAG_DEFAULT_DURATION)) val elapsedSlotTime = tlvReader.getUInt(ContextSpecificTag(TAG_ELAPSED_SLOT_TIME)) val remainingSlotTime = tlvReader.getUInt(ContextSpecificTag(TAG_REMAINING_SLOT_TIME)) - val slotIsPausable = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_SLOT_IS_PAUSABLE))) { - Optional.of(tlvReader.getBoolean(ContextSpecificTag(TAG_SLOT_IS_PAUSABLE))) - } else { - Optional.empty() - } - val minPauseDuration = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_MIN_PAUSE_DURATION))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_MIN_PAUSE_DURATION))) - } else { - Optional.empty() - } - val maxPauseDuration = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_MAX_PAUSE_DURATION))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_MAX_PAUSE_DURATION))) - } else { - Optional.empty() - } - val manufacturerESAState = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_MANUFACTURER_ESA_STATE))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_MANUFACTURER_ESA_STATE))) - } else { - Optional.empty() - } - val nominalPower = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_NOMINAL_POWER))) { - Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_NOMINAL_POWER))) - } else { - Optional.empty() - } - val minPower = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_MIN_POWER))) { - Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_MIN_POWER))) - } else { - Optional.empty() - } - val maxPower = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_MAX_POWER))) { - Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_MAX_POWER))) - } else { - Optional.empty() - } - val nominalEnergy = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_NOMINAL_ENERGY))) { - Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_NOMINAL_ENERGY))) - } else { - Optional.empty() - } - val costs = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_COSTS))) { - Optional.of( - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_COSTS)) - while (!tlvReader.isEndOfContainer()) { - add(DeviceEnergyManagementClusterCostStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - ) - } else { - Optional.empty() - } - val minPowerAdjustment = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_MIN_POWER_ADJUSTMENT))) { - Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_MIN_POWER_ADJUSTMENT))) - } else { - Optional.empty() - } - val maxPowerAdjustment = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_MAX_POWER_ADJUSTMENT))) { - Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_MAX_POWER_ADJUSTMENT))) - } else { - Optional.empty() - } - val minDurationAdjustment = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_MIN_DURATION_ADJUSTMENT))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_MIN_DURATION_ADJUSTMENT))) - } else { - Optional.empty() - } - val maxDurationAdjustment = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_MAX_DURATION_ADJUSTMENT))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_MAX_DURATION_ADJUSTMENT))) - } else { - Optional.empty() - } - + val slotIsPausable = if (tlvReader.isNextTag(ContextSpecificTag(TAG_SLOT_IS_PAUSABLE))) { + Optional.of(tlvReader.getBoolean(ContextSpecificTag(TAG_SLOT_IS_PAUSABLE))) + } else { + Optional.empty() + } + val minPauseDuration = if (tlvReader.isNextTag(ContextSpecificTag(TAG_MIN_PAUSE_DURATION))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_MIN_PAUSE_DURATION))) + } else { + Optional.empty() + } + val maxPauseDuration = if (tlvReader.isNextTag(ContextSpecificTag(TAG_MAX_PAUSE_DURATION))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_MAX_PAUSE_DURATION))) + } else { + Optional.empty() + } + val manufacturerESAState = if (tlvReader.isNextTag(ContextSpecificTag(TAG_MANUFACTURER_ESA_STATE))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_MANUFACTURER_ESA_STATE))) + } else { + Optional.empty() + } + val nominalPower = if (tlvReader.isNextTag(ContextSpecificTag(TAG_NOMINAL_POWER))) { + Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_NOMINAL_POWER))) + } else { + Optional.empty() + } + val minPower = if (tlvReader.isNextTag(ContextSpecificTag(TAG_MIN_POWER))) { + Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_MIN_POWER))) + } else { + Optional.empty() + } + val maxPower = if (tlvReader.isNextTag(ContextSpecificTag(TAG_MAX_POWER))) { + Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_MAX_POWER))) + } else { + Optional.empty() + } + val nominalEnergy = if (tlvReader.isNextTag(ContextSpecificTag(TAG_NOMINAL_ENERGY))) { + Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_NOMINAL_ENERGY))) + } else { + Optional.empty() + } + val costs = if (tlvReader.isNextTag(ContextSpecificTag(TAG_COSTS))) { + Optional.of(buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_COSTS)) + while(!tlvReader.isEndOfContainer()) { + add(DeviceEnergyManagementClusterCostStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + }) + } else { + Optional.empty() + } + val minPowerAdjustment = if (tlvReader.isNextTag(ContextSpecificTag(TAG_MIN_POWER_ADJUSTMENT))) { + Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_MIN_POWER_ADJUSTMENT))) + } else { + Optional.empty() + } + val maxPowerAdjustment = if (tlvReader.isNextTag(ContextSpecificTag(TAG_MAX_POWER_ADJUSTMENT))) { + Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_MAX_POWER_ADJUSTMENT))) + } else { + Optional.empty() + } + val minDurationAdjustment = if (tlvReader.isNextTag(ContextSpecificTag(TAG_MIN_DURATION_ADJUSTMENT))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_MIN_DURATION_ADJUSTMENT))) + } else { + Optional.empty() + } + val maxDurationAdjustment = if (tlvReader.isNextTag(ContextSpecificTag(TAG_MAX_DURATION_ADJUSTMENT))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_MAX_DURATION_ADJUSTMENT))) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return DeviceEnergyManagementClusterSlotStruct( - minDuration, - maxDuration, - defaultDuration, - elapsedSlotTime, - remainingSlotTime, - slotIsPausable, - minPauseDuration, - maxPauseDuration, - manufacturerESAState, - nominalPower, - minPower, - maxPower, - nominalEnergy, - costs, - minPowerAdjustment, - maxPowerAdjustment, - minDurationAdjustment, - maxDurationAdjustment, - ) + return DeviceEnergyManagementClusterSlotStruct(minDuration, maxDuration, defaultDuration, elapsedSlotTime, remainingSlotTime, slotIsPausable, minPauseDuration, maxPauseDuration, manufacturerESAState, nominalPower, minPower, maxPower, nominalEnergy, costs, minPowerAdjustment, maxPowerAdjustment, minDurationAdjustment, maxDurationAdjustment) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementModeClusterModeOptionStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementModeClusterModeOptionStruct.kt index 1193974cf9a915..e506d757bc4d25 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementModeClusterModeOptionStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementModeClusterModeOptionStruct.kt @@ -16,6 +16,7 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -26,7 +27,7 @@ import matter.tlv.TlvWriter class DeviceEnergyManagementModeClusterModeOptionStruct( val label: String, val mode: UByte, - val modeTags: List, + val modeTags: List ) { override fun toString(): String = buildString { append("DeviceEnergyManagementModeClusterModeOptionStruct {\n") @@ -55,22 +56,18 @@ class DeviceEnergyManagementModeClusterModeOptionStruct( private const val TAG_MODE = 1 private const val TAG_MODE_TAGS = 2 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): DeviceEnergyManagementModeClusterModeOptionStruct { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): DeviceEnergyManagementModeClusterModeOptionStruct { tlvReader.enterStructure(tlvTag) val label = tlvReader.getString(ContextSpecificTag(TAG_LABEL)) val mode = tlvReader.getUByte(ContextSpecificTag(TAG_MODE)) - val modeTags = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_MODE_TAGS)) - while (!tlvReader.isEndOfContainer()) { - add(DeviceEnergyManagementModeClusterModeTagStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - + val modeTags = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_MODE_TAGS)) + while(!tlvReader.isEndOfContainer()) { + add(DeviceEnergyManagementModeClusterModeTagStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + tlvReader.exitContainer() return DeviceEnergyManagementModeClusterModeOptionStruct(label, mode, modeTags) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementModeClusterModeTagStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementModeClusterModeTagStruct.kt index 740b9abf0fd5b2..50409c33b33106 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementModeClusterModeTagStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementModeClusterModeTagStruct.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -25,7 +26,7 @@ import matter.tlv.TlvWriter class DeviceEnergyManagementModeClusterModeTagStruct( val mfgCode: Optional, - val value: UShort, + val value: UShort ) { override fun toString(): String = buildString { append("DeviceEnergyManagementModeClusterModeTagStruct {\n") @@ -52,14 +53,13 @@ class DeviceEnergyManagementModeClusterModeTagStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): DeviceEnergyManagementModeClusterModeTagStruct { tlvReader.enterStructure(tlvTag) - val mfgCode = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_MFG_CODE))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_MFG_CODE))) - } else { - Optional.empty() - } + val mfgCode = if (tlvReader.isNextTag(ContextSpecificTag(TAG_MFG_CODE))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_MFG_CODE))) + } else { + Optional.empty() + } val value = tlvReader.getUShort(ContextSpecificTag(TAG_VALUE)) - + tlvReader.exitContainer() return DeviceEnergyManagementModeClusterModeTagStruct(mfgCode, value) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/DishwasherModeClusterModeOptionStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/DishwasherModeClusterModeOptionStruct.kt index f0b1a134612e7d..d250f1c10ccccc 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/DishwasherModeClusterModeOptionStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/DishwasherModeClusterModeOptionStruct.kt @@ -16,6 +16,7 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -26,7 +27,7 @@ import matter.tlv.TlvWriter class DishwasherModeClusterModeOptionStruct( val label: String, val mode: UByte, - val modeTags: List, + val modeTags: List ) { override fun toString(): String = buildString { append("DishwasherModeClusterModeOptionStruct {\n") @@ -59,15 +60,14 @@ class DishwasherModeClusterModeOptionStruct( tlvReader.enterStructure(tlvTag) val label = tlvReader.getString(ContextSpecificTag(TAG_LABEL)) val mode = tlvReader.getUByte(ContextSpecificTag(TAG_MODE)) - val modeTags = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_MODE_TAGS)) - while (!tlvReader.isEndOfContainer()) { - add(DishwasherModeClusterModeTagStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - + val modeTags = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_MODE_TAGS)) + while(!tlvReader.isEndOfContainer()) { + add(DishwasherModeClusterModeTagStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + tlvReader.exitContainer() return DishwasherModeClusterModeOptionStruct(label, mode, modeTags) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/DishwasherModeClusterModeTagStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/DishwasherModeClusterModeTagStruct.kt index 584dc79028182c..033e60f5419f37 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/DishwasherModeClusterModeTagStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/DishwasherModeClusterModeTagStruct.kt @@ -18,12 +18,16 @@ package matter.controller.cluster.structs import java.util.Optional 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 DishwasherModeClusterModeTagStruct(val mfgCode: Optional, val value: UShort) { +class DishwasherModeClusterModeTagStruct( + val mfgCode: Optional, + val value: UShort +) { override fun toString(): String = buildString { append("DishwasherModeClusterModeTagStruct {\n") append("\tmfgCode : $mfgCode\n") @@ -49,14 +53,13 @@ class DishwasherModeClusterModeTagStruct(val mfgCode: Optional, val valu fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): DishwasherModeClusterModeTagStruct { tlvReader.enterStructure(tlvTag) - val mfgCode = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_MFG_CODE))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_MFG_CODE))) - } else { - Optional.empty() - } + val mfgCode = if (tlvReader.isNextTag(ContextSpecificTag(TAG_MFG_CODE))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_MFG_CODE))) + } else { + Optional.empty() + } val value = tlvReader.getUShort(ContextSpecificTag(TAG_VALUE)) - + tlvReader.exitContainer() return DishwasherModeClusterModeTagStruct(mfgCode, value) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/DoorLockClusterCredentialStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/DoorLockClusterCredentialStruct.kt index f66b57f47660ca..5f2b5c37f2d96e 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/DoorLockClusterCredentialStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/DoorLockClusterCredentialStruct.kt @@ -16,13 +16,18 @@ */ package matter.controller.cluster.structs +import java.util.Optional 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 DoorLockClusterCredentialStruct(val credentialType: UByte, val credentialIndex: UShort) { +class DoorLockClusterCredentialStruct( + val credentialType: UByte, + val credentialIndex: UShort +) { override fun toString(): String = buildString { append("DoorLockClusterCredentialStruct {\n") append("\tcredentialType : $credentialType\n") @@ -47,7 +52,7 @@ class DoorLockClusterCredentialStruct(val credentialType: UByte, val credentialI tlvReader.enterStructure(tlvTag) val credentialType = tlvReader.getUByte(ContextSpecificTag(TAG_CREDENTIAL_TYPE)) val credentialIndex = tlvReader.getUShort(ContextSpecificTag(TAG_CREDENTIAL_INDEX)) - + tlvReader.exitContainer() return DoorLockClusterCredentialStruct(credentialType, credentialIndex) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/EcosystemInformationClusterDeviceTypeStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/EcosystemInformationClusterDeviceTypeStruct.kt index 1ebb7b6abd3f60..899c6a799f293e 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/EcosystemInformationClusterDeviceTypeStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/EcosystemInformationClusterDeviceTypeStruct.kt @@ -16,13 +16,18 @@ */ package matter.controller.cluster.structs +import java.util.Optional 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 EcosystemInformationClusterDeviceTypeStruct(val deviceType: UInt, val revision: UShort) { +class EcosystemInformationClusterDeviceTypeStruct( + val deviceType: UInt, + val revision: UShort +) { override fun toString(): String = buildString { append("EcosystemInformationClusterDeviceTypeStruct {\n") append("\tdeviceType : $deviceType\n") @@ -47,7 +52,7 @@ class EcosystemInformationClusterDeviceTypeStruct(val deviceType: UInt, val revi tlvReader.enterStructure(tlvTag) val deviceType = tlvReader.getUInt(ContextSpecificTag(TAG_DEVICE_TYPE)) val revision = tlvReader.getUShort(ContextSpecificTag(TAG_REVISION)) - + tlvReader.exitContainer() return EcosystemInformationClusterDeviceTypeStruct(deviceType, revision) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/EcosystemInformationClusterEcosystemDeviceStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/EcosystemInformationClusterEcosystemDeviceStruct.kt index 0f04e02f973a58..1a5d4c1d620374 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/EcosystemInformationClusterEcosystemDeviceStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/EcosystemInformationClusterEcosystemDeviceStruct.kt @@ -32,7 +32,7 @@ class EcosystemInformationClusterEcosystemDeviceStruct( val deviceTypes: List, val uniqueLocationIDs: List, val uniqueLocationIDsLastEdit: ULong, - val fabricIndex: UByte, + val fabricIndex: UByte ) { override fun toString(): String = buildString { append("EcosystemInformationClusterEcosystemDeviceStruct {\n") @@ -86,57 +86,40 @@ class EcosystemInformationClusterEcosystemDeviceStruct( private const val TAG_UNIQUE_LOCATION_I_DS_LAST_EDIT = 6 private const val TAG_FABRIC_INDEX = 254 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): EcosystemInformationClusterEcosystemDeviceStruct { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): EcosystemInformationClusterEcosystemDeviceStruct { tlvReader.enterStructure(tlvTag) - val deviceName = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_DEVICE_NAME))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_DEVICE_NAME))) - } else { - Optional.empty() - } - val deviceNameLastEdit = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_DEVICE_NAME_LAST_EDIT))) { - Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_DEVICE_NAME_LAST_EDIT))) - } else { - Optional.empty() - } + val deviceName = if (tlvReader.isNextTag(ContextSpecificTag(TAG_DEVICE_NAME))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_DEVICE_NAME))) + } else { + Optional.empty() + } + val deviceNameLastEdit = if (tlvReader.isNextTag(ContextSpecificTag(TAG_DEVICE_NAME_LAST_EDIT))) { + Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_DEVICE_NAME_LAST_EDIT))) + } else { + Optional.empty() + } val bridgedEndpoint = tlvReader.getUShort(ContextSpecificTag(TAG_BRIDGED_ENDPOINT)) val originalEndpoint = tlvReader.getUShort(ContextSpecificTag(TAG_ORIGINAL_ENDPOINT)) - val deviceTypes = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_DEVICE_TYPES)) - while (!tlvReader.isEndOfContainer()) { - add(EcosystemInformationClusterDeviceTypeStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - val uniqueLocationIDs = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_UNIQUE_LOCATION_I_DS)) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getString(AnonymousTag)) - } - tlvReader.exitContainer() - } - val uniqueLocationIDsLastEdit = - tlvReader.getULong(ContextSpecificTag(TAG_UNIQUE_LOCATION_I_DS_LAST_EDIT)) + val deviceTypes = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_DEVICE_TYPES)) + while(!tlvReader.isEndOfContainer()) { + add(EcosystemInformationClusterDeviceTypeStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + val uniqueLocationIDs = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_UNIQUE_LOCATION_I_DS)) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getString(AnonymousTag)) + } + tlvReader.exitContainer() + } + val uniqueLocationIDsLastEdit = tlvReader.getULong(ContextSpecificTag(TAG_UNIQUE_LOCATION_I_DS_LAST_EDIT)) val fabricIndex = tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) - + tlvReader.exitContainer() - return EcosystemInformationClusterEcosystemDeviceStruct( - deviceName, - deviceNameLastEdit, - bridgedEndpoint, - originalEndpoint, - deviceTypes, - uniqueLocationIDs, - uniqueLocationIDsLastEdit, - fabricIndex, - ) + return EcosystemInformationClusterEcosystemDeviceStruct(deviceName, deviceNameLastEdit, bridgedEndpoint, originalEndpoint, deviceTypes, uniqueLocationIDs, uniqueLocationIDsLastEdit, fabricIndex) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/EcosystemInformationClusterEcosystemLocationStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/EcosystemInformationClusterEcosystemLocationStruct.kt index f59492e6195cfd..7e161959c5c9e6 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/EcosystemInformationClusterEcosystemLocationStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/EcosystemInformationClusterEcosystemLocationStruct.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +28,7 @@ class EcosystemInformationClusterEcosystemLocationStruct( val uniqueLocationID: String, val locationDescriptor: EcosystemInformationClusterLocationDescriptorStruct, val locationDescriptorLastEdit: ULong, - val fabricIndex: UByte, + val fabricIndex: UByte ) { override fun toString(): String = buildString { append("EcosystemInformationClusterEcosystemLocationStruct {\n") @@ -54,29 +56,16 @@ class EcosystemInformationClusterEcosystemLocationStruct( private const val TAG_LOCATION_DESCRIPTOR_LAST_EDIT = 2 private const val TAG_FABRIC_INDEX = 254 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): EcosystemInformationClusterEcosystemLocationStruct { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): EcosystemInformationClusterEcosystemLocationStruct { tlvReader.enterStructure(tlvTag) val uniqueLocationID = tlvReader.getString(ContextSpecificTag(TAG_UNIQUE_LOCATION_ID)) - val locationDescriptor = - EcosystemInformationClusterLocationDescriptorStruct.fromTlv( - ContextSpecificTag(TAG_LOCATION_DESCRIPTOR), - tlvReader, - ) - val locationDescriptorLastEdit = - tlvReader.getULong(ContextSpecificTag(TAG_LOCATION_DESCRIPTOR_LAST_EDIT)) + val locationDescriptor = EcosystemInformationClusterLocationDescriptorStruct.fromTlv(ContextSpecificTag(TAG_LOCATION_DESCRIPTOR), tlvReader) + val locationDescriptorLastEdit = tlvReader.getULong(ContextSpecificTag(TAG_LOCATION_DESCRIPTOR_LAST_EDIT)) val fabricIndex = tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) - + tlvReader.exitContainer() - return EcosystemInformationClusterEcosystemLocationStruct( - uniqueLocationID, - locationDescriptor, - locationDescriptorLastEdit, - fabricIndex, - ) + return EcosystemInformationClusterEcosystemLocationStruct(uniqueLocationID, locationDescriptor, locationDescriptorLastEdit, fabricIndex) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/EcosystemInformationClusterLocationDescriptorStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/EcosystemInformationClusterLocationDescriptorStruct.kt index ddb0f9498efefc..596c2c5c7ad6c7 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/EcosystemInformationClusterLocationDescriptorStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/EcosystemInformationClusterLocationDescriptorStruct.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -25,7 +27,7 @@ import matter.tlv.TlvWriter class EcosystemInformationClusterLocationDescriptorStruct( val locationName: String, val floorNumber: Short?, - val areaType: UByte?, + val areaType: UByte? ) { override fun toString(): String = buildString { append("EcosystemInformationClusterLocationDescriptorStruct {\n") @@ -58,34 +60,25 @@ class EcosystemInformationClusterLocationDescriptorStruct( private const val TAG_FLOOR_NUMBER = 1 private const val TAG_AREA_TYPE = 2 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): EcosystemInformationClusterLocationDescriptorStruct { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): EcosystemInformationClusterLocationDescriptorStruct { tlvReader.enterStructure(tlvTag) val locationName = tlvReader.getString(ContextSpecificTag(TAG_LOCATION_NAME)) - val floorNumber = - if (!tlvReader.isNull()) { - tlvReader.getShort(ContextSpecificTag(TAG_FLOOR_NUMBER)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_FLOOR_NUMBER)) - null - } - val areaType = - if (!tlvReader.isNull()) { - tlvReader.getUByte(ContextSpecificTag(TAG_AREA_TYPE)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_AREA_TYPE)) - null - } - + val floorNumber = if (!tlvReader.isNull()) { + tlvReader.getShort(ContextSpecificTag(TAG_FLOOR_NUMBER)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_FLOOR_NUMBER)) + null + } + val areaType = if (!tlvReader.isNull()) { + tlvReader.getUByte(ContextSpecificTag(TAG_AREA_TYPE)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_AREA_TYPE)) + null + } + tlvReader.exitContainer() - return EcosystemInformationClusterLocationDescriptorStruct( - locationName, - floorNumber, - areaType, - ) + return EcosystemInformationClusterLocationDescriptorStruct(locationName, floorNumber, areaType) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct.kt index 8189ee00cb6b0a..0827d8124cf55e 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -27,7 +28,7 @@ class ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct( val importedResetTimestamp: Optional?, val exportedResetTimestamp: Optional?, val importedResetSystime: Optional?, - val exportedResetSystime: Optional?, + val exportedResetSystime: Optional? ) { override fun toString(): String = buildString { append("ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct {\n") @@ -43,33 +44,33 @@ class ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct( startStructure(tlvTag) if (importedResetTimestamp != null) { if (importedResetTimestamp.isPresent) { - val optimportedResetTimestamp = importedResetTimestamp.get() - put(ContextSpecificTag(TAG_IMPORTED_RESET_TIMESTAMP), optimportedResetTimestamp) - } + val optimportedResetTimestamp = importedResetTimestamp.get() + put(ContextSpecificTag(TAG_IMPORTED_RESET_TIMESTAMP), optimportedResetTimestamp) + } } else { putNull(ContextSpecificTag(TAG_IMPORTED_RESET_TIMESTAMP)) } if (exportedResetTimestamp != null) { if (exportedResetTimestamp.isPresent) { - val optexportedResetTimestamp = exportedResetTimestamp.get() - put(ContextSpecificTag(TAG_EXPORTED_RESET_TIMESTAMP), optexportedResetTimestamp) - } + val optexportedResetTimestamp = exportedResetTimestamp.get() + put(ContextSpecificTag(TAG_EXPORTED_RESET_TIMESTAMP), optexportedResetTimestamp) + } } else { putNull(ContextSpecificTag(TAG_EXPORTED_RESET_TIMESTAMP)) } if (importedResetSystime != null) { if (importedResetSystime.isPresent) { - val optimportedResetSystime = importedResetSystime.get() - put(ContextSpecificTag(TAG_IMPORTED_RESET_SYSTIME), optimportedResetSystime) - } + val optimportedResetSystime = importedResetSystime.get() + put(ContextSpecificTag(TAG_IMPORTED_RESET_SYSTIME), optimportedResetSystime) + } } else { putNull(ContextSpecificTag(TAG_IMPORTED_RESET_SYSTIME)) } if (exportedResetSystime != null) { if (exportedResetSystime.isPresent) { - val optexportedResetSystime = exportedResetSystime.get() - put(ContextSpecificTag(TAG_EXPORTED_RESET_SYSTIME), optexportedResetSystime) - } + val optexportedResetSystime = exportedResetSystime.get() + put(ContextSpecificTag(TAG_EXPORTED_RESET_SYSTIME), optexportedResetSystime) + } } else { putNull(ContextSpecificTag(TAG_EXPORTED_RESET_SYSTIME)) } @@ -83,64 +84,52 @@ class ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct( private const val TAG_IMPORTED_RESET_SYSTIME = 2 private const val TAG_EXPORTED_RESET_SYSTIME = 3 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct { tlvReader.enterStructure(tlvTag) - val importedResetTimestamp = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_IMPORTED_RESET_TIMESTAMP))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_IMPORTED_RESET_TIMESTAMP))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_IMPORTED_RESET_TIMESTAMP)) - null - } - val exportedResetTimestamp = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_EXPORTED_RESET_TIMESTAMP))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_EXPORTED_RESET_TIMESTAMP))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_EXPORTED_RESET_TIMESTAMP)) - null - } - val importedResetSystime = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_IMPORTED_RESET_SYSTIME))) { - Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_IMPORTED_RESET_SYSTIME))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_IMPORTED_RESET_SYSTIME)) - null - } - val exportedResetSystime = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_EXPORTED_RESET_SYSTIME))) { - Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_EXPORTED_RESET_SYSTIME))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_EXPORTED_RESET_SYSTIME)) - null - } - + val importedResetTimestamp = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_IMPORTED_RESET_TIMESTAMP))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_IMPORTED_RESET_TIMESTAMP))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_IMPORTED_RESET_TIMESTAMP)) + null + } + val exportedResetTimestamp = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_EXPORTED_RESET_TIMESTAMP))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_EXPORTED_RESET_TIMESTAMP))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_EXPORTED_RESET_TIMESTAMP)) + null + } + val importedResetSystime = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_IMPORTED_RESET_SYSTIME))) { + Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_IMPORTED_RESET_SYSTIME))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_IMPORTED_RESET_SYSTIME)) + null + } + val exportedResetSystime = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_EXPORTED_RESET_SYSTIME))) { + Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_EXPORTED_RESET_SYSTIME))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_EXPORTED_RESET_SYSTIME)) + null + } + tlvReader.exitContainer() - return ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct( - importedResetTimestamp, - exportedResetTimestamp, - importedResetSystime, - exportedResetSystime, - ) + return ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct(importedResetTimestamp, exportedResetTimestamp, importedResetSystime, exportedResetSystime) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalEnergyMeasurementClusterEnergyMeasurementStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalEnergyMeasurementClusterEnergyMeasurementStruct.kt index 5842533174f022..397f1eab428ecf 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalEnergyMeasurementClusterEnergyMeasurementStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalEnergyMeasurementClusterEnergyMeasurementStruct.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -28,7 +29,7 @@ class ElectricalEnergyMeasurementClusterEnergyMeasurementStruct( val startTimestamp: Optional, val endTimestamp: Optional, val startSystime: Optional, - val endSystime: Optional, + val endSystime: Optional ) { override fun toString(): String = buildString { append("ElectricalEnergyMeasurementClusterEnergyMeasurementStruct {\n") @@ -71,46 +72,33 @@ class ElectricalEnergyMeasurementClusterEnergyMeasurementStruct( private const val TAG_START_SYSTIME = 3 private const val TAG_END_SYSTIME = 4 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): ElectricalEnergyMeasurementClusterEnergyMeasurementStruct { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ElectricalEnergyMeasurementClusterEnergyMeasurementStruct { tlvReader.enterStructure(tlvTag) val energy = tlvReader.getLong(ContextSpecificTag(TAG_ENERGY)) - val startTimestamp = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_START_TIMESTAMP))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_START_TIMESTAMP))) - } else { - Optional.empty() - } - val endTimestamp = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_END_TIMESTAMP))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_END_TIMESTAMP))) - } else { - Optional.empty() - } - val startSystime = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_START_SYSTIME))) { - Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_START_SYSTIME))) - } else { - Optional.empty() - } - val endSystime = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_END_SYSTIME))) { - Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_END_SYSTIME))) - } else { - Optional.empty() - } - + val startTimestamp = if (tlvReader.isNextTag(ContextSpecificTag(TAG_START_TIMESTAMP))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_START_TIMESTAMP))) + } else { + Optional.empty() + } + val endTimestamp = if (tlvReader.isNextTag(ContextSpecificTag(TAG_END_TIMESTAMP))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_END_TIMESTAMP))) + } else { + Optional.empty() + } + val startSystime = if (tlvReader.isNextTag(ContextSpecificTag(TAG_START_SYSTIME))) { + Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_START_SYSTIME))) + } else { + Optional.empty() + } + val endSystime = if (tlvReader.isNextTag(ContextSpecificTag(TAG_END_SYSTIME))) { + Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_END_SYSTIME))) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return ElectricalEnergyMeasurementClusterEnergyMeasurementStruct( - energy, - startTimestamp, - endTimestamp, - startSystime, - endSystime, - ) + return ElectricalEnergyMeasurementClusterEnergyMeasurementStruct(energy, startTimestamp, endTimestamp, startSystime, endSystime) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalEnergyMeasurementClusterMeasurementAccuracyRangeStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalEnergyMeasurementClusterMeasurementAccuracyRangeStruct.kt index 8234247fa327ea..4e0ca217ce09fe 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalEnergyMeasurementClusterMeasurementAccuracyRangeStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalEnergyMeasurementClusterMeasurementAccuracyRangeStruct.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -31,7 +32,7 @@ class ElectricalEnergyMeasurementClusterMeasurementAccuracyRangeStruct( val percentTypical: Optional, val fixedMax: Optional, val fixedMin: Optional, - val fixedTypical: Optional, + val fixedTypical: Optional ) { override fun toString(): String = buildString { append("ElectricalEnergyMeasurementClusterMeasurementAccuracyRangeStruct {\n") @@ -89,62 +90,44 @@ class ElectricalEnergyMeasurementClusterMeasurementAccuracyRangeStruct( private const val TAG_FIXED_MIN = 6 private const val TAG_FIXED_TYPICAL = 7 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): ElectricalEnergyMeasurementClusterMeasurementAccuracyRangeStruct { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ElectricalEnergyMeasurementClusterMeasurementAccuracyRangeStruct { tlvReader.enterStructure(tlvTag) val rangeMin = tlvReader.getLong(ContextSpecificTag(TAG_RANGE_MIN)) val rangeMax = tlvReader.getLong(ContextSpecificTag(TAG_RANGE_MAX)) - val percentMax = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_PERCENT_MAX))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_PERCENT_MAX))) - } else { - Optional.empty() - } - val percentMin = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_PERCENT_MIN))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_PERCENT_MIN))) - } else { - Optional.empty() - } - val percentTypical = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_PERCENT_TYPICAL))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_PERCENT_TYPICAL))) - } else { - Optional.empty() - } - val fixedMax = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_FIXED_MAX))) { - Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_FIXED_MAX))) - } else { - Optional.empty() - } - val fixedMin = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_FIXED_MIN))) { - Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_FIXED_MIN))) - } else { - Optional.empty() - } - val fixedTypical = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_FIXED_TYPICAL))) { - Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_FIXED_TYPICAL))) - } else { - Optional.empty() - } - + val percentMax = if (tlvReader.isNextTag(ContextSpecificTag(TAG_PERCENT_MAX))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_PERCENT_MAX))) + } else { + Optional.empty() + } + val percentMin = if (tlvReader.isNextTag(ContextSpecificTag(TAG_PERCENT_MIN))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_PERCENT_MIN))) + } else { + Optional.empty() + } + val percentTypical = if (tlvReader.isNextTag(ContextSpecificTag(TAG_PERCENT_TYPICAL))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_PERCENT_TYPICAL))) + } else { + Optional.empty() + } + val fixedMax = if (tlvReader.isNextTag(ContextSpecificTag(TAG_FIXED_MAX))) { + Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_FIXED_MAX))) + } else { + Optional.empty() + } + val fixedMin = if (tlvReader.isNextTag(ContextSpecificTag(TAG_FIXED_MIN))) { + Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_FIXED_MIN))) + } else { + Optional.empty() + } + val fixedTypical = if (tlvReader.isNextTag(ContextSpecificTag(TAG_FIXED_TYPICAL))) { + Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_FIXED_TYPICAL))) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return ElectricalEnergyMeasurementClusterMeasurementAccuracyRangeStruct( - rangeMin, - rangeMax, - percentMax, - percentMin, - percentTypical, - fixedMax, - fixedMin, - fixedTypical, - ) + return ElectricalEnergyMeasurementClusterMeasurementAccuracyRangeStruct(rangeMin, rangeMax, percentMax, percentMin, percentTypical, fixedMax, fixedMin, fixedTypical) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalEnergyMeasurementClusterMeasurementAccuracyStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalEnergyMeasurementClusterMeasurementAccuracyStruct.kt index b4068935ee9aef..b0ec26832b7c2d 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalEnergyMeasurementClusterMeasurementAccuracyStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalEnergyMeasurementClusterMeasurementAccuracyStruct.kt @@ -16,6 +16,7 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -28,7 +29,7 @@ class ElectricalEnergyMeasurementClusterMeasurementAccuracyStruct( val measured: Boolean, val minMeasuredValue: Long, val maxMeasuredValue: Long, - val accuracyRanges: List, + val accuracyRanges: List ) { override fun toString(): String = buildString { append("ElectricalEnergyMeasurementClusterMeasurementAccuracyStruct {\n") @@ -63,38 +64,23 @@ class ElectricalEnergyMeasurementClusterMeasurementAccuracyStruct( private const val TAG_MAX_MEASURED_VALUE = 3 private const val TAG_ACCURACY_RANGES = 4 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): ElectricalEnergyMeasurementClusterMeasurementAccuracyStruct { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ElectricalEnergyMeasurementClusterMeasurementAccuracyStruct { tlvReader.enterStructure(tlvTag) 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)) - val accuracyRanges = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_ACCURACY_RANGES)) - while (!tlvReader.isEndOfContainer()) { - add( - ElectricalEnergyMeasurementClusterMeasurementAccuracyRangeStruct.fromTlv( - AnonymousTag, - tlvReader, - ) - ) - } - tlvReader.exitContainer() - } - + val accuracyRanges = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_ACCURACY_RANGES)) + while(!tlvReader.isEndOfContainer()) { + add(ElectricalEnergyMeasurementClusterMeasurementAccuracyRangeStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + tlvReader.exitContainer() - return ElectricalEnergyMeasurementClusterMeasurementAccuracyStruct( - measurementType, - measured, - minMeasuredValue, - maxMeasuredValue, - accuracyRanges, - ) + return ElectricalEnergyMeasurementClusterMeasurementAccuracyStruct(measurementType, measured, minMeasuredValue, maxMeasuredValue, accuracyRanges) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalPowerMeasurementClusterHarmonicMeasurementStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalPowerMeasurementClusterHarmonicMeasurementStruct.kt index 2a83816368e304..48533cc86b8586 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalPowerMeasurementClusterHarmonicMeasurementStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalPowerMeasurementClusterHarmonicMeasurementStruct.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -24,7 +26,7 @@ import matter.tlv.TlvWriter class ElectricalPowerMeasurementClusterHarmonicMeasurementStruct( val order: UByte, - val measurement: Long?, + val measurement: Long? ) { override fun toString(): String = buildString { append("ElectricalPowerMeasurementClusterHarmonicMeasurementStruct {\n") @@ -50,20 +52,16 @@ class ElectricalPowerMeasurementClusterHarmonicMeasurementStruct( private const val TAG_ORDER = 0 private const val TAG_MEASUREMENT = 1 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): ElectricalPowerMeasurementClusterHarmonicMeasurementStruct { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ElectricalPowerMeasurementClusterHarmonicMeasurementStruct { tlvReader.enterStructure(tlvTag) val order = tlvReader.getUByte(ContextSpecificTag(TAG_ORDER)) - val measurement = - if (!tlvReader.isNull()) { - tlvReader.getLong(ContextSpecificTag(TAG_MEASUREMENT)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_MEASUREMENT)) - null - } - + val measurement = if (!tlvReader.isNull()) { + tlvReader.getLong(ContextSpecificTag(TAG_MEASUREMENT)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_MEASUREMENT)) + null + } + tlvReader.exitContainer() return ElectricalPowerMeasurementClusterHarmonicMeasurementStruct(order, measurement) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalPowerMeasurementClusterMeasurementAccuracyRangeStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalPowerMeasurementClusterMeasurementAccuracyRangeStruct.kt index b6c08c0fdbab38..7cbe39cec83fae 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalPowerMeasurementClusterMeasurementAccuracyRangeStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalPowerMeasurementClusterMeasurementAccuracyRangeStruct.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -31,7 +32,7 @@ class ElectricalPowerMeasurementClusterMeasurementAccuracyRangeStruct( val percentTypical: Optional, val fixedMax: Optional, val fixedMin: Optional, - val fixedTypical: Optional, + val fixedTypical: Optional ) { override fun toString(): String = buildString { append("ElectricalPowerMeasurementClusterMeasurementAccuracyRangeStruct {\n") @@ -89,62 +90,44 @@ class ElectricalPowerMeasurementClusterMeasurementAccuracyRangeStruct( private const val TAG_FIXED_MIN = 6 private const val TAG_FIXED_TYPICAL = 7 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): ElectricalPowerMeasurementClusterMeasurementAccuracyRangeStruct { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ElectricalPowerMeasurementClusterMeasurementAccuracyRangeStruct { tlvReader.enterStructure(tlvTag) val rangeMin = tlvReader.getLong(ContextSpecificTag(TAG_RANGE_MIN)) val rangeMax = tlvReader.getLong(ContextSpecificTag(TAG_RANGE_MAX)) - val percentMax = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_PERCENT_MAX))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_PERCENT_MAX))) - } else { - Optional.empty() - } - val percentMin = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_PERCENT_MIN))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_PERCENT_MIN))) - } else { - Optional.empty() - } - val percentTypical = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_PERCENT_TYPICAL))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_PERCENT_TYPICAL))) - } else { - Optional.empty() - } - val fixedMax = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_FIXED_MAX))) { - Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_FIXED_MAX))) - } else { - Optional.empty() - } - val fixedMin = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_FIXED_MIN))) { - Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_FIXED_MIN))) - } else { - Optional.empty() - } - val fixedTypical = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_FIXED_TYPICAL))) { - Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_FIXED_TYPICAL))) - } else { - Optional.empty() - } - + val percentMax = if (tlvReader.isNextTag(ContextSpecificTag(TAG_PERCENT_MAX))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_PERCENT_MAX))) + } else { + Optional.empty() + } + val percentMin = if (tlvReader.isNextTag(ContextSpecificTag(TAG_PERCENT_MIN))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_PERCENT_MIN))) + } else { + Optional.empty() + } + val percentTypical = if (tlvReader.isNextTag(ContextSpecificTag(TAG_PERCENT_TYPICAL))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_PERCENT_TYPICAL))) + } else { + Optional.empty() + } + val fixedMax = if (tlvReader.isNextTag(ContextSpecificTag(TAG_FIXED_MAX))) { + Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_FIXED_MAX))) + } else { + Optional.empty() + } + val fixedMin = if (tlvReader.isNextTag(ContextSpecificTag(TAG_FIXED_MIN))) { + Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_FIXED_MIN))) + } else { + Optional.empty() + } + val fixedTypical = if (tlvReader.isNextTag(ContextSpecificTag(TAG_FIXED_TYPICAL))) { + Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_FIXED_TYPICAL))) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return ElectricalPowerMeasurementClusterMeasurementAccuracyRangeStruct( - rangeMin, - rangeMax, - percentMax, - percentMin, - percentTypical, - fixedMax, - fixedMin, - fixedTypical, - ) + return ElectricalPowerMeasurementClusterMeasurementAccuracyRangeStruct(rangeMin, rangeMax, percentMax, percentMin, percentTypical, fixedMax, fixedMin, fixedTypical) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalPowerMeasurementClusterMeasurementAccuracyStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalPowerMeasurementClusterMeasurementAccuracyStruct.kt index a646766ca7d6a5..63fa1a24a39a54 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalPowerMeasurementClusterMeasurementAccuracyStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalPowerMeasurementClusterMeasurementAccuracyStruct.kt @@ -16,6 +16,7 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -28,7 +29,7 @@ class ElectricalPowerMeasurementClusterMeasurementAccuracyStruct( val measured: Boolean, val minMeasuredValue: Long, val maxMeasuredValue: Long, - val accuracyRanges: List, + val accuracyRanges: List ) { override fun toString(): String = buildString { append("ElectricalPowerMeasurementClusterMeasurementAccuracyStruct {\n") @@ -63,38 +64,23 @@ class ElectricalPowerMeasurementClusterMeasurementAccuracyStruct( private const val TAG_MAX_MEASURED_VALUE = 3 private const val TAG_ACCURACY_RANGES = 4 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): ElectricalPowerMeasurementClusterMeasurementAccuracyStruct { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ElectricalPowerMeasurementClusterMeasurementAccuracyStruct { tlvReader.enterStructure(tlvTag) 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)) - val accuracyRanges = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_ACCURACY_RANGES)) - while (!tlvReader.isEndOfContainer()) { - add( - ElectricalPowerMeasurementClusterMeasurementAccuracyRangeStruct.fromTlv( - AnonymousTag, - tlvReader, - ) - ) - } - tlvReader.exitContainer() - } - + val accuracyRanges = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_ACCURACY_RANGES)) + while(!tlvReader.isEndOfContainer()) { + add(ElectricalPowerMeasurementClusterMeasurementAccuracyRangeStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + tlvReader.exitContainer() - return ElectricalPowerMeasurementClusterMeasurementAccuracyStruct( - measurementType, - measured, - minMeasuredValue, - maxMeasuredValue, - accuracyRanges, - ) + return ElectricalPowerMeasurementClusterMeasurementAccuracyStruct(measurementType, measured, minMeasuredValue, maxMeasuredValue, accuracyRanges) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalPowerMeasurementClusterMeasurementRangeStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalPowerMeasurementClusterMeasurementRangeStruct.kt index eabd12a80a1358..e612421d19d891 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalPowerMeasurementClusterMeasurementRangeStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalPowerMeasurementClusterMeasurementRangeStruct.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -34,7 +35,7 @@ class ElectricalPowerMeasurementClusterMeasurementRangeStruct( val startSystime: Optional, val endSystime: Optional, val minSystime: Optional, - val maxSystime: Optional, + val maxSystime: Optional ) { override fun toString(): String = buildString { append("ElectricalPowerMeasurementClusterMeasurementRangeStruct {\n") @@ -107,78 +108,55 @@ class ElectricalPowerMeasurementClusterMeasurementRangeStruct( private const val TAG_MIN_SYSTIME = 9 private const val TAG_MAX_SYSTIME = 10 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): ElectricalPowerMeasurementClusterMeasurementRangeStruct { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ElectricalPowerMeasurementClusterMeasurementRangeStruct { tlvReader.enterStructure(tlvTag) val measurementType = tlvReader.getUShort(ContextSpecificTag(TAG_MEASUREMENT_TYPE)) val min = tlvReader.getLong(ContextSpecificTag(TAG_MIN)) val max = tlvReader.getLong(ContextSpecificTag(TAG_MAX)) - val startTimestamp = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_START_TIMESTAMP))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_START_TIMESTAMP))) - } else { - Optional.empty() - } - val endTimestamp = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_END_TIMESTAMP))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_END_TIMESTAMP))) - } else { - Optional.empty() - } - val minTimestamp = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_MIN_TIMESTAMP))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_MIN_TIMESTAMP))) - } else { - Optional.empty() - } - val maxTimestamp = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_MAX_TIMESTAMP))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_MAX_TIMESTAMP))) - } else { - Optional.empty() - } - val startSystime = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_START_SYSTIME))) { - Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_START_SYSTIME))) - } else { - Optional.empty() - } - val endSystime = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_END_SYSTIME))) { - Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_END_SYSTIME))) - } else { - Optional.empty() - } - val minSystime = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_MIN_SYSTIME))) { - Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_MIN_SYSTIME))) - } else { - Optional.empty() - } - val maxSystime = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_MAX_SYSTIME))) { - Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_MAX_SYSTIME))) - } else { - Optional.empty() - } - + val startTimestamp = if (tlvReader.isNextTag(ContextSpecificTag(TAG_START_TIMESTAMP))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_START_TIMESTAMP))) + } else { + Optional.empty() + } + val endTimestamp = if (tlvReader.isNextTag(ContextSpecificTag(TAG_END_TIMESTAMP))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_END_TIMESTAMP))) + } else { + Optional.empty() + } + val minTimestamp = if (tlvReader.isNextTag(ContextSpecificTag(TAG_MIN_TIMESTAMP))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_MIN_TIMESTAMP))) + } else { + Optional.empty() + } + val maxTimestamp = if (tlvReader.isNextTag(ContextSpecificTag(TAG_MAX_TIMESTAMP))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_MAX_TIMESTAMP))) + } else { + Optional.empty() + } + val startSystime = if (tlvReader.isNextTag(ContextSpecificTag(TAG_START_SYSTIME))) { + Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_START_SYSTIME))) + } else { + Optional.empty() + } + val endSystime = if (tlvReader.isNextTag(ContextSpecificTag(TAG_END_SYSTIME))) { + Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_END_SYSTIME))) + } else { + Optional.empty() + } + val minSystime = if (tlvReader.isNextTag(ContextSpecificTag(TAG_MIN_SYSTIME))) { + Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_MIN_SYSTIME))) + } else { + Optional.empty() + } + val maxSystime = if (tlvReader.isNextTag(ContextSpecificTag(TAG_MAX_SYSTIME))) { + Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_MAX_SYSTIME))) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return ElectricalPowerMeasurementClusterMeasurementRangeStruct( - measurementType, - min, - max, - startTimestamp, - endTimestamp, - minTimestamp, - maxTimestamp, - startSystime, - endSystime, - minSystime, - maxSystime, - ) + return ElectricalPowerMeasurementClusterMeasurementRangeStruct(measurementType, min, max, startTimestamp, endTimestamp, minTimestamp, maxTimestamp, startSystime, endSystime, minSystime, maxSystime) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/EnergyEvseClusterChargingTargetScheduleStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/EnergyEvseClusterChargingTargetScheduleStruct.kt index a293094e84b288..3ed256441cd2ff 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/EnergyEvseClusterChargingTargetScheduleStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/EnergyEvseClusterChargingTargetScheduleStruct.kt @@ -16,6 +16,7 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -25,7 +26,7 @@ import matter.tlv.TlvWriter class EnergyEvseClusterChargingTargetScheduleStruct( val dayOfWeekForSequence: UByte, - val chargingTargets: List, + val chargingTargets: List ) { override fun toString(): String = buildString { append("EnergyEvseClusterChargingTargetScheduleStruct {\n") @@ -53,17 +54,15 @@ class EnergyEvseClusterChargingTargetScheduleStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): EnergyEvseClusterChargingTargetScheduleStruct { tlvReader.enterStructure(tlvTag) - val dayOfWeekForSequence = - tlvReader.getUByte(ContextSpecificTag(TAG_DAY_OF_WEEK_FOR_SEQUENCE)) - val chargingTargets = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_CHARGING_TARGETS)) - while (!tlvReader.isEndOfContainer()) { - add(EnergyEvseClusterChargingTargetStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - + val dayOfWeekForSequence = tlvReader.getUByte(ContextSpecificTag(TAG_DAY_OF_WEEK_FOR_SEQUENCE)) + val chargingTargets = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_CHARGING_TARGETS)) + while(!tlvReader.isEndOfContainer()) { + add(EnergyEvseClusterChargingTargetStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + tlvReader.exitContainer() return EnergyEvseClusterChargingTargetScheduleStruct(dayOfWeekForSequence, chargingTargets) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/EnergyEvseClusterChargingTargetStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/EnergyEvseClusterChargingTargetStruct.kt index 8a18bbab605267..72826868a15260 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/EnergyEvseClusterChargingTargetStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/EnergyEvseClusterChargingTargetStruct.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +27,7 @@ import matter.tlv.TlvWriter class EnergyEvseClusterChargingTargetStruct( val targetTimeMinutesPastMidnight: UShort, val targetSoC: Optional, - val addedEnergy: Optional, + val addedEnergy: Optional ) { override fun toString(): String = buildString { append("EnergyEvseClusterChargingTargetStruct {\n") @@ -59,28 +60,21 @@ class EnergyEvseClusterChargingTargetStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): EnergyEvseClusterChargingTargetStruct { tlvReader.enterStructure(tlvTag) - val targetTimeMinutesPastMidnight = - tlvReader.getUShort(ContextSpecificTag(TAG_TARGET_TIME_MINUTES_PAST_MIDNIGHT)) - val targetSoC = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_TARGET_SO_C))) { - Optional.of(tlvReader.getUByte(ContextSpecificTag(TAG_TARGET_SO_C))) - } else { - Optional.empty() - } - val addedEnergy = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_ADDED_ENERGY))) { - Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_ADDED_ENERGY))) - } else { - Optional.empty() - } - + val targetTimeMinutesPastMidnight = tlvReader.getUShort(ContextSpecificTag(TAG_TARGET_TIME_MINUTES_PAST_MIDNIGHT)) + val targetSoC = if (tlvReader.isNextTag(ContextSpecificTag(TAG_TARGET_SO_C))) { + Optional.of(tlvReader.getUByte(ContextSpecificTag(TAG_TARGET_SO_C))) + } else { + Optional.empty() + } + val addedEnergy = if (tlvReader.isNextTag(ContextSpecificTag(TAG_ADDED_ENERGY))) { + Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_ADDED_ENERGY))) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return EnergyEvseClusterChargingTargetStruct( - targetTimeMinutesPastMidnight, - targetSoC, - addedEnergy, - ) + return EnergyEvseClusterChargingTargetStruct(targetTimeMinutesPastMidnight, targetSoC, addedEnergy) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/EnergyEvseModeClusterModeOptionStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/EnergyEvseModeClusterModeOptionStruct.kt index ae35cef781c18b..19ee22542f25a9 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/EnergyEvseModeClusterModeOptionStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/EnergyEvseModeClusterModeOptionStruct.kt @@ -16,6 +16,7 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -26,7 +27,7 @@ import matter.tlv.TlvWriter class EnergyEvseModeClusterModeOptionStruct( val label: String, val mode: UByte, - val modeTags: List, + val modeTags: List ) { override fun toString(): String = buildString { append("EnergyEvseModeClusterModeOptionStruct {\n") @@ -59,15 +60,14 @@ class EnergyEvseModeClusterModeOptionStruct( tlvReader.enterStructure(tlvTag) val label = tlvReader.getString(ContextSpecificTag(TAG_LABEL)) val mode = tlvReader.getUByte(ContextSpecificTag(TAG_MODE)) - val modeTags = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_MODE_TAGS)) - while (!tlvReader.isEndOfContainer()) { - add(EnergyEvseModeClusterModeTagStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - + val modeTags = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_MODE_TAGS)) + while(!tlvReader.isEndOfContainer()) { + add(EnergyEvseModeClusterModeTagStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + tlvReader.exitContainer() return EnergyEvseModeClusterModeOptionStruct(label, mode, modeTags) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/EnergyEvseModeClusterModeTagStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/EnergyEvseModeClusterModeTagStruct.kt index e4a9a48c9244eb..c5c55fd1efc89e 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/EnergyEvseModeClusterModeTagStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/EnergyEvseModeClusterModeTagStruct.kt @@ -18,12 +18,16 @@ package matter.controller.cluster.structs import java.util.Optional 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 EnergyEvseModeClusterModeTagStruct(val mfgCode: Optional, val value: UShort) { +class EnergyEvseModeClusterModeTagStruct( + val mfgCode: Optional, + val value: UShort +) { override fun toString(): String = buildString { append("EnergyEvseModeClusterModeTagStruct {\n") append("\tmfgCode : $mfgCode\n") @@ -49,14 +53,13 @@ class EnergyEvseModeClusterModeTagStruct(val mfgCode: Optional, val valu fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): EnergyEvseModeClusterModeTagStruct { tlvReader.enterStructure(tlvTag) - val mfgCode = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_MFG_CODE))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_MFG_CODE))) - } else { - Optional.empty() - } + val mfgCode = if (tlvReader.isNextTag(ContextSpecificTag(TAG_MFG_CODE))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_MFG_CODE))) + } else { + Optional.empty() + } val value = tlvReader.getUShort(ContextSpecificTag(TAG_VALUE)) - + tlvReader.exitContainer() return EnergyEvseModeClusterModeTagStruct(mfgCode, value) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/EnergyPreferenceClusterBalanceStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/EnergyPreferenceClusterBalanceStruct.kt index 29980664d4cbec..80e4c2b06d9cad 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/EnergyPreferenceClusterBalanceStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/EnergyPreferenceClusterBalanceStruct.kt @@ -18,12 +18,16 @@ package matter.controller.cluster.structs import java.util.Optional 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 EnergyPreferenceClusterBalanceStruct(val step: UByte, val label: Optional) { +class EnergyPreferenceClusterBalanceStruct( + val step: UByte, + val label: Optional +) { override fun toString(): String = buildString { append("EnergyPreferenceClusterBalanceStruct {\n") append("\tstep : $step\n") @@ -50,13 +54,12 @@ class EnergyPreferenceClusterBalanceStruct(val step: UByte, val label: Optional< fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): EnergyPreferenceClusterBalanceStruct { tlvReader.enterStructure(tlvTag) val step = tlvReader.getUByte(ContextSpecificTag(TAG_STEP)) - val label = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_LABEL))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_LABEL))) - } else { - Optional.empty() - } - + val label = if (tlvReader.isNextTag(ContextSpecificTag(TAG_LABEL))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_LABEL))) + } else { + Optional.empty() + } + tlvReader.exitContainer() return EnergyPreferenceClusterBalanceStruct(step, label) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/FixedLabelClusterLabelStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/FixedLabelClusterLabelStruct.kt index b5181c44417b6d..2465dd492ace99 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/FixedLabelClusterLabelStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/FixedLabelClusterLabelStruct.kt @@ -16,13 +16,18 @@ */ package matter.controller.cluster.structs +import java.util.Optional 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 FixedLabelClusterLabelStruct(val label: String, val value: String) { +class FixedLabelClusterLabelStruct( + val label: String, + val value: String +) { override fun toString(): String = buildString { append("FixedLabelClusterLabelStruct {\n") append("\tlabel : $label\n") @@ -47,7 +52,7 @@ class FixedLabelClusterLabelStruct(val label: String, val value: String) { tlvReader.enterStructure(tlvTag) val label = tlvReader.getString(ContextSpecificTag(TAG_LABEL)) val value = tlvReader.getString(ContextSpecificTag(TAG_VALUE)) - + tlvReader.exitContainer() return FixedLabelClusterLabelStruct(label, value) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/GeneralCommissioningClusterBasicCommissioningInfo.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/GeneralCommissioningClusterBasicCommissioningInfo.kt index 0ae15dd9ae01fe..b2d6b7e97638e6 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/GeneralCommissioningClusterBasicCommissioningInfo.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/GeneralCommissioningClusterBasicCommissioningInfo.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -24,7 +26,7 @@ import matter.tlv.TlvWriter class GeneralCommissioningClusterBasicCommissioningInfo( val failSafeExpiryLengthSeconds: UShort, - val maxCumulativeFailsafeSeconds: UShort, + val maxCumulativeFailsafeSeconds: UShort ) { override fun toString(): String = buildString { append("GeneralCommissioningClusterBasicCommissioningInfo {\n") @@ -46,22 +48,14 @@ class GeneralCommissioningClusterBasicCommissioningInfo( private const val TAG_FAIL_SAFE_EXPIRY_LENGTH_SECONDS = 0 private const val TAG_MAX_CUMULATIVE_FAILSAFE_SECONDS = 1 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): GeneralCommissioningClusterBasicCommissioningInfo { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): GeneralCommissioningClusterBasicCommissioningInfo { tlvReader.enterStructure(tlvTag) - val failSafeExpiryLengthSeconds = - tlvReader.getUShort(ContextSpecificTag(TAG_FAIL_SAFE_EXPIRY_LENGTH_SECONDS)) - val maxCumulativeFailsafeSeconds = - tlvReader.getUShort(ContextSpecificTag(TAG_MAX_CUMULATIVE_FAILSAFE_SECONDS)) - + val failSafeExpiryLengthSeconds = tlvReader.getUShort(ContextSpecificTag(TAG_FAIL_SAFE_EXPIRY_LENGTH_SECONDS)) + val maxCumulativeFailsafeSeconds = tlvReader.getUShort(ContextSpecificTag(TAG_MAX_CUMULATIVE_FAILSAFE_SECONDS)) + tlvReader.exitContainer() - return GeneralCommissioningClusterBasicCommissioningInfo( - failSafeExpiryLengthSeconds, - maxCumulativeFailsafeSeconds, - ) + return GeneralCommissioningClusterBasicCommissioningInfo(failSafeExpiryLengthSeconds, maxCumulativeFailsafeSeconds) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/GeneralDiagnosticsClusterNetworkInterface.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/GeneralDiagnosticsClusterNetworkInterface.kt index b39378349cc934..61f8691c5f053a 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/GeneralDiagnosticsClusterNetworkInterface.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/GeneralDiagnosticsClusterNetworkInterface.kt @@ -16,6 +16,7 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -31,7 +32,7 @@ class GeneralDiagnosticsClusterNetworkInterface( val hardwareAddress: ByteArray, val IPv4Addresses: List, val IPv6Addresses: List, - val type: UByte, + val type: UByte ) { override fun toString(): String = buildString { append("GeneralDiagnosticsClusterNetworkInterface {\n") @@ -52,18 +53,12 @@ class GeneralDiagnosticsClusterNetworkInterface( put(ContextSpecificTag(TAG_NAME), name) put(ContextSpecificTag(TAG_IS_OPERATIONAL), isOperational) if (offPremiseServicesReachableIPv4 != null) { - put( - ContextSpecificTag(TAG_OFF_PREMISE_SERVICES_REACHABLE_I_PV4), - offPremiseServicesReachableIPv4, - ) + put(ContextSpecificTag(TAG_OFF_PREMISE_SERVICES_REACHABLE_I_PV4), offPremiseServicesReachableIPv4) } else { putNull(ContextSpecificTag(TAG_OFF_PREMISE_SERVICES_REACHABLE_I_PV4)) } if (offPremiseServicesReachableIPv6 != null) { - put( - ContextSpecificTag(TAG_OFF_PREMISE_SERVICES_REACHABLE_I_PV6), - offPremiseServicesReachableIPv6, - ) + put(ContextSpecificTag(TAG_OFF_PREMISE_SERVICES_REACHABLE_I_PV6), offPremiseServicesReachableIPv6) } else { putNull(ContextSpecificTag(TAG_OFF_PREMISE_SERVICES_REACHABLE_I_PV6)) } @@ -97,51 +92,38 @@ class GeneralDiagnosticsClusterNetworkInterface( tlvReader.enterStructure(tlvTag) val name = tlvReader.getString(ContextSpecificTag(TAG_NAME)) val isOperational = tlvReader.getBoolean(ContextSpecificTag(TAG_IS_OPERATIONAL)) - val offPremiseServicesReachableIPv4 = - if (!tlvReader.isNull()) { - tlvReader.getBoolean(ContextSpecificTag(TAG_OFF_PREMISE_SERVICES_REACHABLE_I_PV4)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_OFF_PREMISE_SERVICES_REACHABLE_I_PV4)) - null - } - val offPremiseServicesReachableIPv6 = - if (!tlvReader.isNull()) { - tlvReader.getBoolean(ContextSpecificTag(TAG_OFF_PREMISE_SERVICES_REACHABLE_I_PV6)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_OFF_PREMISE_SERVICES_REACHABLE_I_PV6)) - null - } + val offPremiseServicesReachableIPv4 = if (!tlvReader.isNull()) { + tlvReader.getBoolean(ContextSpecificTag(TAG_OFF_PREMISE_SERVICES_REACHABLE_I_PV4)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_OFF_PREMISE_SERVICES_REACHABLE_I_PV4)) + null + } + val offPremiseServicesReachableIPv6 = if (!tlvReader.isNull()) { + tlvReader.getBoolean(ContextSpecificTag(TAG_OFF_PREMISE_SERVICES_REACHABLE_I_PV6)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_OFF_PREMISE_SERVICES_REACHABLE_I_PV6)) + null + } val hardwareAddress = tlvReader.getByteArray(ContextSpecificTag(TAG_HARDWARE_ADDRESS)) - val IPv4Addresses = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_I_PV4_ADDRESSES)) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getByteArray(AnonymousTag)) - } - tlvReader.exitContainer() - } - val IPv6Addresses = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_I_PV6_ADDRESSES)) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getByteArray(AnonymousTag)) - } - tlvReader.exitContainer() - } + val IPv4Addresses = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_I_PV4_ADDRESSES)) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getByteArray(AnonymousTag)) + } + tlvReader.exitContainer() + } + val IPv6Addresses = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_I_PV6_ADDRESSES)) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getByteArray(AnonymousTag)) + } + tlvReader.exitContainer() + } val type = tlvReader.getUByte(ContextSpecificTag(TAG_TYPE)) - + tlvReader.exitContainer() - return GeneralDiagnosticsClusterNetworkInterface( - name, - isOperational, - offPremiseServicesReachableIPv4, - offPremiseServicesReachableIPv6, - hardwareAddress, - IPv4Addresses, - IPv6Addresses, - type, - ) + return GeneralDiagnosticsClusterNetworkInterface(name, isOperational, offPremiseServicesReachableIPv4, offPremiseServicesReachableIPv6, hardwareAddress, IPv4Addresses, IPv6Addresses, type) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/GroupKeyManagementClusterGroupInfoMapStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/GroupKeyManagementClusterGroupInfoMapStruct.kt index be8a3954bd0acb..ef8286072bfcfd 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/GroupKeyManagementClusterGroupInfoMapStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/GroupKeyManagementClusterGroupInfoMapStruct.kt @@ -28,7 +28,7 @@ class GroupKeyManagementClusterGroupInfoMapStruct( val groupId: UShort, val endpoints: List, val groupName: Optional, - val fabricIndex: UByte, + val fabricIndex: UByte ) { override fun toString(): String = buildString { append("GroupKeyManagementClusterGroupInfoMapStruct {\n") @@ -66,22 +66,20 @@ class GroupKeyManagementClusterGroupInfoMapStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): GroupKeyManagementClusterGroupInfoMapStruct { tlvReader.enterStructure(tlvTag) val groupId = tlvReader.getUShort(ContextSpecificTag(TAG_GROUP_ID)) - val endpoints = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_ENDPOINTS)) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getUShort(AnonymousTag)) - } - tlvReader.exitContainer() - } - val groupName = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_GROUP_NAME))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_GROUP_NAME))) - } else { - Optional.empty() - } + val endpoints = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_ENDPOINTS)) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUShort(AnonymousTag)) + } + tlvReader.exitContainer() + } + val groupName = if (tlvReader.isNextTag(ContextSpecificTag(TAG_GROUP_NAME))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_GROUP_NAME))) + } else { + Optional.empty() + } val fabricIndex = tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) - + tlvReader.exitContainer() return GroupKeyManagementClusterGroupInfoMapStruct(groupId, endpoints, groupName, fabricIndex) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/GroupKeyManagementClusterGroupKeyMapStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/GroupKeyManagementClusterGroupKeyMapStruct.kt index ad1823e569c56e..4c3fcea3b1e47b 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/GroupKeyManagementClusterGroupKeyMapStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/GroupKeyManagementClusterGroupKeyMapStruct.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -25,7 +27,7 @@ import matter.tlv.TlvWriter class GroupKeyManagementClusterGroupKeyMapStruct( val groupId: UShort, val groupKeySetID: UShort, - val fabricIndex: UByte, + val fabricIndex: UByte ) { override fun toString(): String = buildString { append("GroupKeyManagementClusterGroupKeyMapStruct {\n") @@ -55,7 +57,7 @@ class GroupKeyManagementClusterGroupKeyMapStruct( val groupId = tlvReader.getUShort(ContextSpecificTag(TAG_GROUP_ID)) val groupKeySetID = tlvReader.getUShort(ContextSpecificTag(TAG_GROUP_KEY_SET_ID)) val fabricIndex = tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) - + tlvReader.exitContainer() return GroupKeyManagementClusterGroupKeyMapStruct(groupId, groupKeySetID, fabricIndex) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/GroupKeyManagementClusterGroupKeySetStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/GroupKeyManagementClusterGroupKeySetStruct.kt index 1419d29377c27a..357e8e78682da0 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/GroupKeyManagementClusterGroupKeySetStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/GroupKeyManagementClusterGroupKeySetStruct.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -30,7 +32,7 @@ class GroupKeyManagementClusterGroupKeySetStruct( val epochKey1: ByteArray?, val epochStartTime1: ULong?, val epochKey2: ByteArray?, - val epochStartTime2: ULong?, + val epochStartTime2: ULong? ) { override fun toString(): String = buildString { append("GroupKeyManagementClusterGroupKeySetStruct {\n") @@ -97,63 +99,47 @@ class GroupKeyManagementClusterGroupKeySetStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): GroupKeyManagementClusterGroupKeySetStruct { tlvReader.enterStructure(tlvTag) val groupKeySetID = tlvReader.getUShort(ContextSpecificTag(TAG_GROUP_KEY_SET_ID)) - val groupKeySecurityPolicy = - tlvReader.getUByte(ContextSpecificTag(TAG_GROUP_KEY_SECURITY_POLICY)) - val epochKey0 = - if (!tlvReader.isNull()) { - tlvReader.getByteArray(ContextSpecificTag(TAG_EPOCH_KEY0)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_EPOCH_KEY0)) - null - } - val epochStartTime0 = - if (!tlvReader.isNull()) { - tlvReader.getULong(ContextSpecificTag(TAG_EPOCH_START_TIME0)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_EPOCH_START_TIME0)) - null - } - val epochKey1 = - if (!tlvReader.isNull()) { - tlvReader.getByteArray(ContextSpecificTag(TAG_EPOCH_KEY1)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_EPOCH_KEY1)) - null - } - val epochStartTime1 = - if (!tlvReader.isNull()) { - tlvReader.getULong(ContextSpecificTag(TAG_EPOCH_START_TIME1)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_EPOCH_START_TIME1)) - null - } - val epochKey2 = - if (!tlvReader.isNull()) { - tlvReader.getByteArray(ContextSpecificTag(TAG_EPOCH_KEY2)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_EPOCH_KEY2)) - null - } - val epochStartTime2 = - if (!tlvReader.isNull()) { - tlvReader.getULong(ContextSpecificTag(TAG_EPOCH_START_TIME2)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_EPOCH_START_TIME2)) - null - } - + val groupKeySecurityPolicy = tlvReader.getUByte(ContextSpecificTag(TAG_GROUP_KEY_SECURITY_POLICY)) + val epochKey0 = if (!tlvReader.isNull()) { + tlvReader.getByteArray(ContextSpecificTag(TAG_EPOCH_KEY0)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_EPOCH_KEY0)) + null + } + val epochStartTime0 = if (!tlvReader.isNull()) { + tlvReader.getULong(ContextSpecificTag(TAG_EPOCH_START_TIME0)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_EPOCH_START_TIME0)) + null + } + val epochKey1 = if (!tlvReader.isNull()) { + tlvReader.getByteArray(ContextSpecificTag(TAG_EPOCH_KEY1)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_EPOCH_KEY1)) + null + } + val epochStartTime1 = if (!tlvReader.isNull()) { + tlvReader.getULong(ContextSpecificTag(TAG_EPOCH_START_TIME1)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_EPOCH_START_TIME1)) + null + } + val epochKey2 = if (!tlvReader.isNull()) { + tlvReader.getByteArray(ContextSpecificTag(TAG_EPOCH_KEY2)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_EPOCH_KEY2)) + null + } + val epochStartTime2 = if (!tlvReader.isNull()) { + tlvReader.getULong(ContextSpecificTag(TAG_EPOCH_START_TIME2)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_EPOCH_START_TIME2)) + null + } + tlvReader.exitContainer() - return GroupKeyManagementClusterGroupKeySetStruct( - groupKeySetID, - groupKeySecurityPolicy, - epochKey0, - epochStartTime0, - epochKey1, - epochStartTime1, - epochKey2, - epochStartTime2, - ) + return GroupKeyManagementClusterGroupKeySetStruct(groupKeySetID, groupKeySecurityPolicy, epochKey0, epochStartTime0, epochKey1, epochStartTime1, epochKey2, epochStartTime2) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/HepaFilterMonitoringClusterReplacementProductStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/HepaFilterMonitoringClusterReplacementProductStruct.kt index 8d8d869afa3e55..c838f5450b4c90 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/HepaFilterMonitoringClusterReplacementProductStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/HepaFilterMonitoringClusterReplacementProductStruct.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -24,7 +26,7 @@ import matter.tlv.TlvWriter class HepaFilterMonitoringClusterReplacementProductStruct( val productIdentifierType: UByte, - val productIdentifierValue: String, + val productIdentifierValue: String ) { override fun toString(): String = buildString { append("HepaFilterMonitoringClusterReplacementProductStruct {\n") @@ -46,22 +48,14 @@ class HepaFilterMonitoringClusterReplacementProductStruct( private const val TAG_PRODUCT_IDENTIFIER_TYPE = 0 private const val TAG_PRODUCT_IDENTIFIER_VALUE = 1 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): HepaFilterMonitoringClusterReplacementProductStruct { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): HepaFilterMonitoringClusterReplacementProductStruct { tlvReader.enterStructure(tlvTag) - val productIdentifierType = - tlvReader.getUByte(ContextSpecificTag(TAG_PRODUCT_IDENTIFIER_TYPE)) - val productIdentifierValue = - tlvReader.getString(ContextSpecificTag(TAG_PRODUCT_IDENTIFIER_VALUE)) - + val productIdentifierType = tlvReader.getUByte(ContextSpecificTag(TAG_PRODUCT_IDENTIFIER_TYPE)) + val productIdentifierValue = tlvReader.getString(ContextSpecificTag(TAG_PRODUCT_IDENTIFIER_VALUE)) + tlvReader.exitContainer() - return HepaFilterMonitoringClusterReplacementProductStruct( - productIdentifierType, - productIdentifierValue, - ) + return HepaFilterMonitoringClusterReplacementProductStruct(productIdentifierType, productIdentifierValue) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/IcdManagementClusterMonitoringRegistrationStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/IcdManagementClusterMonitoringRegistrationStruct.kt index 478ce9f25c4cd6..d88acef6d7dd5c 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/IcdManagementClusterMonitoringRegistrationStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/IcdManagementClusterMonitoringRegistrationStruct.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +28,7 @@ class IcdManagementClusterMonitoringRegistrationStruct( val checkInNodeID: ULong, val monitoredSubject: ULong, val clientType: UByte, - val fabricIndex: UByte, + val fabricIndex: UByte ) { override fun toString(): String = buildString { append("IcdManagementClusterMonitoringRegistrationStruct {\n") @@ -54,24 +56,16 @@ class IcdManagementClusterMonitoringRegistrationStruct( private const val TAG_CLIENT_TYPE = 4 private const val TAG_FABRIC_INDEX = 254 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): IcdManagementClusterMonitoringRegistrationStruct { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): IcdManagementClusterMonitoringRegistrationStruct { tlvReader.enterStructure(tlvTag) val checkInNodeID = tlvReader.getULong(ContextSpecificTag(TAG_CHECK_IN_NODE_ID)) val monitoredSubject = tlvReader.getULong(ContextSpecificTag(TAG_MONITORED_SUBJECT)) val clientType = tlvReader.getUByte(ContextSpecificTag(TAG_CLIENT_TYPE)) val fabricIndex = tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) - + tlvReader.exitContainer() - return IcdManagementClusterMonitoringRegistrationStruct( - checkInNodeID, - monitoredSubject, - clientType, - fabricIndex, - ) + return IcdManagementClusterMonitoringRegistrationStruct(checkInNodeID, monitoredSubject, clientType, fabricIndex) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/LaundryWasherModeClusterModeOptionStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/LaundryWasherModeClusterModeOptionStruct.kt index 5d738a4020bda5..869fc790e2c371 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/LaundryWasherModeClusterModeOptionStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/LaundryWasherModeClusterModeOptionStruct.kt @@ -16,6 +16,7 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -26,7 +27,7 @@ import matter.tlv.TlvWriter class LaundryWasherModeClusterModeOptionStruct( val label: String, val mode: UByte, - val modeTags: List, + val modeTags: List ) { override fun toString(): String = buildString { append("LaundryWasherModeClusterModeOptionStruct {\n") @@ -59,15 +60,14 @@ class LaundryWasherModeClusterModeOptionStruct( tlvReader.enterStructure(tlvTag) val label = tlvReader.getString(ContextSpecificTag(TAG_LABEL)) val mode = tlvReader.getUByte(ContextSpecificTag(TAG_MODE)) - val modeTags = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_MODE_TAGS)) - while (!tlvReader.isEndOfContainer()) { - add(LaundryWasherModeClusterModeTagStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - + val modeTags = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_MODE_TAGS)) + while(!tlvReader.isEndOfContainer()) { + add(LaundryWasherModeClusterModeTagStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + tlvReader.exitContainer() return LaundryWasherModeClusterModeOptionStruct(label, mode, modeTags) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/LaundryWasherModeClusterModeTagStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/LaundryWasherModeClusterModeTagStruct.kt index a12e2840ead4ab..1b9aaf99f45c57 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/LaundryWasherModeClusterModeTagStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/LaundryWasherModeClusterModeTagStruct.kt @@ -18,12 +18,16 @@ package matter.controller.cluster.structs import java.util.Optional 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 LaundryWasherModeClusterModeTagStruct(val mfgCode: Optional, val value: UShort) { +class LaundryWasherModeClusterModeTagStruct( + val mfgCode: Optional, + val value: UShort +) { override fun toString(): String = buildString { append("LaundryWasherModeClusterModeTagStruct {\n") append("\tmfgCode : $mfgCode\n") @@ -49,14 +53,13 @@ class LaundryWasherModeClusterModeTagStruct(val mfgCode: Optional, val v fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): LaundryWasherModeClusterModeTagStruct { tlvReader.enterStructure(tlvTag) - val mfgCode = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_MFG_CODE))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_MFG_CODE))) - } else { - Optional.empty() - } + val mfgCode = if (tlvReader.isNextTag(ContextSpecificTag(TAG_MFG_CODE))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_MFG_CODE))) + } else { + Optional.empty() + } val value = tlvReader.getUShort(ContextSpecificTag(TAG_VALUE)) - + tlvReader.exitContainer() return LaundryWasherModeClusterModeTagStruct(mfgCode, value) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/MediaInputClusterInputInfoStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/MediaInputClusterInputInfoStruct.kt index 129dee7510d0b3..13d46092d3725f 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/MediaInputClusterInputInfoStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/MediaInputClusterInputInfoStruct.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +28,7 @@ class MediaInputClusterInputInfoStruct( val index: UByte, val inputType: UByte, val name: String, - val description: String, + val description: String ) { override fun toString(): String = buildString { append("MediaInputClusterInputInfoStruct {\n") @@ -60,7 +62,7 @@ class MediaInputClusterInputInfoStruct( val inputType = tlvReader.getUByte(ContextSpecificTag(TAG_INPUT_TYPE)) val name = tlvReader.getString(ContextSpecificTag(TAG_NAME)) val description = tlvReader.getString(ContextSpecificTag(TAG_DESCRIPTION)) - + tlvReader.exitContainer() return MediaInputClusterInputInfoStruct(index, inputType, name, description) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/MediaPlaybackClusterPlaybackPositionStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/MediaPlaybackClusterPlaybackPositionStruct.kt index 518da6b739efc8..6df4407304fc0d 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/MediaPlaybackClusterPlaybackPositionStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/MediaPlaybackClusterPlaybackPositionStruct.kt @@ -16,13 +16,18 @@ */ package matter.controller.cluster.structs +import java.util.Optional 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 MediaPlaybackClusterPlaybackPositionStruct(val updatedAt: ULong, val position: ULong?) { +class MediaPlaybackClusterPlaybackPositionStruct( + val updatedAt: ULong, + val position: ULong? +) { override fun toString(): String = buildString { append("MediaPlaybackClusterPlaybackPositionStruct {\n") append("\tupdatedAt : $updatedAt\n") @@ -50,14 +55,13 @@ class MediaPlaybackClusterPlaybackPositionStruct(val updatedAt: ULong, val posit fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): MediaPlaybackClusterPlaybackPositionStruct { tlvReader.enterStructure(tlvTag) val updatedAt = tlvReader.getULong(ContextSpecificTag(TAG_UPDATED_AT)) - val position = - if (!tlvReader.isNull()) { - tlvReader.getULong(ContextSpecificTag(TAG_POSITION)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_POSITION)) - null - } - + val position = if (!tlvReader.isNull()) { + tlvReader.getULong(ContextSpecificTag(TAG_POSITION)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_POSITION)) + null + } + tlvReader.exitContainer() return MediaPlaybackClusterPlaybackPositionStruct(updatedAt, position) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/MediaPlaybackClusterTrackAttributesStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/MediaPlaybackClusterTrackAttributesStruct.kt index 15ee4ec93fbc54..b82ec49c17f735 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/MediaPlaybackClusterTrackAttributesStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/MediaPlaybackClusterTrackAttributesStruct.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -25,7 +26,7 @@ import matter.tlv.TlvWriter class MediaPlaybackClusterTrackAttributesStruct( val languageCode: String, - val displayName: Optional?, + val displayName: Optional? ) { override fun toString(): String = buildString { append("MediaPlaybackClusterTrackAttributesStruct {\n") @@ -40,9 +41,9 @@ class MediaPlaybackClusterTrackAttributesStruct( put(ContextSpecificTag(TAG_LANGUAGE_CODE), languageCode) if (displayName != null) { if (displayName.isPresent) { - val optdisplayName = displayName.get() - put(ContextSpecificTag(TAG_DISPLAY_NAME), optdisplayName) - } + val optdisplayName = displayName.get() + put(ContextSpecificTag(TAG_DISPLAY_NAME), optdisplayName) + } } else { putNull(ContextSpecificTag(TAG_DISPLAY_NAME)) } @@ -57,18 +58,17 @@ class MediaPlaybackClusterTrackAttributesStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): MediaPlaybackClusterTrackAttributesStruct { tlvReader.enterStructure(tlvTag) val languageCode = tlvReader.getString(ContextSpecificTag(TAG_LANGUAGE_CODE)) - val displayName = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_DISPLAY_NAME))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_DISPLAY_NAME))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_DISPLAY_NAME)) - null - } - + val displayName = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_DISPLAY_NAME))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_DISPLAY_NAME))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_DISPLAY_NAME)) + null + } + tlvReader.exitContainer() return MediaPlaybackClusterTrackAttributesStruct(languageCode, displayName) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/MediaPlaybackClusterTrackStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/MediaPlaybackClusterTrackStruct.kt index 53ef5178a0c06a..f4c43f16e2337f 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/MediaPlaybackClusterTrackStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/MediaPlaybackClusterTrackStruct.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -24,7 +26,7 @@ import matter.tlv.TlvWriter class MediaPlaybackClusterTrackStruct( val id: String, - val trackAttributes: MediaPlaybackClusterTrackAttributesStruct?, + val trackAttributes: MediaPlaybackClusterTrackAttributesStruct? ) { override fun toString(): String = buildString { append("MediaPlaybackClusterTrackStruct {\n") @@ -53,17 +55,13 @@ class MediaPlaybackClusterTrackStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): MediaPlaybackClusterTrackStruct { tlvReader.enterStructure(tlvTag) val id = tlvReader.getString(ContextSpecificTag(TAG_ID)) - val trackAttributes = - if (!tlvReader.isNull()) { - MediaPlaybackClusterTrackAttributesStruct.fromTlv( - ContextSpecificTag(TAG_TRACK_ATTRIBUTES), - tlvReader, - ) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_TRACK_ATTRIBUTES)) - null - } - + val trackAttributes = if (!tlvReader.isNull()) { + MediaPlaybackClusterTrackAttributesStruct.fromTlv(ContextSpecificTag(TAG_TRACK_ATTRIBUTES), tlvReader) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_TRACK_ATTRIBUTES)) + null + } + tlvReader.exitContainer() return MediaPlaybackClusterTrackStruct(id, trackAttributes) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/MessagesClusterMessageResponseOptionStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/MessagesClusterMessageResponseOptionStruct.kt index 7240826c29fe10..3589a12c78c37f 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/MessagesClusterMessageResponseOptionStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/MessagesClusterMessageResponseOptionStruct.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -25,7 +26,7 @@ import matter.tlv.TlvWriter class MessagesClusterMessageResponseOptionStruct( val messageResponseID: Optional, - val label: Optional, + val label: Optional ) { override fun toString(): String = buildString { append("MessagesClusterMessageResponseOptionStruct {\n") @@ -55,19 +56,17 @@ class MessagesClusterMessageResponseOptionStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): MessagesClusterMessageResponseOptionStruct { tlvReader.enterStructure(tlvTag) - val messageResponseID = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_MESSAGE_RESPONSE_ID))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_MESSAGE_RESPONSE_ID))) - } else { - Optional.empty() - } - val label = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_LABEL))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_LABEL))) - } else { - Optional.empty() - } - + val messageResponseID = if (tlvReader.isNextTag(ContextSpecificTag(TAG_MESSAGE_RESPONSE_ID))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_MESSAGE_RESPONSE_ID))) + } else { + Optional.empty() + } + val label = if (tlvReader.isNextTag(ContextSpecificTag(TAG_LABEL))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_LABEL))) + } else { + Optional.empty() + } + tlvReader.exitContainer() return MessagesClusterMessageResponseOptionStruct(messageResponseID, label) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/MessagesClusterMessageStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/MessagesClusterMessageStruct.kt index ff033fa133550b..352e0f3a8a4840 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/MessagesClusterMessageStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/MessagesClusterMessageStruct.kt @@ -31,7 +31,7 @@ class MessagesClusterMessageStruct( val startTime: UInt?, val duration: ULong?, val messageText: String, - val responses: Optional>, + val responses: Optional> ) { override fun toString(): String = buildString { append("MessagesClusterMessageStruct {\n") @@ -65,10 +65,10 @@ class MessagesClusterMessageStruct( if (responses.isPresent) { val optresponses = responses.get() startArray(ContextSpecificTag(TAG_RESPONSES)) - for (item in optresponses.iterator()) { - item.toTlv(AnonymousTag, this) - } - endArray() + for (item in optresponses.iterator()) { + item.toTlv(AnonymousTag, this) + } + endArray() } endStructure() } @@ -88,47 +88,34 @@ class MessagesClusterMessageStruct( val messageID = tlvReader.getByteArray(ContextSpecificTag(TAG_MESSAGE_ID)) val priority = tlvReader.getUByte(ContextSpecificTag(TAG_PRIORITY)) val messageControl = tlvReader.getUByte(ContextSpecificTag(TAG_MESSAGE_CONTROL)) - val startTime = - if (!tlvReader.isNull()) { - tlvReader.getUInt(ContextSpecificTag(TAG_START_TIME)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_START_TIME)) - null - } - val duration = - if (!tlvReader.isNull()) { - tlvReader.getULong(ContextSpecificTag(TAG_DURATION)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_DURATION)) - null - } + val startTime = if (!tlvReader.isNull()) { + tlvReader.getUInt(ContextSpecificTag(TAG_START_TIME)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_START_TIME)) + null + } + val duration = if (!tlvReader.isNull()) { + tlvReader.getULong(ContextSpecificTag(TAG_DURATION)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_DURATION)) + null + } val messageText = tlvReader.getString(ContextSpecificTag(TAG_MESSAGE_TEXT)) - val responses = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_RESPONSES))) { - Optional.of( - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_RESPONSES)) - while (!tlvReader.isEndOfContainer()) { - add(MessagesClusterMessageResponseOptionStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - ) - } else { - Optional.empty() - } - + val responses = if (tlvReader.isNextTag(ContextSpecificTag(TAG_RESPONSES))) { + Optional.of(buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_RESPONSES)) + while(!tlvReader.isEndOfContainer()) { + add(MessagesClusterMessageResponseOptionStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + }) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return MessagesClusterMessageStruct( - messageID, - priority, - messageControl, - startTime, - duration, - messageText, - responses, - ) + return MessagesClusterMessageStruct(messageID, priority, messageControl, startTime, duration, messageText, responses) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/MicrowaveOvenModeClusterModeOptionStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/MicrowaveOvenModeClusterModeOptionStruct.kt index fbffd7bc7714bc..90d2e905cad2b1 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/MicrowaveOvenModeClusterModeOptionStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/MicrowaveOvenModeClusterModeOptionStruct.kt @@ -16,6 +16,7 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -26,7 +27,7 @@ import matter.tlv.TlvWriter class MicrowaveOvenModeClusterModeOptionStruct( val label: String, val mode: UByte, - val modeTags: List, + val modeTags: List ) { override fun toString(): String = buildString { append("MicrowaveOvenModeClusterModeOptionStruct {\n") @@ -59,15 +60,14 @@ class MicrowaveOvenModeClusterModeOptionStruct( tlvReader.enterStructure(tlvTag) val label = tlvReader.getString(ContextSpecificTag(TAG_LABEL)) val mode = tlvReader.getUByte(ContextSpecificTag(TAG_MODE)) - val modeTags = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_MODE_TAGS)) - while (!tlvReader.isEndOfContainer()) { - add(MicrowaveOvenModeClusterModeTagStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - + val modeTags = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_MODE_TAGS)) + while(!tlvReader.isEndOfContainer()) { + add(MicrowaveOvenModeClusterModeTagStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + tlvReader.exitContainer() return MicrowaveOvenModeClusterModeOptionStruct(label, mode, modeTags) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/MicrowaveOvenModeClusterModeTagStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/MicrowaveOvenModeClusterModeTagStruct.kt index ee00730c425f47..6ac44a062ca27a 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/MicrowaveOvenModeClusterModeTagStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/MicrowaveOvenModeClusterModeTagStruct.kt @@ -18,12 +18,16 @@ package matter.controller.cluster.structs import java.util.Optional 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 MicrowaveOvenModeClusterModeTagStruct(val mfgCode: Optional, val value: UShort) { +class MicrowaveOvenModeClusterModeTagStruct( + val mfgCode: Optional, + val value: UShort +) { override fun toString(): String = buildString { append("MicrowaveOvenModeClusterModeTagStruct {\n") append("\tmfgCode : $mfgCode\n") @@ -49,14 +53,13 @@ class MicrowaveOvenModeClusterModeTagStruct(val mfgCode: Optional, val v fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): MicrowaveOvenModeClusterModeTagStruct { tlvReader.enterStructure(tlvTag) - val mfgCode = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_MFG_CODE))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_MFG_CODE))) - } else { - Optional.empty() - } + val mfgCode = if (tlvReader.isNextTag(ContextSpecificTag(TAG_MFG_CODE))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_MFG_CODE))) + } else { + Optional.empty() + } val value = tlvReader.getUShort(ContextSpecificTag(TAG_VALUE)) - + tlvReader.exitContainer() return MicrowaveOvenModeClusterModeTagStruct(mfgCode, value) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ModeSelectClusterModeOptionStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ModeSelectClusterModeOptionStruct.kt index 8a4730716992f9..ee501cf2d85532 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ModeSelectClusterModeOptionStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ModeSelectClusterModeOptionStruct.kt @@ -16,6 +16,7 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -26,7 +27,7 @@ import matter.tlv.TlvWriter class ModeSelectClusterModeOptionStruct( val label: String, val mode: UByte, - val semanticTags: List, + val semanticTags: List ) { override fun toString(): String = buildString { append("ModeSelectClusterModeOptionStruct {\n") @@ -59,15 +60,14 @@ class ModeSelectClusterModeOptionStruct( tlvReader.enterStructure(tlvTag) val label = tlvReader.getString(ContextSpecificTag(TAG_LABEL)) val mode = tlvReader.getUByte(ContextSpecificTag(TAG_MODE)) - val semanticTags = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_SEMANTIC_TAGS)) - while (!tlvReader.isEndOfContainer()) { - add(ModeSelectClusterSemanticTagStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - + val semanticTags = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_SEMANTIC_TAGS)) + while(!tlvReader.isEndOfContainer()) { + add(ModeSelectClusterSemanticTagStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + tlvReader.exitContainer() return ModeSelectClusterModeOptionStruct(label, mode, semanticTags) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ModeSelectClusterSemanticTagStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ModeSelectClusterSemanticTagStruct.kt index fe6cdd3b787f01..323f73c99e7820 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ModeSelectClusterSemanticTagStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ModeSelectClusterSemanticTagStruct.kt @@ -16,13 +16,18 @@ */ package matter.controller.cluster.structs +import java.util.Optional 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 ModeSelectClusterSemanticTagStruct(val mfgCode: UShort, val value: UShort) { +class ModeSelectClusterSemanticTagStruct( + val mfgCode: UShort, + val value: UShort +) { override fun toString(): String = buildString { append("ModeSelectClusterSemanticTagStruct {\n") append("\tmfgCode : $mfgCode\n") @@ -47,7 +52,7 @@ class ModeSelectClusterSemanticTagStruct(val mfgCode: UShort, val value: UShort) tlvReader.enterStructure(tlvTag) val mfgCode = tlvReader.getUShort(ContextSpecificTag(TAG_MFG_CODE)) val value = tlvReader.getUShort(ContextSpecificTag(TAG_VALUE)) - + tlvReader.exitContainer() return ModeSelectClusterSemanticTagStruct(mfgCode, value) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/NetworkCommissioningClusterNetworkInfoStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/NetworkCommissioningClusterNetworkInfoStruct.kt index e7503f37514dc7..b7c7fe29c93d48 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/NetworkCommissioningClusterNetworkInfoStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/NetworkCommissioningClusterNetworkInfoStruct.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -27,7 +28,7 @@ class NetworkCommissioningClusterNetworkInfoStruct( val networkID: ByteArray, val connected: Boolean, val networkIdentifier: Optional?, - val clientIdentifier: Optional?, + val clientIdentifier: Optional? ) { override fun toString(): String = buildString { append("NetworkCommissioningClusterNetworkInfoStruct {\n") @@ -45,17 +46,17 @@ class NetworkCommissioningClusterNetworkInfoStruct( put(ContextSpecificTag(TAG_CONNECTED), connected) if (networkIdentifier != null) { if (networkIdentifier.isPresent) { - val optnetworkIdentifier = networkIdentifier.get() - put(ContextSpecificTag(TAG_NETWORK_IDENTIFIER), optnetworkIdentifier) - } + val optnetworkIdentifier = networkIdentifier.get() + put(ContextSpecificTag(TAG_NETWORK_IDENTIFIER), optnetworkIdentifier) + } } else { putNull(ContextSpecificTag(TAG_NETWORK_IDENTIFIER)) } if (clientIdentifier != null) { if (clientIdentifier.isPresent) { - val optclientIdentifier = clientIdentifier.get() - put(ContextSpecificTag(TAG_CLIENT_IDENTIFIER), optclientIdentifier) - } + val optclientIdentifier = clientIdentifier.get() + put(ContextSpecificTag(TAG_CLIENT_IDENTIFIER), optclientIdentifier) + } } else { putNull(ContextSpecificTag(TAG_CLIENT_IDENTIFIER)) } @@ -73,37 +74,30 @@ class NetworkCommissioningClusterNetworkInfoStruct( tlvReader.enterStructure(tlvTag) val networkID = tlvReader.getByteArray(ContextSpecificTag(TAG_NETWORK_ID)) val connected = tlvReader.getBoolean(ContextSpecificTag(TAG_CONNECTED)) - val networkIdentifier = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_NETWORK_IDENTIFIER))) { - Optional.of(tlvReader.getByteArray(ContextSpecificTag(TAG_NETWORK_IDENTIFIER))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_NETWORK_IDENTIFIER)) - null - } - val clientIdentifier = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_CLIENT_IDENTIFIER))) { - Optional.of(tlvReader.getByteArray(ContextSpecificTag(TAG_CLIENT_IDENTIFIER))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_CLIENT_IDENTIFIER)) - null - } - + val networkIdentifier = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_NETWORK_IDENTIFIER))) { + Optional.of(tlvReader.getByteArray(ContextSpecificTag(TAG_NETWORK_IDENTIFIER))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_NETWORK_IDENTIFIER)) + null + } + val clientIdentifier = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_CLIENT_IDENTIFIER))) { + Optional.of(tlvReader.getByteArray(ContextSpecificTag(TAG_CLIENT_IDENTIFIER))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_CLIENT_IDENTIFIER)) + null + } + tlvReader.exitContainer() - return NetworkCommissioningClusterNetworkInfoStruct( - networkID, - connected, - networkIdentifier, - clientIdentifier, - ) + return NetworkCommissioningClusterNetworkInfoStruct(networkID, connected, networkIdentifier, clientIdentifier) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/NetworkCommissioningClusterThreadInterfaceScanResultStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/NetworkCommissioningClusterThreadInterfaceScanResultStruct.kt index 89fd771c76a87b..c052531cdda164 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/NetworkCommissioningClusterThreadInterfaceScanResultStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/NetworkCommissioningClusterThreadInterfaceScanResultStruct.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -30,7 +32,7 @@ class NetworkCommissioningClusterThreadInterfaceScanResultStruct( val version: UByte, val extendedAddress: ByteArray, val rssi: Byte, - val lqi: UByte, + val lqi: UByte ) { override fun toString(): String = buildString { append("NetworkCommissioningClusterThreadInterfaceScanResultStruct {\n") @@ -70,10 +72,7 @@ class NetworkCommissioningClusterThreadInterfaceScanResultStruct( private const val TAG_RSSI = 6 private const val TAG_LQI = 7 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): NetworkCommissioningClusterThreadInterfaceScanResultStruct { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): NetworkCommissioningClusterThreadInterfaceScanResultStruct { tlvReader.enterStructure(tlvTag) val panId = tlvReader.getUShort(ContextSpecificTag(TAG_PAN_ID)) val extendedPanId = tlvReader.getULong(ContextSpecificTag(TAG_EXTENDED_PAN_ID)) @@ -83,19 +82,10 @@ class NetworkCommissioningClusterThreadInterfaceScanResultStruct( val extendedAddress = tlvReader.getByteArray(ContextSpecificTag(TAG_EXTENDED_ADDRESS)) val rssi = tlvReader.getByte(ContextSpecificTag(TAG_RSSI)) val lqi = tlvReader.getUByte(ContextSpecificTag(TAG_LQI)) - + tlvReader.exitContainer() - return NetworkCommissioningClusterThreadInterfaceScanResultStruct( - panId, - extendedPanId, - networkName, - channel, - version, - extendedAddress, - rssi, - lqi, - ) + return NetworkCommissioningClusterThreadInterfaceScanResultStruct(panId, extendedPanId, networkName, channel, version, extendedAddress, rssi, lqi) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/NetworkCommissioningClusterWiFiInterfaceScanResultStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/NetworkCommissioningClusterWiFiInterfaceScanResultStruct.kt index 10de507ac304b1..85c6cf71f7c47b 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/NetworkCommissioningClusterWiFiInterfaceScanResultStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/NetworkCommissioningClusterWiFiInterfaceScanResultStruct.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -28,7 +30,7 @@ class NetworkCommissioningClusterWiFiInterfaceScanResultStruct( val bssid: ByteArray, val channel: UShort, val wiFiBand: UByte, - val rssi: Byte, + val rssi: Byte ) { override fun toString(): String = buildString { append("NetworkCommissioningClusterWiFiInterfaceScanResultStruct {\n") @@ -62,10 +64,7 @@ class NetworkCommissioningClusterWiFiInterfaceScanResultStruct( private const val TAG_WI_FI_BAND = 4 private const val TAG_RSSI = 5 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): NetworkCommissioningClusterWiFiInterfaceScanResultStruct { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): NetworkCommissioningClusterWiFiInterfaceScanResultStruct { tlvReader.enterStructure(tlvTag) val security = tlvReader.getUByte(ContextSpecificTag(TAG_SECURITY)) val ssid = tlvReader.getByteArray(ContextSpecificTag(TAG_SSID)) @@ -73,17 +72,10 @@ class NetworkCommissioningClusterWiFiInterfaceScanResultStruct( val channel = tlvReader.getUShort(ContextSpecificTag(TAG_CHANNEL)) val wiFiBand = tlvReader.getUByte(ContextSpecificTag(TAG_WI_FI_BAND)) val rssi = tlvReader.getByte(ContextSpecificTag(TAG_RSSI)) - + tlvReader.exitContainer() - return NetworkCommissioningClusterWiFiInterfaceScanResultStruct( - security, - ssid, - bssid, - channel, - wiFiBand, - rssi, - ) + return NetworkCommissioningClusterWiFiInterfaceScanResultStruct(security, ssid, bssid, channel, wiFiBand, rssi) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/OccupancySensingClusterHoldTimeLimitsStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/OccupancySensingClusterHoldTimeLimitsStruct.kt index be70d3b11ccbb3..56e69487fa2e90 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/OccupancySensingClusterHoldTimeLimitsStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/OccupancySensingClusterHoldTimeLimitsStruct.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -25,7 +27,7 @@ import matter.tlv.TlvWriter class OccupancySensingClusterHoldTimeLimitsStruct( val holdTimeMin: UShort, val holdTimeMax: UShort, - val holdTimeDefault: UShort, + val holdTimeDefault: UShort ) { override fun toString(): String = buildString { append("OccupancySensingClusterHoldTimeLimitsStruct {\n") @@ -55,7 +57,7 @@ class OccupancySensingClusterHoldTimeLimitsStruct( val holdTimeMin = tlvReader.getUShort(ContextSpecificTag(TAG_HOLD_TIME_MIN)) val holdTimeMax = tlvReader.getUShort(ContextSpecificTag(TAG_HOLD_TIME_MAX)) val holdTimeDefault = tlvReader.getUShort(ContextSpecificTag(TAG_HOLD_TIME_DEFAULT)) - + tlvReader.exitContainer() return OccupancySensingClusterHoldTimeLimitsStruct(holdTimeMin, holdTimeMax, holdTimeDefault) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/OperationalCredentialsClusterFabricDescriptorStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/OperationalCredentialsClusterFabricDescriptorStruct.kt index 6fad97097ca764..1a186d2fcd77f3 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/OperationalCredentialsClusterFabricDescriptorStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/OperationalCredentialsClusterFabricDescriptorStruct.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -28,7 +30,7 @@ class OperationalCredentialsClusterFabricDescriptorStruct( val fabricID: ULong, val nodeID: ULong, val label: String, - val fabricIndex: UByte, + val fabricIndex: UByte ) { override fun toString(): String = buildString { append("OperationalCredentialsClusterFabricDescriptorStruct {\n") @@ -62,10 +64,7 @@ class OperationalCredentialsClusterFabricDescriptorStruct( private const val TAG_LABEL = 5 private const val TAG_FABRIC_INDEX = 254 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): OperationalCredentialsClusterFabricDescriptorStruct { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): OperationalCredentialsClusterFabricDescriptorStruct { tlvReader.enterStructure(tlvTag) val rootPublicKey = tlvReader.getByteArray(ContextSpecificTag(TAG_ROOT_PUBLIC_KEY)) val vendorID = tlvReader.getUShort(ContextSpecificTag(TAG_VENDOR_ID)) @@ -73,17 +72,10 @@ class OperationalCredentialsClusterFabricDescriptorStruct( val nodeID = tlvReader.getULong(ContextSpecificTag(TAG_NODE_ID)) val label = tlvReader.getString(ContextSpecificTag(TAG_LABEL)) val fabricIndex = tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) - + tlvReader.exitContainer() - return OperationalCredentialsClusterFabricDescriptorStruct( - rootPublicKey, - vendorID, - fabricID, - nodeID, - label, - fabricIndex, - ) + return OperationalCredentialsClusterFabricDescriptorStruct(rootPublicKey, vendorID, fabricID, nodeID, label, fabricIndex) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/OperationalCredentialsClusterNOCStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/OperationalCredentialsClusterNOCStruct.kt index 3a743a2fcf0423..1a27ee6624fe40 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/OperationalCredentialsClusterNOCStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/OperationalCredentialsClusterNOCStruct.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -25,7 +27,7 @@ import matter.tlv.TlvWriter class OperationalCredentialsClusterNOCStruct( val noc: ByteArray, val icac: ByteArray?, - val fabricIndex: UByte, + val fabricIndex: UByte ) { override fun toString(): String = buildString { append("OperationalCredentialsClusterNOCStruct {\n") @@ -57,15 +59,14 @@ class OperationalCredentialsClusterNOCStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): OperationalCredentialsClusterNOCStruct { tlvReader.enterStructure(tlvTag) val noc = tlvReader.getByteArray(ContextSpecificTag(TAG_NOC)) - val icac = - if (!tlvReader.isNull()) { - tlvReader.getByteArray(ContextSpecificTag(TAG_ICAC)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_ICAC)) - null - } + val icac = if (!tlvReader.isNull()) { + tlvReader.getByteArray(ContextSpecificTag(TAG_ICAC)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_ICAC)) + null + } val fabricIndex = tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) - + tlvReader.exitContainer() return OperationalCredentialsClusterNOCStruct(noc, icac, fabricIndex) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/OperationalStateClusterErrorStateStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/OperationalStateClusterErrorStateStruct.kt index bea86d884fdc49..f94b415fa99727 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/OperationalStateClusterErrorStateStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/OperationalStateClusterErrorStateStruct.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +27,7 @@ import matter.tlv.TlvWriter class OperationalStateClusterErrorStateStruct( val errorStateID: UByte, val errorStateLabel: Optional, - val errorStateDetails: Optional, + val errorStateDetails: Optional ) { override fun toString(): String = buildString { append("OperationalStateClusterErrorStateStruct {\n") @@ -60,26 +61,20 @@ class OperationalStateClusterErrorStateStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): OperationalStateClusterErrorStateStruct { tlvReader.enterStructure(tlvTag) val errorStateID = tlvReader.getUByte(ContextSpecificTag(TAG_ERROR_STATE_ID)) - val errorStateLabel = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_ERROR_STATE_LABEL))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_ERROR_STATE_LABEL))) - } else { - Optional.empty() - } - val errorStateDetails = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_ERROR_STATE_DETAILS))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_ERROR_STATE_DETAILS))) - } else { - Optional.empty() - } - + val errorStateLabel = if (tlvReader.isNextTag(ContextSpecificTag(TAG_ERROR_STATE_LABEL))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_ERROR_STATE_LABEL))) + } else { + Optional.empty() + } + val errorStateDetails = if (tlvReader.isNextTag(ContextSpecificTag(TAG_ERROR_STATE_DETAILS))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_ERROR_STATE_DETAILS))) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return OperationalStateClusterErrorStateStruct( - errorStateID, - errorStateLabel, - errorStateDetails, - ) + return OperationalStateClusterErrorStateStruct(errorStateID, errorStateLabel, errorStateDetails) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/OperationalStateClusterOperationalStateStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/OperationalStateClusterOperationalStateStruct.kt index 7626d4a76910f8..2c35206ce1f43a 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/OperationalStateClusterOperationalStateStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/OperationalStateClusterOperationalStateStruct.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -25,7 +26,7 @@ import matter.tlv.TlvWriter class OperationalStateClusterOperationalStateStruct( val operationalStateID: UByte, - val operationalStateLabel: Optional, + val operationalStateLabel: Optional ) { override fun toString(): String = buildString { append("OperationalStateClusterOperationalStateStruct {\n") @@ -53,19 +54,15 @@ class OperationalStateClusterOperationalStateStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): OperationalStateClusterOperationalStateStruct { tlvReader.enterStructure(tlvTag) val operationalStateID = tlvReader.getUByte(ContextSpecificTag(TAG_OPERATIONAL_STATE_ID)) - val operationalStateLabel = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_OPERATIONAL_STATE_LABEL))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_OPERATIONAL_STATE_LABEL))) - } else { - Optional.empty() - } - + val operationalStateLabel = if (tlvReader.isNextTag(ContextSpecificTag(TAG_OPERATIONAL_STATE_LABEL))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_OPERATIONAL_STATE_LABEL))) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return OperationalStateClusterOperationalStateStruct( - operationalStateID, - operationalStateLabel, - ) + return OperationalStateClusterOperationalStateStruct(operationalStateID, operationalStateLabel) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/OtaSoftwareUpdateRequestorClusterProviderLocation.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/OtaSoftwareUpdateRequestorClusterProviderLocation.kt index 209c1580f35df2..774f039f2825ac 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/OtaSoftwareUpdateRequestorClusterProviderLocation.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/OtaSoftwareUpdateRequestorClusterProviderLocation.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -25,7 +27,7 @@ import matter.tlv.TlvWriter class OtaSoftwareUpdateRequestorClusterProviderLocation( val providerNodeID: ULong, val endpoint: UShort, - val fabricIndex: UByte, + val fabricIndex: UByte ) { override fun toString(): String = buildString { append("OtaSoftwareUpdateRequestorClusterProviderLocation {\n") @@ -50,22 +52,15 @@ class OtaSoftwareUpdateRequestorClusterProviderLocation( private const val TAG_ENDPOINT = 2 private const val TAG_FABRIC_INDEX = 254 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): OtaSoftwareUpdateRequestorClusterProviderLocation { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): OtaSoftwareUpdateRequestorClusterProviderLocation { tlvReader.enterStructure(tlvTag) val providerNodeID = tlvReader.getULong(ContextSpecificTag(TAG_PROVIDER_NODE_ID)) val endpoint = tlvReader.getUShort(ContextSpecificTag(TAG_ENDPOINT)) val fabricIndex = tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) - + tlvReader.exitContainer() - return OtaSoftwareUpdateRequestorClusterProviderLocation( - providerNodeID, - endpoint, - fabricIndex, - ) + return OtaSoftwareUpdateRequestorClusterProviderLocation(providerNodeID, endpoint, fabricIndex) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/OvenCavityOperationalStateClusterErrorStateStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/OvenCavityOperationalStateClusterErrorStateStruct.kt index 442c55ea088e3d..799c197712bf38 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/OvenCavityOperationalStateClusterErrorStateStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/OvenCavityOperationalStateClusterErrorStateStruct.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +27,7 @@ import matter.tlv.TlvWriter class OvenCavityOperationalStateClusterErrorStateStruct( val errorStateID: UByte, val errorStateLabel: Optional, - val errorStateDetails: Optional, + val errorStateDetails: Optional ) { override fun toString(): String = buildString { append("OvenCavityOperationalStateClusterErrorStateStruct {\n") @@ -57,32 +58,23 @@ class OvenCavityOperationalStateClusterErrorStateStruct( private const val TAG_ERROR_STATE_LABEL = 1 private const val TAG_ERROR_STATE_DETAILS = 2 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): OvenCavityOperationalStateClusterErrorStateStruct { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): OvenCavityOperationalStateClusterErrorStateStruct { tlvReader.enterStructure(tlvTag) val errorStateID = tlvReader.getUByte(ContextSpecificTag(TAG_ERROR_STATE_ID)) - val errorStateLabel = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_ERROR_STATE_LABEL))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_ERROR_STATE_LABEL))) - } else { - Optional.empty() - } - val errorStateDetails = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_ERROR_STATE_DETAILS))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_ERROR_STATE_DETAILS))) - } else { - Optional.empty() - } - + val errorStateLabel = if (tlvReader.isNextTag(ContextSpecificTag(TAG_ERROR_STATE_LABEL))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_ERROR_STATE_LABEL))) + } else { + Optional.empty() + } + val errorStateDetails = if (tlvReader.isNextTag(ContextSpecificTag(TAG_ERROR_STATE_DETAILS))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_ERROR_STATE_DETAILS))) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return OvenCavityOperationalStateClusterErrorStateStruct( - errorStateID, - errorStateLabel, - errorStateDetails, - ) + return OvenCavityOperationalStateClusterErrorStateStruct(errorStateID, errorStateLabel, errorStateDetails) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/OvenCavityOperationalStateClusterOperationalStateStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/OvenCavityOperationalStateClusterOperationalStateStruct.kt index ef6a876dcef05f..7f31dc31e05bb7 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/OvenCavityOperationalStateClusterOperationalStateStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/OvenCavityOperationalStateClusterOperationalStateStruct.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -25,7 +26,7 @@ import matter.tlv.TlvWriter class OvenCavityOperationalStateClusterOperationalStateStruct( val operationalStateID: UByte, - val operationalStateLabel: Optional, + val operationalStateLabel: Optional ) { override fun toString(): String = buildString { append("OvenCavityOperationalStateClusterOperationalStateStruct {\n") @@ -50,25 +51,18 @@ class OvenCavityOperationalStateClusterOperationalStateStruct( private const val TAG_OPERATIONAL_STATE_ID = 0 private const val TAG_OPERATIONAL_STATE_LABEL = 1 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): OvenCavityOperationalStateClusterOperationalStateStruct { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): OvenCavityOperationalStateClusterOperationalStateStruct { tlvReader.enterStructure(tlvTag) val operationalStateID = tlvReader.getUByte(ContextSpecificTag(TAG_OPERATIONAL_STATE_ID)) - val operationalStateLabel = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_OPERATIONAL_STATE_LABEL))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_OPERATIONAL_STATE_LABEL))) - } else { - Optional.empty() - } - + val operationalStateLabel = if (tlvReader.isNextTag(ContextSpecificTag(TAG_OPERATIONAL_STATE_LABEL))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_OPERATIONAL_STATE_LABEL))) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return OvenCavityOperationalStateClusterOperationalStateStruct( - operationalStateID, - operationalStateLabel, - ) + return OvenCavityOperationalStateClusterOperationalStateStruct(operationalStateID, operationalStateLabel) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/OvenModeClusterModeOptionStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/OvenModeClusterModeOptionStruct.kt index 6ae08faf4c850f..47fda3f789599e 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/OvenModeClusterModeOptionStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/OvenModeClusterModeOptionStruct.kt @@ -16,6 +16,7 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -26,7 +27,7 @@ import matter.tlv.TlvWriter class OvenModeClusterModeOptionStruct( val label: String, val mode: UByte, - val modeTags: List, + val modeTags: List ) { override fun toString(): String = buildString { append("OvenModeClusterModeOptionStruct {\n") @@ -59,15 +60,14 @@ class OvenModeClusterModeOptionStruct( tlvReader.enterStructure(tlvTag) val label = tlvReader.getString(ContextSpecificTag(TAG_LABEL)) val mode = tlvReader.getUByte(ContextSpecificTag(TAG_MODE)) - val modeTags = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_MODE_TAGS)) - while (!tlvReader.isEndOfContainer()) { - add(OvenModeClusterModeTagStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - + val modeTags = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_MODE_TAGS)) + while(!tlvReader.isEndOfContainer()) { + add(OvenModeClusterModeTagStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + tlvReader.exitContainer() return OvenModeClusterModeOptionStruct(label, mode, modeTags) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/OvenModeClusterModeTagStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/OvenModeClusterModeTagStruct.kt index 4ba9d368de022f..3715c9253bd394 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/OvenModeClusterModeTagStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/OvenModeClusterModeTagStruct.kt @@ -18,12 +18,16 @@ package matter.controller.cluster.structs import java.util.Optional 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 OvenModeClusterModeTagStruct(val mfgCode: Optional, val value: UShort) { +class OvenModeClusterModeTagStruct( + val mfgCode: Optional, + val value: UShort +) { override fun toString(): String = buildString { append("OvenModeClusterModeTagStruct {\n") append("\tmfgCode : $mfgCode\n") @@ -49,14 +53,13 @@ class OvenModeClusterModeTagStruct(val mfgCode: Optional, val value: USh fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): OvenModeClusterModeTagStruct { tlvReader.enterStructure(tlvTag) - val mfgCode = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_MFG_CODE))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_MFG_CODE))) - } else { - Optional.empty() - } + val mfgCode = if (tlvReader.isNextTag(ContextSpecificTag(TAG_MFG_CODE))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_MFG_CODE))) + } else { + Optional.empty() + } val value = tlvReader.getUShort(ContextSpecificTag(TAG_VALUE)) - + tlvReader.exitContainer() return OvenModeClusterModeTagStruct(mfgCode, value) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/PowerSourceClusterBatChargeFaultChangeType.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/PowerSourceClusterBatChargeFaultChangeType.kt index f4b9df55b032cf..93b2e01e8dcd67 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/PowerSourceClusterBatChargeFaultChangeType.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/PowerSourceClusterBatChargeFaultChangeType.kt @@ -16,6 +16,7 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -25,7 +26,7 @@ import matter.tlv.TlvWriter class PowerSourceClusterBatChargeFaultChangeType( val current: List, - val previous: List, + val previous: List ) { override fun toString(): String = buildString { append("PowerSourceClusterBatChargeFaultChangeType {\n") @@ -57,23 +58,21 @@ class PowerSourceClusterBatChargeFaultChangeType( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): PowerSourceClusterBatChargeFaultChangeType { tlvReader.enterStructure(tlvTag) - val current = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_CURRENT)) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } - val previous = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_PREVIOUS)) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } - + val current = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_CURRENT)) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + val previous = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_PREVIOUS)) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + tlvReader.exitContainer() return PowerSourceClusterBatChargeFaultChangeType(current, previous) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/PowerSourceClusterBatFaultChangeType.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/PowerSourceClusterBatFaultChangeType.kt index 6b849cc5874313..f5c4803e0482ac 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/PowerSourceClusterBatFaultChangeType.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/PowerSourceClusterBatFaultChangeType.kt @@ -16,6 +16,7 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -23,7 +24,10 @@ import matter.tlv.Tag import matter.tlv.TlvReader import matter.tlv.TlvWriter -class PowerSourceClusterBatFaultChangeType(val current: List, val previous: List) { +class PowerSourceClusterBatFaultChangeType( + val current: List, + val previous: List +) { override fun toString(): String = buildString { append("PowerSourceClusterBatFaultChangeType {\n") append("\tcurrent : $current\n") @@ -54,23 +58,21 @@ class PowerSourceClusterBatFaultChangeType(val current: List, val previou fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): PowerSourceClusterBatFaultChangeType { tlvReader.enterStructure(tlvTag) - val current = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_CURRENT)) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } - val previous = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_PREVIOUS)) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } - + val current = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_CURRENT)) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + val previous = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_PREVIOUS)) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + tlvReader.exitContainer() return PowerSourceClusterBatFaultChangeType(current, previous) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/PowerSourceClusterWiredFaultChangeType.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/PowerSourceClusterWiredFaultChangeType.kt index 9354883b16e760..0eb132ceb49b1e 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/PowerSourceClusterWiredFaultChangeType.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/PowerSourceClusterWiredFaultChangeType.kt @@ -16,6 +16,7 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -23,7 +24,10 @@ import matter.tlv.Tag import matter.tlv.TlvReader import matter.tlv.TlvWriter -class PowerSourceClusterWiredFaultChangeType(val current: List, val previous: List) { +class PowerSourceClusterWiredFaultChangeType( + val current: List, + val previous: List +) { override fun toString(): String = buildString { append("PowerSourceClusterWiredFaultChangeType {\n") append("\tcurrent : $current\n") @@ -54,23 +58,21 @@ class PowerSourceClusterWiredFaultChangeType(val current: List, val previ fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): PowerSourceClusterWiredFaultChangeType { tlvReader.enterStructure(tlvTag) - val current = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_CURRENT)) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } - val previous = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_PREVIOUS)) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } - + val current = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_CURRENT)) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + val previous = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_PREVIOUS)) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + tlvReader.exitContainer() return PowerSourceClusterWiredFaultChangeType(current, previous) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/RefrigeratorAndTemperatureControlledCabinetModeClusterModeOptionStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/RefrigeratorAndTemperatureControlledCabinetModeClusterModeOptionStruct.kt index fd00724de7b7ac..59482e83c5039d 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/RefrigeratorAndTemperatureControlledCabinetModeClusterModeOptionStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/RefrigeratorAndTemperatureControlledCabinetModeClusterModeOptionStruct.kt @@ -16,6 +16,7 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -26,7 +27,7 @@ import matter.tlv.TlvWriter class RefrigeratorAndTemperatureControlledCabinetModeClusterModeOptionStruct( val label: String, val mode: UByte, - val modeTags: List, + val modeTags: List ) { override fun toString(): String = buildString { append("RefrigeratorAndTemperatureControlledCabinetModeClusterModeOptionStruct {\n") @@ -55,34 +56,21 @@ class RefrigeratorAndTemperatureControlledCabinetModeClusterModeOptionStruct( private const val TAG_MODE = 1 private const val TAG_MODE_TAGS = 2 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): RefrigeratorAndTemperatureControlledCabinetModeClusterModeOptionStruct { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): RefrigeratorAndTemperatureControlledCabinetModeClusterModeOptionStruct { tlvReader.enterStructure(tlvTag) val label = tlvReader.getString(ContextSpecificTag(TAG_LABEL)) val mode = tlvReader.getUByte(ContextSpecificTag(TAG_MODE)) - val modeTags = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_MODE_TAGS)) - while (!tlvReader.isEndOfContainer()) { - add( - RefrigeratorAndTemperatureControlledCabinetModeClusterModeTagStruct.fromTlv( - AnonymousTag, - tlvReader, - ) - ) - } - tlvReader.exitContainer() - } - + val modeTags = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_MODE_TAGS)) + while(!tlvReader.isEndOfContainer()) { + add(RefrigeratorAndTemperatureControlledCabinetModeClusterModeTagStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + tlvReader.exitContainer() - return RefrigeratorAndTemperatureControlledCabinetModeClusterModeOptionStruct( - label, - mode, - modeTags, - ) + return RefrigeratorAndTemperatureControlledCabinetModeClusterModeOptionStruct(label, mode, modeTags) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/RefrigeratorAndTemperatureControlledCabinetModeClusterModeTagStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/RefrigeratorAndTemperatureControlledCabinetModeClusterModeTagStruct.kt index 46462a296a0d53..2ec589a6c0df35 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/RefrigeratorAndTemperatureControlledCabinetModeClusterModeTagStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/RefrigeratorAndTemperatureControlledCabinetModeClusterModeTagStruct.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -25,7 +26,7 @@ import matter.tlv.TlvWriter class RefrigeratorAndTemperatureControlledCabinetModeClusterModeTagStruct( val mfgCode: Optional, - val value: UShort, + val value: UShort ) { override fun toString(): String = buildString { append("RefrigeratorAndTemperatureControlledCabinetModeClusterModeTagStruct {\n") @@ -50,19 +51,15 @@ class RefrigeratorAndTemperatureControlledCabinetModeClusterModeTagStruct( private const val TAG_MFG_CODE = 0 private const val TAG_VALUE = 1 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): RefrigeratorAndTemperatureControlledCabinetModeClusterModeTagStruct { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): RefrigeratorAndTemperatureControlledCabinetModeClusterModeTagStruct { tlvReader.enterStructure(tlvTag) - val mfgCode = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_MFG_CODE))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_MFG_CODE))) - } else { - Optional.empty() - } + val mfgCode = if (tlvReader.isNextTag(ContextSpecificTag(TAG_MFG_CODE))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_MFG_CODE))) + } else { + Optional.empty() + } val value = tlvReader.getUShort(ContextSpecificTag(TAG_VALUE)) - + tlvReader.exitContainer() return RefrigeratorAndTemperatureControlledCabinetModeClusterModeTagStruct(mfgCode, value) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/RvcCleanModeClusterModeOptionStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/RvcCleanModeClusterModeOptionStruct.kt index e44fa3f8bc0e21..a79f2a02599eba 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/RvcCleanModeClusterModeOptionStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/RvcCleanModeClusterModeOptionStruct.kt @@ -16,6 +16,7 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -26,7 +27,7 @@ import matter.tlv.TlvWriter class RvcCleanModeClusterModeOptionStruct( val label: String, val mode: UByte, - val modeTags: List, + val modeTags: List ) { override fun toString(): String = buildString { append("RvcCleanModeClusterModeOptionStruct {\n") @@ -59,15 +60,14 @@ class RvcCleanModeClusterModeOptionStruct( tlvReader.enterStructure(tlvTag) val label = tlvReader.getString(ContextSpecificTag(TAG_LABEL)) val mode = tlvReader.getUByte(ContextSpecificTag(TAG_MODE)) - val modeTags = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_MODE_TAGS)) - while (!tlvReader.isEndOfContainer()) { - add(RvcCleanModeClusterModeTagStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - + val modeTags = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_MODE_TAGS)) + while(!tlvReader.isEndOfContainer()) { + add(RvcCleanModeClusterModeTagStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + tlvReader.exitContainer() return RvcCleanModeClusterModeOptionStruct(label, mode, modeTags) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/RvcCleanModeClusterModeTagStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/RvcCleanModeClusterModeTagStruct.kt index ce35ad9a5a9960..88ea7b7b2f7002 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/RvcCleanModeClusterModeTagStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/RvcCleanModeClusterModeTagStruct.kt @@ -18,12 +18,16 @@ package matter.controller.cluster.structs import java.util.Optional 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 RvcCleanModeClusterModeTagStruct(val mfgCode: Optional, val value: UShort) { +class RvcCleanModeClusterModeTagStruct( + val mfgCode: Optional, + val value: UShort +) { override fun toString(): String = buildString { append("RvcCleanModeClusterModeTagStruct {\n") append("\tmfgCode : $mfgCode\n") @@ -49,14 +53,13 @@ class RvcCleanModeClusterModeTagStruct(val mfgCode: Optional, val value: fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): RvcCleanModeClusterModeTagStruct { tlvReader.enterStructure(tlvTag) - val mfgCode = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_MFG_CODE))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_MFG_CODE))) - } else { - Optional.empty() - } + val mfgCode = if (tlvReader.isNextTag(ContextSpecificTag(TAG_MFG_CODE))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_MFG_CODE))) + } else { + Optional.empty() + } val value = tlvReader.getUShort(ContextSpecificTag(TAG_VALUE)) - + tlvReader.exitContainer() return RvcCleanModeClusterModeTagStruct(mfgCode, value) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/RvcOperationalStateClusterErrorStateStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/RvcOperationalStateClusterErrorStateStruct.kt index e60738d973b0c5..aa4c5e47a918e7 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/RvcOperationalStateClusterErrorStateStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/RvcOperationalStateClusterErrorStateStruct.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +27,7 @@ import matter.tlv.TlvWriter class RvcOperationalStateClusterErrorStateStruct( val errorStateID: UByte, val errorStateLabel: Optional, - val errorStateDetails: Optional, + val errorStateDetails: Optional ) { override fun toString(): String = buildString { append("RvcOperationalStateClusterErrorStateStruct {\n") @@ -60,26 +61,20 @@ class RvcOperationalStateClusterErrorStateStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): RvcOperationalStateClusterErrorStateStruct { tlvReader.enterStructure(tlvTag) val errorStateID = tlvReader.getUByte(ContextSpecificTag(TAG_ERROR_STATE_ID)) - val errorStateLabel = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_ERROR_STATE_LABEL))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_ERROR_STATE_LABEL))) - } else { - Optional.empty() - } - val errorStateDetails = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_ERROR_STATE_DETAILS))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_ERROR_STATE_DETAILS))) - } else { - Optional.empty() - } - + val errorStateLabel = if (tlvReader.isNextTag(ContextSpecificTag(TAG_ERROR_STATE_LABEL))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_ERROR_STATE_LABEL))) + } else { + Optional.empty() + } + val errorStateDetails = if (tlvReader.isNextTag(ContextSpecificTag(TAG_ERROR_STATE_DETAILS))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_ERROR_STATE_DETAILS))) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return RvcOperationalStateClusterErrorStateStruct( - errorStateID, - errorStateLabel, - errorStateDetails, - ) + return RvcOperationalStateClusterErrorStateStruct(errorStateID, errorStateLabel, errorStateDetails) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/RvcOperationalStateClusterOperationalStateStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/RvcOperationalStateClusterOperationalStateStruct.kt index 00680b85bb0c7b..78d0a91b1533c1 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/RvcOperationalStateClusterOperationalStateStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/RvcOperationalStateClusterOperationalStateStruct.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -25,7 +26,7 @@ import matter.tlv.TlvWriter class RvcOperationalStateClusterOperationalStateStruct( val operationalStateID: UByte, - val operationalStateLabel: Optional, + val operationalStateLabel: Optional ) { override fun toString(): String = buildString { append("RvcOperationalStateClusterOperationalStateStruct {\n") @@ -50,25 +51,18 @@ class RvcOperationalStateClusterOperationalStateStruct( private const val TAG_OPERATIONAL_STATE_ID = 0 private const val TAG_OPERATIONAL_STATE_LABEL = 1 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): RvcOperationalStateClusterOperationalStateStruct { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): RvcOperationalStateClusterOperationalStateStruct { tlvReader.enterStructure(tlvTag) val operationalStateID = tlvReader.getUByte(ContextSpecificTag(TAG_OPERATIONAL_STATE_ID)) - val operationalStateLabel = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_OPERATIONAL_STATE_LABEL))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_OPERATIONAL_STATE_LABEL))) - } else { - Optional.empty() - } - + val operationalStateLabel = if (tlvReader.isNextTag(ContextSpecificTag(TAG_OPERATIONAL_STATE_LABEL))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_OPERATIONAL_STATE_LABEL))) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return RvcOperationalStateClusterOperationalStateStruct( - operationalStateID, - operationalStateLabel, - ) + return RvcOperationalStateClusterOperationalStateStruct(operationalStateID, operationalStateLabel) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/RvcRunModeClusterModeOptionStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/RvcRunModeClusterModeOptionStruct.kt index 3835b84979c2e2..c98a49235c774f 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/RvcRunModeClusterModeOptionStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/RvcRunModeClusterModeOptionStruct.kt @@ -16,6 +16,7 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -26,7 +27,7 @@ import matter.tlv.TlvWriter class RvcRunModeClusterModeOptionStruct( val label: String, val mode: UByte, - val modeTags: List, + val modeTags: List ) { override fun toString(): String = buildString { append("RvcRunModeClusterModeOptionStruct {\n") @@ -59,15 +60,14 @@ class RvcRunModeClusterModeOptionStruct( tlvReader.enterStructure(tlvTag) val label = tlvReader.getString(ContextSpecificTag(TAG_LABEL)) val mode = tlvReader.getUByte(ContextSpecificTag(TAG_MODE)) - val modeTags = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_MODE_TAGS)) - while (!tlvReader.isEndOfContainer()) { - add(RvcRunModeClusterModeTagStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - + val modeTags = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_MODE_TAGS)) + while(!tlvReader.isEndOfContainer()) { + add(RvcRunModeClusterModeTagStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + tlvReader.exitContainer() return RvcRunModeClusterModeOptionStruct(label, mode, modeTags) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/RvcRunModeClusterModeTagStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/RvcRunModeClusterModeTagStruct.kt index 7ad69693847d17..d9c65679552d63 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/RvcRunModeClusterModeTagStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/RvcRunModeClusterModeTagStruct.kt @@ -18,12 +18,16 @@ package matter.controller.cluster.structs import java.util.Optional 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 RvcRunModeClusterModeTagStruct(val mfgCode: Optional, val value: UShort) { +class RvcRunModeClusterModeTagStruct( + val mfgCode: Optional, + val value: UShort +) { override fun toString(): String = buildString { append("RvcRunModeClusterModeTagStruct {\n") append("\tmfgCode : $mfgCode\n") @@ -49,14 +53,13 @@ class RvcRunModeClusterModeTagStruct(val mfgCode: Optional, val value: U fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): RvcRunModeClusterModeTagStruct { tlvReader.enterStructure(tlvTag) - val mfgCode = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_MFG_CODE))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_MFG_CODE))) - } else { - Optional.empty() - } + val mfgCode = if (tlvReader.isNextTag(ContextSpecificTag(TAG_MFG_CODE))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_MFG_CODE))) + } else { + Optional.empty() + } val value = tlvReader.getUShort(ContextSpecificTag(TAG_VALUE)) - + tlvReader.exitContainer() return RvcRunModeClusterModeTagStruct(mfgCode, value) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ScenesManagementClusterAttributeValuePairStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ScenesManagementClusterAttributeValuePairStruct.kt index 232bfea8c1e5a7..a7016afac59d5d 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ScenesManagementClusterAttributeValuePairStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ScenesManagementClusterAttributeValuePairStruct.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -32,7 +33,7 @@ class ScenesManagementClusterAttributeValuePairStruct( val valueUnsigned32: Optional, val valueSigned32: Optional, val valueUnsigned64: Optional, - val valueSigned64: Optional, + val valueSigned64: Optional ) { override fun toString(): String = buildString { append("ScenesManagementClusterAttributeValuePairStruct {\n") @@ -99,74 +100,53 @@ class ScenesManagementClusterAttributeValuePairStruct( private const val TAG_VALUE_UNSIGNED64 = 7 private const val TAG_VALUE_SIGNED64 = 8 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): ScenesManagementClusterAttributeValuePairStruct { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ScenesManagementClusterAttributeValuePairStruct { tlvReader.enterStructure(tlvTag) val attributeID = tlvReader.getUInt(ContextSpecificTag(TAG_ATTRIBUTE_ID)) - val valueUnsigned8 = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_VALUE_UNSIGNED8))) { - Optional.of(tlvReader.getUByte(ContextSpecificTag(TAG_VALUE_UNSIGNED8))) - } else { - Optional.empty() - } - val valueSigned8 = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_VALUE_SIGNED8))) { - Optional.of(tlvReader.getByte(ContextSpecificTag(TAG_VALUE_SIGNED8))) - } else { - Optional.empty() - } - val valueUnsigned16 = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_VALUE_UNSIGNED16))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_VALUE_UNSIGNED16))) - } else { - Optional.empty() - } - val valueSigned16 = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_VALUE_SIGNED16))) { - Optional.of(tlvReader.getShort(ContextSpecificTag(TAG_VALUE_SIGNED16))) - } else { - Optional.empty() - } - val valueUnsigned32 = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_VALUE_UNSIGNED32))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_VALUE_UNSIGNED32))) - } else { - Optional.empty() - } - val valueSigned32 = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_VALUE_SIGNED32))) { - Optional.of(tlvReader.getInt(ContextSpecificTag(TAG_VALUE_SIGNED32))) - } else { - Optional.empty() - } - val valueUnsigned64 = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_VALUE_UNSIGNED64))) { - Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_VALUE_UNSIGNED64))) - } else { - Optional.empty() - } - val valueSigned64 = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_VALUE_SIGNED64))) { - Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_VALUE_SIGNED64))) - } else { - Optional.empty() - } - + val valueUnsigned8 = if (tlvReader.isNextTag(ContextSpecificTag(TAG_VALUE_UNSIGNED8))) { + Optional.of(tlvReader.getUByte(ContextSpecificTag(TAG_VALUE_UNSIGNED8))) + } else { + Optional.empty() + } + val valueSigned8 = if (tlvReader.isNextTag(ContextSpecificTag(TAG_VALUE_SIGNED8))) { + Optional.of(tlvReader.getByte(ContextSpecificTag(TAG_VALUE_SIGNED8))) + } else { + Optional.empty() + } + val valueUnsigned16 = if (tlvReader.isNextTag(ContextSpecificTag(TAG_VALUE_UNSIGNED16))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_VALUE_UNSIGNED16))) + } else { + Optional.empty() + } + val valueSigned16 = if (tlvReader.isNextTag(ContextSpecificTag(TAG_VALUE_SIGNED16))) { + Optional.of(tlvReader.getShort(ContextSpecificTag(TAG_VALUE_SIGNED16))) + } else { + Optional.empty() + } + val valueUnsigned32 = if (tlvReader.isNextTag(ContextSpecificTag(TAG_VALUE_UNSIGNED32))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_VALUE_UNSIGNED32))) + } else { + Optional.empty() + } + val valueSigned32 = if (tlvReader.isNextTag(ContextSpecificTag(TAG_VALUE_SIGNED32))) { + Optional.of(tlvReader.getInt(ContextSpecificTag(TAG_VALUE_SIGNED32))) + } else { + Optional.empty() + } + val valueUnsigned64 = if (tlvReader.isNextTag(ContextSpecificTag(TAG_VALUE_UNSIGNED64))) { + Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_VALUE_UNSIGNED64))) + } else { + Optional.empty() + } + val valueSigned64 = if (tlvReader.isNextTag(ContextSpecificTag(TAG_VALUE_SIGNED64))) { + Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_VALUE_SIGNED64))) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return ScenesManagementClusterAttributeValuePairStruct( - attributeID, - valueUnsigned8, - valueSigned8, - valueUnsigned16, - valueSigned16, - valueUnsigned32, - valueSigned32, - valueUnsigned64, - valueSigned64, - ) + return ScenesManagementClusterAttributeValuePairStruct(attributeID, valueUnsigned8, valueSigned8, valueUnsigned16, valueSigned16, valueUnsigned32, valueSigned32, valueUnsigned64, valueSigned64) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ScenesManagementClusterExtensionFieldSet.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ScenesManagementClusterExtensionFieldSet.kt index 4fcc98ecaf5921..0d27b983c567d4 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ScenesManagementClusterExtensionFieldSet.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ScenesManagementClusterExtensionFieldSet.kt @@ -16,6 +16,7 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -25,7 +26,7 @@ import matter.tlv.TlvWriter class ScenesManagementClusterExtensionFieldSet( val clusterID: UInt, - val attributeValueList: List, + val attributeValueList: List ) { override fun toString(): String = buildString { append("ScenesManagementClusterExtensionFieldSet {\n") @@ -54,15 +55,14 @@ class ScenesManagementClusterExtensionFieldSet( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ScenesManagementClusterExtensionFieldSet { tlvReader.enterStructure(tlvTag) val clusterID = tlvReader.getUInt(ContextSpecificTag(TAG_CLUSTER_ID)) - val attributeValueList = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_ATTRIBUTE_VALUE_LIST)) - while (!tlvReader.isEndOfContainer()) { - add(ScenesManagementClusterAttributeValuePairStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - + val attributeValueList = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_ATTRIBUTE_VALUE_LIST)) + while(!tlvReader.isEndOfContainer()) { + add(ScenesManagementClusterAttributeValuePairStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + tlvReader.exitContainer() return ScenesManagementClusterExtensionFieldSet(clusterID, attributeValueList) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ScenesManagementClusterSceneInfoStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ScenesManagementClusterSceneInfoStruct.kt index 915f63f84894ed..ea23bcb97924f6 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ScenesManagementClusterSceneInfoStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ScenesManagementClusterSceneInfoStruct.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -28,7 +30,7 @@ class ScenesManagementClusterSceneInfoStruct( val currentGroup: UShort, val sceneValid: Boolean, val remainingCapacity: UByte, - val fabricIndex: UByte, + val fabricIndex: UByte ) { override fun toString(): String = buildString { append("ScenesManagementClusterSceneInfoStruct {\n") @@ -70,17 +72,10 @@ class ScenesManagementClusterSceneInfoStruct( 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 ScenesManagementClusterSceneInfoStruct( - sceneCount, - currentScene, - currentGroup, - sceneValid, - remainingCapacity, - fabricIndex, - ) + return ScenesManagementClusterSceneInfoStruct(sceneCount, currentScene, currentGroup, sceneValid, remainingCapacity, fabricIndex) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ServiceAreaClusterAreaInfoStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ServiceAreaClusterAreaInfoStruct.kt index 1c71c6bcd1ff68..97c042d1ffef49 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ServiceAreaClusterAreaInfoStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ServiceAreaClusterAreaInfoStruct.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -24,7 +26,7 @@ import matter.tlv.TlvWriter class ServiceAreaClusterAreaInfoStruct( val locationInfo: ServiceAreaClusterLocationDescriptorStruct?, - val landmarkInfo: ServiceAreaClusterLandmarkInfoStruct?, + val landmarkInfo: ServiceAreaClusterLandmarkInfoStruct? ) { override fun toString(): String = buildString { append("ServiceAreaClusterAreaInfoStruct {\n") @@ -56,27 +58,19 @@ class ServiceAreaClusterAreaInfoStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ServiceAreaClusterAreaInfoStruct { tlvReader.enterStructure(tlvTag) - val locationInfo = - if (!tlvReader.isNull()) { - ServiceAreaClusterLocationDescriptorStruct.fromTlv( - ContextSpecificTag(TAG_LOCATION_INFO), - tlvReader, - ) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_LOCATION_INFO)) - null - } - val landmarkInfo = - if (!tlvReader.isNull()) { - ServiceAreaClusterLandmarkInfoStruct.fromTlv( - ContextSpecificTag(TAG_LANDMARK_INFO), - tlvReader, - ) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_LANDMARK_INFO)) - null - } - + val locationInfo = if (!tlvReader.isNull()) { + ServiceAreaClusterLocationDescriptorStruct.fromTlv(ContextSpecificTag(TAG_LOCATION_INFO), tlvReader) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_LOCATION_INFO)) + null + } + val landmarkInfo = if (!tlvReader.isNull()) { + ServiceAreaClusterLandmarkInfoStruct.fromTlv(ContextSpecificTag(TAG_LANDMARK_INFO), tlvReader) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_LANDMARK_INFO)) + null + } + tlvReader.exitContainer() return ServiceAreaClusterAreaInfoStruct(locationInfo, landmarkInfo) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ServiceAreaClusterAreaStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ServiceAreaClusterAreaStruct.kt index d310fe5c315bf8..d990f47c40ec3e 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ServiceAreaClusterAreaStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ServiceAreaClusterAreaStruct.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -25,7 +27,7 @@ import matter.tlv.TlvWriter class ServiceAreaClusterAreaStruct( val areaID: UInt, val mapID: UInt?, - val areaDesc: ServiceAreaClusterAreaInfoStruct, + val areaDesc: ServiceAreaClusterAreaInfoStruct ) { override fun toString(): String = buildString { append("ServiceAreaClusterAreaStruct {\n") @@ -57,16 +59,14 @@ class ServiceAreaClusterAreaStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ServiceAreaClusterAreaStruct { tlvReader.enterStructure(tlvTag) val areaID = tlvReader.getUInt(ContextSpecificTag(TAG_AREA_ID)) - val mapID = - if (!tlvReader.isNull()) { - tlvReader.getUInt(ContextSpecificTag(TAG_MAP_ID)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_MAP_ID)) - null - } - val areaDesc = - ServiceAreaClusterAreaInfoStruct.fromTlv(ContextSpecificTag(TAG_AREA_DESC), tlvReader) - + val mapID = if (!tlvReader.isNull()) { + tlvReader.getUInt(ContextSpecificTag(TAG_MAP_ID)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_MAP_ID)) + null + } + val areaDesc = ServiceAreaClusterAreaInfoStruct.fromTlv(ContextSpecificTag(TAG_AREA_DESC), tlvReader) + tlvReader.exitContainer() return ServiceAreaClusterAreaStruct(areaID, mapID, areaDesc) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ServiceAreaClusterLandmarkInfoStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ServiceAreaClusterLandmarkInfoStruct.kt index 119667c339d88c..0bff30d349bf28 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ServiceAreaClusterLandmarkInfoStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ServiceAreaClusterLandmarkInfoStruct.kt @@ -16,13 +16,18 @@ */ package matter.controller.cluster.structs +import java.util.Optional 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 ServiceAreaClusterLandmarkInfoStruct(val landmarkTag: UByte, val positionTag: UByte?) { +class ServiceAreaClusterLandmarkInfoStruct( + val landmarkTag: UByte, + val positionTag: UByte? +) { override fun toString(): String = buildString { append("ServiceAreaClusterLandmarkInfoStruct {\n") append("\tlandmarkTag : $landmarkTag\n") @@ -50,14 +55,13 @@ class ServiceAreaClusterLandmarkInfoStruct(val landmarkTag: UByte, val positionT fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ServiceAreaClusterLandmarkInfoStruct { tlvReader.enterStructure(tlvTag) val landmarkTag = tlvReader.getUByte(ContextSpecificTag(TAG_LANDMARK_TAG)) - val positionTag = - if (!tlvReader.isNull()) { - tlvReader.getUByte(ContextSpecificTag(TAG_POSITION_TAG)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_POSITION_TAG)) - null - } - + val positionTag = if (!tlvReader.isNull()) { + tlvReader.getUByte(ContextSpecificTag(TAG_POSITION_TAG)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_POSITION_TAG)) + null + } + tlvReader.exitContainer() return ServiceAreaClusterLandmarkInfoStruct(landmarkTag, positionTag) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ServiceAreaClusterLocationDescriptorStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ServiceAreaClusterLocationDescriptorStruct.kt index fd24fa9218c22d..3ba125abe0dd9b 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ServiceAreaClusterLocationDescriptorStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ServiceAreaClusterLocationDescriptorStruct.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -25,7 +27,7 @@ import matter.tlv.TlvWriter class ServiceAreaClusterLocationDescriptorStruct( val locationName: String, val floorNumber: Short?, - val areaType: UByte?, + val areaType: UByte? ) { override fun toString(): String = buildString { append("ServiceAreaClusterLocationDescriptorStruct {\n") @@ -61,21 +63,19 @@ class ServiceAreaClusterLocationDescriptorStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ServiceAreaClusterLocationDescriptorStruct { tlvReader.enterStructure(tlvTag) val locationName = tlvReader.getString(ContextSpecificTag(TAG_LOCATION_NAME)) - val floorNumber = - if (!tlvReader.isNull()) { - tlvReader.getShort(ContextSpecificTag(TAG_FLOOR_NUMBER)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_FLOOR_NUMBER)) - null - } - val areaType = - if (!tlvReader.isNull()) { - tlvReader.getUByte(ContextSpecificTag(TAG_AREA_TYPE)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_AREA_TYPE)) - null - } - + val floorNumber = if (!tlvReader.isNull()) { + tlvReader.getShort(ContextSpecificTag(TAG_FLOOR_NUMBER)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_FLOOR_NUMBER)) + null + } + val areaType = if (!tlvReader.isNull()) { + tlvReader.getUByte(ContextSpecificTag(TAG_AREA_TYPE)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_AREA_TYPE)) + null + } + tlvReader.exitContainer() return ServiceAreaClusterLocationDescriptorStruct(locationName, floorNumber, areaType) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ServiceAreaClusterMapStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ServiceAreaClusterMapStruct.kt index 19df0938c57b93..83b961f4a3aa9b 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ServiceAreaClusterMapStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ServiceAreaClusterMapStruct.kt @@ -16,13 +16,18 @@ */ package matter.controller.cluster.structs +import java.util.Optional 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 ServiceAreaClusterMapStruct(val mapID: UInt, val name: String) { +class ServiceAreaClusterMapStruct( + val mapID: UInt, + val name: String +) { override fun toString(): String = buildString { append("ServiceAreaClusterMapStruct {\n") append("\tmapID : $mapID\n") @@ -47,7 +52,7 @@ class ServiceAreaClusterMapStruct(val mapID: UInt, val name: String) { tlvReader.enterStructure(tlvTag) val mapID = tlvReader.getUInt(ContextSpecificTag(TAG_MAP_ID)) val name = tlvReader.getString(ContextSpecificTag(TAG_NAME)) - + tlvReader.exitContainer() return ServiceAreaClusterMapStruct(mapID, name) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ServiceAreaClusterProgressStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ServiceAreaClusterProgressStruct.kt index 02b16f17cd101d..8e322fdfcd223f 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ServiceAreaClusterProgressStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ServiceAreaClusterProgressStruct.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -27,7 +28,7 @@ class ServiceAreaClusterProgressStruct( val areaID: UInt, val status: UByte, val totalOperationalTime: Optional?, - val estimatedTime: Optional?, + val estimatedTime: Optional? ) { override fun toString(): String = buildString { append("ServiceAreaClusterProgressStruct {\n") @@ -45,17 +46,17 @@ class ServiceAreaClusterProgressStruct( put(ContextSpecificTag(TAG_STATUS), status) if (totalOperationalTime != null) { if (totalOperationalTime.isPresent) { - val opttotalOperationalTime = totalOperationalTime.get() - put(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME), opttotalOperationalTime) - } + val opttotalOperationalTime = totalOperationalTime.get() + put(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME), opttotalOperationalTime) + } } else { putNull(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME)) } if (estimatedTime != null) { if (estimatedTime.isPresent) { - val optestimatedTime = estimatedTime.get() - put(ContextSpecificTag(TAG_ESTIMATED_TIME), optestimatedTime) - } + val optestimatedTime = estimatedTime.get() + put(ContextSpecificTag(TAG_ESTIMATED_TIME), optestimatedTime) + } } else { putNull(ContextSpecificTag(TAG_ESTIMATED_TIME)) } @@ -73,29 +74,27 @@ class ServiceAreaClusterProgressStruct( tlvReader.enterStructure(tlvTag) val areaID = tlvReader.getUInt(ContextSpecificTag(TAG_AREA_ID)) val status = tlvReader.getUByte(ContextSpecificTag(TAG_STATUS)) - val totalOperationalTime = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME)) - null - } - val estimatedTime = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_ESTIMATED_TIME))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_ESTIMATED_TIME))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_ESTIMATED_TIME)) - null - } - + val totalOperationalTime = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME)) + null + } + val estimatedTime = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_ESTIMATED_TIME))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_ESTIMATED_TIME))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_ESTIMATED_TIME)) + null + } + tlvReader.exitContainer() return ServiceAreaClusterProgressStruct(areaID, status, totalOperationalTime, estimatedTime) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/SoftwareDiagnosticsClusterThreadMetricsStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/SoftwareDiagnosticsClusterThreadMetricsStruct.kt index 3ddcff494d0580..75b362e21df943 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/SoftwareDiagnosticsClusterThreadMetricsStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/SoftwareDiagnosticsClusterThreadMetricsStruct.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -28,7 +29,7 @@ class SoftwareDiagnosticsClusterThreadMetricsStruct( val name: Optional, val stackFreeCurrent: Optional, val stackFreeMinimum: Optional, - val stackSize: Optional, + val stackSize: Optional ) { override fun toString(): String = buildString { append("SoftwareDiagnosticsClusterThreadMetricsStruct {\n") @@ -74,40 +75,30 @@ class SoftwareDiagnosticsClusterThreadMetricsStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): SoftwareDiagnosticsClusterThreadMetricsStruct { tlvReader.enterStructure(tlvTag) val id = tlvReader.getULong(ContextSpecificTag(TAG_ID)) - val name = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_NAME))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_NAME))) - } else { - Optional.empty() - } - val stackFreeCurrent = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_STACK_FREE_CURRENT))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_STACK_FREE_CURRENT))) - } else { - Optional.empty() - } - val stackFreeMinimum = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_STACK_FREE_MINIMUM))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_STACK_FREE_MINIMUM))) - } else { - Optional.empty() - } - val stackSize = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_STACK_SIZE))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_STACK_SIZE))) - } else { - Optional.empty() - } - + val name = if (tlvReader.isNextTag(ContextSpecificTag(TAG_NAME))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_NAME))) + } else { + Optional.empty() + } + val stackFreeCurrent = if (tlvReader.isNextTag(ContextSpecificTag(TAG_STACK_FREE_CURRENT))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_STACK_FREE_CURRENT))) + } else { + Optional.empty() + } + val stackFreeMinimum = if (tlvReader.isNextTag(ContextSpecificTag(TAG_STACK_FREE_MINIMUM))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_STACK_FREE_MINIMUM))) + } else { + Optional.empty() + } + val stackSize = if (tlvReader.isNextTag(ContextSpecificTag(TAG_STACK_SIZE))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_STACK_SIZE))) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return SoftwareDiagnosticsClusterThreadMetricsStruct( - id, - name, - stackFreeCurrent, - stackFreeMinimum, - stackSize, - ) + return SoftwareDiagnosticsClusterThreadMetricsStruct(id, name, stackFreeCurrent, stackFreeMinimum, stackSize) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/TargetNavigatorClusterTargetInfoStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/TargetNavigatorClusterTargetInfoStruct.kt index d1c115ff44e58e..804fa744fe4660 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/TargetNavigatorClusterTargetInfoStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/TargetNavigatorClusterTargetInfoStruct.kt @@ -16,13 +16,18 @@ */ package matter.controller.cluster.structs +import java.util.Optional 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 TargetNavigatorClusterTargetInfoStruct(val identifier: UByte, val name: String) { +class TargetNavigatorClusterTargetInfoStruct( + val identifier: UByte, + val name: String +) { override fun toString(): String = buildString { append("TargetNavigatorClusterTargetInfoStruct {\n") append("\tidentifier : $identifier\n") @@ -47,7 +52,7 @@ class TargetNavigatorClusterTargetInfoStruct(val identifier: UByte, val name: St tlvReader.enterStructure(tlvTag) val identifier = tlvReader.getUByte(ContextSpecificTag(TAG_IDENTIFIER)) val name = tlvReader.getString(ContextSpecificTag(TAG_NAME)) - + tlvReader.exitContainer() return TargetNavigatorClusterTargetInfoStruct(identifier, name) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterAtomicAttributeStatusStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterAtomicAttributeStatusStruct.kt index 42fc80b898b3b8..56527a73c80544 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterAtomicAttributeStatusStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterAtomicAttributeStatusStruct.kt @@ -16,13 +16,18 @@ */ package matter.controller.cluster.structs +import java.util.Optional 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 ThermostatClusterAtomicAttributeStatusStruct(val attributeID: UInt, val statusCode: UByte) { +class ThermostatClusterAtomicAttributeStatusStruct( + val attributeID: UInt, + val statusCode: UByte +) { override fun toString(): String = buildString { append("ThermostatClusterAtomicAttributeStatusStruct {\n") append("\tattributeID : $attributeID\n") @@ -47,7 +52,7 @@ class ThermostatClusterAtomicAttributeStatusStruct(val attributeID: UInt, val st tlvReader.enterStructure(tlvTag) val attributeID = tlvReader.getUInt(ContextSpecificTag(TAG_ATTRIBUTE_ID)) val statusCode = tlvReader.getUByte(ContextSpecificTag(TAG_STATUS_CODE)) - + tlvReader.exitContainer() return ThermostatClusterAtomicAttributeStatusStruct(attributeID, statusCode) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterPresetStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterPresetStruct.kt index ede9623aa74fbb..be590ab0cbc7f8 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterPresetStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterPresetStruct.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -29,7 +30,7 @@ class ThermostatClusterPresetStruct( val name: Optional?, val coolingSetpoint: Optional, val heatingSetpoint: Optional, - val builtIn: Boolean?, + val builtIn: Boolean? ) { override fun toString(): String = buildString { append("ThermostatClusterPresetStruct {\n") @@ -53,9 +54,9 @@ class ThermostatClusterPresetStruct( put(ContextSpecificTag(TAG_PRESET_SCENARIO), presetScenario) if (name != null) { if (name.isPresent) { - val optname = name.get() - put(ContextSpecificTag(TAG_NAME), optname) - } + val optname = name.get() + put(ContextSpecificTag(TAG_NAME), optname) + } } else { putNull(ContextSpecificTag(TAG_NAME)) } @@ -86,55 +87,43 @@ class ThermostatClusterPresetStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ThermostatClusterPresetStruct { tlvReader.enterStructure(tlvTag) - val presetHandle = - if (!tlvReader.isNull()) { - tlvReader.getByteArray(ContextSpecificTag(TAG_PRESET_HANDLE)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_PRESET_HANDLE)) - null - } + val presetHandle = if (!tlvReader.isNull()) { + tlvReader.getByteArray(ContextSpecificTag(TAG_PRESET_HANDLE)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_PRESET_HANDLE)) + null + } val presetScenario = tlvReader.getUByte(ContextSpecificTag(TAG_PRESET_SCENARIO)) - val name = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_NAME))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_NAME))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_NAME)) - null - } - val coolingSetpoint = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_COOLING_SETPOINT))) { - Optional.of(tlvReader.getShort(ContextSpecificTag(TAG_COOLING_SETPOINT))) - } else { - Optional.empty() - } - val heatingSetpoint = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_HEATING_SETPOINT))) { - Optional.of(tlvReader.getShort(ContextSpecificTag(TAG_HEATING_SETPOINT))) - } else { - Optional.empty() - } - val builtIn = - if (!tlvReader.isNull()) { - tlvReader.getBoolean(ContextSpecificTag(TAG_BUILT_IN)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_BUILT_IN)) - null - } - + val name = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_NAME))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_NAME))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_NAME)) + null + } + val coolingSetpoint = if (tlvReader.isNextTag(ContextSpecificTag(TAG_COOLING_SETPOINT))) { + Optional.of(tlvReader.getShort(ContextSpecificTag(TAG_COOLING_SETPOINT))) + } else { + Optional.empty() + } + val heatingSetpoint = if (tlvReader.isNextTag(ContextSpecificTag(TAG_HEATING_SETPOINT))) { + Optional.of(tlvReader.getShort(ContextSpecificTag(TAG_HEATING_SETPOINT))) + } else { + Optional.empty() + } + val builtIn = if (!tlvReader.isNull()) { + tlvReader.getBoolean(ContextSpecificTag(TAG_BUILT_IN)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_BUILT_IN)) + null + } + tlvReader.exitContainer() - return ThermostatClusterPresetStruct( - presetHandle, - presetScenario, - name, - coolingSetpoint, - heatingSetpoint, - builtIn, - ) + return ThermostatClusterPresetStruct(presetHandle, presetScenario, name, coolingSetpoint, heatingSetpoint, builtIn) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterPresetTypeStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterPresetTypeStruct.kt index d0a100321f278d..e9d029d6a542f3 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterPresetTypeStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterPresetTypeStruct.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -25,7 +27,7 @@ import matter.tlv.TlvWriter class ThermostatClusterPresetTypeStruct( val presetScenario: UByte, val numberOfPresets: UByte, - val presetTypeFeatures: UShort, + val presetTypeFeatures: UShort ) { override fun toString(): String = buildString { append("ThermostatClusterPresetTypeStruct {\n") @@ -55,7 +57,7 @@ class ThermostatClusterPresetTypeStruct( val presetScenario = tlvReader.getUByte(ContextSpecificTag(TAG_PRESET_SCENARIO)) val numberOfPresets = tlvReader.getUByte(ContextSpecificTag(TAG_NUMBER_OF_PRESETS)) val presetTypeFeatures = tlvReader.getUShort(ContextSpecificTag(TAG_PRESET_TYPE_FEATURES)) - + tlvReader.exitContainer() return ThermostatClusterPresetTypeStruct(presetScenario, numberOfPresets, presetTypeFeatures) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterScheduleStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterScheduleStruct.kt index 90ca5ab50b6514..57f20a9bd42299 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterScheduleStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterScheduleStruct.kt @@ -30,7 +30,7 @@ class ThermostatClusterScheduleStruct( val name: Optional, val presetHandle: Optional, val transitions: List, - val builtIn: Boolean?, + val builtIn: Boolean? ) { override fun toString(): String = buildString { append("ThermostatClusterScheduleStruct {\n") @@ -84,52 +84,40 @@ class ThermostatClusterScheduleStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ThermostatClusterScheduleStruct { tlvReader.enterStructure(tlvTag) - val scheduleHandle = - if (!tlvReader.isNull()) { - tlvReader.getByteArray(ContextSpecificTag(TAG_SCHEDULE_HANDLE)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_SCHEDULE_HANDLE)) - null - } + val scheduleHandle = if (!tlvReader.isNull()) { + tlvReader.getByteArray(ContextSpecificTag(TAG_SCHEDULE_HANDLE)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_SCHEDULE_HANDLE)) + null + } val systemMode = tlvReader.getUByte(ContextSpecificTag(TAG_SYSTEM_MODE)) - val name = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_NAME))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_NAME))) - } else { - Optional.empty() - } - val presetHandle = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_PRESET_HANDLE))) { - Optional.of(tlvReader.getByteArray(ContextSpecificTag(TAG_PRESET_HANDLE))) - } else { - Optional.empty() - } - val transitions = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_TRANSITIONS)) - while (!tlvReader.isEndOfContainer()) { - add(ThermostatClusterScheduleTransitionStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - val builtIn = - if (!tlvReader.isNull()) { - tlvReader.getBoolean(ContextSpecificTag(TAG_BUILT_IN)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_BUILT_IN)) - null - } - + val name = if (tlvReader.isNextTag(ContextSpecificTag(TAG_NAME))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_NAME))) + } else { + Optional.empty() + } + val presetHandle = if (tlvReader.isNextTag(ContextSpecificTag(TAG_PRESET_HANDLE))) { + Optional.of(tlvReader.getByteArray(ContextSpecificTag(TAG_PRESET_HANDLE))) + } else { + Optional.empty() + } + val transitions = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_TRANSITIONS)) + while(!tlvReader.isEndOfContainer()) { + add(ThermostatClusterScheduleTransitionStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + val builtIn = if (!tlvReader.isNull()) { + tlvReader.getBoolean(ContextSpecificTag(TAG_BUILT_IN)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_BUILT_IN)) + null + } + tlvReader.exitContainer() - return ThermostatClusterScheduleStruct( - scheduleHandle, - systemMode, - name, - presetHandle, - transitions, - builtIn, - ) + return ThermostatClusterScheduleStruct(scheduleHandle, systemMode, name, presetHandle, transitions, builtIn) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterScheduleTransitionStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterScheduleTransitionStruct.kt index 5bcc01a15d4f90..1bd8bfe8cbf3be 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterScheduleTransitionStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterScheduleTransitionStruct.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -29,7 +30,7 @@ class ThermostatClusterScheduleTransitionStruct( val presetHandle: Optional, val systemMode: Optional, val coolingSetpoint: Optional, - val heatingSetpoint: Optional, + val heatingSetpoint: Optional ) { override fun toString(): String = buildString { append("ThermostatClusterScheduleTransitionStruct {\n") @@ -79,41 +80,30 @@ class ThermostatClusterScheduleTransitionStruct( tlvReader.enterStructure(tlvTag) val dayOfWeek = tlvReader.getUByte(ContextSpecificTag(TAG_DAY_OF_WEEK)) val transitionTime = tlvReader.getUShort(ContextSpecificTag(TAG_TRANSITION_TIME)) - val presetHandle = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_PRESET_HANDLE))) { - Optional.of(tlvReader.getByteArray(ContextSpecificTag(TAG_PRESET_HANDLE))) - } else { - Optional.empty() - } - val systemMode = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_SYSTEM_MODE))) { - Optional.of(tlvReader.getUByte(ContextSpecificTag(TAG_SYSTEM_MODE))) - } else { - Optional.empty() - } - val coolingSetpoint = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_COOLING_SETPOINT))) { - Optional.of(tlvReader.getShort(ContextSpecificTag(TAG_COOLING_SETPOINT))) - } else { - Optional.empty() - } - val heatingSetpoint = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_HEATING_SETPOINT))) { - Optional.of(tlvReader.getShort(ContextSpecificTag(TAG_HEATING_SETPOINT))) - } else { - Optional.empty() - } - + val presetHandle = if (tlvReader.isNextTag(ContextSpecificTag(TAG_PRESET_HANDLE))) { + Optional.of(tlvReader.getByteArray(ContextSpecificTag(TAG_PRESET_HANDLE))) + } else { + Optional.empty() + } + val systemMode = if (tlvReader.isNextTag(ContextSpecificTag(TAG_SYSTEM_MODE))) { + Optional.of(tlvReader.getUByte(ContextSpecificTag(TAG_SYSTEM_MODE))) + } else { + Optional.empty() + } + val coolingSetpoint = if (tlvReader.isNextTag(ContextSpecificTag(TAG_COOLING_SETPOINT))) { + Optional.of(tlvReader.getShort(ContextSpecificTag(TAG_COOLING_SETPOINT))) + } else { + Optional.empty() + } + val heatingSetpoint = if (tlvReader.isNextTag(ContextSpecificTag(TAG_HEATING_SETPOINT))) { + Optional.of(tlvReader.getShort(ContextSpecificTag(TAG_HEATING_SETPOINT))) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return ThermostatClusterScheduleTransitionStruct( - dayOfWeek, - transitionTime, - presetHandle, - systemMode, - coolingSetpoint, - heatingSetpoint, - ) + return ThermostatClusterScheduleTransitionStruct(dayOfWeek, transitionTime, presetHandle, systemMode, coolingSetpoint, heatingSetpoint) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterScheduleTypeStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterScheduleTypeStruct.kt index 4c9a9b879477b9..781f9fdd1aee97 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterScheduleTypeStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterScheduleTypeStruct.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -25,7 +27,7 @@ import matter.tlv.TlvWriter class ThermostatClusterScheduleTypeStruct( val systemMode: UByte, val numberOfSchedules: UByte, - val scheduleTypeFeatures: UShort, + val scheduleTypeFeatures: UShort ) { override fun toString(): String = buildString { append("ThermostatClusterScheduleTypeStruct {\n") @@ -55,14 +57,10 @@ class ThermostatClusterScheduleTypeStruct( val systemMode = tlvReader.getUByte(ContextSpecificTag(TAG_SYSTEM_MODE)) val numberOfSchedules = tlvReader.getUByte(ContextSpecificTag(TAG_NUMBER_OF_SCHEDULES)) val scheduleTypeFeatures = tlvReader.getUShort(ContextSpecificTag(TAG_SCHEDULE_TYPE_FEATURES)) - + tlvReader.exitContainer() - return ThermostatClusterScheduleTypeStruct( - systemMode, - numberOfSchedules, - scheduleTypeFeatures, - ) + return ThermostatClusterScheduleTypeStruct(systemMode, numberOfSchedules, scheduleTypeFeatures) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterWeeklyScheduleTransitionStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterWeeklyScheduleTransitionStruct.kt index f3c6dd6260c386..98721edcba9faa 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterWeeklyScheduleTransitionStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterWeeklyScheduleTransitionStruct.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -25,7 +27,7 @@ import matter.tlv.TlvWriter class ThermostatClusterWeeklyScheduleTransitionStruct( val transitionTime: UShort, val heatSetpoint: Short?, - val coolSetpoint: Short?, + val coolSetpoint: Short? ) { override fun toString(): String = buildString { append("ThermostatClusterWeeklyScheduleTransitionStruct {\n") @@ -58,34 +60,25 @@ class ThermostatClusterWeeklyScheduleTransitionStruct( private const val TAG_HEAT_SETPOINT = 1 private const val TAG_COOL_SETPOINT = 2 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): ThermostatClusterWeeklyScheduleTransitionStruct { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ThermostatClusterWeeklyScheduleTransitionStruct { tlvReader.enterStructure(tlvTag) val transitionTime = tlvReader.getUShort(ContextSpecificTag(TAG_TRANSITION_TIME)) - val heatSetpoint = - if (!tlvReader.isNull()) { - tlvReader.getShort(ContextSpecificTag(TAG_HEAT_SETPOINT)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_HEAT_SETPOINT)) - null - } - val coolSetpoint = - if (!tlvReader.isNull()) { - tlvReader.getShort(ContextSpecificTag(TAG_COOL_SETPOINT)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_COOL_SETPOINT)) - null - } - + val heatSetpoint = if (!tlvReader.isNull()) { + tlvReader.getShort(ContextSpecificTag(TAG_HEAT_SETPOINT)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_HEAT_SETPOINT)) + null + } + val coolSetpoint = if (!tlvReader.isNull()) { + tlvReader.getShort(ContextSpecificTag(TAG_COOL_SETPOINT)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_COOL_SETPOINT)) + null + } + tlvReader.exitContainer() - return ThermostatClusterWeeklyScheduleTransitionStruct( - transitionTime, - heatSetpoint, - coolSetpoint, - ) + return ThermostatClusterWeeklyScheduleTransitionStruct(transitionTime, heatSetpoint, coolSetpoint) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ThreadNetworkDiagnosticsClusterNeighborTableStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ThreadNetworkDiagnosticsClusterNeighborTableStruct.kt index 1804582d9d3402..21ee03ed5e51b3 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ThreadNetworkDiagnosticsClusterNeighborTableStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ThreadNetworkDiagnosticsClusterNeighborTableStruct.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -36,7 +38,7 @@ class ThreadNetworkDiagnosticsClusterNeighborTableStruct( val rxOnWhenIdle: Boolean, val fullThreadDevice: Boolean, val fullNetworkData: Boolean, - val isChild: Boolean, + val isChild: Boolean ) { override fun toString(): String = buildString { append("ThreadNetworkDiagnosticsClusterNeighborTableStruct {\n") @@ -102,10 +104,7 @@ class ThreadNetworkDiagnosticsClusterNeighborTableStruct( private const val TAG_FULL_NETWORK_DATA = 12 private const val TAG_IS_CHILD = 13 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): ThreadNetworkDiagnosticsClusterNeighborTableStruct { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ThreadNetworkDiagnosticsClusterNeighborTableStruct { tlvReader.enterStructure(tlvTag) val extAddress = tlvReader.getULong(ContextSpecificTag(TAG_EXT_ADDRESS)) val age = tlvReader.getUInt(ContextSpecificTag(TAG_AGE)) @@ -113,45 +112,28 @@ class ThreadNetworkDiagnosticsClusterNeighborTableStruct( val linkFrameCounter = tlvReader.getUInt(ContextSpecificTag(TAG_LINK_FRAME_COUNTER)) val mleFrameCounter = tlvReader.getUInt(ContextSpecificTag(TAG_MLE_FRAME_COUNTER)) val lqi = tlvReader.getUByte(ContextSpecificTag(TAG_LQI)) - val averageRssi = - if (!tlvReader.isNull()) { - tlvReader.getByte(ContextSpecificTag(TAG_AVERAGE_RSSI)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_AVERAGE_RSSI)) - null - } - val lastRssi = - if (!tlvReader.isNull()) { - tlvReader.getByte(ContextSpecificTag(TAG_LAST_RSSI)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_LAST_RSSI)) - null - } + val averageRssi = if (!tlvReader.isNull()) { + tlvReader.getByte(ContextSpecificTag(TAG_AVERAGE_RSSI)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_AVERAGE_RSSI)) + null + } + val lastRssi = if (!tlvReader.isNull()) { + tlvReader.getByte(ContextSpecificTag(TAG_LAST_RSSI)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_LAST_RSSI)) + null + } val frameErrorRate = tlvReader.getUByte(ContextSpecificTag(TAG_FRAME_ERROR_RATE)) val messageErrorRate = tlvReader.getUByte(ContextSpecificTag(TAG_MESSAGE_ERROR_RATE)) val rxOnWhenIdle = tlvReader.getBoolean(ContextSpecificTag(TAG_RX_ON_WHEN_IDLE)) val fullThreadDevice = tlvReader.getBoolean(ContextSpecificTag(TAG_FULL_THREAD_DEVICE)) val fullNetworkData = tlvReader.getBoolean(ContextSpecificTag(TAG_FULL_NETWORK_DATA)) val isChild = tlvReader.getBoolean(ContextSpecificTag(TAG_IS_CHILD)) - + tlvReader.exitContainer() - return ThreadNetworkDiagnosticsClusterNeighborTableStruct( - extAddress, - age, - rloc16, - linkFrameCounter, - mleFrameCounter, - lqi, - averageRssi, - lastRssi, - frameErrorRate, - messageErrorRate, - rxOnWhenIdle, - fullThreadDevice, - fullNetworkData, - isChild, - ) + return ThreadNetworkDiagnosticsClusterNeighborTableStruct(extAddress, age, rloc16, linkFrameCounter, mleFrameCounter, lqi, averageRssi, lastRssi, frameErrorRate, messageErrorRate, rxOnWhenIdle, fullThreadDevice, fullNetworkData, isChild) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ThreadNetworkDiagnosticsClusterOperationalDatasetComponents.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ThreadNetworkDiagnosticsClusterOperationalDatasetComponents.kt index 167f1411d1c386..91975101984aaa 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ThreadNetworkDiagnosticsClusterOperationalDatasetComponents.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ThreadNetworkDiagnosticsClusterOperationalDatasetComponents.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -34,7 +36,7 @@ class ThreadNetworkDiagnosticsClusterOperationalDatasetComponents( val channelPresent: Boolean, val pskcPresent: Boolean, val securityPolicyPresent: Boolean, - val channelMaskPresent: Boolean, + val channelMaskPresent: Boolean ) { override fun toString(): String = buildString { append("ThreadNetworkDiagnosticsClusterOperationalDatasetComponents {\n") @@ -86,45 +88,24 @@ class ThreadNetworkDiagnosticsClusterOperationalDatasetComponents( private const val TAG_SECURITY_POLICY_PRESENT = 10 private const val TAG_CHANNEL_MASK_PRESENT = 11 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): ThreadNetworkDiagnosticsClusterOperationalDatasetComponents { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ThreadNetworkDiagnosticsClusterOperationalDatasetComponents { tlvReader.enterStructure(tlvTag) - val activeTimestampPresent = - tlvReader.getBoolean(ContextSpecificTag(TAG_ACTIVE_TIMESTAMP_PRESENT)) - val pendingTimestampPresent = - tlvReader.getBoolean(ContextSpecificTag(TAG_PENDING_TIMESTAMP_PRESENT)) + val activeTimestampPresent = tlvReader.getBoolean(ContextSpecificTag(TAG_ACTIVE_TIMESTAMP_PRESENT)) + val pendingTimestampPresent = tlvReader.getBoolean(ContextSpecificTag(TAG_PENDING_TIMESTAMP_PRESENT)) val masterKeyPresent = tlvReader.getBoolean(ContextSpecificTag(TAG_MASTER_KEY_PRESENT)) val networkNamePresent = tlvReader.getBoolean(ContextSpecificTag(TAG_NETWORK_NAME_PRESENT)) - val extendedPanIdPresent = - tlvReader.getBoolean(ContextSpecificTag(TAG_EXTENDED_PAN_ID_PRESENT)) - val meshLocalPrefixPresent = - tlvReader.getBoolean(ContextSpecificTag(TAG_MESH_LOCAL_PREFIX_PRESENT)) + val extendedPanIdPresent = tlvReader.getBoolean(ContextSpecificTag(TAG_EXTENDED_PAN_ID_PRESENT)) + val meshLocalPrefixPresent = tlvReader.getBoolean(ContextSpecificTag(TAG_MESH_LOCAL_PREFIX_PRESENT)) val delayPresent = tlvReader.getBoolean(ContextSpecificTag(TAG_DELAY_PRESENT)) val panIdPresent = tlvReader.getBoolean(ContextSpecificTag(TAG_PAN_ID_PRESENT)) val channelPresent = tlvReader.getBoolean(ContextSpecificTag(TAG_CHANNEL_PRESENT)) val pskcPresent = tlvReader.getBoolean(ContextSpecificTag(TAG_PSKC_PRESENT)) - val securityPolicyPresent = - tlvReader.getBoolean(ContextSpecificTag(TAG_SECURITY_POLICY_PRESENT)) + val securityPolicyPresent = tlvReader.getBoolean(ContextSpecificTag(TAG_SECURITY_POLICY_PRESENT)) val channelMaskPresent = tlvReader.getBoolean(ContextSpecificTag(TAG_CHANNEL_MASK_PRESENT)) - + tlvReader.exitContainer() - return ThreadNetworkDiagnosticsClusterOperationalDatasetComponents( - activeTimestampPresent, - pendingTimestampPresent, - masterKeyPresent, - networkNamePresent, - extendedPanIdPresent, - meshLocalPrefixPresent, - delayPresent, - panIdPresent, - channelPresent, - pskcPresent, - securityPolicyPresent, - channelMaskPresent, - ) + return ThreadNetworkDiagnosticsClusterOperationalDatasetComponents(activeTimestampPresent, pendingTimestampPresent, masterKeyPresent, networkNamePresent, extendedPanIdPresent, meshLocalPrefixPresent, delayPresent, panIdPresent, channelPresent, pskcPresent, securityPolicyPresent, channelMaskPresent) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ThreadNetworkDiagnosticsClusterRouteTableStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ThreadNetworkDiagnosticsClusterRouteTableStruct.kt index 86860ea6803c82..1d9802bca85da4 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ThreadNetworkDiagnosticsClusterRouteTableStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ThreadNetworkDiagnosticsClusterRouteTableStruct.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -32,7 +34,7 @@ class ThreadNetworkDiagnosticsClusterRouteTableStruct( val LQIOut: UByte, val age: UByte, val allocated: Boolean, - val linkEstablished: Boolean, + val linkEstablished: Boolean ) { override fun toString(): String = buildString { append("ThreadNetworkDiagnosticsClusterRouteTableStruct {\n") @@ -78,10 +80,7 @@ class ThreadNetworkDiagnosticsClusterRouteTableStruct( private const val TAG_ALLOCATED = 8 private const val TAG_LINK_ESTABLISHED = 9 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): ThreadNetworkDiagnosticsClusterRouteTableStruct { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ThreadNetworkDiagnosticsClusterRouteTableStruct { tlvReader.enterStructure(tlvTag) val extAddress = tlvReader.getULong(ContextSpecificTag(TAG_EXT_ADDRESS)) val rloc16 = tlvReader.getUShort(ContextSpecificTag(TAG_RLOC16)) @@ -93,21 +92,10 @@ class ThreadNetworkDiagnosticsClusterRouteTableStruct( val age = tlvReader.getUByte(ContextSpecificTag(TAG_AGE)) val allocated = tlvReader.getBoolean(ContextSpecificTag(TAG_ALLOCATED)) val linkEstablished = tlvReader.getBoolean(ContextSpecificTag(TAG_LINK_ESTABLISHED)) - + tlvReader.exitContainer() - return ThreadNetworkDiagnosticsClusterRouteTableStruct( - extAddress, - rloc16, - routerId, - nextHop, - pathCost, - LQIIn, - LQIOut, - age, - allocated, - linkEstablished, - ) + return ThreadNetworkDiagnosticsClusterRouteTableStruct(extAddress, rloc16, routerId, nextHop, pathCost, LQIIn, LQIOut, age, allocated, linkEstablished) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ThreadNetworkDiagnosticsClusterSecurityPolicy.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ThreadNetworkDiagnosticsClusterSecurityPolicy.kt index 720cdd6c854a72..3228a78b13b000 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ThreadNetworkDiagnosticsClusterSecurityPolicy.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ThreadNetworkDiagnosticsClusterSecurityPolicy.kt @@ -16,13 +16,18 @@ */ package matter.controller.cluster.structs +import java.util.Optional 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 ThreadNetworkDiagnosticsClusterSecurityPolicy(val rotationTime: UShort, val flags: UShort) { +class ThreadNetworkDiagnosticsClusterSecurityPolicy( + val rotationTime: UShort, + val flags: UShort +) { override fun toString(): String = buildString { append("ThreadNetworkDiagnosticsClusterSecurityPolicy {\n") append("\trotationTime : $rotationTime\n") @@ -47,7 +52,7 @@ class ThreadNetworkDiagnosticsClusterSecurityPolicy(val rotationTime: UShort, va tlvReader.enterStructure(tlvTag) val rotationTime = tlvReader.getUShort(ContextSpecificTag(TAG_ROTATION_TIME)) val flags = tlvReader.getUShort(ContextSpecificTag(TAG_FLAGS)) - + tlvReader.exitContainer() return ThreadNetworkDiagnosticsClusterSecurityPolicy(rotationTime, flags) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ThreadNetworkDirectoryClusterThreadNetworkStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ThreadNetworkDirectoryClusterThreadNetworkStruct.kt index 04f8c6abcd3ba8..cf60e4f50d8a7a 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ThreadNetworkDirectoryClusterThreadNetworkStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ThreadNetworkDirectoryClusterThreadNetworkStruct.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +28,7 @@ class ThreadNetworkDirectoryClusterThreadNetworkStruct( val extendedPanID: ByteArray, val networkName: String, val channel: UShort, - val activeTimestamp: ULong, + val activeTimestamp: ULong ) { override fun toString(): String = buildString { append("ThreadNetworkDirectoryClusterThreadNetworkStruct {\n") @@ -54,24 +56,16 @@ class ThreadNetworkDirectoryClusterThreadNetworkStruct( private const val TAG_CHANNEL = 2 private const val TAG_ACTIVE_TIMESTAMP = 3 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): ThreadNetworkDirectoryClusterThreadNetworkStruct { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ThreadNetworkDirectoryClusterThreadNetworkStruct { tlvReader.enterStructure(tlvTag) val extendedPanID = tlvReader.getByteArray(ContextSpecificTag(TAG_EXTENDED_PAN_ID)) val networkName = tlvReader.getString(ContextSpecificTag(TAG_NETWORK_NAME)) val channel = tlvReader.getUShort(ContextSpecificTag(TAG_CHANNEL)) val activeTimestamp = tlvReader.getULong(ContextSpecificTag(TAG_ACTIVE_TIMESTAMP)) - + tlvReader.exitContainer() - return ThreadNetworkDirectoryClusterThreadNetworkStruct( - extendedPanID, - networkName, - channel, - activeTimestamp, - ) + return ThreadNetworkDirectoryClusterThreadNetworkStruct(extendedPanID, networkName, channel, activeTimestamp) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/TimeSynchronizationClusterDSTOffsetStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/TimeSynchronizationClusterDSTOffsetStruct.kt index a40f9fb0c74943..366d9e19dc429b 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/TimeSynchronizationClusterDSTOffsetStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/TimeSynchronizationClusterDSTOffsetStruct.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -25,7 +27,7 @@ import matter.tlv.TlvWriter class TimeSynchronizationClusterDSTOffsetStruct( val offset: Int, val validStarting: ULong, - val validUntil: ULong?, + val validUntil: ULong? ) { override fun toString(): String = buildString { append("TimeSynchronizationClusterDSTOffsetStruct {\n") @@ -58,14 +60,13 @@ class TimeSynchronizationClusterDSTOffsetStruct( tlvReader.enterStructure(tlvTag) val offset = tlvReader.getInt(ContextSpecificTag(TAG_OFFSET)) val validStarting = tlvReader.getULong(ContextSpecificTag(TAG_VALID_STARTING)) - val validUntil = - if (!tlvReader.isNull()) { - tlvReader.getULong(ContextSpecificTag(TAG_VALID_UNTIL)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_VALID_UNTIL)) - null - } - + val validUntil = if (!tlvReader.isNull()) { + tlvReader.getULong(ContextSpecificTag(TAG_VALID_UNTIL)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_VALID_UNTIL)) + null + } + tlvReader.exitContainer() return TimeSynchronizationClusterDSTOffsetStruct(offset, validStarting, validUntil) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/TimeSynchronizationClusterFabricScopedTrustedTimeSourceStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/TimeSynchronizationClusterFabricScopedTrustedTimeSourceStruct.kt index f294cfbe427ee1..d1393bff247d8a 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/TimeSynchronizationClusterFabricScopedTrustedTimeSourceStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/TimeSynchronizationClusterFabricScopedTrustedTimeSourceStruct.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -24,7 +26,7 @@ import matter.tlv.TlvWriter class TimeSynchronizationClusterFabricScopedTrustedTimeSourceStruct( val nodeID: ULong, - val endpoint: UShort, + val endpoint: UShort ) { override fun toString(): String = buildString { append("TimeSynchronizationClusterFabricScopedTrustedTimeSourceStruct {\n") @@ -46,14 +48,11 @@ class TimeSynchronizationClusterFabricScopedTrustedTimeSourceStruct( private const val TAG_NODE_ID = 0 private const val TAG_ENDPOINT = 1 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): TimeSynchronizationClusterFabricScopedTrustedTimeSourceStruct { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): TimeSynchronizationClusterFabricScopedTrustedTimeSourceStruct { tlvReader.enterStructure(tlvTag) val nodeID = tlvReader.getULong(ContextSpecificTag(TAG_NODE_ID)) val endpoint = tlvReader.getUShort(ContextSpecificTag(TAG_ENDPOINT)) - + tlvReader.exitContainer() return TimeSynchronizationClusterFabricScopedTrustedTimeSourceStruct(nodeID, endpoint) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/TimeSynchronizationClusterTimeZoneStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/TimeSynchronizationClusterTimeZoneStruct.kt index 91ad83d2624a76..d8b7a7a33d130e 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/TimeSynchronizationClusterTimeZoneStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/TimeSynchronizationClusterTimeZoneStruct.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +27,7 @@ import matter.tlv.TlvWriter class TimeSynchronizationClusterTimeZoneStruct( val offset: Int, val validAt: ULong, - val name: Optional, + val name: Optional ) { override fun toString(): String = buildString { append("TimeSynchronizationClusterTimeZoneStruct {\n") @@ -58,13 +59,12 @@ class TimeSynchronizationClusterTimeZoneStruct( tlvReader.enterStructure(tlvTag) val offset = tlvReader.getInt(ContextSpecificTag(TAG_OFFSET)) val validAt = tlvReader.getULong(ContextSpecificTag(TAG_VALID_AT)) - val name = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_NAME))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_NAME))) - } else { - Optional.empty() - } - + val name = if (tlvReader.isNextTag(ContextSpecificTag(TAG_NAME))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_NAME))) + } else { + Optional.empty() + } + tlvReader.exitContainer() return TimeSynchronizationClusterTimeZoneStruct(offset, validAt, name) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/TimeSynchronizationClusterTrustedTimeSourceStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/TimeSynchronizationClusterTrustedTimeSourceStruct.kt index 215bb8c35d2e57..290f507604c31f 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/TimeSynchronizationClusterTrustedTimeSourceStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/TimeSynchronizationClusterTrustedTimeSourceStruct.kt @@ -16,7 +16,9 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -25,7 +27,7 @@ import matter.tlv.TlvWriter class TimeSynchronizationClusterTrustedTimeSourceStruct( val fabricIndex: UByte, val nodeID: ULong, - val endpoint: UShort, + val endpoint: UShort ) { override fun toString(): String = buildString { append("TimeSynchronizationClusterTrustedTimeSourceStruct {\n") @@ -50,15 +52,12 @@ class TimeSynchronizationClusterTrustedTimeSourceStruct( private const val TAG_NODE_ID = 1 private const val TAG_ENDPOINT = 2 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): TimeSynchronizationClusterTrustedTimeSourceStruct { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): TimeSynchronizationClusterTrustedTimeSourceStruct { tlvReader.enterStructure(tlvTag) val fabricIndex = tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) val nodeID = tlvReader.getULong(ContextSpecificTag(TAG_NODE_ID)) val endpoint = tlvReader.getUShort(ContextSpecificTag(TAG_ENDPOINT)) - + tlvReader.exitContainer() return TimeSynchronizationClusterTrustedTimeSourceStruct(fabricIndex, nodeID, endpoint) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterDoubleNestedStructList.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterDoubleNestedStructList.kt index b308907db2a90c..a78f035f9d5e70 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterDoubleNestedStructList.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterDoubleNestedStructList.kt @@ -16,6 +16,7 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -23,7 +24,9 @@ import matter.tlv.Tag import matter.tlv.TlvReader import matter.tlv.TlvWriter -class UnitTestingClusterDoubleNestedStructList(val a: List) { +class UnitTestingClusterDoubleNestedStructList( + val a: List +) { override fun toString(): String = buildString { append("UnitTestingClusterDoubleNestedStructList {\n") append("\ta : $a\n") @@ -47,15 +50,14 @@ class UnitTestingClusterDoubleNestedStructList(val a: List { - tlvReader.enterArray(ContextSpecificTag(TAG_A)) - while (!tlvReader.isEndOfContainer()) { - add(UnitTestingClusterNestedStructList.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - + val a = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_A)) + while(!tlvReader.isEndOfContainer()) { + add(UnitTestingClusterNestedStructList.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + tlvReader.exitContainer() return UnitTestingClusterDoubleNestedStructList(a) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterNestedStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterNestedStruct.kt index d57a0432a7c7ed..f208e28093e2b6 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterNestedStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterNestedStruct.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -27,7 +28,7 @@ class UnitTestingClusterNestedStruct( val a: UByte, val b: Boolean, val c: UnitTestingClusterSimpleStruct, - val d: Optional, + val d: Optional ) { override fun toString(): String = buildString { append("UnitTestingClusterNestedStruct {\n") @@ -63,15 +64,12 @@ class UnitTestingClusterNestedStruct( val a = tlvReader.getUByte(ContextSpecificTag(TAG_A)) val b = tlvReader.getBoolean(ContextSpecificTag(TAG_B)) val c = UnitTestingClusterSimpleStruct.fromTlv(ContextSpecificTag(TAG_C), tlvReader) - val d = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_D))) { - Optional.of( - UnitTestingClusterTestGlobalStruct.fromTlv(ContextSpecificTag(TAG_D), tlvReader) - ) - } else { - Optional.empty() - } - + val d = if (tlvReader.isNextTag(ContextSpecificTag(TAG_D))) { + Optional.of(UnitTestingClusterTestGlobalStruct.fromTlv(ContextSpecificTag(TAG_D), tlvReader)) + } else { + Optional.empty() + } + tlvReader.exitContainer() return UnitTestingClusterNestedStruct(a, b, c, d) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterNestedStructList.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterNestedStructList.kt index fe1df8f2f231e6..653e0e8f3a39d8 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterNestedStructList.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterNestedStructList.kt @@ -16,6 +16,7 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -30,7 +31,7 @@ class UnitTestingClusterNestedStructList( val d: List, val e: List, val f: List, - val g: List, + val g: List ) { override fun toString(): String = buildString { append("UnitTestingClusterNestedStructList {\n") @@ -88,39 +89,35 @@ class UnitTestingClusterNestedStructList( val a = tlvReader.getUByte(ContextSpecificTag(TAG_A)) val b = tlvReader.getBoolean(ContextSpecificTag(TAG_B)) val c = UnitTestingClusterSimpleStruct.fromTlv(ContextSpecificTag(TAG_C), tlvReader) - val d = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_D)) - while (!tlvReader.isEndOfContainer()) { - add(UnitTestingClusterSimpleStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - val e = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_E)) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getUInt(AnonymousTag)) - } - tlvReader.exitContainer() - } - val f = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_F)) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getByteArray(AnonymousTag)) - } - tlvReader.exitContainer() - } - val g = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_G)) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } - + val d = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_D)) + while(!tlvReader.isEndOfContainer()) { + add(UnitTestingClusterSimpleStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + val e = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_E)) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } + val f = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_F)) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getByteArray(AnonymousTag)) + } + tlvReader.exitContainer() + } + val g = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_G)) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + tlvReader.exitContainer() return UnitTestingClusterNestedStructList(a, b, c, d, e, f, g) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterNullablesAndOptionalsStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterNullablesAndOptionalsStruct.kt index a0bbb707e46a51..279d19e7f4ed48 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterNullablesAndOptionalsStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterNullablesAndOptionalsStruct.kt @@ -36,7 +36,7 @@ class UnitTestingClusterNullablesAndOptionalsStruct( val nullableOptionalStruct: Optional?, val nullableList: List?, val optionalList: Optional>, - val nullableOptionalList: Optional>?, + val nullableOptionalList: Optional>? ) { override fun toString(): String = buildString { append("UnitTestingClusterNullablesAndOptionalsStruct {\n") @@ -69,9 +69,9 @@ class UnitTestingClusterNullablesAndOptionalsStruct( } if (nullableOptionalInt != null) { if (nullableOptionalInt.isPresent) { - val optnullableOptionalInt = nullableOptionalInt.get() - put(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_INT), optnullableOptionalInt) - } + val optnullableOptionalInt = nullableOptionalInt.get() + put(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_INT), optnullableOptionalInt) + } } else { putNull(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_INT)) } @@ -86,9 +86,9 @@ class UnitTestingClusterNullablesAndOptionalsStruct( } if (nullableOptionalString != null) { if (nullableOptionalString.isPresent) { - val optnullableOptionalString = nullableOptionalString.get() - put(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRING), optnullableOptionalString) - } + val optnullableOptionalString = nullableOptionalString.get() + put(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRING), optnullableOptionalString) + } } else { putNull(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRING)) } @@ -103,38 +103,38 @@ class UnitTestingClusterNullablesAndOptionalsStruct( } if (nullableOptionalStruct != null) { if (nullableOptionalStruct.isPresent) { - val optnullableOptionalStruct = nullableOptionalStruct.get() - optnullableOptionalStruct.toTlv(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRUCT), this) - } + val optnullableOptionalStruct = nullableOptionalStruct.get() + optnullableOptionalStruct.toTlv(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRUCT), this) + } } else { putNull(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRUCT)) } if (nullableList != null) { startArray(ContextSpecificTag(TAG_NULLABLE_LIST)) - for (item in nullableList.iterator()) { - put(AnonymousTag, item) - } - endArray() + for (item in nullableList.iterator()) { + put(AnonymousTag, item) + } + endArray() } else { putNull(ContextSpecificTag(TAG_NULLABLE_LIST)) } if (optionalList.isPresent) { val optoptionalList = optionalList.get() startArray(ContextSpecificTag(TAG_OPTIONAL_LIST)) - for (item in optoptionalList.iterator()) { - put(AnonymousTag, item) - } - endArray() + for (item in optoptionalList.iterator()) { + put(AnonymousTag, item) + } + endArray() } if (nullableOptionalList != null) { if (nullableOptionalList.isPresent) { - val optnullableOptionalList = nullableOptionalList.get() - startArray(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_LIST)) - for (item in optnullableOptionalList.iterator()) { - put(AnonymousTag, item) - } - endArray() - } + val optnullableOptionalList = nullableOptionalList.get() + startArray(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_LIST)) + for (item in optnullableOptionalList.iterator()) { + put(AnonymousTag, item) + } + endArray() + } } else { putNull(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_LIST)) } @@ -158,151 +158,112 @@ class UnitTestingClusterNullablesAndOptionalsStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): UnitTestingClusterNullablesAndOptionalsStruct { tlvReader.enterStructure(tlvTag) - val nullableInt = - if (!tlvReader.isNull()) { - tlvReader.getUShort(ContextSpecificTag(TAG_NULLABLE_INT)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_NULLABLE_INT)) - null - } - val optionalInt = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_OPTIONAL_INT))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_OPTIONAL_INT))) - } else { - Optional.empty() - } - val nullableOptionalInt = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_INT))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_INT))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_INT)) - null - } - val nullableString = - if (!tlvReader.isNull()) { - tlvReader.getString(ContextSpecificTag(TAG_NULLABLE_STRING)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_NULLABLE_STRING)) - null - } - val optionalString = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_OPTIONAL_STRING))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_OPTIONAL_STRING))) - } else { - Optional.empty() - } - val nullableOptionalString = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRING))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRING))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRING)) - null - } - val nullableStruct = - if (!tlvReader.isNull()) { - UnitTestingClusterSimpleStruct.fromTlv(ContextSpecificTag(TAG_NULLABLE_STRUCT), tlvReader) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_NULLABLE_STRUCT)) - null - } - val optionalStruct = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_OPTIONAL_STRUCT))) { - Optional.of( - UnitTestingClusterSimpleStruct.fromTlv( - ContextSpecificTag(TAG_OPTIONAL_STRUCT), - tlvReader, - ) - ) - } else { - Optional.empty() - } - val nullableOptionalStruct = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRUCT))) { - Optional.of( - UnitTestingClusterSimpleStruct.fromTlv( - ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRUCT), - tlvReader, - ) - ) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRUCT)) - null - } - val nullableList = - if (!tlvReader.isNull()) { - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_NULLABLE_LIST)) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_NULLABLE_LIST)) - null - } - val optionalList = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_OPTIONAL_LIST))) { - Optional.of( - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_OPTIONAL_LIST)) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } - ) - } else { - Optional.empty() - } - val nullableOptionalList = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_LIST))) { - Optional.of( - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_LIST)) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } - ) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_LIST)) - null - } - + val nullableInt = if (!tlvReader.isNull()) { + tlvReader.getUShort(ContextSpecificTag(TAG_NULLABLE_INT)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_NULLABLE_INT)) + null + } + val optionalInt = if (tlvReader.isNextTag(ContextSpecificTag(TAG_OPTIONAL_INT))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_OPTIONAL_INT))) + } else { + Optional.empty() + } + val nullableOptionalInt = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_INT))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_INT))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_INT)) + null + } + val nullableString = if (!tlvReader.isNull()) { + tlvReader.getString(ContextSpecificTag(TAG_NULLABLE_STRING)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_NULLABLE_STRING)) + null + } + val optionalString = if (tlvReader.isNextTag(ContextSpecificTag(TAG_OPTIONAL_STRING))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_OPTIONAL_STRING))) + } else { + Optional.empty() + } + val nullableOptionalString = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRING))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRING))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRING)) + null + } + val nullableStruct = if (!tlvReader.isNull()) { + UnitTestingClusterSimpleStruct.fromTlv(ContextSpecificTag(TAG_NULLABLE_STRUCT), tlvReader) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_NULLABLE_STRUCT)) + null + } + val optionalStruct = if (tlvReader.isNextTag(ContextSpecificTag(TAG_OPTIONAL_STRUCT))) { + Optional.of(UnitTestingClusterSimpleStruct.fromTlv(ContextSpecificTag(TAG_OPTIONAL_STRUCT), tlvReader)) + } else { + Optional.empty() + } + val nullableOptionalStruct = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRUCT))) { + Optional.of(UnitTestingClusterSimpleStruct.fromTlv(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRUCT), tlvReader)) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRUCT)) + null + } + val nullableList = if (!tlvReader.isNull()) { + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_NULLABLE_LIST)) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_NULLABLE_LIST)) + null + } + val optionalList = if (tlvReader.isNextTag(ContextSpecificTag(TAG_OPTIONAL_LIST))) { + Optional.of(buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_OPTIONAL_LIST)) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + }) + } else { + Optional.empty() + } + val nullableOptionalList = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_LIST))) { + Optional.of(buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_LIST)) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + }) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_LIST)) + null + } + tlvReader.exitContainer() - return UnitTestingClusterNullablesAndOptionalsStruct( - nullableInt, - optionalInt, - nullableOptionalInt, - nullableString, - optionalString, - nullableOptionalString, - nullableStruct, - optionalStruct, - nullableOptionalStruct, - nullableList, - optionalList, - nullableOptionalList, - ) + return UnitTestingClusterNullablesAndOptionalsStruct(nullableInt, optionalInt, nullableOptionalInt, nullableString, optionalString, nullableOptionalString, nullableStruct, optionalStruct, nullableOptionalStruct, nullableList, optionalList, nullableOptionalList) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterSimpleStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterSimpleStruct.kt index 722445efea8504..d591b816461da2 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterSimpleStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterSimpleStruct.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -32,7 +33,7 @@ class UnitTestingClusterSimpleStruct( val f: UByte, val g: Float, val h: Double, - val i: Optional, + val i: Optional ) { override fun toString(): String = buildString { append("UnitTestingClusterSimpleStruct {\n") @@ -88,13 +89,12 @@ class UnitTestingClusterSimpleStruct( val f = tlvReader.getUByte(ContextSpecificTag(TAG_F)) val g = tlvReader.getFloat(ContextSpecificTag(TAG_G)) val h = tlvReader.getDouble(ContextSpecificTag(TAG_H)) - val i = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_I))) { - Optional.of(tlvReader.getUByte(ContextSpecificTag(TAG_I))) - } else { - Optional.empty() - } - + val i = if (tlvReader.isNextTag(ContextSpecificTag(TAG_I))) { + Optional.of(tlvReader.getUByte(ContextSpecificTag(TAG_I))) + } else { + Optional.empty() + } + tlvReader.exitContainer() return UnitTestingClusterSimpleStruct(a, b, c, d, e, f, g, h, i) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterTestFabricScoped.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterTestFabricScoped.kt index b6196f58d7546a..1f38827ddec220 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterTestFabricScoped.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterTestFabricScoped.kt @@ -32,7 +32,7 @@ class UnitTestingClusterTestFabricScoped( val fabricSensitiveCharString: String, val fabricSensitiveStruct: UnitTestingClusterSimpleStruct, val fabricSensitiveInt8uList: List, - val fabricIndex: UByte, + val fabricIndex: UByte ) { override fun toString(): String = buildString { append("UnitTestingClusterTestFabricScoped {\n") @@ -53,10 +53,7 @@ class UnitTestingClusterTestFabricScoped( put(ContextSpecificTag(TAG_FABRIC_SENSITIVE_INT8U), fabricSensitiveInt8u) if (optionalFabricSensitiveInt8u.isPresent) { val optoptionalFabricSensitiveInt8u = optionalFabricSensitiveInt8u.get() - put( - ContextSpecificTag(TAG_OPTIONAL_FABRIC_SENSITIVE_INT8U), - optoptionalFabricSensitiveInt8u, - ) + put(ContextSpecificTag(TAG_OPTIONAL_FABRIC_SENSITIVE_INT8U), optoptionalFabricSensitiveInt8u) } if (nullableFabricSensitiveInt8u != null) { put(ContextSpecificTag(TAG_NULLABLE_FABRIC_SENSITIVE_INT8U), nullableFabricSensitiveInt8u) @@ -65,12 +62,9 @@ class UnitTestingClusterTestFabricScoped( } if (nullableOptionalFabricSensitiveInt8u != null) { if (nullableOptionalFabricSensitiveInt8u.isPresent) { - val optnullableOptionalFabricSensitiveInt8u = nullableOptionalFabricSensitiveInt8u.get() - put( - ContextSpecificTag(TAG_NULLABLE_OPTIONAL_FABRIC_SENSITIVE_INT8U), - optnullableOptionalFabricSensitiveInt8u, - ) - } + val optnullableOptionalFabricSensitiveInt8u = nullableOptionalFabricSensitiveInt8u.get() + put(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_FABRIC_SENSITIVE_INT8U), optnullableOptionalFabricSensitiveInt8u) + } } else { putNull(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_FABRIC_SENSITIVE_INT8U)) } @@ -99,63 +93,41 @@ class UnitTestingClusterTestFabricScoped( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): UnitTestingClusterTestFabricScoped { tlvReader.enterStructure(tlvTag) val fabricSensitiveInt8u = tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_SENSITIVE_INT8U)) - val optionalFabricSensitiveInt8u = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_OPTIONAL_FABRIC_SENSITIVE_INT8U))) { - Optional.of(tlvReader.getUByte(ContextSpecificTag(TAG_OPTIONAL_FABRIC_SENSITIVE_INT8U))) - } else { - Optional.empty() - } - val nullableFabricSensitiveInt8u = - if (!tlvReader.isNull()) { - tlvReader.getUByte(ContextSpecificTag(TAG_NULLABLE_FABRIC_SENSITIVE_INT8U)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_NULLABLE_FABRIC_SENSITIVE_INT8U)) - null - } - val nullableOptionalFabricSensitiveInt8u = - if (!tlvReader.isNull()) { - if ( - tlvReader.isNextTag(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_FABRIC_SENSITIVE_INT8U)) - ) { - Optional.of( - tlvReader.getUByte(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_FABRIC_SENSITIVE_INT8U)) - ) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_FABRIC_SENSITIVE_INT8U)) - null - } - val fabricSensitiveCharString = - tlvReader.getString(ContextSpecificTag(TAG_FABRIC_SENSITIVE_CHAR_STRING)) - val fabricSensitiveStruct = - UnitTestingClusterSimpleStruct.fromTlv( - ContextSpecificTag(TAG_FABRIC_SENSITIVE_STRUCT), - tlvReader, - ) - val fabricSensitiveInt8uList = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_FABRIC_SENSITIVE_INT8U_LIST)) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } + val optionalFabricSensitiveInt8u = if (tlvReader.isNextTag(ContextSpecificTag(TAG_OPTIONAL_FABRIC_SENSITIVE_INT8U))) { + Optional.of(tlvReader.getUByte(ContextSpecificTag(TAG_OPTIONAL_FABRIC_SENSITIVE_INT8U))) + } else { + Optional.empty() + } + val nullableFabricSensitiveInt8u = if (!tlvReader.isNull()) { + tlvReader.getUByte(ContextSpecificTag(TAG_NULLABLE_FABRIC_SENSITIVE_INT8U)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_NULLABLE_FABRIC_SENSITIVE_INT8U)) + null + } + val nullableOptionalFabricSensitiveInt8u = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_FABRIC_SENSITIVE_INT8U))) { + Optional.of(tlvReader.getUByte(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_FABRIC_SENSITIVE_INT8U))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_FABRIC_SENSITIVE_INT8U)) + null + } + val fabricSensitiveCharString = tlvReader.getString(ContextSpecificTag(TAG_FABRIC_SENSITIVE_CHAR_STRING)) + val fabricSensitiveStruct = UnitTestingClusterSimpleStruct.fromTlv(ContextSpecificTag(TAG_FABRIC_SENSITIVE_STRUCT), tlvReader) + val fabricSensitiveInt8uList = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_FABRIC_SENSITIVE_INT8U_LIST)) + while(!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } val fabricIndex = tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) - + tlvReader.exitContainer() - return UnitTestingClusterTestFabricScoped( - fabricSensitiveInt8u, - optionalFabricSensitiveInt8u, - nullableFabricSensitiveInt8u, - nullableOptionalFabricSensitiveInt8u, - fabricSensitiveCharString, - fabricSensitiveStruct, - fabricSensitiveInt8uList, - fabricIndex, - ) + return UnitTestingClusterTestFabricScoped(fabricSensitiveInt8u, optionalFabricSensitiveInt8u, nullableFabricSensitiveInt8u, nullableOptionalFabricSensitiveInt8u, fabricSensitiveCharString, fabricSensitiveStruct, fabricSensitiveInt8uList, fabricIndex) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterTestGlobalStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterTestGlobalStruct.kt index 66caded2c08ab3..2f80d7a22c226d 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterTestGlobalStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterTestGlobalStruct.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +27,7 @@ import matter.tlv.TlvWriter class UnitTestingClusterTestGlobalStruct( val name: String, val myBitmap: UInt?, - val myEnum: Optional?, + val myEnum: Optional? ) { override fun toString(): String = buildString { append("UnitTestingClusterTestGlobalStruct {\n") @@ -47,9 +48,9 @@ class UnitTestingClusterTestGlobalStruct( } if (myEnum != null) { if (myEnum.isPresent) { - val optmyEnum = myEnum.get() - put(ContextSpecificTag(TAG_MY_ENUM), optmyEnum) - } + val optmyEnum = myEnum.get() + put(ContextSpecificTag(TAG_MY_ENUM), optmyEnum) + } } else { putNull(ContextSpecificTag(TAG_MY_ENUM)) } @@ -65,25 +66,23 @@ class UnitTestingClusterTestGlobalStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): UnitTestingClusterTestGlobalStruct { tlvReader.enterStructure(tlvTag) val name = tlvReader.getString(ContextSpecificTag(TAG_NAME)) - val myBitmap = - if (!tlvReader.isNull()) { - tlvReader.getUInt(ContextSpecificTag(TAG_MY_BITMAP)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_MY_BITMAP)) - null - } - val myEnum = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_MY_ENUM))) { - Optional.of(tlvReader.getUByte(ContextSpecificTag(TAG_MY_ENUM))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_MY_ENUM)) - null - } - + val myBitmap = if (!tlvReader.isNull()) { + tlvReader.getUInt(ContextSpecificTag(TAG_MY_BITMAP)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_MY_BITMAP)) + null + } + val myEnum = if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_MY_ENUM))) { + Optional.of(tlvReader.getUByte(ContextSpecificTag(TAG_MY_ENUM))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_MY_ENUM)) + null + } + tlvReader.exitContainer() return UnitTestingClusterTestGlobalStruct(name, myBitmap, myEnum) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterTestListStructOctet.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterTestListStructOctet.kt index 9a7f7d3ba58b08..5478f2bd44b175 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterTestListStructOctet.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterTestListStructOctet.kt @@ -16,13 +16,18 @@ */ package matter.controller.cluster.structs +import java.util.Optional 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 UnitTestingClusterTestListStructOctet(val member1: ULong, val member2: ByteArray) { +class UnitTestingClusterTestListStructOctet( + val member1: ULong, + val member2: ByteArray +) { override fun toString(): String = buildString { append("UnitTestingClusterTestListStructOctet {\n") append("\tmember1 : $member1\n") @@ -47,7 +52,7 @@ class UnitTestingClusterTestListStructOctet(val member1: ULong, val member2: Byt tlvReader.enterStructure(tlvTag) val member1 = tlvReader.getULong(ContextSpecificTag(TAG_MEMBER1)) val member2 = tlvReader.getByteArray(ContextSpecificTag(TAG_MEMBER2)) - + tlvReader.exitContainer() return UnitTestingClusterTestListStructOctet(member1, member2) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/UserLabelClusterLabelStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/UserLabelClusterLabelStruct.kt index 8840aec05a78bd..fd4efa9375bbe4 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/UserLabelClusterLabelStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/UserLabelClusterLabelStruct.kt @@ -16,13 +16,18 @@ */ package matter.controller.cluster.structs +import java.util.Optional 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 UserLabelClusterLabelStruct(val label: String, val value: String) { +class UserLabelClusterLabelStruct( + val label: String, + val value: String +) { override fun toString(): String = buildString { append("UserLabelClusterLabelStruct {\n") append("\tlabel : $label\n") @@ -47,7 +52,7 @@ class UserLabelClusterLabelStruct(val label: String, val value: String) { tlvReader.enterStructure(tlvTag) val label = tlvReader.getString(ContextSpecificTag(TAG_LABEL)) val value = tlvReader.getString(ContextSpecificTag(TAG_VALUE)) - + tlvReader.exitContainer() return UserLabelClusterLabelStruct(label, value) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/WaterHeaterManagementClusterWaterHeaterBoostInfoStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/WaterHeaterManagementClusterWaterHeaterBoostInfoStruct.kt index 0b2fede4f1537a..ef90bea8b30b6c 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/WaterHeaterManagementClusterWaterHeaterBoostInfoStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/WaterHeaterManagementClusterWaterHeaterBoostInfoStruct.kt @@ -18,6 +18,7 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* +import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -29,7 +30,7 @@ class WaterHeaterManagementClusterWaterHeaterBoostInfoStruct( val emergencyBoost: Optional, val temporarySetpoint: Optional, val targetPercentage: Optional, - val targetReheat: Optional, + val targetReheat: Optional ) { override fun toString(): String = buildString { append("WaterHeaterManagementClusterWaterHeaterBoostInfoStruct {\n") @@ -78,53 +79,38 @@ class WaterHeaterManagementClusterWaterHeaterBoostInfoStruct( private const val TAG_TARGET_PERCENTAGE = 4 private const val TAG_TARGET_REHEAT = 5 - fun fromTlv( - tlvTag: Tag, - tlvReader: TlvReader, - ): WaterHeaterManagementClusterWaterHeaterBoostInfoStruct { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): WaterHeaterManagementClusterWaterHeaterBoostInfoStruct { tlvReader.enterStructure(tlvTag) val duration = tlvReader.getUInt(ContextSpecificTag(TAG_DURATION)) - val oneShot = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_ONE_SHOT))) { - Optional.of(tlvReader.getBoolean(ContextSpecificTag(TAG_ONE_SHOT))) - } else { - Optional.empty() - } - val emergencyBoost = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_EMERGENCY_BOOST))) { - Optional.of(tlvReader.getBoolean(ContextSpecificTag(TAG_EMERGENCY_BOOST))) - } else { - Optional.empty() - } - val temporarySetpoint = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_TEMPORARY_SETPOINT))) { - Optional.of(tlvReader.getShort(ContextSpecificTag(TAG_TEMPORARY_SETPOINT))) - } else { - Optional.empty() - } - val targetPercentage = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_TARGET_PERCENTAGE))) { - Optional.of(tlvReader.getUByte(ContextSpecificTag(TAG_TARGET_PERCENTAGE))) - } else { - Optional.empty() - } - val targetReheat = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_TARGET_REHEAT))) { - Optional.of(tlvReader.getUByte(ContextSpecificTag(TAG_TARGET_REHEAT))) - } else { - Optional.empty() - } - + val oneShot = if (tlvReader.isNextTag(ContextSpecificTag(TAG_ONE_SHOT))) { + Optional.of(tlvReader.getBoolean(ContextSpecificTag(TAG_ONE_SHOT))) + } else { + Optional.empty() + } + val emergencyBoost = if (tlvReader.isNextTag(ContextSpecificTag(TAG_EMERGENCY_BOOST))) { + Optional.of(tlvReader.getBoolean(ContextSpecificTag(TAG_EMERGENCY_BOOST))) + } else { + Optional.empty() + } + val temporarySetpoint = if (tlvReader.isNextTag(ContextSpecificTag(TAG_TEMPORARY_SETPOINT))) { + Optional.of(tlvReader.getShort(ContextSpecificTag(TAG_TEMPORARY_SETPOINT))) + } else { + Optional.empty() + } + val targetPercentage = if (tlvReader.isNextTag(ContextSpecificTag(TAG_TARGET_PERCENTAGE))) { + Optional.of(tlvReader.getUByte(ContextSpecificTag(TAG_TARGET_PERCENTAGE))) + } else { + Optional.empty() + } + val targetReheat = if (tlvReader.isNextTag(ContextSpecificTag(TAG_TARGET_REHEAT))) { + Optional.of(tlvReader.getUByte(ContextSpecificTag(TAG_TARGET_REHEAT))) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return WaterHeaterManagementClusterWaterHeaterBoostInfoStruct( - duration, - oneShot, - emergencyBoost, - temporarySetpoint, - targetPercentage, - targetReheat, - ) + return WaterHeaterManagementClusterWaterHeaterBoostInfoStruct(duration, oneShot, emergencyBoost, temporarySetpoint, targetPercentage, targetReheat) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/WaterHeaterModeClusterModeOptionStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/WaterHeaterModeClusterModeOptionStruct.kt index 52252bf6e4cc56..05c0c4a36421cc 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/WaterHeaterModeClusterModeOptionStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/WaterHeaterModeClusterModeOptionStruct.kt @@ -16,6 +16,7 @@ */ package matter.controller.cluster.structs +import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -26,7 +27,7 @@ import matter.tlv.TlvWriter class WaterHeaterModeClusterModeOptionStruct( val label: String, val mode: UByte, - val modeTags: List, + val modeTags: List ) { override fun toString(): String = buildString { append("WaterHeaterModeClusterModeOptionStruct {\n") @@ -59,15 +60,14 @@ class WaterHeaterModeClusterModeOptionStruct( tlvReader.enterStructure(tlvTag) val label = tlvReader.getString(ContextSpecificTag(TAG_LABEL)) val mode = tlvReader.getUByte(ContextSpecificTag(TAG_MODE)) - val modeTags = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_MODE_TAGS)) - while (!tlvReader.isEndOfContainer()) { - add(WaterHeaterModeClusterModeTagStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - + val modeTags = buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_MODE_TAGS)) + while(!tlvReader.isEndOfContainer()) { + add(WaterHeaterModeClusterModeTagStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + tlvReader.exitContainer() return WaterHeaterModeClusterModeOptionStruct(label, mode, modeTags) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/WaterHeaterModeClusterModeTagStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/WaterHeaterModeClusterModeTagStruct.kt index fc91c1389574ab..42c4cea0a93cd2 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/WaterHeaterModeClusterModeTagStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/WaterHeaterModeClusterModeTagStruct.kt @@ -18,12 +18,16 @@ package matter.controller.cluster.structs import java.util.Optional 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 WaterHeaterModeClusterModeTagStruct(val mfgCode: Optional, val value: UShort) { +class WaterHeaterModeClusterModeTagStruct( + val mfgCode: Optional, + val value: UShort +) { override fun toString(): String = buildString { append("WaterHeaterModeClusterModeTagStruct {\n") append("\tmfgCode : $mfgCode\n") @@ -49,14 +53,13 @@ class WaterHeaterModeClusterModeTagStruct(val mfgCode: Optional, val val fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): WaterHeaterModeClusterModeTagStruct { tlvReader.enterStructure(tlvTag) - val mfgCode = - if (tlvReader.isNextTag(ContextSpecificTag(TAG_MFG_CODE))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_MFG_CODE))) - } else { - Optional.empty() - } + val mfgCode = if (tlvReader.isNextTag(ContextSpecificTag(TAG_MFG_CODE))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_MFG_CODE))) + } else { + Optional.empty() + } val value = tlvReader.getUShort(ContextSpecificTag(TAG_VALUE)) - + tlvReader.exitContainer() return WaterHeaterModeClusterModeTagStruct(mfgCode, value) From 75411a6e203ab776e3fb84cd89506a4fe71db227 Mon Sep 17 00:00:00 2001 From: pcoleman Date: Thu, 22 Aug 2024 06:11:09 +0100 Subject: [PATCH 13/45] Get DEM 1.1 test passing --- src/python_testing/TC_DEM_1_1.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/python_testing/TC_DEM_1_1.py b/src/python_testing/TC_DEM_1_1.py index ba18b7eb34f454..fdcc4585d66925 100644 --- a/src/python_testing/TC_DEM_1_1.py +++ b/src/python_testing/TC_DEM_1_1.py @@ -23,7 +23,7 @@ # test-runner-run/run1/app: ${ENERGY_MANAGEMENT_APP} # test-runner-run/run1/factoryreset: True # test-runner-run/run1/quiet: True -# test-runner-run/run1/app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json --enable-key 000102030405060708090a0b0c0d0e0f --featureSet 0x23 +# test-runner-run/run1/app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json --enable-key 000102030405060708090a0b0c0d0e0f --featureSet 0x7f # test-runner-run/run1/script-args: --storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --hex-arg enableKey:000102030405060708090a0b0c0d0e0f --endpoint 1 --trace-to json:${TRACE_TEST_JSON}.json --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto # === END CI TEST ARGUMENTS === @@ -86,15 +86,15 @@ async def test_TC_DEM_1_1(self): self.step("2") await self.check_dem_attribute("ClusterRevision", 4) - self.step("3") - #await self.validate_feature_map([Clusters.DeviceEnergyManagement.Bitmaps.Feature.kForecastAdjustment, - # Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerForecastReporting], - # [Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerAdjustment, - # Clusters.DeviceEnergyManagement.Bitmaps.Feature.kStateForecastReporting, - # Clusters.DeviceEnergyManagement.Bitmaps.Feature.kStartTimeAdjustment, - # Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPausable, - # Clusters.DeviceEnergyManagement.Bitmaps.Feature.kConstraintBasedAdjustment]) + await self.validate_feature_map([Clusters.DeviceEnergyManagement.Bitmaps.Feature.kForecastAdjustment, + Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerForecastReporting, + Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerAdjustment, + Clusters.DeviceEnergyManagement.Bitmaps.Feature.kStateForecastReporting, + Clusters.DeviceEnergyManagement.Bitmaps.Feature.kStartTimeAdjustment, + Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPausable, + Clusters.DeviceEnergyManagement.Bitmaps.Feature.kConstraintBasedAdjustment], + []) self.step("4") attribute_list = await self.read_dem_attribute_expect_success(attribute="AttributeList") @@ -152,10 +152,8 @@ async def test_TC_DEM_1_1(self): asserts.assert_equal(len(attribute_list), 0) self.step("5") - #event_list = await self.read_dem_attribute_expect_success(attribute="EventList") - #logging.info(f"event_list {event_list}") + logging.info(f"Not supported/skipped") - #n- 0x00, 0x01: SHALL be included if and only if DEM.S.F00(PowerAdjustment).\n- 0x02, 0x03: SHALL be included if and only if DEM.S.F04(Pausable)."), self.step("6") accepted_command_list = await self.read_dem_attribute_expect_success(attribute="AcceptedCommandList") logging.info(f"accepted_command_list {accepted_command_list}") From 951bab683e95213611c3d5884a216f113487954c Mon Sep 17 00:00:00 2001 From: pcoleman Date: Thu, 22 Aug 2024 06:42:01 +0100 Subject: [PATCH 14/45] Update test step definitions --- src/python_testing/TC_DEM_1_1.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/python_testing/TC_DEM_1_1.py b/src/python_testing/TC_DEM_1_1.py index fdcc4585d66925..53ca55f4bdd229 100644 --- a/src/python_testing/TC_DEM_1_1.py +++ b/src/python_testing/TC_DEM_1_1.py @@ -65,11 +65,11 @@ def steps_TC_DEM_1_1(self) -> list[TestStep]: TestStep("3", "TH reads from the DUT the FeatureMap attribute.", "Verify that the DUT response contains the FeatureMap attribute and have the following bit set:\n- bit 0: SHALL be 1 if and only if DEM.S.F00(PowerAdjustment).\n- bit 1: SHALL be 1 if and only if DEM.S.F01(PowerForecastReporting).\n- bit 2: SHALL be 1 if and only if DEM.S.F02(StateForecastReporting).\n- bit 3: SHALL be 1 if and only if DEM.S.F03(StartTimeAdjustment).\n- bit 4: SHALL be 1 if and only if DEM.S.F04(Pausable).\nAll remaining bits SHALL be 0. Provisional features DEM.S.F05(ForecastAdjustment) and DEM.S.F06(ConstraintBasedAdjustment) must not be supported."), TestStep("4", "TH reads from the DUT the AttributeList attribute.", - "Verify that the DUT response contains the AttributeList attribute and have the list of supported attributes:\nThe list SHALL include all the mandatory entries: +\n0x0000, 0x0001, 0x0002, 0x0003, 0x0004\n0xfff8, 0xfff9, 0xfffb, 0xfffc and 0xfffd.\nThe list includes entries based on feature support: +\n- 0x0005: SHALL be included if and only if DEM.S.F00(PowerAdjustment).\nDEM.S.F02(StateForecastReporting).\n- 0x0007: SHALL be included if and only if DEM.S.F00(PowerAdjustment)"), + "Verify that the DUT response contains the AttributeList attribute and have the list of supported attributes:\nThe list SHALL include all the mandatory entries: +\n0x0000, 0x0001, 0x0002, 0x0003, 0x0004\n0xfff8, 0xfff9, 0xfffb, 0xfffc and 0xfffd.\nThe list includes entries based on feature support: +\n- 0x0005: SHALL be included if and only if DEM.S.F00(PowerAdjustment).\n- 0x0006: SHALL be included if and only if DEM.S.F01(PowerForecastReporting) | DEM.S.F02(StateForecastReporting).\n- 0x0007: SHALL be included if and only if DEM.S.F00(PowerAdjustment) | DEM.S.F03(StartTimeAdjustment) | DEM.S.F04(Pausable) | DEM.S.F05(ForecastAdjustment) | DEM.S.F06(ConstraintBasedAdjustment)."), TestStep("5", "TH reads from the DUT the EventList attribute.", "Verify that the DUT response contains the EventList attribute and have the list of supported events:\nThe list includes entries based on feature support: +\n- 0x00, 0x01: SHALL be included if and only if DEM.S.F00(PowerAdjustment).\n- 0x02, 0x03: SHALL be included if and only if DEM.S.F04(Pausable)."), TestStep("6", "TH reads from the DUT the AcceptedCommandList attribute.", - "Verify that the DUT response contains the AcceptedCommandList attribute and have the list of Accepted Command:\nThe list includes entries based on feature support: +\n- 0x00, 0x01: SHALL be included if and only if DEM.S.F00(PowerAdjustment).\n- 0x02: SHALL be included if and only if DEM.S.F03(StartTimeAdjustment).\n- 0x03, 0x04: SHALL be included if and only if DEM.S.F04(Pausable).\n- 0x05: SHALL be included if and only if DEM.S.F05(ForecastAdjustment).\n- 0x06: SHALL be included if and only if DEM.S.F06(ConstraintBasedAdjustment).\n- 0x07: SHALL be included if and only if DEM.S.F03(StartTimeAdjustment)"), + "Verify that the DUT response contains the AcceptedCommandList attribute and have the list of Accepted Command:\nThe list includes entries based on feature support: +\n- 0x00, 0x01: SHALL be included if and only if DEM.S.F00(PowerAdjustment).\n- 0x02: SHALL be included if and only if DEM.S.F03(StartTimeAdjustment).\n- 0x03, 0x04: SHALL be included if and only if DEM.S.F04(Pausable).\n- 0x05: SHALL be included if and only if DEM.S.F05(ForecastAdjustment).\n- 0x06: SHALL be included if and only if DEM.S.F06(ConstraintBasedAdjustment).\n- 0x07: SHALL be included if and only if DEM.S.F03(StartTimeAdjustment)|DEM.S.F05(ForecastAdjustment)|DEM.S.F06(ConstraintBasedAdjustment)"), TestStep("7", "TH reads from the DUT the GeneratedCommandList attribute.", "Verify that the DUT response contains the GeneratedCommandList attribute and have the list of Generated Command:\nThis cluster has no entries in the standard or scoped range. +"), ] From b9a71439153e5bc52efe62165c8f2e4f3e4c763d Mon Sep 17 00:00:00 2001 From: pcoleman Date: Thu, 22 Aug 2024 06:51:32 +0100 Subject: [PATCH 15/45] Get featureSet option correct --- src/python_testing/TC_DEM_1_1.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/python_testing/TC_DEM_1_1.py b/src/python_testing/TC_DEM_1_1.py index 53ca55f4bdd229..1ed97cfb180a5d 100644 --- a/src/python_testing/TC_DEM_1_1.py +++ b/src/python_testing/TC_DEM_1_1.py @@ -23,7 +23,7 @@ # test-runner-run/run1/app: ${ENERGY_MANAGEMENT_APP} # test-runner-run/run1/factoryreset: True # test-runner-run/run1/quiet: True -# test-runner-run/run1/app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json --enable-key 000102030405060708090a0b0c0d0e0f --featureSet 0x7f +# test-runner-run/run1/app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json --enable-key 000102030405060708090a0b0c0d0e0f --featureSet 0x7b # test-runner-run/run1/script-args: --storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --hex-arg enableKey:000102030405060708090a0b0c0d0e0f --endpoint 1 --trace-to json:${TRACE_TEST_JSON}.json --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto # === END CI TEST ARGUMENTS === @@ -90,11 +90,10 @@ async def test_TC_DEM_1_1(self): await self.validate_feature_map([Clusters.DeviceEnergyManagement.Bitmaps.Feature.kForecastAdjustment, Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerForecastReporting, Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerAdjustment, - Clusters.DeviceEnergyManagement.Bitmaps.Feature.kStateForecastReporting, Clusters.DeviceEnergyManagement.Bitmaps.Feature.kStartTimeAdjustment, Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPausable, Clusters.DeviceEnergyManagement.Bitmaps.Feature.kConstraintBasedAdjustment], - []) + [Clusters.DeviceEnergyManagement.Bitmaps.Feature.kStateForecastReporting]) self.step("4") attribute_list = await self.read_dem_attribute_expect_success(attribute="AttributeList") From e52b7dab0dcaa05c452cba58bfb728f53a0f8e61 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 22 Aug 2024 05:52:09 +0000 Subject: [PATCH 16/45] Restyled by autopep8 --- src/python_testing/TC_DEM_1_1.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/python_testing/TC_DEM_1_1.py b/src/python_testing/TC_DEM_1_1.py index 1ed97cfb180a5d..d9eaadda07657a 100644 --- a/src/python_testing/TC_DEM_1_1.py +++ b/src/python_testing/TC_DEM_1_1.py @@ -192,7 +192,7 @@ async def test_TC_DEM_1_1(self): def check_attribute_valid_and_remove_from_list(self, attribute_id, feature_map, attribute_list, required_features): if feature_map & required_features: asserts.assert_true(attribute_id in attribute_list, - f"Expected to find attribute {attribute_id} in attribute_list {attribute_list} given feature_map 0x{feature_map:x}") + f"Expected to find attribute {attribute_id} in attribute_list {attribute_list} given feature_map 0x{feature_map:x}") attribute_list.remove(attribute_id) else: @@ -208,6 +208,8 @@ def check_expected_commands_in_list(self, expected_commands, feature_map, accept else: for command in expected_commands: asserts.assert_false(command in accepted_command_list, - f"Did not expect command {command} to be in accepted_command_list {accepted_command_list} given required_features {required_features} in feature_map 0x{feature_map:x}") + f"Did not expect command {command} to be in accepted_command_list {accepted_command_list} given required_features {required_features} in feature_map 0x{feature_map:x}") + + if __name__ == "__main__": default_matter_test_main() From 90b7aff0618952f61c49e6281a0f8d493bfd747f Mon Sep 17 00:00:00 2001 From: pcoleman Date: Thu, 22 Aug 2024 08:43:33 +0100 Subject: [PATCH 17/45] First cut of a Q quality test --- src/python_testing/TC_DEM_2_10.py | 153 ++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 src/python_testing/TC_DEM_2_10.py diff --git a/src/python_testing/TC_DEM_2_10.py b/src/python_testing/TC_DEM_2_10.py new file mode 100644 index 00000000000000..0be913e2194632 --- /dev/null +++ b/src/python_testing/TC_DEM_2_10.py @@ -0,0 +1,153 @@ +# +# Copyright (c) 2024 Project CHIP Authors +# All rights reserved. +# +# 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. +# pylint: disable=invalid-name + +# See https://github.com/project-chip/connectedhomeip/blob/master/docs/testing/python.md#defining-the-ci-test-arguments +# for details about the block below. +# +# === BEGIN CI TEST ARGUMENTS === +# test-runner-runs: run1 +# test-runner-run/run1/app: ${ENERGY_MANAGEMENT_APP} +# test-runner-run/run1/factoryreset: True +# test-runner-run/run1/quiet: True +# test-runner-run/run1/app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json --enable-key 000102030405060708090a0b0c0d0e0f --featureSet 0x7c +# test-runner-run/run1/script-args: --storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --hex-arg enableKey:000102030405060708090a0b0c0d0e0f --endpoint 1 --trace-to json:${TRACE_TEST_JSON}.json --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto +# === END CI TEST ARGUMENTS === + +"""Define Matter test case TC_DEM_2_10.""" + + +import logging +import datetime +import time + +import chip.clusters as Clusters +from chip.interaction_model import Status +from matter_testing_support import ClusterAttributeChangeAccumulator, MatterBaseTest, TestStep, async_test_body, default_matter_test_main +from mobly import asserts +from TC_DEMTestBase import DEMTestBase + +logger = logging.getLogger(__name__) + + +class TC_DEM_2_10(MatterBaseTest, DEMTestBase): + """Implementation of test case TC_DEM_2_10.""" + + def desc_TC_DEM_2_10(self) -> str: + """Return a description of this test.""" + return "4.1.3. [TC-DEM-2.10] This test case verifies attributes of the Device Energy Mangement cluster server having the Q quality." + + def pics_TC_DEM_2_10(self): + """Return the PICS definitions associated with this test.""" + pics = [ + # Depends on Feature 05 (ForecastAdjustment) & Feature 02 (StateForecastReporting) + "DEM.S.F05", "DEM.S.F02" + ] + return pics + + def steps_TC_DEM_2_10(self) -> list[TestStep]: + """Execute the test steps.""" + steps = [ + TestStep("1", "Commission DUT to TH"), + TestStep("2", "TH reads from the DUT the Featuremap attribute", + "Verify that the DUT response contains the Featuremap attribute. Verify ForecastAdjustment and StateForecastReporting is supported. Verify PowerForecastReporting is not supported."), + TestStep("3", "TH reads TestEventTriggersEnabled attribute from General Diagnostics Cluster", + "Value has to be 1 (True)"), + TestStep("4", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TESTEVENT_TRIGGERKEY and EventTrigger field set to PIXIT.DEM.TESTEVENTTRIGGER for Forecast Adjustment Test Event", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("4a", "TH reads from the DUT the ESAState", + "Value has to be 0x01 (Online)"), + TestStep("4b", "TH reads from the DUT the Forecast", + "Value has to include slots[0].MinDurationAdjustment, slots[0].MaxDurationAdjustment"), + TestStep("4c", "TH reads from the DUT the OptOutState", + "Value has to be 0x00 (NoOptOut)"), + TestStep("5", "Set up a subscription to the Forecast attribute, with MinIntervalFloor set to 0, MaxIntervalCeiling set to 10 and KeepSubscriptions set to false", + "Subscription successfully established"), + TestStep("6", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TESTEVENT_TRIGGERKEY and EventTrigger field set to PIXIT.DEM.TESTEVENTTRIGGER for User Opt-out Local Optimization Test Event", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("6a", "TH reads from the DUT the ESAState", + "Value has to be 0x01 (Online)"), + TestStep("6b", "TH reads from the DUT the OptOutState", + "Value has to be 0x02 (LocalOptOut)"), + TestStep("7", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, Duration=Forecast.Slots[0].MinDurationAdjustment}, Cause=GridOptimization", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("8", "TH counts all report transactions with an attribute report for the Forecast attribute over the next Forecast.Slots[0].MinDurationAdjustment}", + "TH verifies that numberOfReportsReceived <= 2 + Forecast.Slots[0].MinDurationAdjustment}"), + TestStep("9", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TESTEVENT_TRIGGERKEY and EventTrigger field set to PIXIT.DEM.TESTEVENTTRIGGER for Forecast Adjustment Test Event Clear", + "Verify DUT responds w/ status SUCCESS(0x00)"), + ] + + return steps + + @async_test_body + async def test_TC_DEM_2_10(self): + # pylint: disable=too-many-locals, too-many-statements + """Run the test steps.""" + self.step("1") + # Commission DUT - already done + + self.step("2") + await self.validate_feature_map([Clusters.DeviceEnergyManagement.Bitmaps.Feature.kForecastAdjustment, + Clusters.DeviceEnergyManagement.Bitmaps.Feature.kStateForecastReporting], + [Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerForecastReporting]) + + self.step("3") + await self.check_test_event_triggers_enabled() + + self.step("4") + await self.send_test_event_trigger_forecast_adjustment() + + self.step("4a") + await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kOnline) + + self.step("4b") + forecast = await self.read_dem_attribute_expect_success(attribute="Forecast") + asserts.assert_is_not_none(forecast.slots[0].minDurationAdjustment) + asserts.assert_is_not_none(forecast.slots[0].maxDurationAdjustment) + + self.step("4c") + await self.check_dem_attribute("OptOutState", Clusters.DeviceEnergyManagement.Enums.OptOutStateEnum.kNoOptOut) + + self.step("5") + sub_handler = ClusterAttributeChangeAccumulator(Clusters.DeviceEnergyManagement) + await sub_handler.start(self.default_controller, self.dut_node_id, self.matter_test_config.endpoint) + sub_handler.reset() + + self.step("6") + await self.send_test_event_trigger_user_opt_out_local() + + self.step("6a") + await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kOnline) + + self.step("6b") + await self.check_dem_attribute("OptOutState", Clusters.DeviceEnergyManagement.Enums.OptOutStateEnum.kLocalOptOut) + + self.step("7") + slotAdjustments = [Clusters.DeviceEnergyManagement.Structs.SlotAdjustmentStruct(slotIndex=0, duration=forecast.slots[0].minDurationAdjustment)] + await self.send_modify_forecast_request_command(forecast.forecastID, slotAdjustments, Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kGridOptimization, expected_status=Status.Success) + + self.step("8") + time.sleep(forecast.slots[0].minDurationAdjustment) + + count = sub_handler.attribute_report_counts[Clusters.DeviceEnergyManagement.Attributes.Forecast] + asserts.assert_less_equal(count, 10, "More than 10 reports received") + + self.step("9") + await self.send_test_event_trigger_forecast_adjustment_clear() + + +if __name__ == "__main__": + default_matter_test_main() From 8c76c9f0e69132025cd713651f35e51387196e0d Mon Sep 17 00:00:00 2001 From: pcoleman Date: Thu, 22 Aug 2024 09:59:46 +0100 Subject: [PATCH 18/45] Regenerate files following a re-bootstrap --- .../cluster/clusters/AccessControlCluster.kt | 1599 +- .../cluster/clusters/AccountLoginCluster.kt | 752 +- .../cluster/clusters/ActionsCluster.kt | 1227 +- .../ActivatedCarbonFilterMonitoringCluster.kt | 1432 +- .../AdministratorCommissioningCluster.kt | 1063 +- .../cluster/clusters/AirQualityCluster.kt | 771 +- .../clusters/ApplicationBasicCluster.kt | 1494 +- .../clusters/ApplicationLauncherCluster.kt | 1152 +- .../cluster/clusters/AudioOutputCluster.kt | 910 +- .../clusters/BallastConfigurationCluster.kt | 2534 ++- .../cluster/clusters/BarrierControlCluster.kt | 1850 +- .../clusters/BasicInformationCluster.kt | 2781 ++- .../clusters/BinaryInputBasicCluster.kt | 1762 +- .../cluster/clusters/BindingCluster.kt | 845 +- .../cluster/clusters/BooleanStateCluster.kt | 776 +- .../BooleanStateConfigurationCluster.kt | 1613 +- .../BridgedDeviceBasicInformationCluster.kt | 2528 ++- ...nDioxideConcentrationMeasurementCluster.kt | 2082 ++- ...MonoxideConcentrationMeasurementCluster.kt | 2082 ++- .../cluster/clusters/ChannelCluster.kt | 1336 +- .../cluster/clusters/ColorControlCluster.kt | 7069 ++++---- .../clusters/CommissionerControlCluster.kt | 866 +- .../clusters/ContentAppObserverCluster.kt | 777 +- .../cluster/clusters/ContentControlCluster.kt | 1696 +- .../clusters/ContentLauncherCluster.kt | 1075 +- .../DemandResponseLoadControlCluster.kt | 1590 +- .../cluster/clusters/DescriptorCluster.kt | 1336 +- .../clusters/DeviceEnergyManagementCluster.kt | 1589 +- .../DeviceEnergyManagementModeCluster.kt | 1299 +- .../cluster/clusters/DiagnosticLogsCluster.kt | 762 +- .../clusters/DishwasherAlarmCluster.kt | 1060 +- .../cluster/clusters/DishwasherModeCluster.kt | 1297 +- .../cluster/clusters/DoorLockCluster.kt | 7068 ++++---- .../clusters/EcosystemInformationCluster.kt | 1094 +- .../ElectricalEnergyMeasurementCluster.kt | 1544 +- .../clusters/ElectricalMeasurementCluster.kt | 14215 ++++++++-------- .../ElectricalPowerMeasurementCluster.kt | 3260 ++-- .../cluster/clusters/EnergyEvseCluster.kt | 3575 ++-- .../cluster/clusters/EnergyEvseModeCluster.kt | 1297 +- .../clusters/EnergyPreferenceCluster.kt | 1405 +- .../EthernetNetworkDiagnosticsCluster.kt | 1792 +- .../cluster/clusters/FanControlCluster.kt | 2161 ++- .../cluster/clusters/FaultInjectionCluster.kt | 725 +- .../cluster/clusters/FixedLabelCluster.kt | 816 +- .../clusters/FlowMeasurementCluster.kt | 1191 +- ...aldehydeConcentrationMeasurementCluster.kt | 2082 ++- .../clusters/GeneralCommissioningCluster.kt | 1757 +- .../clusters/GeneralDiagnosticsCluster.kt | 1850 +- .../clusters/GroupKeyManagementCluster.kt | 1229 +- .../cluster/clusters/GroupsCluster.kt | 1012 +- .../clusters/HepaFilterMonitoringCluster.kt | 1432 +- .../cluster/clusters/IcdManagementCluster.kt | 1833 +- .../cluster/clusters/IdentifyCluster.kt | 895 +- .../clusters/IlluminanceMeasurementCluster.kt | 1336 +- .../cluster/clusters/KeypadInputCluster.kt | 719 +- .../clusters/LaundryDryerControlsCluster.kt | 970 +- .../clusters/LaundryWasherControlsCluster.kt | 1294 +- .../clusters/LaundryWasherModeCluster.kt | 1297 +- .../cluster/clusters/LevelControlCluster.kt | 2614 ++- .../LocalizationConfigurationCluster.kt | 924 +- .../cluster/clusters/LowPowerCluster.kt | 695 +- .../cluster/clusters/MediaInputCluster.kt | 918 +- .../cluster/clusters/MediaPlaybackCluster.kt | 2706 ++- .../cluster/clusters/MessagesCluster.kt | 987 +- .../clusters/MicrowaveOvenControlCluster.kt | 1698 +- .../clusters/MicrowaveOvenModeCluster.kt | 899 +- .../cluster/clusters/ModeSelectCluster.kt | 1456 +- .../clusters/NetworkCommissioningCluster.kt | 2648 ++- ...nDioxideConcentrationMeasurementCluster.kt | 2082 ++- .../clusters/OccupancySensingCluster.kt | 2407 ++- .../cluster/clusters/OnOffCluster.kt | 1370 +- .../OnOffSwitchConfigurationCluster.kt | 879 +- .../clusters/OperationalCredentialsCluster.kt | 1751 +- .../clusters/OperationalStateCluster.kt | 1518 +- .../OtaSoftwareUpdateProviderCluster.kt | 940 +- .../OtaSoftwareUpdateRequestorCluster.kt | 1157 +- .../OvenCavityOperationalStateCluster.kt | 1525 +- .../cluster/clusters/OvenModeCluster.kt | 1292 +- .../OzoneConcentrationMeasurementCluster.kt | 2079 ++- .../Pm10ConcentrationMeasurementCluster.kt | 2079 ++- .../Pm1ConcentrationMeasurementCluster.kt | 2079 ++- .../Pm25ConcentrationMeasurementCluster.kt | 2079 ++- .../cluster/clusters/PowerSourceCluster.kt | 4347 +++-- .../PowerSourceConfigurationCluster.kt | 818 +- .../cluster/clusters/PowerTopologyCluster.kt | 988 +- .../clusters/PressureMeasurementCluster.kt | 1847 +- .../clusters/ProxyConfigurationCluster.kt | 694 +- .../cluster/clusters/ProxyDiscoveryCluster.kt | 694 +- .../cluster/clusters/ProxyValidCluster.kt | 691 +- .../clusters/PulseWidthModulationCluster.kt | 694 +- .../PumpConfigurationAndControlCluster.kt | 3685 ++-- .../RadonConcentrationMeasurementCluster.kt | 2079 ++- .../clusters/RefrigeratorAlarmCluster.kt | 937 +- ...TemperatureControlledCabinetModeCluster.kt | 1306 +- .../RelativeHumidityMeasurementCluster.kt | 1191 +- .../cluster/clusters/RvcCleanModeCluster.kt | 954 +- .../clusters/RvcOperationalStateCluster.kt | 1497 +- .../cluster/clusters/RvcRunModeCluster.kt | 949 +- .../cluster/clusters/SampleMeiCluster.kt | 835 +- .../clusters/ScenesManagementCluster.kt | 1570 +- .../cluster/clusters/ServiceAreaCluster.kt | 1620 +- .../cluster/clusters/SmokeCoAlarmCluster.kt | 2007 ++- .../clusters/SoftwareDiagnosticsCluster.kt | 1177 +- .../cluster/clusters/SwitchCluster.kt | 962 +- .../clusters/TargetNavigatorCluster.kt | 987 +- .../clusters/TemperatureControlCluster.kt | 1402 +- .../clusters/TemperatureMeasurementCluster.kt | 1191 +- .../cluster/clusters/ThermostatCluster.kt | 8599 +++++----- ...mostatUserInterfaceConfigurationCluster.kt | 1046 +- .../ThreadBorderRouterManagementCluster.kt | 1357 +- .../ThreadNetworkDiagnosticsCluster.kt | 7669 ++++----- .../clusters/ThreadNetworkDirectoryCluster.kt | 1101 +- .../clusters/TimeFormatLocalizationCluster.kt | 1084 +- .../clusters/TimeSynchronizationCluster.kt | 2386 ++- .../cluster/clusters/TimerCluster.kt | 957 +- ...ompoundsConcentrationMeasurementCluster.kt | 2084 ++- .../clusters/UnitLocalizationCluster.kt | 827 +- .../cluster/clusters/UnitTestingCluster.kt | 13442 +++++++-------- .../cluster/clusters/UserLabelCluster.kt | 845 +- .../ValveConfigurationAndControlCluster.kt | 2173 ++- .../cluster/clusters/WakeOnLanCluster.kt | 913 +- .../clusters/WaterHeaterManagementCluster.kt | 1280 +- .../clusters/WaterHeaterModeCluster.kt | 1297 +- .../clusters/WiFiNetworkDiagnosticsCluster.kt | 2503 ++- .../clusters/WiFiNetworkManagementCluster.kt | 983 +- .../cluster/clusters/WindowCoveringCluster.kt | 3196 ++-- ...olClusterAccessControlEntryChangedEvent.kt | 61 +- ...usterAccessControlExtensionChangedEvent.kt | 62 +- ...usterAccessRestrictionEntryChangedEvent.kt | 13 +- ...usterFabricRestrictionReviewUpdateEvent.kt | 44 +- .../AccountLoginClusterLoggedOutEvent.kt | 20 +- .../ActionsClusterActionFailedEvent.kt | 8 +- .../ActionsClusterStateChangedEvent.kt | 8 +- .../BasicInformationClusterLeaveEvent.kt | 10 +- ...InformationClusterReachableChangedEvent.kt | 10 +- .../BasicInformationClusterStartUpEvent.kt | 10 +- .../BooleanStateClusterStateChangeEvent.kt | 10 +- ...igurationClusterAlarmsStateChangedEvent.kt | 21 +- ...ateConfigurationClusterSensorFaultEvent.kt | 13 +- ...sicInformationClusterActiveChangedEvent.kt | 16 +- ...InformationClusterReachableChangedEvent.kt | 13 +- ...viceBasicInformationClusterStartUpEvent.kt | 13 +- ...lClusterCommissioningRequestResultEvent.kt | 18 +- ...lusterLoadControlEventStatusChangeEvent.kt | 214 +- ...rgyManagementClusterPowerAdjustEndEvent.kt | 11 +- ...viceEnergyManagementClusterResumedEvent.kt | 10 +- .../DishwasherAlarmClusterNotifyEvent.kt | 8 +- .../DoorLockClusterDoorLockAlarmEvent.kt | 10 +- .../DoorLockClusterDoorStateChangeEvent.kt | 10 +- .../DoorLockClusterLockOperationErrorEvent.kt | 108 +- .../DoorLockClusterLockOperationEvent.kt | 107 +- .../DoorLockClusterLockUserChangeEvent.kt | 70 +- ...entClusterCumulativeEnergyMeasuredEvent.kt | 53 +- ...ementClusterPeriodicEnergyMeasuredEvent.kt | 53 +- ...mentClusterMeasurementPeriodRangesEvent.kt | 30 +- .../EnergyEvseClusterEVConnectedEvent.kt | 10 +- .../EnergyEvseClusterEVNotDetectedEvent.kt | 26 +- ...gyEvseClusterEnergyTransferStartedEvent.kt | 25 +- ...gyEvseClusterEnergyTransferStoppedEvent.kt | 26 +- .../EnergyEvseClusterFaultEvent.kt | 34 +- .../EnergyEvseClusterRFIDEvent.kt | 10 +- ...eneralDiagnosticsClusterBootReasonEvent.kt | 10 +- ...gnosticsClusterHardwareFaultChangeEvent.kt | 36 +- ...agnosticsClusterNetworkFaultChangeEvent.kt | 36 +- ...DiagnosticsClusterRadioFaultChangeEvent.kt | 33 +- .../MediaPlaybackClusterStateChangedEvent.kt | 36 +- .../MessagesClusterMessageCompleteEvent.kt | 81 +- .../MessagesClusterMessagePresentedEvent.kt | 10 +- .../MessagesClusterMessageQueuedEvent.kt | 10 +- ...nalStateClusterOperationCompletionEvent.kt | 70 +- ...tionalStateClusterOperationalErrorEvent.kt | 12 +- ...pdateRequestorClusterDownloadErrorEvent.kt | 44 +- ...ateRequestorClusterStateTransitionEvent.kt | 31 +- ...dateRequestorClusterVersionAppliedEvent.kt | 11 +- ...nalStateClusterOperationCompletionEvent.kt | 70 +- ...tionalStateClusterOperationalErrorEvent.kt | 18 +- ...rSourceClusterBatChargeFaultChangeEvent.kt | 33 +- .../PowerSourceClusterBatFaultChangeEvent.kt | 36 +- ...PowerSourceClusterWiredFaultChangeEvent.kt | 36 +- .../RefrigeratorAlarmClusterNotifyEvent.kt | 8 +- ...nalStateClusterOperationCompletionEvent.kt | 70 +- ...tionalStateClusterOperationalErrorEvent.kt | 15 +- .../SampleMeiClusterPingCountEventEvent.kt | 11 +- .../SmokeCoAlarmClusterCOAlarmEvent.kt | 10 +- ...eCoAlarmClusterInterconnectCOAlarmEvent.kt | 10 +- ...AlarmClusterInterconnectSmokeAlarmEvent.kt | 10 +- .../SmokeCoAlarmClusterLowBatteryEvent.kt | 10 +- .../SmokeCoAlarmClusterSmokeAlarmEvent.kt | 10 +- ...areDiagnosticsClusterSoftwareFaultEvent.kt | 29 +- .../SwitchClusterInitialPressEvent.kt | 10 +- .../SwitchClusterLongPressEvent.kt | 10 +- .../SwitchClusterLongReleaseEvent.kt | 10 +- .../SwitchClusterMultiPressCompleteEvent.kt | 11 +- .../SwitchClusterMultiPressOngoingEvent.kt | 11 +- .../SwitchClusterShortReleaseEvent.kt | 10 +- .../SwitchClusterSwitchLatchedEvent.kt | 10 +- ...argetNavigatorClusterTargetUpdatedEvent.kt | 25 +- ...DiagnosticsClusterConnectionStatusEvent.kt | 13 +- ...agnosticsClusterNetworkFaultChangeEvent.kt | 36 +- ...imeSynchronizationClusterDSTStatusEvent.kt | 10 +- ...nchronizationClusterTimeZoneStatusEvent.kt | 21 +- ...ClusterTestDifferentVendorMeiEventEvent.kt | 13 +- .../UnitTestingClusterTestEventEvent.kt | 44 +- ...estingClusterTestFabricScopedEventEvent.kt | 10 +- ...urationAndControlClusterValveFaultEvent.kt | 13 +- ...AndControlClusterValveStateChangedEvent.kt | 21 +- ...eaterManagementClusterBoostStartedEvent.kt | 13 +- ...agnosticsClusterAssociationFailureEvent.kt | 14 +- ...DiagnosticsClusterConnectionStatusEvent.kt | 13 +- ...orkDiagnosticsClusterDisconnectionEvent.kt | 13 +- ...sControlClusterAccessControlEntryStruct.kt | 79 +- ...trolClusterAccessControlExtensionStruct.kt | 11 +- ...ControlClusterAccessControlTargetStruct.kt | 45 +- ...trolClusterAccessRestrictionEntryStruct.kt | 32 +- ...ssControlClusterAccessRestrictionStruct.kt | 22 +- ...mmissioningAccessRestrictionEntryStruct.kt | 31 +- .../structs/ActionsClusterActionStruct.kt | 15 +- .../ActionsClusterEndpointListStruct.kt | 20 +- ...nitoringClusterReplacementProductStruct.kt | 22 +- ...pplicationBasicClusterApplicationStruct.kt | 6 +- ...ationLauncherClusterApplicationEPStruct.kt | 22 +- ...icationLauncherClusterApplicationStruct.kt | 6 +- .../AudioOutputClusterOutputInfoStruct.kt | 6 +- ...nformationClusterCapabilityMinimaStruct.kt | 17 +- ...formationClusterProductAppearanceStruct.kt | 22 +- .../structs/BindingClusterTargetStruct.kt | 49 +- ...formationClusterProductAppearanceStruct.kt | 24 +- .../ChannelClusterAdditionalInfoStruct.kt | 9 +- .../ChannelClusterChannelInfoStruct.kt | 70 +- .../ChannelClusterChannelPagingStruct.kt | 66 +- .../structs/ChannelClusterLineupInfoStruct.kt | 27 +- .../structs/ChannelClusterPageTokenStruct.kt | 38 +- .../ChannelClusterProgramCastStruct.kt | 9 +- .../ChannelClusterProgramCategoryStruct.kt | 19 +- .../structs/ChannelClusterProgramStruct.kt | 311 +- .../structs/ChannelClusterSeriesInfoStruct.kt | 9 +- .../ContentControlClusterRatingNameStruct.kt | 16 +- ...tentLauncherClusterAdditionalInfoStruct.kt | 9 +- ...auncherClusterBrandingInformationStruct.kt | 99 +- ...ntentLauncherClusterContentSearchStruct.kt | 18 +- .../ContentLauncherClusterDimensionStruct.kt | 6 +- .../ContentLauncherClusterParameterStruct.kt | 37 +- ...auncherClusterPlaybackPreferencesStruct.kt | 54 +- ...ntLauncherClusterStyleInformationStruct.kt | 40 +- ...entLauncherClusterTrackPreferenceStruct.kt | 43 +- ...dControlClusterAverageLoadControlStruct.kt | 13 +- ...oadControlClusterDutyCycleControlStruct.kt | 13 +- ...ontrolClusterHeatingSourceControlStruct.kt | 13 +- ...oadControlClusterLoadControlEventStruct.kt | 77 +- ...ClusterLoadControlEventTransitionStruct.kt | 100 +- ...dControlClusterLoadControlProgramStruct.kt | 58 +- ...ControlClusterPowerSavingsControlStruct.kt | 13 +- ...dControlClusterTemperatureControlStruct.kt | 125 +- .../DescriptorClusterDeviceTypeStruct.kt | 9 +- .../DescriptorClusterSemanticTagStruct.kt | 45 +- ...nergyManagementClusterConstraintsStruct.kt | 46 +- ...DeviceEnergyManagementClusterCostStruct.kt | 16 +- ...ceEnergyManagementClusterForecastStruct.kt | 82 +- ...ementClusterPowerAdjustCapabilityStruct.kt | 43 +- ...nergyManagementClusterPowerAdjustStruct.kt | 13 +- ...gyManagementClusterSlotAdjustmentStruct.kt | 21 +- ...DeviceEnergyManagementClusterSlotStruct.kt | 190 +- ...gyManagementModeClusterModeOptionStruct.kt | 25 +- ...nergyManagementModeClusterModeTagStruct.kt | 16 +- .../DishwasherModeClusterModeOptionStruct.kt | 20 +- .../DishwasherModeClusterModeTagStruct.kt | 19 +- .../DoorLockClusterCredentialStruct.kt | 9 +- ...ystemInformationClusterDeviceTypeStruct.kt | 9 +- ...InformationClusterEcosystemDeviceStruct.kt | 75 +- ...formationClusterEcosystemLocationStruct.kt | 27 +- ...ormationClusterLocationDescriptorStruct.kt | 43 +- ...ementClusterCumulativeEnergyResetStruct.kt | 125 +- ...asurementClusterEnergyMeasurementStruct.kt | 62 +- ...ntClusterMeasurementAccuracyRangeStruct.kt | 87 +- ...urementClusterMeasurementAccuracyStruct.kt | 38 +- ...urementClusterHarmonicMeasurementStruct.kt | 24 +- ...ntClusterMeasurementAccuracyRangeStruct.kt | 87 +- ...urementClusterMeasurementAccuracyStruct.kt | 38 +- ...easurementClusterMeasurementRangeStruct.kt | 112 +- ...EvseClusterChargingTargetScheduleStruct.kt | 23 +- .../EnergyEvseClusterChargingTargetStruct.kt | 36 +- .../EnergyEvseModeClusterModeOptionStruct.kt | 20 +- .../EnergyEvseModeClusterModeTagStruct.kt | 19 +- .../EnergyPreferenceClusterBalanceStruct.kt | 19 +- .../structs/FixedLabelClusterLabelStruct.kt | 9 +- ...missioningClusterBasicCommissioningInfo.kt | 22 +- ...neralDiagnosticsClusterNetworkInterface.kt | 82 +- ...pKeyManagementClusterGroupInfoMapStruct.kt | 30 +- ...upKeyManagementClusterGroupKeyMapStruct.kt | 6 +- ...upKeyManagementClusterGroupKeySetStruct.kt | 98 +- ...nitoringClusterReplacementProductStruct.kt | 22 +- ...mentClusterMonitoringRegistrationStruct.kt | 18 +- ...aundryWasherModeClusterModeOptionStruct.kt | 20 +- .../LaundryWasherModeClusterModeTagStruct.kt | 19 +- .../MediaInputClusterInputInfoStruct.kt | 6 +- ...iaPlaybackClusterPlaybackPositionStruct.kt | 22 +- ...diaPlaybackClusterTrackAttributesStruct.kt | 32 +- .../MediaPlaybackClusterTrackStruct.kt | 22 +- ...sagesClusterMessageResponseOptionStruct.kt | 27 +- .../structs/MessagesClusterMessageStruct.kt | 73 +- ...icrowaveOvenModeClusterModeOptionStruct.kt | 20 +- .../MicrowaveOvenModeClusterModeTagStruct.kt | 19 +- .../ModeSelectClusterModeOptionStruct.kt | 20 +- .../ModeSelectClusterSemanticTagStruct.kt | 9 +- ...rkCommissioningClusterNetworkInfoStruct.kt | 66 +- ...gClusterThreadInterfaceScanResultStruct.kt | 22 +- ...ingClusterWiFiInterfaceScanResultStruct.kt | 20 +- ...pancySensingClusterHoldTimeLimitsStruct.kt | 6 +- ...redentialsClusterFabricDescriptorStruct.kt | 20 +- .../OperationalCredentialsClusterNOCStruct.kt | 19 +- ...OperationalStateClusterErrorStateStruct.kt | 33 +- ...ionalStateClusterOperationalStateStruct.kt | 21 +- ...eUpdateRequestorClusterProviderLocation.kt | 17 +- ...OperationalStateClusterErrorStateStruct.kt | 38 +- ...ionalStateClusterOperationalStateStruct.kt | 26 +- .../OvenModeClusterModeOptionStruct.kt | 20 +- .../structs/OvenModeClusterModeTagStruct.kt | 19 +- ...erSourceClusterBatChargeFaultChangeType.kt | 35 +- .../PowerSourceClusterBatFaultChangeType.kt | 38 +- .../PowerSourceClusterWiredFaultChangeType.kt | 38 +- ...olledCabinetModeClusterModeOptionStruct.kt | 36 +- ...ntrolledCabinetModeClusterModeTagStruct.kt | 21 +- .../RvcCleanModeClusterModeOptionStruct.kt | 20 +- .../RvcCleanModeClusterModeTagStruct.kt | 19 +- ...OperationalStateClusterErrorStateStruct.kt | 33 +- ...ionalStateClusterOperationalStateStruct.kt | 26 +- .../RvcRunModeClusterModeOptionStruct.kt | 20 +- .../structs/RvcRunModeClusterModeTagStruct.kt | 19 +- ...nagementClusterAttributeValuePairStruct.kt | 110 +- ...cenesManagementClusterExtensionFieldSet.kt | 20 +- .../ScenesManagementClusterSceneInfoStruct.kt | 15 +- .../ServiceAreaClusterAreaInfoStruct.kt | 38 +- .../structs/ServiceAreaClusterAreaStruct.kt | 22 +- .../ServiceAreaClusterLandmarkInfoStruct.kt | 22 +- ...viceAreaClusterLocationDescriptorStruct.kt | 32 +- .../structs/ServiceAreaClusterMapStruct.kt | 9 +- .../ServiceAreaClusterProgressStruct.kt | 59 +- ...reDiagnosticsClusterThreadMetricsStruct.kt | 57 +- .../TargetNavigatorClusterTargetInfoStruct.kt | 9 +- ...ostatClusterAtomicAttributeStatusStruct.kt | 9 +- .../structs/ThermostatClusterPresetStruct.kt | 89 +- .../ThermostatClusterPresetTypeStruct.kt | 6 +- .../ThermostatClusterScheduleStruct.kt | 76 +- ...ermostatClusterScheduleTransitionStruct.kt | 58 +- .../ThermostatClusterScheduleTypeStruct.kt | 12 +- ...atClusterWeeklyScheduleTransitionStruct.kt | 43 +- ...rkDiagnosticsClusterNeighborTableStruct.kt | 54 +- ...ticsClusterOperationalDatasetComponents.kt | 41 +- ...tworkDiagnosticsClusterRouteTableStruct.kt | 24 +- ...NetworkDiagnosticsClusterSecurityPolicy.kt | 9 +- ...workDirectoryClusterThreadNetworkStruct.kt | 18 +- ...meSynchronizationClusterDSTOffsetStruct.kt | 19 +- ...sterFabricScopedTrustedTimeSourceStruct.kt | 11 +- ...imeSynchronizationClusterTimeZoneStruct.kt | 16 +- ...onizationClusterTrustedTimeSourceStruct.kt | 11 +- ...nitTestingClusterDoubleNestedStructList.kt | 22 +- .../structs/UnitTestingClusterNestedStruct.kt | 18 +- .../UnitTestingClusterNestedStructList.kt | 65 +- ...stingClusterNullablesAndOptionalsStruct.kt | 297 +- .../structs/UnitTestingClusterSimpleStruct.kt | 16 +- .../UnitTestingClusterTestFabricScoped.kt | 102 +- .../UnitTestingClusterTestGlobalStruct.kt | 45 +- .../UnitTestingClusterTestListStructOctet.kt | 9 +- .../structs/UserLabelClusterLabelStruct.kt | 9 +- ...gementClusterWaterHeaterBoostInfoStruct.kt | 74 +- .../WaterHeaterModeClusterModeOptionStruct.kt | 20 +- .../WaterHeaterModeClusterModeTagStruct.kt | 19 +- 367 files changed, 116165 insertions(+), 128539 deletions(-) diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/AccessControlCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/AccessControlCluster.kt index a3ee5ef67646cf..099162a899b419 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/AccessControlCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/AccessControlCluster.kt @@ -17,155 +17,126 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState -import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class AccessControlCluster(private val controller: MatterController, private val endpointId: UShort) {class AclAttribute( - val value: List - ) +class AccessControlCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class AclAttribute(val value: List) sealed class AclAttributeSubscriptionState { - data class Success( - val value: List - ) : AclAttributeSubscriptionState() - + data class Success(val value: List) : + AclAttributeSubscriptionState() + data class Error(val exception: Exception) : AclAttributeSubscriptionState() - object SubscriptionEstablished : AclAttributeSubscriptionState() - } -class ExtensionAttribute( - val value: List? - ) + object SubscriptionEstablished : AclAttributeSubscriptionState() + } + + class ExtensionAttribute(val value: List?) sealed class ExtensionAttributeSubscriptionState { - data class Success( - val value: List? - ) : ExtensionAttributeSubscriptionState() - + data class Success(val value: List?) : + ExtensionAttributeSubscriptionState() + data class Error(val exception: Exception) : ExtensionAttributeSubscriptionState() - object SubscriptionEstablished : ExtensionAttributeSubscriptionState() - } -class CommissioningARLAttribute( + object SubscriptionEstablished : ExtensionAttributeSubscriptionState() + } + + class CommissioningARLAttribute( val value: List? ) sealed class CommissioningARLAttributeSubscriptionState { data class Success( - val value: List? + val value: List? ) : CommissioningARLAttributeSubscriptionState() - + data class Error(val exception: Exception) : CommissioningARLAttributeSubscriptionState() - object SubscriptionEstablished : CommissioningARLAttributeSubscriptionState() - } -class ArlAttribute( - val value: List? - ) + object SubscriptionEstablished : CommissioningARLAttributeSubscriptionState() + } + + class ArlAttribute(val value: List?) sealed class ArlAttributeSubscriptionState { - data class Success( - val value: List? - ) : ArlAttributeSubscriptionState() - + data class Success(val value: List?) : + ArlAttributeSubscriptionState() + data class Error(val exception: Exception) : ArlAttributeSubscriptionState() - object SubscriptionEstablished : ArlAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : ArlAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun reviewFabricRestrictions(arl: List - ,timedInvokeTimeout: Duration? = null) { + suspend fun reviewFabricRestrictions( + arl: List, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 0u val tlvWriter = TlvWriter() @@ -173,92 +144,85 @@ class AttributeListAttribute( val TAG_ARL_REQ: Int = 0 tlvWriter.startArray(ContextSpecificTag(TAG_ARL_REQ)) - for (item in arl.iterator()) { - item.toTlv(AnonymousTag, tlvWriter) - } - tlvWriter.endArray() + for (item in arl.iterator()) { + item.toTlv(AnonymousTag, tlvWriter) + } + tlvWriter.endArray() tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } -suspend fun readAclAttribute(): AclAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readAclAttribute(): AclAttribute { + 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}") - } + 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) { - "Acl attribute not found in response" - } + } + + requireNotNull(attributeData) { "Acl 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(AccessControlClusterAccessControlEntryStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(AccessControlClusterAccessControlEntryStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AclAttribute(decodedValue) } suspend fun writeAclAttribute( value: List, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startArray(AnonymousTag) - for (item in value.iterator()) { - item.toTlv(AnonymousTag, tlvWriter) - } - tlvWriter.endArray() + for (item in value.iterator()) { + item.toTlv(AnonymousTag, tlvWriter) + } + tlvWriter.endArray() val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -279,53 +243,56 @@ suspend fun readAclAttribute(): AclAttribute {val ATTRIBUTE_ID: UInt = 0u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeAclAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(AclAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + AclAttributeSubscriptionState.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) { - "Acl attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Acl 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(AccessControlClusterAccessControlEntryStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(AccessControlClusterAccessControlEntryStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(AclAttributeSubscriptionState.Success(decodedValue)) } @@ -333,82 +300,75 @@ suspend fun readAclAttribute(): AclAttribute {val ATTRIBUTE_ID: UInt = 0u emit(AclAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readExtensionAttribute(): ExtensionAttribute {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readExtensionAttribute(): ExtensionAttribute { + 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}") - } + 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) { - "Extension attribute not found in response" - } + } + + requireNotNull(attributeData) { "Extension attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(AccessControlClusterAccessControlExtensionStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(AccessControlClusterAccessControlExtensionStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null } - tlvReader.exitContainer() - } - } else { - null - } - return ExtensionAttribute(decodedValue) } suspend fun writeExtensionAttribute( value: List, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 1u val tlvWriter = TlvWriter() tlvWriter.startArray(AnonymousTag) - for (item in value.iterator()) { - item.toTlv(AnonymousTag, tlvWriter) - } - tlvWriter.endArray() + for (item in value.iterator()) { + item.toTlv(AnonymousTag, tlvWriter) + } + tlvWriter.endArray() val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -429,141 +389,145 @@ suspend fun readExtensionAttribute(): ExtensionAttribute {val ATTRIBUTE_ID: UInt throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeExtensionAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ExtensionAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ExtensionAttributeSubscriptionState.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) { - "Extension attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Extension attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(AccessControlClusterAccessControlExtensionStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { - emit(ExtensionAttributeSubscriptionState.Success(it)) - } - + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add( + AccessControlClusterAccessControlExtensionStruct.fromTlv( + AnonymousTag, + tlvReader, + ) + ) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { emit(ExtensionAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ExtensionAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readSubjectsPerAccessControlEntryAttribute(): 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) - ) - + + suspend fun readSubjectsPerAccessControlEntryAttribute(): 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}") - } + 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) { - "Subjectsperaccesscontrolentry attribute not found in response" + } + + requireNotNull(attributeData) { + "Subjectsperaccesscontrolentry 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 subscribeSubjectsPerAccessControlEntryAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Subjectsperaccesscontrolentry attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Subjectsperaccesscontrolentry attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -576,80 +540,77 @@ suspend fun readSubjectsPerAccessControlEntryAttribute(): UShort {val ATTRIBUTE_ emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readTargetsPerAccessControlEntryAttribute(): UShort {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readTargetsPerAccessControlEntryAttribute(): UShort { + 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}") - } + 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) { - "Targetsperaccesscontrolentry attribute not found in response" - } + } + + requireNotNull(attributeData) { "Targetsperaccesscontrolentry 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 subscribeTargetsPerAccessControlEntryAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Targetsperaccesscontrolentry attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Targetsperaccesscontrolentry attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -662,80 +623,79 @@ suspend fun readTargetsPerAccessControlEntryAttribute(): UShort {val ATTRIBUTE_I emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAccessControlEntriesPerFabricAttribute(): UShort {val ATTRIBUTE_ID: UInt = 4u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readAccessControlEntriesPerFabricAttribute(): UShort { + 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}") - } + 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) { - "Accesscontrolentriesperfabric attribute not found in response" + } + + requireNotNull(attributeData) { + "Accesscontrolentriesperfabric 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 subscribeAccessControlEntriesPerFabricAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Accesscontrolentriesperfabric attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Accesscontrolentriesperfabric attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -748,315 +708,319 @@ suspend fun readAccessControlEntriesPerFabricAttribute(): UShort {val ATTRIBUTE_ emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCommissioningARLAttribute(): CommissioningARLAttribute {val ATTRIBUTE_ID: UInt = 5u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readCommissioningARLAttribute(): CommissioningARLAttribute { + 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}") - } + 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) { - "Commissioningarl attribute not found in response" - } + } + + requireNotNull(attributeData) { "Commissioningarl attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(AccessControlClusterCommissioningAccessRestrictionEntryStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add( + AccessControlClusterCommissioningAccessRestrictionEntryStruct.fromTlv( + AnonymousTag, + tlvReader, + ) + ) + } + tlvReader.exitContainer() + } + } else { + null } - tlvReader.exitContainer() - } - } else { - null - } - return CommissioningARLAttribute(decodedValue) } suspend fun subscribeCommissioningARLAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(CommissioningARLAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + CommissioningARLAttributeSubscriptionState.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) { - "Commissioningarl attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Commissioningarl attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(AccessControlClusterCommissioningAccessRestrictionEntryStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { - emit(CommissioningARLAttributeSubscriptionState.Success(it)) - } - + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add( + AccessControlClusterCommissioningAccessRestrictionEntryStruct.fromTlv( + AnonymousTag, + tlvReader, + ) + ) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { emit(CommissioningARLAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(CommissioningARLAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readArlAttribute(): ArlAttribute {val ATTRIBUTE_ID: UInt = 6u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readArlAttribute(): ArlAttribute { + 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}") - } + 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) { - "Arl attribute not found in response" - } + } + + requireNotNull(attributeData) { "Arl attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(AccessControlClusterAccessRestrictionEntryStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(AccessControlClusterAccessRestrictionEntryStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null } - tlvReader.exitContainer() - } - } else { - null - } - return ArlAttribute(decodedValue) } suspend fun subscribeArlAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ArlAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ArlAttributeSubscriptionState.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) { - "Arl attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Arl attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(AccessControlClusterAccessRestrictionEntryStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { - emit(ArlAttributeSubscriptionState.Success(it)) - } - + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add( + AccessControlClusterAccessRestrictionEntryStruct.fromTlv( + AnonymousTag, + tlvReader, + ) + ) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { emit(ArlAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ArlAttributeSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1064,97 +1028,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1162,97 +1125,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1260,97 +1220,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1358,81 +1315,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1444,80 +1396,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1530,7 +1479,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/AccountLoginCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/AccountLoginCluster.kt index d8f104bfd40c06..3357ffff9b5b1a 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/AccountLoginCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/AccountLoginCluster.kt @@ -17,121 +17,92 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState -import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.UShortSubscriptionState +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class AccountLoginCluster(private val controller: MatterController, private val endpointId: UShort) { - class GetSetupPINResponse( - val setupPIN: String - ) -class GeneratedCommandListAttribute( - val value: List - ) +class AccountLoginCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class GetSetupPINResponse(val setupPIN: String) + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun getSetupPIN(tempAccountIdentifier: String - ,timedInvokeTimeout: Duration): GetSetupPINResponse { + suspend fun getSetupPIN( + tempAccountIdentifier: String, + timedInvokeTimeout: Duration, + ): GetSetupPINResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_TEMP_ACCOUNT_IDENTIFIER_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_TEMP_ACCOUNT_IDENTIFIER_REQ), tempAccountIdentifier) + tlvWriter.put(ContextSpecificTag(TAG_TEMP_ACCOUNT_IDENTIFIER_REQ), tempAccountIdentifier) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -141,38 +112,32 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_SETUP_PIN: Int = 0 var setupPIN_decoded: String? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_SETUP_PIN)) {setupPIN_decoded = tlvReader.getString(tag)} - - - else { + if (tag == ContextSpecificTag(TAG_SETUP_PIN)) { + setupPIN_decoded = tlvReader.getString(tag) + } else { tlvReader.skipElement() } } - - if (setupPIN_decoded == null) { - throw IllegalStateException("setupPIN not found in TLV") + throw IllegalStateException("setupPIN not found in TLV") } - tlvReader.exitContainer() - return GetSetupPINResponse( - setupPIN_decoded - ) + return GetSetupPINResponse(setupPIN_decoded) } - suspend fun login(tempAccountIdentifier: String - ,setupPIN: String - ,node: ULong? - ,timedInvokeTimeout: Duration) { + suspend fun login( + tempAccountIdentifier: String, + setupPIN: String, + node: ULong?, + timedInvokeTimeout: Duration, + ) { val commandId: UInt = 2u val tlvWriter = TlvWriter() @@ -185,134 +150,128 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_SETUP_PIN_REQ), setupPIN) val TAG_NODE_REQ: Int = 2 - node?.let { - tlvWriter.put(ContextSpecificTag(TAG_NODE_REQ), node) - } + node?.let { tlvWriter.put(ContextSpecificTag(TAG_NODE_REQ), node) } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun logout(node: ULong? - ,timedInvokeTimeout: Duration) { + suspend fun logout(node: ULong?, timedInvokeTimeout: Duration) { val commandId: UInt = 3u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_NODE_REQ: Int = 0 - node?.let { - tlvWriter.put(ContextSpecificTag(TAG_NODE_REQ), node) - } + node?.let { tlvWriter.put(ContextSpecificTag(TAG_NODE_REQ), node) } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } -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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -320,97 +279,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -418,97 +376,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -516,97 +471,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -614,81 +566,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -700,80 +647,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -786,7 +730,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/ActionsCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/ActionsCluster.kt index f3f845d1368c16..79245c8dc8657b 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/ActionsCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/ActionsCluster.kt @@ -17,130 +17,97 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest +import matter.controller.StringSubscriptionState import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState -import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.UShortSubscriptionState +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class ActionsCluster(private val controller: MatterController, private val endpointId: UShort) {class ActionListAttribute( - val value: List - ) +class ActionsCluster(private val controller: MatterController, private val endpointId: UShort) { + class ActionListAttribute(val value: List) sealed class ActionListAttributeSubscriptionState { - data class Success( - val value: List - ) : ActionListAttributeSubscriptionState() - + data class Success(val value: List) : + ActionListAttributeSubscriptionState() + data class Error(val exception: Exception) : ActionListAttributeSubscriptionState() - object SubscriptionEstablished : ActionListAttributeSubscriptionState() - } -class EndpointListsAttribute( - val value: List - ) + object SubscriptionEstablished : ActionListAttributeSubscriptionState() + } + + class EndpointListsAttribute(val value: List) sealed class EndpointListsAttributeSubscriptionState { - data class Success( - val value: List - ) : EndpointListsAttributeSubscriptionState() - + data class Success(val value: List) : + EndpointListsAttributeSubscriptionState() + data class Error(val exception: Exception) : EndpointListsAttributeSubscriptionState() - object SubscriptionEstablished : EndpointListsAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : EndpointListsAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun instantAction(actionID: UShort - ,invokeID: UInt? - ,timedInvokeTimeout: Duration? = null) { + suspend fun instantAction( + actionID: UShort, + invokeID: UInt?, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 0u val tlvWriter = TlvWriter() @@ -150,26 +117,26 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_ACTION_ID_REQ), actionID) val TAG_INVOKE_ID_REQ: Int = 1 - invokeID?.let { - tlvWriter.put(ContextSpecificTag(TAG_INVOKE_ID_REQ), invokeID) - } + invokeID?.let { tlvWriter.put(ContextSpecificTag(TAG_INVOKE_ID_REQ), invokeID) } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun instantActionWithTransition(actionID: UShort - ,invokeID: UInt? - ,transitionTime: UShort - ,timedInvokeTimeout: Duration? = null) { + suspend fun instantActionWithTransition( + actionID: UShort, + invokeID: UInt?, + transitionTime: UShort, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 1u val tlvWriter = TlvWriter() @@ -179,28 +146,24 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_ACTION_ID_REQ), actionID) val TAG_INVOKE_ID_REQ: Int = 1 - invokeID?.let { - tlvWriter.put(ContextSpecificTag(TAG_INVOKE_ID_REQ), invokeID) - } + invokeID?.let { tlvWriter.put(ContextSpecificTag(TAG_INVOKE_ID_REQ), invokeID) } val TAG_TRANSITION_TIME_REQ: Int = 2 - tlvWriter.put(ContextSpecificTag(TAG_TRANSITION_TIME_REQ), transitionTime) + 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 + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun startAction(actionID: UShort - ,invokeID: UInt? - ,timedInvokeTimeout: Duration? = null) { + suspend fun startAction(actionID: UShort, invokeID: UInt?, timedInvokeTimeout: Duration? = null) { val commandId: UInt = 2u val tlvWriter = TlvWriter() @@ -210,26 +173,26 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_ACTION_ID_REQ), actionID) val TAG_INVOKE_ID_REQ: Int = 1 - invokeID?.let { - tlvWriter.put(ContextSpecificTag(TAG_INVOKE_ID_REQ), invokeID) - } + invokeID?.let { tlvWriter.put(ContextSpecificTag(TAG_INVOKE_ID_REQ), invokeID) } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun startActionWithDuration(actionID: UShort - ,invokeID: UInt? - ,duration: UInt - ,timedInvokeTimeout: Duration? = null) { + suspend fun startActionWithDuration( + actionID: UShort, + invokeID: UInt?, + duration: UInt, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 3u val tlvWriter = TlvWriter() @@ -239,28 +202,24 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_ACTION_ID_REQ), actionID) val TAG_INVOKE_ID_REQ: Int = 1 - invokeID?.let { - tlvWriter.put(ContextSpecificTag(TAG_INVOKE_ID_REQ), invokeID) - } + invokeID?.let { tlvWriter.put(ContextSpecificTag(TAG_INVOKE_ID_REQ), invokeID) } val TAG_DURATION_REQ: Int = 2 - tlvWriter.put(ContextSpecificTag(TAG_DURATION_REQ), duration) + tlvWriter.put(ContextSpecificTag(TAG_DURATION_REQ), duration) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun stopAction(actionID: UShort - ,invokeID: UInt? - ,timedInvokeTimeout: Duration? = null) { + suspend fun stopAction(actionID: UShort, invokeID: UInt?, timedInvokeTimeout: Duration? = null) { val commandId: UInt = 4u val tlvWriter = TlvWriter() @@ -270,25 +229,21 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_ACTION_ID_REQ), actionID) val TAG_INVOKE_ID_REQ: Int = 1 - invokeID?.let { - tlvWriter.put(ContextSpecificTag(TAG_INVOKE_ID_REQ), invokeID) - } + invokeID?.let { tlvWriter.put(ContextSpecificTag(TAG_INVOKE_ID_REQ), invokeID) } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun pauseAction(actionID: UShort - ,invokeID: UInt? - ,timedInvokeTimeout: Duration? = null) { + suspend fun pauseAction(actionID: UShort, invokeID: UInt?, timedInvokeTimeout: Duration? = null) { val commandId: UInt = 5u val tlvWriter = TlvWriter() @@ -298,26 +253,26 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_ACTION_ID_REQ), actionID) val TAG_INVOKE_ID_REQ: Int = 1 - invokeID?.let { - tlvWriter.put(ContextSpecificTag(TAG_INVOKE_ID_REQ), invokeID) - } + invokeID?.let { tlvWriter.put(ContextSpecificTag(TAG_INVOKE_ID_REQ), invokeID) } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun pauseActionWithDuration(actionID: UShort - ,invokeID: UInt? - ,duration: UInt - ,timedInvokeTimeout: Duration? = null) { + suspend fun pauseActionWithDuration( + actionID: UShort, + invokeID: UInt?, + duration: UInt, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 6u val tlvWriter = TlvWriter() @@ -327,28 +282,28 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_ACTION_ID_REQ), actionID) val TAG_INVOKE_ID_REQ: Int = 1 - invokeID?.let { - tlvWriter.put(ContextSpecificTag(TAG_INVOKE_ID_REQ), invokeID) - } + invokeID?.let { tlvWriter.put(ContextSpecificTag(TAG_INVOKE_ID_REQ), invokeID) } val TAG_DURATION_REQ: Int = 2 - tlvWriter.put(ContextSpecificTag(TAG_DURATION_REQ), duration) + tlvWriter.put(ContextSpecificTag(TAG_DURATION_REQ), duration) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun resumeAction(actionID: UShort - ,invokeID: UInt? - ,timedInvokeTimeout: Duration? = null) { + suspend fun resumeAction( + actionID: UShort, + invokeID: UInt?, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 7u val tlvWriter = TlvWriter() @@ -358,25 +313,25 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_ACTION_ID_REQ), actionID) val TAG_INVOKE_ID_REQ: Int = 1 - invokeID?.let { - tlvWriter.put(ContextSpecificTag(TAG_INVOKE_ID_REQ), invokeID) - } + invokeID?.let { tlvWriter.put(ContextSpecificTag(TAG_INVOKE_ID_REQ), invokeID) } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun enableAction(actionID: UShort - ,invokeID: UInt? - ,timedInvokeTimeout: Duration? = null) { + suspend fun enableAction( + actionID: UShort, + invokeID: UInt?, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 8u val tlvWriter = TlvWriter() @@ -386,26 +341,26 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_ACTION_ID_REQ), actionID) val TAG_INVOKE_ID_REQ: Int = 1 - invokeID?.let { - tlvWriter.put(ContextSpecificTag(TAG_INVOKE_ID_REQ), invokeID) - } + invokeID?.let { tlvWriter.put(ContextSpecificTag(TAG_INVOKE_ID_REQ), invokeID) } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun enableActionWithDuration(actionID: UShort - ,invokeID: UInt? - ,duration: UInt - ,timedInvokeTimeout: Duration? = null) { + suspend fun enableActionWithDuration( + actionID: UShort, + invokeID: UInt?, + duration: UInt, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 9u val tlvWriter = TlvWriter() @@ -415,28 +370,28 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_ACTION_ID_REQ), actionID) val TAG_INVOKE_ID_REQ: Int = 1 - invokeID?.let { - tlvWriter.put(ContextSpecificTag(TAG_INVOKE_ID_REQ), invokeID) - } + invokeID?.let { tlvWriter.put(ContextSpecificTag(TAG_INVOKE_ID_REQ), invokeID) } val TAG_DURATION_REQ: Int = 2 - tlvWriter.put(ContextSpecificTag(TAG_DURATION_REQ), duration) + tlvWriter.put(ContextSpecificTag(TAG_DURATION_REQ), duration) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun disableAction(actionID: UShort - ,invokeID: UInt? - ,timedInvokeTimeout: Duration? = null) { + suspend fun disableAction( + actionID: UShort, + invokeID: UInt?, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 10u val tlvWriter = TlvWriter() @@ -446,26 +401,26 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_ACTION_ID_REQ), actionID) val TAG_INVOKE_ID_REQ: Int = 1 - invokeID?.let { - tlvWriter.put(ContextSpecificTag(TAG_INVOKE_ID_REQ), invokeID) - } + invokeID?.let { tlvWriter.put(ContextSpecificTag(TAG_INVOKE_ID_REQ), invokeID) } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun disableActionWithDuration(actionID: UShort - ,invokeID: UInt? - ,duration: UInt - ,timedInvokeTimeout: Duration? = null) { + suspend fun disableActionWithDuration( + actionID: UShort, + invokeID: UInt?, + duration: UInt, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 11u val tlvWriter = TlvWriter() @@ -475,113 +430,108 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_ACTION_ID_REQ), actionID) val TAG_INVOKE_ID_REQ: Int = 1 - invokeID?.let { - tlvWriter.put(ContextSpecificTag(TAG_INVOKE_ID_REQ), invokeID) - } + invokeID?.let { tlvWriter.put(ContextSpecificTag(TAG_INVOKE_ID_REQ), invokeID) } val TAG_DURATION_REQ: Int = 2 - tlvWriter.put(ContextSpecificTag(TAG_DURATION_REQ), duration) + tlvWriter.put(ContextSpecificTag(TAG_DURATION_REQ), duration) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } -suspend fun readActionListAttribute(): ActionListAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readActionListAttribute(): ActionListAttribute { + 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}") - } + 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) { - "Actionlist attribute not found in response" - } + } + + requireNotNull(attributeData) { "Actionlist 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(ActionsClusterActionStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(ActionsClusterActionStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return ActionListAttribute(decodedValue) } suspend fun subscribeActionListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ActionListAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ActionListAttributeSubscriptionState.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) { - "Actionlist attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Actionlist 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(ActionsClusterActionStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(ActionsClusterActionStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(ActionListAttributeSubscriptionState.Success(decodedValue)) } @@ -589,97 +539,94 @@ suspend fun readActionListAttribute(): ActionListAttribute {val ATTRIBUTE_ID: UI emit(ActionListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readEndpointListsAttribute(): EndpointListsAttribute {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readEndpointListsAttribute(): EndpointListsAttribute { + 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}") - } + 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) { - "Endpointlists attribute not found in response" - } + } + + requireNotNull(attributeData) { "Endpointlists 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(ActionsClusterEndpointListStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(ActionsClusterEndpointListStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EndpointListsAttribute(decodedValue) } suspend fun subscribeEndpointListsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(EndpointListsAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + EndpointListsAttributeSubscriptionState.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) { - "Endpointlists attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Endpointlists 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(ActionsClusterEndpointListStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(ActionsClusterEndpointListStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(EndpointListsAttributeSubscriptionState.Success(decodedValue)) } @@ -687,194 +634,187 @@ suspend fun readEndpointListsAttribute(): EndpointListsAttribute {val ATTRIBUTE_ emit(EndpointListsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readSetupURLAttribute(): String? {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readSetupURLAttribute(): String? { + 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}") - } + 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) { - "Setupurl attribute not found in response" - } + } + + requireNotNull(attributeData) { "Setupurl attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeSetupURLAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StringSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StringSubscriptionState.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) { - "Setupurl attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Setupurl attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(StringSubscriptionState.Success(it)) - } - + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(StringSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -882,97 +822,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -980,97 +919,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1078,97 +1014,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1176,81 +1109,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1262,80 +1190,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1348,7 +1273,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/ActivatedCarbonFilterMonitoringCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/ActivatedCarbonFilterMonitoringCluster.kt index 73fbba68b06ac4..07a7a1191d5881 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/ActivatedCarbonFilterMonitoringCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/ActivatedCarbonFilterMonitoringCluster.kt @@ -17,410 +17,370 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration 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.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class ActivatedCarbonFilterMonitoringCluster(private val controller: MatterController, private val endpointId: UShort) {class LastChangedTimeAttribute( - val value: UInt? - ) +class ActivatedCarbonFilterMonitoringCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class LastChangedTimeAttribute(val value: UInt?) sealed class LastChangedTimeAttributeSubscriptionState { - data class Success( - val value: UInt? - ) : LastChangedTimeAttributeSubscriptionState() - + data class Success(val value: UInt?) : LastChangedTimeAttributeSubscriptionState() + data class Error(val exception: Exception) : LastChangedTimeAttributeSubscriptionState() - object SubscriptionEstablished : LastChangedTimeAttributeSubscriptionState() - } -class ReplacementProductListAttribute( + object SubscriptionEstablished : LastChangedTimeAttributeSubscriptionState() + } + + class ReplacementProductListAttribute( val value: List? ) sealed class ReplacementProductListAttributeSubscriptionState { data class Success( - val value: List? + val value: List? ) : ReplacementProductListAttributeSubscriptionState() - + data class Error(val exception: Exception) : ReplacementProductListAttributeSubscriptionState() - object SubscriptionEstablished : ReplacementProductListAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : ReplacementProductListAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } suspend fun resetCondition(timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } -suspend fun readConditionAttribute(): 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) - ) - + + suspend fun readConditionAttribute(): 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}") - } + 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) { - "Condition attribute not found in response" - } + } + + requireNotNull(attributeData) { "Condition 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeConditionAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Condition attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Condition 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)) - } - + 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 readDegradationDirectionAttribute(): 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) - ) - + + suspend fun readDegradationDirectionAttribute(): 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}") - } + 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) { - "Degradationdirection attribute not found in response" - } + } + + requireNotNull(attributeData) { "Degradationdirection 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeDegradationDirectionAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Degradationdirection attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Degradationdirection 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)) - } - + 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 readChangeIndicationAttribute(): UByte {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readChangeIndicationAttribute(): UByte { + 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}") - } + 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) { - "Changeindication attribute not found in response" - } + } + + requireNotNull(attributeData) { "Changeindication 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 subscribeChangeIndicationAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Changeindication attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Changeindication attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -433,174 +393,160 @@ suspend fun readChangeIndicationAttribute(): UByte {val ATTRIBUTE_ID: UInt = 2u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readInPlaceIndicatorAttribute(): 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) - ) - + + suspend fun readInPlaceIndicatorAttribute(): 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}") - } + 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) { - "Inplaceindicator attribute not found in response" - } + } + + requireNotNull(attributeData) { "Inplaceindicator 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 - } - + val decodedValue: Boolean? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeInPlaceIndicatorAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Inplaceindicator attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Inplaceindicator 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)) - } - + 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 readLastChangedTimeAttribute(): LastChangedTimeAttribute {val ATTRIBUTE_ID: UInt = 4u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readLastChangedTimeAttribute(): LastChangedTimeAttribute { + 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}") - } + 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) { - "Lastchangedtime attribute not found in response" - } + } + + requireNotNull(attributeData) { "Lastchangedtime attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return LastChangedTimeAttribute(decodedValue) } - suspend fun writeLastChangedTimeAttribute( - value: UInt, - timedWriteTimeout: Duration? = null) { + suspend fun writeLastChangedTimeAttribute(value: UInt, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 4u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -621,266 +567,273 @@ suspend fun readLastChangedTimeAttribute(): LastChangedTimeAttribute {val ATTRIB throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeLastChangedTimeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(LastChangedTimeAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + LastChangedTimeAttributeSubscriptionState.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) { - "Lastchangedtime attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Lastchangedtime attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(LastChangedTimeAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(LastChangedTimeAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(LastChangedTimeAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readReplacementProductListAttribute(): ReplacementProductListAttribute {val ATTRIBUTE_ID: UInt = 5u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readReplacementProductListAttribute(): ReplacementProductListAttribute { + 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}") - } + 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) { - "Replacementproductlist attribute not found in response" - } + } + + requireNotNull(attributeData) { "Replacementproductlist attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(ActivatedCarbonFilterMonitoringClusterReplacementProductStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add( + ActivatedCarbonFilterMonitoringClusterReplacementProductStruct.fromTlv( + AnonymousTag, + tlvReader, + ) + ) + } + tlvReader.exitContainer() + } + } else { + null } - tlvReader.exitContainer() - } - } else { - null - } - return ReplacementProductListAttribute(decodedValue) } suspend fun subscribeReplacementProductListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ReplacementProductListAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ReplacementProductListAttributeSubscriptionState.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) { - "Replacementproductlist attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Replacementproductlist attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(ActivatedCarbonFilterMonitoringClusterReplacementProductStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { - emit(ReplacementProductListAttributeSubscriptionState.Success(it)) - } - + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add( + ActivatedCarbonFilterMonitoringClusterReplacementProductStruct.fromTlv( + AnonymousTag, + tlvReader, + ) + ) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { emit(ReplacementProductListAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ReplacementProductListAttributeSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -888,97 +841,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -986,97 +938,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1084,97 +1033,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1182,81 +1128,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1268,80 +1209,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1354,7 +1292,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/AdministratorCommissioningCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/AdministratorCommissioningCluster.kt index 50dc00e41902ff..5ac1e18a200d19 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/AdministratorCommissioningCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/AdministratorCommissioningCluster.kt @@ -17,133 +17,101 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.UShortSubscriptionState +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class AdministratorCommissioningCluster(private val controller: MatterController, private val endpointId: UShort) {class AdminFabricIndexAttribute( - val value: UByte? - ) +class AdministratorCommissioningCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class AdminFabricIndexAttribute(val value: UByte?) sealed class AdminFabricIndexAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : AdminFabricIndexAttributeSubscriptionState() - + data class Success(val value: UByte?) : AdminFabricIndexAttributeSubscriptionState() + data class Error(val exception: Exception) : AdminFabricIndexAttributeSubscriptionState() - object SubscriptionEstablished : AdminFabricIndexAttributeSubscriptionState() - } -class AdminVendorIdAttribute( - val value: UShort? - ) + object SubscriptionEstablished : AdminFabricIndexAttributeSubscriptionState() + } + + class AdminVendorIdAttribute(val value: UShort?) sealed class AdminVendorIdAttributeSubscriptionState { - data class Success( - val value: UShort? - ) : AdminVendorIdAttributeSubscriptionState() - + data class Success(val value: UShort?) : AdminVendorIdAttributeSubscriptionState() + data class Error(val exception: Exception) : AdminVendorIdAttributeSubscriptionState() - object SubscriptionEstablished : AdminVendorIdAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : AdminVendorIdAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun openCommissioningWindow(commissioningTimeout: UShort - ,PAKEPasscodeVerifier: ByteArray - ,discriminator: UShort - ,iterations: UInt - ,salt: ByteArray - ,timedInvokeTimeout: Duration) { + suspend fun openCommissioningWindow( + commissioningTimeout: UShort, + PAKEPasscodeVerifier: ByteArray, + discriminator: UShort, + iterations: UInt, + salt: ByteArray, + timedInvokeTimeout: Duration, + ) { val commandId: UInt = 0u val tlvWriter = TlvWriter() @@ -162,36 +130,38 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_ITERATIONS_REQ), iterations) val TAG_SALT_REQ: Int = 4 - tlvWriter.put(ContextSpecificTag(TAG_SALT_REQ), salt) + tlvWriter.put(ContextSpecificTag(TAG_SALT_REQ), salt) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun openBasicCommissioningWindow(commissioningTimeout: UShort - ,timedInvokeTimeout: Duration) { + suspend fun openBasicCommissioningWindow( + commissioningTimeout: UShort, + timedInvokeTimeout: Duration, + ) { val commandId: UInt = 1u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_COMMISSIONING_TIMEOUT_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_COMMISSIONING_TIMEOUT_REQ), commissioningTimeout) + tlvWriter.put(ContextSpecificTag(TAG_COMMISSIONING_TIMEOUT_REQ), commissioningTimeout) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -202,92 +172,87 @@ class AttributeListAttribute( val commandId: UInt = 2u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } -suspend fun readWindowStatusAttribute(): 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) - ) - + + suspend fun readWindowStatusAttribute(): 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}") - } + 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) { - "Windowstatus attribute not found in response" - } + } + + requireNotNull(attributeData) { "Windowstatus 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 subscribeWindowStatusAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Windowstatus attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Windowstatus attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -299,295 +264,284 @@ suspend fun readWindowStatusAttribute(): UByte {val ATTRIBUTE_ID: UInt = 0u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAdminFabricIndexAttribute(): AdminFabricIndexAttribute {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readAdminFabricIndexAttribute(): AdminFabricIndexAttribute { + 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}") - } + 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) { - "Adminfabricindex attribute not found in response" - } + } + + requireNotNull(attributeData) { "Adminfabricindex attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return AdminFabricIndexAttribute(decodedValue) } suspend fun subscribeAdminFabricIndexAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(AdminFabricIndexAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + AdminFabricIndexAttributeSubscriptionState.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) { - "Adminfabricindex attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Adminfabricindex 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.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(AdminFabricIndexAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(AdminFabricIndexAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(AdminFabricIndexAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAdminVendorIdAttribute(): AdminVendorIdAttribute {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readAdminVendorIdAttribute(): AdminVendorIdAttribute { + 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}") - } + 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) { - "Adminvendorid attribute not found in response" - } + } + + requireNotNull(attributeData) { "Adminvendorid attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = if (!tlvReader.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return AdminVendorIdAttribute(decodedValue) } suspend fun subscribeAdminVendorIdAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(AdminVendorIdAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + AdminVendorIdAttributeSubscriptionState.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) { - "Adminvendorid attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Adminvendorid 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.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(AdminVendorIdAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(AdminVendorIdAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(AdminVendorIdAttributeSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -595,97 +549,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -693,97 +646,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -791,97 +741,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -889,81 +836,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -975,80 +917,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1061,7 +1000,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/AirQualityCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/AirQualityCluster.kt index 7622ac8f893d32..3b8b97c9484f10 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/AirQualityCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/AirQualityCluster.kt @@ -17,173 +17,132 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse -import matter.controller.model.AttributePath -import matter.controller.model.CommandPath +import matter.controller.UShortSubscriptionState import matter.controller.cluster.structs.* +import matter.controller.model.AttributePath import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader -import matter.tlv.TlvWriter -class AirQualityCluster(private val controller: MatterController, private val endpointId: UShort) {class GeneratedCommandListAttribute( - val value: List - ) +class AirQualityCluster(private val controller: MatterController, private val endpointId: UShort) { + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } -suspend fun readAirQualityAttribute(): 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) - ) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } + + suspend fun readAirQualityAttribute(): 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}") - } + 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) { - "Airquality attribute not found in response" - } + } + + requireNotNull(attributeData) { "Airquality 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 subscribeAirQualityAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Airquality attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Airquality attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -195,97 +154,96 @@ suspend fun readAirQualityAttribute(): UByte {val ATTRIBUTE_ID: UInt = 0u emit(UByteSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -293,97 +251,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -391,97 +348,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -489,97 +443,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -587,81 +538,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -673,80 +619,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -759,7 +702,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/ApplicationBasicCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/ApplicationBasicCluster.kt index 880e6385833234..02e84a912d3fd0 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/ApplicationBasicCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/ApplicationBasicCluster.kt @@ -17,392 +17,340 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest +import matter.controller.StringSubscriptionState import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse -import matter.controller.model.AttributePath -import matter.controller.model.CommandPath +import matter.controller.UShortSubscriptionState import matter.controller.cluster.structs.* +import matter.controller.model.AttributePath import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader -import matter.tlv.TlvWriter -class ApplicationBasicCluster(private val controller: MatterController, private val endpointId: UShort) {class ApplicationAttribute( - val value: ApplicationBasicClusterApplicationStruct - ) +class ApplicationBasicCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class ApplicationAttribute(val value: ApplicationBasicClusterApplicationStruct) sealed class ApplicationAttributeSubscriptionState { - data class Success( - val value: ApplicationBasicClusterApplicationStruct - ) : ApplicationAttributeSubscriptionState() - + data class Success(val value: ApplicationBasicClusterApplicationStruct) : + ApplicationAttributeSubscriptionState() + data class Error(val exception: Exception) : ApplicationAttributeSubscriptionState() - object SubscriptionEstablished : ApplicationAttributeSubscriptionState() - } -class AllowedVendorListAttribute( - val value: List - ) + object SubscriptionEstablished : ApplicationAttributeSubscriptionState() + } + + class AllowedVendorListAttribute(val value: List) sealed class AllowedVendorListAttributeSubscriptionState { - data class Success( - val value: List - ) : AllowedVendorListAttributeSubscriptionState() - + data class Success(val value: List) : AllowedVendorListAttributeSubscriptionState() + data class Error(val exception: Exception) : AllowedVendorListAttributeSubscriptionState() - object SubscriptionEstablished : AllowedVendorListAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : AllowedVendorListAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } -suspend fun readVendorNameAttribute(): String? {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } + + suspend fun readVendorNameAttribute(): String? { + 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}") - } + 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) { - "Vendorname attribute not found in response" - } + } + + requireNotNull(attributeData) { "Vendorname attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeVendorNameAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StringSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StringSubscriptionState.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) { - "Vendorname attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Vendorname attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(StringSubscriptionState.Success(it)) - } - + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(StringSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readVendorIDAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readVendorIDAttribute(): UShort? { + 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}") - } + 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) { - "Vendorid attribute not found in response" - } + } + + requireNotNull(attributeData) { "Vendorid 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeVendorIDAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Vendorid attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Vendorid 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)) - } - + 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 readApplicationNameAttribute(): String {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readApplicationNameAttribute(): String { + 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}") - } + 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) { - "Applicationname attribute not found in response" - } + } + + requireNotNull(attributeData) { "Applicationname attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: String = tlvReader.getString(AnonymousTag) - return decodedValue } suspend fun subscribeApplicationNameAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StringSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StringSubscriptionState.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) { - "Applicationname attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Applicationname attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -415,182 +363,173 @@ suspend fun readApplicationNameAttribute(): String {val ATTRIBUTE_ID: UInt = 2u emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readProductIDAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readProductIDAttribute(): UShort? { + 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}") - } + 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) { - "Productid attribute not found in response" - } + } + + requireNotNull(attributeData) { "Productid 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeProductIDAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Productid attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Productid 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)) - } - + 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 readApplicationAttribute(): ApplicationAttribute {val ATTRIBUTE_ID: UInt = 4u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readApplicationAttribute(): ApplicationAttribute { + 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}") - } + 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) { - "Application attribute not found in response" - } + } + + requireNotNull(attributeData) { "Application attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ApplicationBasicClusterApplicationStruct = ApplicationBasicClusterApplicationStruct.fromTlv(AnonymousTag, tlvReader) - + val decodedValue: ApplicationBasicClusterApplicationStruct = + ApplicationBasicClusterApplicationStruct.fromTlv(AnonymousTag, tlvReader) return ApplicationAttribute(decodedValue) } suspend fun subscribeApplicationAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ApplicationAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ApplicationAttributeSubscriptionState.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) { - "Application attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Application attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ApplicationBasicClusterApplicationStruct = ApplicationBasicClusterApplicationStruct.fromTlv(AnonymousTag, tlvReader) + val decodedValue: ApplicationBasicClusterApplicationStruct = + ApplicationBasicClusterApplicationStruct.fromTlv(AnonymousTag, tlvReader) emit(ApplicationAttributeSubscriptionState.Success(decodedValue)) } @@ -598,81 +537,76 @@ suspend fun readApplicationAttribute(): ApplicationAttribute {val ATTRIBUTE_ID: emit(ApplicationAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readStatusAttribute(): UByte {val ATTRIBUTE_ID: UInt = 5u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readStatusAttribute(): UByte { + 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}") - } + 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) { - "Status attribute not found in response" - } + } + + requireNotNull(attributeData) { "Status 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 subscribeStatusAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Status attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Status attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -684,80 +618,77 @@ suspend fun readStatusAttribute(): UByte {val ATTRIBUTE_ID: UInt = 5u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readApplicationVersionAttribute(): String {val ATTRIBUTE_ID: UInt = 6u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readApplicationVersionAttribute(): String { + 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}") - } + 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) { - "Applicationversion attribute not found in response" - } + } + + requireNotNull(attributeData) { "Applicationversion attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: String = tlvReader.getString(AnonymousTag) - return decodedValue } suspend fun subscribeApplicationVersionAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StringSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StringSubscriptionState.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) { - "Applicationversion attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Applicationversion attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -770,97 +701,96 @@ suspend fun readApplicationVersionAttribute(): String {val ATTRIBUTE_ID: UInt = emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAllowedVendorListAttribute(): AllowedVendorListAttribute {val ATTRIBUTE_ID: UInt = 7u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readAllowedVendorListAttribute(): AllowedVendorListAttribute { + 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}") - } + 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) { - "Allowedvendorlist attribute not found in response" - } + } + + requireNotNull(attributeData) { "Allowedvendorlist 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.getUShort(AnonymousTag)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUShort(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AllowedVendorListAttribute(decodedValue) } suspend fun subscribeAllowedVendorListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(AllowedVendorListAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + AllowedVendorListAttributeSubscriptionState.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) { - "Allowedvendorlist attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Allowedvendorlist 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.getUShort(AnonymousTag)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUShort(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AllowedVendorListAttributeSubscriptionState.Success(decodedValue)) } @@ -868,97 +798,96 @@ suspend fun readAllowedVendorListAttribute(): AllowedVendorListAttribute {val AT emit(AllowedVendorListAttributeSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -966,97 +895,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1064,97 +992,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1162,97 +1087,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1260,81 +1182,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1346,80 +1263,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1432,7 +1346,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/ApplicationLauncherCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/ApplicationLauncherCluster.kt index 5045bf8de2e5ee..2f6d4b74bdbb85 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/ApplicationLauncherCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/ApplicationLauncherCluster.kt @@ -17,156 +17,117 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState -import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.UShortSubscriptionState +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class ApplicationLauncherCluster(private val controller: MatterController, private val endpointId: UShort) { - class LauncherResponse( - val status: UByte, - val data: ByteArray? - ) -class CatalogListAttribute( - val value: List? - ) +class ApplicationLauncherCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class LauncherResponse(val status: UByte, val data: ByteArray?) + + class CatalogListAttribute(val value: List?) sealed class CatalogListAttributeSubscriptionState { - data class Success( - val value: List? - ) : CatalogListAttributeSubscriptionState() - + data class Success(val value: List?) : CatalogListAttributeSubscriptionState() + data class Error(val exception: Exception) : CatalogListAttributeSubscriptionState() - object SubscriptionEstablished : CatalogListAttributeSubscriptionState() - } -class CurrentAppAttribute( - val value: ApplicationLauncherClusterApplicationEPStruct? - ) + object SubscriptionEstablished : CatalogListAttributeSubscriptionState() + } + + class CurrentAppAttribute(val value: ApplicationLauncherClusterApplicationEPStruct?) sealed class CurrentAppAttributeSubscriptionState { - data class Success( - val value: ApplicationLauncherClusterApplicationEPStruct? - ) : CurrentAppAttributeSubscriptionState() - + data class Success(val value: ApplicationLauncherClusterApplicationEPStruct?) : + CurrentAppAttributeSubscriptionState() + data class Error(val exception: Exception) : CurrentAppAttributeSubscriptionState() - object SubscriptionEstablished : CurrentAppAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : CurrentAppAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun launchApp(application: ApplicationLauncherClusterApplicationStruct? - ,data: ByteArray? - ,timedInvokeTimeout: Duration? = null): LauncherResponse { + suspend fun launchApp( + application: ApplicationLauncherClusterApplicationStruct?, + data: ByteArray?, + timedInvokeTimeout: Duration? = null, + ): LauncherResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_APPLICATION_REQ: Int = 0 - application?.let { - application.toTlv(ContextSpecificTag(TAG_APPLICATION_REQ), tlvWriter) - } + application?.let { application.toTlv(ContextSpecificTag(TAG_APPLICATION_REQ), tlvWriter) } val TAG_DATA_REQ: Int = 1 - data?.let { - tlvWriter.put(ContextSpecificTag(TAG_DATA_REQ), data) - } + data?.let { tlvWriter.put(ContextSpecificTag(TAG_DATA_REQ), data) } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -176,70 +137,61 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_DATA: Int = 1 var data_decoded: ByteArray? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_DATA)) {data_decoded = + if (tag == ContextSpecificTag(TAG_STATUS)) { + status_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_DATA)) { + data_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getByteArray(tag) - } else { - null - } - }} - - - else { + tlvReader.getByteArray(tag) + } else { + null + } + } + } else { tlvReader.skipElement() } } - - if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - - - tlvReader.exitContainer() - return LauncherResponse( - status_decoded, - data_decoded - ) + return LauncherResponse(status_decoded, data_decoded) } - suspend fun stopApp(application: ApplicationLauncherClusterApplicationStruct? - ,timedInvokeTimeout: Duration? = null): LauncherResponse { + suspend fun stopApp( + application: ApplicationLauncherClusterApplicationStruct?, + timedInvokeTimeout: Duration? = null, + ): LauncherResponse { val commandId: UInt = 1u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_APPLICATION_REQ: Int = 0 - application?.let { - application.toTlv(ContextSpecificTag(TAG_APPLICATION_REQ), tlvWriter) - } + application?.let { application.toTlv(ContextSpecificTag(TAG_APPLICATION_REQ), tlvWriter) } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -249,70 +201,61 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_DATA: Int = 1 var data_decoded: ByteArray? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_DATA)) {data_decoded = + if (tag == ContextSpecificTag(TAG_STATUS)) { + status_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_DATA)) { + data_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getByteArray(tag) - } else { - null - } - }} - - - else { + tlvReader.getByteArray(tag) + } else { + null + } + } + } else { tlvReader.skipElement() } } - - if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - - - tlvReader.exitContainer() - return LauncherResponse( - status_decoded, - data_decoded - ) + return LauncherResponse(status_decoded, data_decoded) } - suspend fun hideApp(application: ApplicationLauncherClusterApplicationStruct? - ,timedInvokeTimeout: Duration? = null): LauncherResponse { + suspend fun hideApp( + application: ApplicationLauncherClusterApplicationStruct?, + timedInvokeTimeout: Duration? = null, + ): LauncherResponse { val commandId: UInt = 2u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_APPLICATION_REQ: Int = 0 - application?.let { - application.toTlv(ContextSpecificTag(TAG_APPLICATION_REQ), tlvWriter) - } + application?.let { application.toTlv(ContextSpecificTag(TAG_APPLICATION_REQ), tlvWriter) } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -322,356 +265,334 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_DATA: Int = 1 var data_decoded: ByteArray? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_DATA)) {data_decoded = + if (tag == ContextSpecificTag(TAG_STATUS)) { + status_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_DATA)) { + data_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getByteArray(tag) - } else { - null - } - }} - - - else { + tlvReader.getByteArray(tag) + } else { + null + } + } + } else { tlvReader.skipElement() } } - - if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - - - tlvReader.exitContainer() - return LauncherResponse( - status_decoded, - data_decoded - ) + return LauncherResponse(status_decoded, data_decoded) } -suspend fun readCatalogListAttribute(): CatalogListAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readCatalogListAttribute(): CatalogListAttribute { + 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}") - } + 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) { - "Cataloglist attribute not found in response" - } + } + + requireNotNull(attributeData) { "Cataloglist attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getUShort(AnonymousTag)) + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUShort(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null } - tlvReader.exitContainer() - } - } else { - null - } - return CatalogListAttribute(decodedValue) } suspend fun subscribeCatalogListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(CatalogListAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + CatalogListAttributeSubscriptionState.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) { - "Cataloglist attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Cataloglist attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getUShort(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { - emit(CatalogListAttributeSubscriptionState.Success(it)) - } - + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUShort(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { emit(CatalogListAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(CatalogListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCurrentAppAttribute(): CurrentAppAttribute {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readCurrentAppAttribute(): CurrentAppAttribute { + 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}") - } + 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) { - "Currentapp attribute not found in response" - } + } + + requireNotNull(attributeData) { "Currentapp attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ApplicationLauncherClusterApplicationEPStruct? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - ApplicationLauncherClusterApplicationEPStruct.fromTlv(AnonymousTag, tlvReader) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: ApplicationLauncherClusterApplicationEPStruct? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + ApplicationLauncherClusterApplicationEPStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return CurrentAppAttribute(decodedValue) } suspend fun subscribeCurrentAppAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(CurrentAppAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + CurrentAppAttributeSubscriptionState.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) { - "Currentapp attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Currentapp attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ApplicationLauncherClusterApplicationEPStruct? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - ApplicationLauncherClusterApplicationEPStruct.fromTlv(AnonymousTag, tlvReader) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(CurrentAppAttributeSubscriptionState.Success(it)) - } - + val decodedValue: ApplicationLauncherClusterApplicationEPStruct? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + ApplicationLauncherClusterApplicationEPStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(CurrentAppAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(CurrentAppAttributeSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -679,97 +600,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -777,97 +697,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -875,97 +792,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -973,81 +887,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1059,80 +968,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1145,7 +1051,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/AudioOutputCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/AudioOutputCluster.kt index c038970d786898..6238d2b18bf749 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/AudioOutputCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/AudioOutputCluster.kt @@ -17,139 +17,103 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.UShortSubscriptionState +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class AudioOutputCluster(private val controller: MatterController, private val endpointId: UShort) {class OutputListAttribute( - val value: List - ) +class AudioOutputCluster(private val controller: MatterController, private val endpointId: UShort) { + class OutputListAttribute(val value: List) sealed class OutputListAttributeSubscriptionState { - data class Success( - val value: List - ) : OutputListAttributeSubscriptionState() - + data class Success(val value: List) : + OutputListAttributeSubscriptionState() + data class Error(val exception: Exception) : OutputListAttributeSubscriptionState() - object SubscriptionEstablished : OutputListAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : OutputListAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun selectOutput(index: UByte - ,timedInvokeTimeout: Duration? = null) { + suspend fun selectOutput(index: UByte, timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_INDEX_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_INDEX_REQ), index) + tlvWriter.put(ContextSpecificTag(TAG_INDEX_REQ), index) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun renameOutput(index: UByte - ,name: String - ,timedInvokeTimeout: Duration? = null) { + suspend fun renameOutput(index: UByte, name: String, timedInvokeTimeout: Duration? = null) { val commandId: UInt = 1u val tlvWriter = TlvWriter() @@ -159,108 +123,105 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_INDEX_REQ), index) val TAG_NAME_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_NAME_REQ), name) + tlvWriter.put(ContextSpecificTag(TAG_NAME_REQ), name) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } -suspend fun readOutputListAttribute(): OutputListAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readOutputListAttribute(): OutputListAttribute { + 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}") - } + 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) { - "Outputlist attribute not found in response" - } + } + + requireNotNull(attributeData) { "Outputlist 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(AudioOutputClusterOutputInfoStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(AudioOutputClusterOutputInfoStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return OutputListAttribute(decodedValue) } suspend fun subscribeOutputListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(OutputListAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + OutputListAttributeSubscriptionState.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) { - "Outputlist attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Outputlist 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(AudioOutputClusterOutputInfoStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(AudioOutputClusterOutputInfoStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(OutputListAttributeSubscriptionState.Success(decodedValue)) } @@ -268,81 +229,76 @@ suspend fun readOutputListAttribute(): OutputListAttribute {val ATTRIBUTE_ID: UI emit(OutputListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCurrentOutputAttribute(): 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) - ) - + + suspend fun readCurrentOutputAttribute(): 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}") - } + 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) { - "Currentoutput attribute not found in response" - } + } + + requireNotNull(attributeData) { "Currentoutput 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 subscribeCurrentOutputAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Currentoutput attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Currentoutput attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -354,97 +310,96 @@ suspend fun readCurrentOutputAttribute(): UByte {val ATTRIBUTE_ID: UInt = 1u emit(UByteSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -452,97 +407,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -550,97 +504,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -648,97 +599,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -746,81 +694,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -832,80 +775,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -918,7 +858,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/BallastConfigurationCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/BallastConfigurationCluster.kt index e733a38744d421..d013a6e1203d0f 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/BallastConfigurationCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/BallastConfigurationCluster.kt @@ -17,237 +17,192 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest +import matter.controller.StringSubscriptionState import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse -import matter.controller.model.AttributePath -import matter.controller.model.CommandPath import matter.controller.cluster.structs.* +import matter.controller.model.AttributePath import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class BallastConfigurationCluster(private val controller: MatterController, private val endpointId: UShort) {class IntrinsicBallastFactorAttribute( - val value: UByte? - ) +class BallastConfigurationCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class IntrinsicBallastFactorAttribute(val value: UByte?) sealed class IntrinsicBallastFactorAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : IntrinsicBallastFactorAttributeSubscriptionState() - + data class Success(val value: UByte?) : IntrinsicBallastFactorAttributeSubscriptionState() + data class Error(val exception: Exception) : IntrinsicBallastFactorAttributeSubscriptionState() - object SubscriptionEstablished : IntrinsicBallastFactorAttributeSubscriptionState() - } -class BallastFactorAdjustmentAttribute( - val value: UByte? - ) + object SubscriptionEstablished : IntrinsicBallastFactorAttributeSubscriptionState() + } + + class BallastFactorAdjustmentAttribute(val value: UByte?) sealed class BallastFactorAdjustmentAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : BallastFactorAdjustmentAttributeSubscriptionState() - - data class Error(val exception: Exception) : BallastFactorAdjustmentAttributeSubscriptionState() - - object SubscriptionEstablished : BallastFactorAdjustmentAttributeSubscriptionState() - } -class LampRatedHoursAttribute( - val value: UInt? - ) + data class Success(val value: UByte?) : BallastFactorAdjustmentAttributeSubscriptionState() + + data class Error(val exception: Exception) : + BallastFactorAdjustmentAttributeSubscriptionState() + + object SubscriptionEstablished : BallastFactorAdjustmentAttributeSubscriptionState() + } + + class LampRatedHoursAttribute(val value: UInt?) sealed class LampRatedHoursAttributeSubscriptionState { - data class Success( - val value: UInt? - ) : LampRatedHoursAttributeSubscriptionState() - + data class Success(val value: UInt?) : LampRatedHoursAttributeSubscriptionState() + data class Error(val exception: Exception) : LampRatedHoursAttributeSubscriptionState() - object SubscriptionEstablished : LampRatedHoursAttributeSubscriptionState() - } -class LampBurnHoursAttribute( - val value: UInt? - ) + object SubscriptionEstablished : LampRatedHoursAttributeSubscriptionState() + } + + class LampBurnHoursAttribute(val value: UInt?) sealed class LampBurnHoursAttributeSubscriptionState { - data class Success( - val value: UInt? - ) : LampBurnHoursAttributeSubscriptionState() - + data class Success(val value: UInt?) : LampBurnHoursAttributeSubscriptionState() + data class Error(val exception: Exception) : LampBurnHoursAttributeSubscriptionState() - object SubscriptionEstablished : LampBurnHoursAttributeSubscriptionState() - } -class LampBurnHoursTripPointAttribute( - val value: UInt? - ) + object SubscriptionEstablished : LampBurnHoursAttributeSubscriptionState() + } + + class LampBurnHoursTripPointAttribute(val value: UInt?) sealed class LampBurnHoursTripPointAttributeSubscriptionState { - data class Success( - val value: UInt? - ) : LampBurnHoursTripPointAttributeSubscriptionState() - + data class Success(val value: UInt?) : LampBurnHoursTripPointAttributeSubscriptionState() + data class Error(val exception: Exception) : LampBurnHoursTripPointAttributeSubscriptionState() - object SubscriptionEstablished : LampBurnHoursTripPointAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : LampBurnHoursTripPointAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } -suspend fun readPhysicalMinLevelAttribute(): 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) - ) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } + + suspend fun readPhysicalMinLevelAttribute(): 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}") - } + 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) { - "Physicalminlevel attribute not found in response" - } + } + + requireNotNull(attributeData) { "Physicalminlevel 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 subscribePhysicalMinLevelAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Physicalminlevel attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Physicalminlevel attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -260,80 +215,77 @@ suspend fun readPhysicalMinLevelAttribute(): UByte {val ATTRIBUTE_ID: UInt = 0u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPhysicalMaxLevelAttribute(): 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) - ) - + + suspend fun readPhysicalMaxLevelAttribute(): 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}") - } + 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) { - "Physicalmaxlevel attribute not found in response" - } + } + + requireNotNull(attributeData) { "Physicalmaxlevel 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 subscribePhysicalMaxLevelAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Physicalmaxlevel attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Physicalmaxlevel attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -346,165 +298,148 @@ suspend fun readPhysicalMaxLevelAttribute(): UByte {val ATTRIBUTE_ID: UInt = 1u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readBallastStatusAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readBallastStatusAttribute(): UByte? { + 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}") - } + 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) { - "Ballaststatus attribute not found in response" - } + } + + requireNotNull(attributeData) { "Ballaststatus 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeBallastStatusAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Ballaststatus attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Ballaststatus 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMinLevelAttribute(): UByte {val ATTRIBUTE_ID: UInt = 16u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMinLevelAttribute(): UByte { + val ATTRIBUTE_ID: UInt = 16u + + 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}") - } + 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) { - "Minlevel attribute not found in response" - } + } + + requireNotNull(attributeData) { "Minlevel 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 writeMinLevelAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeMinLevelAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -525,43 +460,45 @@ suspend fun readMinLevelAttribute(): UByte {val ATTRIBUTE_ID: UInt = 16u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeMinLevelAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Minlevel attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Minlevel attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -573,68 +510,57 @@ suspend fun readMinLevelAttribute(): UByte {val ATTRIBUTE_ID: UInt = 16u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMaxLevelAttribute(): UByte {val ATTRIBUTE_ID: UInt = 17u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMaxLevelAttribute(): UByte { + val ATTRIBUTE_ID: UInt = 17u + + 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}") - } + 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) { - "Maxlevel attribute not found in response" - } + } + + requireNotNull(attributeData) { "Maxlevel 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 writeMaxLevelAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeMaxLevelAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 17u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -655,43 +581,45 @@ suspend fun readMaxLevelAttribute(): UByte {val ATTRIBUTE_ID: UInt = 17u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeMaxLevelAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 17u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Maxlevel attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Maxlevel attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -703,77 +631,70 @@ suspend fun readMaxLevelAttribute(): UByte {val ATTRIBUTE_ID: UInt = 17u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readIntrinsicBallastFactorAttribute(): IntrinsicBallastFactorAttribute {val ATTRIBUTE_ID: UInt = 20u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readIntrinsicBallastFactorAttribute(): IntrinsicBallastFactorAttribute { + val ATTRIBUTE_ID: UInt = 20u + + 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}") - } + 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) { - "Intrinsicballastfactor attribute not found in response" - } + } + + requireNotNull(attributeData) { "Intrinsicballastfactor attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return IntrinsicBallastFactorAttribute(decodedValue) } suspend fun writeIntrinsicBallastFactorAttribute( value: UByte, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 20u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -794,137 +715,132 @@ suspend fun readIntrinsicBallastFactorAttribute(): IntrinsicBallastFactorAttribu throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeIntrinsicBallastFactorAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 20u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(IntrinsicBallastFactorAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + IntrinsicBallastFactorAttributeSubscriptionState.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) { - "Intrinsicballastfactor attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Intrinsicballastfactor 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(IntrinsicBallastFactorAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(IntrinsicBallastFactorAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(IntrinsicBallastFactorAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readBallastFactorAdjustmentAttribute(): BallastFactorAdjustmentAttribute {val ATTRIBUTE_ID: UInt = 21u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readBallastFactorAdjustmentAttribute(): BallastFactorAdjustmentAttribute { + val ATTRIBUTE_ID: UInt = 21u + + 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}") - } + 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) { - "Ballastfactoradjustment attribute not found in response" - } + } + + requireNotNull(attributeData) { "Ballastfactoradjustment attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return BallastFactorAdjustmentAttribute(decodedValue) } suspend fun writeBallastFactorAdjustmentAttribute( value: UByte, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 21u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -945,141 +861,138 @@ suspend fun readBallastFactorAdjustmentAttribute(): BallastFactorAdjustmentAttri throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeBallastFactorAdjustmentAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 21u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(BallastFactorAdjustmentAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + BallastFactorAdjustmentAttributeSubscriptionState.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) { - "Ballastfactoradjustment attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Ballastfactoradjustment 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(BallastFactorAdjustmentAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(BallastFactorAdjustmentAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(BallastFactorAdjustmentAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readLampQuantityAttribute(): UByte {val ATTRIBUTE_ID: UInt = 32u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readLampQuantityAttribute(): UByte { + val ATTRIBUTE_ID: UInt = 32u + + 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}") - } + 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) { - "Lampquantity attribute not found in response" - } + } + + requireNotNull(attributeData) { "Lampquantity 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 subscribeLampQuantityAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 32u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Lampquantity attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Lampquantity attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -1091,72 +1004,62 @@ suspend fun readLampQuantityAttribute(): UByte {val ATTRIBUTE_ID: UInt = 32u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readLampTypeAttribute(): String? {val ATTRIBUTE_ID: UInt = 48u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readLampTypeAttribute(): String? { + val ATTRIBUTE_ID: UInt = 48u + + 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}") - } + 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) { - "Lamptype attribute not found in response" - } + } + + requireNotNull(attributeData) { "Lamptype attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } return decodedValue } - suspend fun writeLampTypeAttribute( - value: String, - timedWriteTimeout: Duration? = null) { + suspend fun writeLampTypeAttribute(value: String, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 48u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -1177,127 +1080,117 @@ suspend fun readLampTypeAttribute(): String? {val ATTRIBUTE_ID: UInt = 48u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeLampTypeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 48u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StringSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StringSubscriptionState.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) { - "Lamptype attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Lamptype attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(StringSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(StringSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readLampManufacturerAttribute(): String? {val ATTRIBUTE_ID: UInt = 49u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readLampManufacturerAttribute(): String? { + val ATTRIBUTE_ID: UInt = 49u + + 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}") - } + 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) { - "Lampmanufacturer attribute not found in response" - } + } + + requireNotNull(attributeData) { "Lampmanufacturer attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } return decodedValue } - suspend fun writeLampManufacturerAttribute( - value: String, - timedWriteTimeout: Duration? = null) { + suspend fun writeLampManufacturerAttribute(value: String, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 49u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -1318,132 +1211,124 @@ suspend fun readLampManufacturerAttribute(): String? {val ATTRIBUTE_ID: UInt = 4 throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeLampManufacturerAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 49u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StringSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StringSubscriptionState.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) { - "Lampmanufacturer attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Lampmanufacturer attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(StringSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(StringSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readLampRatedHoursAttribute(): LampRatedHoursAttribute {val ATTRIBUTE_ID: UInt = 50u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readLampRatedHoursAttribute(): LampRatedHoursAttribute { + val ATTRIBUTE_ID: UInt = 50u + + 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}") - } + 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) { - "Lampratedhours attribute not found in response" - } + } + + requireNotNull(attributeData) { "Lampratedhours attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return LampRatedHoursAttribute(decodedValue) } - suspend fun writeLampRatedHoursAttribute( - value: UInt, - timedWriteTimeout: Duration? = null) { + suspend fun writeLampRatedHoursAttribute(value: UInt, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 50u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -1464,137 +1349,129 @@ suspend fun readLampRatedHoursAttribute(): LampRatedHoursAttribute {val ATTRIBUT throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeLampRatedHoursAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 50u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(LampRatedHoursAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + LampRatedHoursAttributeSubscriptionState.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) { - "Lampratedhours attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Lampratedhours attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(LampRatedHoursAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(LampRatedHoursAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(LampRatedHoursAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readLampBurnHoursAttribute(): LampBurnHoursAttribute {val ATTRIBUTE_ID: UInt = 51u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readLampBurnHoursAttribute(): LampBurnHoursAttribute { + val ATTRIBUTE_ID: UInt = 51u + + 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}") - } + 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) { - "Lampburnhours attribute not found in response" - } + } + + requireNotNull(attributeData) { "Lampburnhours attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return LampBurnHoursAttribute(decodedValue) } - suspend fun writeLampBurnHoursAttribute( - value: UInt, - timedWriteTimeout: Duration? = null) { + suspend fun writeLampBurnHoursAttribute(value: UInt, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 51u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -1615,132 +1492,122 @@ suspend fun readLampBurnHoursAttribute(): LampBurnHoursAttribute {val ATTRIBUTE_ throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeLampBurnHoursAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 51u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(LampBurnHoursAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + LampBurnHoursAttributeSubscriptionState.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) { - "Lampburnhours attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Lampburnhours attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(LampBurnHoursAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(LampBurnHoursAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(LampBurnHoursAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readLampAlarmModeAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 52u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readLampAlarmModeAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 52u + + 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}") - } + 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) { - "Lampalarmmode attribute not found in response" - } + } + + requireNotNull(attributeData) { "Lampalarmmode 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } - suspend fun writeLampAlarmModeAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeLampAlarmModeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 52u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -1761,132 +1628,125 @@ suspend fun readLampAlarmModeAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 52u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeLampAlarmModeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 52u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Lampalarmmode attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Lampalarmmode 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readLampBurnHoursTripPointAttribute(): LampBurnHoursTripPointAttribute {val ATTRIBUTE_ID: UInt = 53u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readLampBurnHoursTripPointAttribute(): LampBurnHoursTripPointAttribute { + val ATTRIBUTE_ID: UInt = 53u + + 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}") - } + 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) { - "Lampburnhourstrippoint attribute not found in response" - } + } + + requireNotNull(attributeData) { "Lampburnhourstrippoint attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return LampBurnHoursTripPointAttribute(decodedValue) } suspend fun writeLampBurnHoursTripPointAttribute( value: UInt, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 53u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -1907,157 +1767,158 @@ suspend fun readLampBurnHoursTripPointAttribute(): LampBurnHoursTripPointAttribu throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeLampBurnHoursTripPointAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 53u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(LampBurnHoursTripPointAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + LampBurnHoursTripPointAttributeSubscriptionState.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) { - "Lampburnhourstrippoint attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Lampburnhourstrippoint attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(LampBurnHoursTripPointAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(LampBurnHoursTripPointAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(LampBurnHoursTripPointAttributeSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -2065,97 +1926,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -2163,97 +2023,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -2261,97 +2118,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -2359,81 +2213,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -2445,80 +2294,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -2531,7 +2377,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/BarrierControlCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/BarrierControlCluster.kt index 01b8f509d4f7af..1c424199292f41 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/BarrierControlCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/BarrierControlCluster.kt @@ -17,117 +17,91 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class BarrierControlCluster(private val controller: MatterController, private val endpointId: UShort) {class GeneratedCommandListAttribute( - val value: List - ) +class BarrierControlCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun barrierControlGoToPercent(percentOpen: UByte - ,timedInvokeTimeout: Duration? = null) { + suspend fun barrierControlGoToPercent(percentOpen: UByte, timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_PERCENT_OPEN_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_PERCENT_OPEN_REQ), percentOpen) + tlvWriter.put(ContextSpecificTag(TAG_PERCENT_OPEN_REQ), percentOpen) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -138,91 +112,88 @@ class AttributeListAttribute( val commandId: UInt = 1u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } -suspend fun readBarrierMovingStateAttribute(): 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) - ) - + + suspend fun readBarrierMovingStateAttribute(): 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}") - } + 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) { - "Barriermovingstate attribute not found in response" - } + } + + requireNotNull(attributeData) { "Barriermovingstate 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 subscribeBarrierMovingStateAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Barriermovingstate attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Barriermovingstate attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -235,80 +206,77 @@ suspend fun readBarrierMovingStateAttribute(): UByte {val ATTRIBUTE_ID: UInt = 1 emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readBarrierSafetyStatusAttribute(): 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) - ) - + + suspend fun readBarrierSafetyStatusAttribute(): 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}") - } + 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) { - "Barriersafetystatus attribute not found in response" - } + } + + requireNotNull(attributeData) { "Barriersafetystatus 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 subscribeBarrierSafetyStatusAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Barriersafetystatus attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Barriersafetystatus attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -321,80 +289,77 @@ suspend fun readBarrierSafetyStatusAttribute(): UShort {val ATTRIBUTE_ID: UInt = emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readBarrierCapabilitiesAttribute(): UByte {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readBarrierCapabilitiesAttribute(): UByte { + 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}") - } + 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) { - "Barriercapabilities attribute not found in response" - } + } + + requireNotNull(attributeData) { "Barriercapabilities 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 subscribeBarrierCapabilitiesAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Barriercapabilities attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Barriercapabilities attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -407,72 +372,62 @@ suspend fun readBarrierCapabilitiesAttribute(): UByte {val ATTRIBUTE_ID: UInt = emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readBarrierOpenEventsAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 4u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readBarrierOpenEventsAttribute(): UShort? { + 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}") - } + 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) { - "Barrieropenevents attribute not found in response" - } + } + + requireNotNull(attributeData) { "Barrieropenevents 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } - suspend fun writeBarrierOpenEventsAttribute( - value: UShort, - timedWriteTimeout: Duration? = null) { + suspend fun writeBarrierOpenEventsAttribute(value: UShort, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 4u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -493,127 +448,119 @@ suspend fun readBarrierOpenEventsAttribute(): UShort? {val ATTRIBUTE_ID: UInt = throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeBarrierOpenEventsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Barrieropenevents attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Barrieropenevents 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)) - } - + 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 readBarrierCloseEventsAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 5u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readBarrierCloseEventsAttribute(): UShort? { + 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}") - } + 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) { - "Barriercloseevents attribute not found in response" - } + } + + requireNotNull(attributeData) { "Barriercloseevents 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } - suspend fun writeBarrierCloseEventsAttribute( - value: UShort, - timedWriteTimeout: Duration? = null) { + suspend fun writeBarrierCloseEventsAttribute(value: UShort, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 5u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -634,127 +581,122 @@ suspend fun readBarrierCloseEventsAttribute(): UShort? {val ATTRIBUTE_ID: UInt = throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeBarrierCloseEventsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Barriercloseevents attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Barriercloseevents 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)) - } - + 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 readBarrierCommandOpenEventsAttribute(): 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) - ) - + + suspend fun readBarrierCommandOpenEventsAttribute(): 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}") - } + 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) { - "Barriercommandopenevents attribute not found in response" - } + } + + requireNotNull(attributeData) { "Barriercommandopenevents 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun writeBarrierCommandOpenEventsAttribute( value: UShort, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 6u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -775,127 +717,122 @@ suspend fun readBarrierCommandOpenEventsAttribute(): UShort? {val ATTRIBUTE_ID: throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeBarrierCommandOpenEventsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Barriercommandopenevents attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Barriercommandopenevents 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)) - } - + 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 readBarrierCommandCloseEventsAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 7u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readBarrierCommandCloseEventsAttribute(): UShort? { + 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}") - } + 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) { - "Barriercommandcloseevents attribute not found in response" - } + } + + requireNotNull(attributeData) { "Barriercommandcloseevents 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun writeBarrierCommandCloseEventsAttribute( value: UShort, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 7u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -916,127 +853,119 @@ suspend fun readBarrierCommandCloseEventsAttribute(): UShort? {val ATTRIBUTE_ID: throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeBarrierCommandCloseEventsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Barriercommandcloseevents attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Barriercommandcloseevents 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)) - } - + 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 readBarrierOpenPeriodAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 8u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readBarrierOpenPeriodAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 8u + + 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}") - } + 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) { - "Barrieropenperiod attribute not found in response" - } + } + + requireNotNull(attributeData) { "Barrieropenperiod 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } - suspend fun writeBarrierOpenPeriodAttribute( - value: UShort, - timedWriteTimeout: Duration? = null) { + suspend fun writeBarrierOpenPeriodAttribute(value: UShort, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 8u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -1057,127 +986,119 @@ suspend fun readBarrierOpenPeriodAttribute(): UShort? {val ATTRIBUTE_ID: UInt = throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeBarrierOpenPeriodAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Barrieropenperiod attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Barrieropenperiod 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)) - } - + 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 readBarrierClosePeriodAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 9u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readBarrierClosePeriodAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 9u + + 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}") - } + 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) { - "Barriercloseperiod attribute not found in response" - } + } + + requireNotNull(attributeData) { "Barriercloseperiod 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } - suspend fun writeBarrierClosePeriodAttribute( - value: UShort, - timedWriteTimeout: Duration? = null) { + suspend fun writeBarrierClosePeriodAttribute(value: UShort, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 9u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -1198,135 +1119,134 @@ suspend fun readBarrierClosePeriodAttribute(): UShort? {val ATTRIBUTE_ID: UInt = throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeBarrierClosePeriodAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Barriercloseperiod attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Barriercloseperiod 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)) - } - + 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 readBarrierPositionAttribute(): UByte {val ATTRIBUTE_ID: UInt = 10u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readBarrierPositionAttribute(): UByte { + val ATTRIBUTE_ID: UInt = 10u + + 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}") - } + 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) { - "Barrierposition attribute not found in response" - } + } + + requireNotNull(attributeData) { "Barrierposition 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 subscribeBarrierPositionAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Barrierposition attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Barrierposition attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -1339,97 +1259,96 @@ suspend fun readBarrierPositionAttribute(): UByte {val ATTRIBUTE_ID: UInt = 10u emit(UByteSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1437,97 +1356,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1535,97 +1453,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1633,97 +1548,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1731,81 +1643,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1817,80 +1724,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1903,7 +1807,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/BasicInformationCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/BasicInformationCluster.kt index 27183e2fe9b379..e60bab759236b3 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/BasicInformationCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/BasicInformationCluster.kt @@ -17,216 +17,184 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration 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.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest +import matter.controller.StringSubscriptionState import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState -import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class BasicInformationCluster(private val controller: MatterController, private val endpointId: UShort) {class CapabilityMinimaAttribute( - val value: BasicInformationClusterCapabilityMinimaStruct - ) +class BasicInformationCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class CapabilityMinimaAttribute(val value: BasicInformationClusterCapabilityMinimaStruct) sealed class CapabilityMinimaAttributeSubscriptionState { - data class Success( - val value: BasicInformationClusterCapabilityMinimaStruct - ) : CapabilityMinimaAttributeSubscriptionState() - + data class Success(val value: BasicInformationClusterCapabilityMinimaStruct) : + CapabilityMinimaAttributeSubscriptionState() + data class Error(val exception: Exception) : CapabilityMinimaAttributeSubscriptionState() - object SubscriptionEstablished : CapabilityMinimaAttributeSubscriptionState() - } -class ProductAppearanceAttribute( - val value: BasicInformationClusterProductAppearanceStruct? - ) + object SubscriptionEstablished : CapabilityMinimaAttributeSubscriptionState() + } + + class ProductAppearanceAttribute(val value: BasicInformationClusterProductAppearanceStruct?) sealed class ProductAppearanceAttributeSubscriptionState { - data class Success( - val value: BasicInformationClusterProductAppearanceStruct? - ) : ProductAppearanceAttributeSubscriptionState() - + data class Success(val value: BasicInformationClusterProductAppearanceStruct?) : + ProductAppearanceAttributeSubscriptionState() + data class Error(val exception: Exception) : ProductAppearanceAttributeSubscriptionState() - object SubscriptionEstablished : ProductAppearanceAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : ProductAppearanceAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } suspend fun mfgSpecificPing(timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } -suspend fun readDataModelRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 0u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readDataModelRevisionAttribute(): UShort { + 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 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}") - } + 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) { - "Datamodelrevision attribute not found in response" - } + } + + requireNotNull(attributeData) { "Datamodelrevision 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 subscribeDataModelRevisionAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Datamodelrevision attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Datamodelrevision attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -239,81 +207,76 @@ suspend fun readDataModelRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 0 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readVendorNameAttribute(): String {val ATTRIBUTE_ID: UInt = 1u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readVendorNameAttribute(): String { + 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 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}") - } + 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) { - "Vendorname attribute not found in response" - } + } + + requireNotNull(attributeData) { "Vendorname attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: String = tlvReader.getString(AnonymousTag) - return decodedValue } suspend fun subscribeVendorNameAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StringSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StringSubscriptionState.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) { - "Vendorname attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Vendorname attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -325,81 +288,76 @@ suspend fun readVendorNameAttribute(): String {val ATTRIBUTE_ID: UInt = 1u emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readVendorIDAttribute(): UShort {val ATTRIBUTE_ID: UInt = 2u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readVendorIDAttribute(): 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 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}") - } + 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) { - "Vendorid attribute not found in response" - } + } + + requireNotNull(attributeData) { "Vendorid 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 subscribeVendorIDAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Vendorid attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Vendorid attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -411,81 +369,76 @@ suspend fun readVendorIDAttribute(): UShort {val ATTRIBUTE_ID: UInt = 2u emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readProductNameAttribute(): String {val ATTRIBUTE_ID: UInt = 3u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readProductNameAttribute(): String { + 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 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}") - } + 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) { - "Productname attribute not found in response" - } + } + + requireNotNull(attributeData) { "Productname attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: String = tlvReader.getString(AnonymousTag) - return decodedValue } suspend fun subscribeProductNameAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StringSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StringSubscriptionState.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) { - "Productname attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Productname attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -497,81 +450,76 @@ suspend fun readProductNameAttribute(): String {val ATTRIBUTE_ID: UInt = 3u emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readProductIDAttribute(): UShort {val ATTRIBUTE_ID: UInt = 4u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readProductIDAttribute(): UShort { + 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 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}") - } + 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) { - "Productid attribute not found in response" - } + } + + requireNotNull(attributeData) { "Productid 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 subscribeProductIDAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Productid attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Productid attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -583,68 +531,57 @@ suspend fun readProductIDAttribute(): UShort {val ATTRIBUTE_ID: UInt = 4u emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNodeLabelAttribute(): String {val ATTRIBUTE_ID: UInt = 5u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNodeLabelAttribute(): String { + 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 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}") - } + 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) { - "Nodelabel attribute not found in response" - } + } + + requireNotNull(attributeData) { "Nodelabel attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: String = tlvReader.getString(AnonymousTag) - return decodedValue } - suspend fun writeNodeLabelAttribute( - value: String, - timedWriteTimeout: Duration? = null) { + suspend fun writeNodeLabelAttribute(value: String, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 5u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -665,43 +602,45 @@ suspend fun readNodeLabelAttribute(): String {val ATTRIBUTE_ID: UInt = 5u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNodeLabelAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StringSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StringSubscriptionState.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) { - "Nodelabel attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Nodelabel attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -713,68 +652,57 @@ suspend fun readNodeLabelAttribute(): String {val ATTRIBUTE_ID: UInt = 5u emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readLocationAttribute(): String {val ATTRIBUTE_ID: UInt = 6u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readLocationAttribute(): String { + 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 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}") - } + 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) { - "Location attribute not found in response" - } + } + + requireNotNull(attributeData) { "Location attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: String = tlvReader.getString(AnonymousTag) - return decodedValue } - suspend fun writeLocationAttribute( - value: String, - timedWriteTimeout: Duration? = null) { + suspend fun writeLocationAttribute(value: String, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 6u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -795,43 +723,45 @@ suspend fun readLocationAttribute(): String {val ATTRIBUTE_ID: UInt = 6u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeLocationAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StringSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StringSubscriptionState.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) { - "Location attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Location attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -843,80 +773,77 @@ suspend fun readLocationAttribute(): String {val ATTRIBUTE_ID: UInt = 6u emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readHardwareVersionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 7u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readHardwareVersionAttribute(): UShort { + 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 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}") - } + 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) { - "Hardwareversion attribute not found in response" - } + } + + requireNotNull(attributeData) { "Hardwareversion 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 subscribeHardwareVersionAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Hardwareversion attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Hardwareversion attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -929,80 +856,77 @@ suspend fun readHardwareVersionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 7u emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readHardwareVersionStringAttribute(): String {val ATTRIBUTE_ID: UInt = 8u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readHardwareVersionStringAttribute(): String { + val ATTRIBUTE_ID: UInt = 8u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Hardwareversionstring attribute not found in response" - } + } + + requireNotNull(attributeData) { "Hardwareversionstring attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: String = tlvReader.getString(AnonymousTag) - return decodedValue } suspend fun subscribeHardwareVersionStringAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StringSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StringSubscriptionState.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) { - "Hardwareversionstring attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Hardwareversionstring attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -1015,80 +939,77 @@ suspend fun readHardwareVersionStringAttribute(): String {val ATTRIBUTE_ID: UInt emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readSoftwareVersionAttribute(): UInt {val ATTRIBUTE_ID: UInt = 9u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readSoftwareVersionAttribute(): UInt { + val ATTRIBUTE_ID: UInt = 9u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Softwareversion attribute not found in response" - } + } + + requireNotNull(attributeData) { "Softwareversion 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 subscribeSoftwareVersionAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Softwareversion attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Softwareversion attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -1101,80 +1022,77 @@ suspend fun readSoftwareVersionAttribute(): UInt {val ATTRIBUTE_ID: UInt = 9u emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readSoftwareVersionStringAttribute(): String {val ATTRIBUTE_ID: UInt = 10u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readSoftwareVersionStringAttribute(): String { + val ATTRIBUTE_ID: UInt = 10u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Softwareversionstring attribute not found in response" - } + } + + requireNotNull(attributeData) { "Softwareversionstring attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: String = tlvReader.getString(AnonymousTag) - return decodedValue } suspend fun subscribeSoftwareVersionStringAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StringSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StringSubscriptionState.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) { - "Softwareversionstring attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Softwareversionstring attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -1187,557 +1105,522 @@ suspend fun readSoftwareVersionStringAttribute(): String {val ATTRIBUTE_ID: UInt emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readManufacturingDateAttribute(): String? {val ATTRIBUTE_ID: UInt = 11u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readManufacturingDateAttribute(): String? { + val ATTRIBUTE_ID: UInt = 11u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Manufacturingdate attribute not found in response" - } + } + + requireNotNull(attributeData) { "Manufacturingdate attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeManufacturingDateAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 11u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StringSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StringSubscriptionState.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) { - "Manufacturingdate attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Manufacturingdate attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(StringSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(StringSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPartNumberAttribute(): String? {val ATTRIBUTE_ID: UInt = 12u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readPartNumberAttribute(): String? { + val ATTRIBUTE_ID: UInt = 12u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Partnumber attribute not found in response" - } + } + + requireNotNull(attributeData) { "Partnumber attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribePartNumberAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 12u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StringSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StringSubscriptionState.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) { - "Partnumber attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Partnumber attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(StringSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(StringSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readProductURLAttribute(): String? {val ATTRIBUTE_ID: UInt = 13u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readProductURLAttribute(): String? { + val ATTRIBUTE_ID: UInt = 13u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Producturl attribute not found in response" - } + } + + requireNotNull(attributeData) { "Producturl attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeProductURLAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 13u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StringSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StringSubscriptionState.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) { - "Producturl attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Producturl attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(StringSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(StringSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readProductLabelAttribute(): String? {val ATTRIBUTE_ID: UInt = 14u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readProductLabelAttribute(): String? { + val ATTRIBUTE_ID: UInt = 14u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Productlabel attribute not found in response" - } + } + + requireNotNull(attributeData) { "Productlabel attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeProductLabelAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 14u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StringSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StringSubscriptionState.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) { - "Productlabel attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Productlabel attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(StringSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(StringSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readSerialNumberAttribute(): String? {val ATTRIBUTE_ID: UInt = 15u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readSerialNumberAttribute(): String? { + val ATTRIBUTE_ID: UInt = 15u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Serialnumber attribute not found in response" - } + } + + requireNotNull(attributeData) { "Serialnumber attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeSerialNumberAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 15u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StringSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StringSubscriptionState.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) { - "Serialnumber attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Serialnumber attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(StringSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(StringSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readLocalConfigDisabledAttribute(): Boolean? {val ATTRIBUTE_ID: UInt = 16u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readLocalConfigDisabledAttribute(): Boolean? { + val ATTRIBUTE_ID: UInt = 16u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Localconfigdisabled attribute not found in response" - } + } + + requireNotNull(attributeData) { "Localconfigdisabled 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 - } - + val decodedValue: Boolean? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } return decodedValue } suspend fun writeLocalConfigDisabledAttribute( value: Boolean, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 16u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -1758,233 +1641,224 @@ suspend fun readLocalConfigDisabledAttribute(): Boolean? {val ATTRIBUTE_ID: UInt throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeLocalConfigDisabledAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Localconfigdisabled attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Localconfigdisabled 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 - } + val decodedValue: Boolean? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(BooleanSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(BooleanSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readReachableAttribute(): Boolean? {val ATTRIBUTE_ID: UInt = 17u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readReachableAttribute(): Boolean? { + val ATTRIBUTE_ID: UInt = 17u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Reachable attribute not found in response" - } + } + + requireNotNull(attributeData) { "Reachable 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 - } - + val decodedValue: Boolean? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeReachableAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 17u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Reachable attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Reachable 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 - } + val decodedValue: Boolean? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(BooleanSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(BooleanSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readUniqueIDAttribute(): String {val ATTRIBUTE_ID: UInt = 18u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readUniqueIDAttribute(): String { + val ATTRIBUTE_ID: UInt = 18u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Uniqueid attribute not found in response" - } + } + + requireNotNull(attributeData) { "Uniqueid attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: String = tlvReader.getString(AnonymousTag) - return decodedValue } suspend fun subscribeUniqueIDAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 18u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StringSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StringSubscriptionState.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) { - "Uniqueid attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Uniqueid attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -1996,85 +1870,84 @@ suspend fun readUniqueIDAttribute(): String {val ATTRIBUTE_ID: UInt = 18u emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCapabilityMinimaAttribute(): CapabilityMinimaAttribute {val ATTRIBUTE_ID: UInt = 19u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readCapabilityMinimaAttribute(): CapabilityMinimaAttribute { + val ATTRIBUTE_ID: UInt = 19u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Capabilityminima attribute not found in response" - } + } + + requireNotNull(attributeData) { "Capabilityminima attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: BasicInformationClusterCapabilityMinimaStruct = BasicInformationClusterCapabilityMinimaStruct.fromTlv(AnonymousTag, tlvReader) - + val decodedValue: BasicInformationClusterCapabilityMinimaStruct = + BasicInformationClusterCapabilityMinimaStruct.fromTlv(AnonymousTag, tlvReader) return CapabilityMinimaAttribute(decodedValue) } suspend fun subscribeCapabilityMinimaAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 19u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(CapabilityMinimaAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + CapabilityMinimaAttributeSubscriptionState.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) { - "Capabilityminima attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Capabilityminima attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: BasicInformationClusterCapabilityMinimaStruct = BasicInformationClusterCapabilityMinimaStruct.fromTlv(AnonymousTag, tlvReader) + val decodedValue: BasicInformationClusterCapabilityMinimaStruct = + BasicInformationClusterCapabilityMinimaStruct.fromTlv(AnonymousTag, tlvReader) emit(CapabilityMinimaAttributeSubscriptionState.Success(decodedValue)) } @@ -2082,177 +1955,170 @@ suspend fun readCapabilityMinimaAttribute(): CapabilityMinimaAttribute {val ATTR emit(CapabilityMinimaAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readProductAppearanceAttribute(): ProductAppearanceAttribute {val ATTRIBUTE_ID: UInt = 20u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readProductAppearanceAttribute(): ProductAppearanceAttribute { + val ATTRIBUTE_ID: UInt = 20u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Productappearance attribute not found in response" - } + } + + requireNotNull(attributeData) { "Productappearance attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: BasicInformationClusterProductAppearanceStruct? = if (tlvReader.isNextTag(AnonymousTag)) { - BasicInformationClusterProductAppearanceStruct.fromTlv(AnonymousTag, tlvReader) - } else { - null - } - + val decodedValue: BasicInformationClusterProductAppearanceStruct? = + if (tlvReader.isNextTag(AnonymousTag)) { + BasicInformationClusterProductAppearanceStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } return ProductAppearanceAttribute(decodedValue) } suspend fun subscribeProductAppearanceAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 20u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ProductAppearanceAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ProductAppearanceAttributeSubscriptionState.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) { - "Productappearance attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Productappearance attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: BasicInformationClusterProductAppearanceStruct? = if (tlvReader.isNextTag(AnonymousTag)) { - BasicInformationClusterProductAppearanceStruct.fromTlv(AnonymousTag, tlvReader) - } else { - null - } + val decodedValue: BasicInformationClusterProductAppearanceStruct? = + if (tlvReader.isNextTag(AnonymousTag)) { + BasicInformationClusterProductAppearanceStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } - decodedValue?.let { - emit(ProductAppearanceAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ProductAppearanceAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ProductAppearanceAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readSpecificationVersionAttribute(): UInt {val ATTRIBUTE_ID: UInt = 21u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readSpecificationVersionAttribute(): UInt { + val ATTRIBUTE_ID: UInt = 21u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Specificationversion attribute not found in response" - } + } + + requireNotNull(attributeData) { "Specificationversion 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 subscribeSpecificationVersionAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 21u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Specificationversion attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Specificationversion attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -2265,80 +2131,77 @@ suspend fun readSpecificationVersionAttribute(): UInt {val ATTRIBUTE_ID: UInt = emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMaxPathsPerInvokeAttribute(): UShort {val ATTRIBUTE_ID: UInt = 22u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readMaxPathsPerInvokeAttribute(): UShort { + val ATTRIBUTE_ID: UInt = 22u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Maxpathsperinvoke attribute not found in response" - } + } + + requireNotNull(attributeData) { "Maxpathsperinvoke 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 subscribeMaxPathsPerInvokeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 22u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Maxpathsperinvoke attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Maxpathsperinvoke attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -2351,97 +2214,96 @@ suspend fun readMaxPathsPerInvokeAttribute(): UShort {val ATTRIBUTE_ID: UInt = 2 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65528u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -2449,97 +2311,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { emit(GeneratedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65529u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -2547,97 +2408,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va emit(AcceptedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt = 65530u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -2645,97 +2503,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt emit(EventListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ID: UInt = 65531u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -2743,81 +2598,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ emit(AttributeListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -2829,80 +2679,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 65533u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -2915,7 +2762,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/BinaryInputBasicCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/BinaryInputBasicCluster.kt index 6573eb5ba275c1..a3aeb110b47fbc 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/BinaryInputBasicCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/BinaryInputBasicCluster.kt @@ -17,164 +17,127 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.BooleanSubscriptionState import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest +import matter.controller.StringSubscriptionState import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse -import matter.controller.model.AttributePath -import matter.controller.model.CommandPath import matter.controller.cluster.structs.* +import matter.controller.model.AttributePath import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class BinaryInputBasicCluster(private val controller: MatterController, private val endpointId: UShort) {class GeneratedCommandListAttribute( - val value: List - ) +class BinaryInputBasicCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } -suspend fun readActiveTextAttribute(): String? {val ATTRIBUTE_ID: UInt = 4u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } + + suspend fun readActiveTextAttribute(): String? { + 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}") - } + 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) { - "Activetext attribute not found in response" - } + } + + requireNotNull(attributeData) { "Activetext attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } return decodedValue } - suspend fun writeActiveTextAttribute( - value: String, - timedWriteTimeout: Duration? = null) { + suspend fun writeActiveTextAttribute(value: String, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 4u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -195,127 +158,117 @@ suspend fun readActiveTextAttribute(): String? {val ATTRIBUTE_ID: UInt = 4u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeActiveTextAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StringSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StringSubscriptionState.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) { - "Activetext attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Activetext attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(StringSubscriptionState.Success(it)) - } - + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(StringSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readDescriptionAttribute(): String? {val ATTRIBUTE_ID: UInt = 28u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readDescriptionAttribute(): String? { + val ATTRIBUTE_ID: UInt = 28u + + 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}") - } + 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) { - "Description attribute not found in response" - } + } + + requireNotNull(attributeData) { "Description attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } return decodedValue } - suspend fun writeDescriptionAttribute( - value: String, - timedWriteTimeout: Duration? = null) { + suspend fun writeDescriptionAttribute(value: String, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 28u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -336,127 +289,117 @@ suspend fun readDescriptionAttribute(): String? {val ATTRIBUTE_ID: UInt = 28u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeDescriptionAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 28u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StringSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StringSubscriptionState.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) { - "Description attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Description attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(StringSubscriptionState.Success(it)) - } - + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(StringSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readInactiveTextAttribute(): String? {val ATTRIBUTE_ID: UInt = 46u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readInactiveTextAttribute(): String? { + val ATTRIBUTE_ID: UInt = 46u + + 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}") - } + 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) { - "Inactivetext attribute not found in response" - } + } + + requireNotNull(attributeData) { "Inactivetext attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } return decodedValue } - suspend fun writeInactiveTextAttribute( - value: String, - timedWriteTimeout: Duration? = null) { + suspend fun writeInactiveTextAttribute(value: String, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 46u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -477,123 +420,112 @@ suspend fun readInactiveTextAttribute(): String? {val ATTRIBUTE_ID: UInt = 46u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeInactiveTextAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 46u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StringSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StringSubscriptionState.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) { - "Inactivetext attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Inactivetext attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(StringSubscriptionState.Success(it)) - } - + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(StringSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readOutOfServiceAttribute(): Boolean {val ATTRIBUTE_ID: UInt = 81u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readOutOfServiceAttribute(): Boolean { + val ATTRIBUTE_ID: UInt = 81u + + 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}") - } + 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) { - "Outofservice attribute not found in response" - } + } + + requireNotNull(attributeData) { "Outofservice attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Boolean = tlvReader.getBoolean(AnonymousTag) - return decodedValue } - suspend fun writeOutOfServiceAttribute( - value: Boolean, - timedWriteTimeout: Duration? = null) { + suspend fun writeOutOfServiceAttribute(value: Boolean, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 81u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -614,43 +546,45 @@ suspend fun readOutOfServiceAttribute(): Boolean {val ATTRIBUTE_ID: UInt = 81u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeOutOfServiceAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 81u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Outofservice attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Outofservice attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -662,165 +596,148 @@ suspend fun readOutOfServiceAttribute(): Boolean {val ATTRIBUTE_ID: UInt = 81u emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPolarityAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 84u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readPolarityAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 84u + + 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}") - } + 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) { - "Polarity attribute not found in response" - } + } + + requireNotNull(attributeData) { "Polarity 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribePolarityAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 84u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Polarity attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Polarity 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)) - } - + 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 readPresentValueAttribute(): Boolean {val ATTRIBUTE_ID: UInt = 85u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readPresentValueAttribute(): Boolean { + val ATTRIBUTE_ID: UInt = 85u + + 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}") - } + 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) { - "Presentvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Presentvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Boolean = tlvReader.getBoolean(AnonymousTag) - return decodedValue } - suspend fun writePresentValueAttribute( - value: Boolean, - timedWriteTimeout: Duration? = null) { + suspend fun writePresentValueAttribute(value: Boolean, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 85u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -841,43 +758,45 @@ suspend fun readPresentValueAttribute(): Boolean {val ATTRIBUTE_ID: UInt = 85u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribePresentValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 85u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Presentvalue attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Presentvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -889,72 +808,62 @@ suspend fun readPresentValueAttribute(): Boolean {val ATTRIBUTE_ID: UInt = 85u emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readReliabilityAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 103u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readReliabilityAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 103u + + 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}") - } + 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) { - "Reliability attribute not found in response" - } + } + + requireNotNull(attributeData) { "Reliability 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } - suspend fun writeReliabilityAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeReliabilityAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 103u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -975,136 +884,131 @@ suspend fun readReliabilityAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 103u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeReliabilityAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 103u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Reliability attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Reliability 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)) - } - + 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 readStatusFlagsAttribute(): UByte {val ATTRIBUTE_ID: UInt = 111u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readStatusFlagsAttribute(): UByte { + val ATTRIBUTE_ID: UInt = 111u + + 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}") - } + 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) { - "Statusflags attribute not found in response" - } + } + + requireNotNull(attributeData) { "Statusflags 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 subscribeStatusFlagsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 111u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Statusflags attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Statusflags attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -1116,194 +1020,189 @@ suspend fun readStatusFlagsAttribute(): UByte {val ATTRIBUTE_ID: UInt = 111u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readApplicationTypeAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 256u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readApplicationTypeAttribute(): UInt? { + val ATTRIBUTE_ID: UInt = 256u + + 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}") - } + 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) { - "Applicationtype attribute not found in response" - } + } + + requireNotNull(attributeData) { "Applicationtype attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeApplicationTypeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 256u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Applicationtype attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Applicationtype attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1311,97 +1210,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1409,97 +1307,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1507,97 +1402,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1605,81 +1497,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1691,80 +1578,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1777,7 +1661,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/BindingCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/BindingCluster.kt index a29864051af0d1..d1309a2bd28ca4 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/BindingCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/BindingCluster.kt @@ -17,183 +17,141 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState -import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse -import matter.controller.model.AttributePath -import matter.controller.model.CommandPath import matter.controller.cluster.structs.* +import matter.controller.model.AttributePath import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class BindingCluster(private val controller: MatterController, private val endpointId: UShort) {class BindingAttribute( - val value: List - ) +class BindingCluster(private val controller: MatterController, private val endpointId: UShort) { + class BindingAttribute(val value: List) sealed class BindingAttributeSubscriptionState { - data class Success( - val value: List - ) : BindingAttributeSubscriptionState() - + data class Success(val value: List) : + BindingAttributeSubscriptionState() + data class Error(val exception: Exception) : BindingAttributeSubscriptionState() - object SubscriptionEstablished : BindingAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : BindingAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } -suspend fun readBindingAttribute(): BindingAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } + + suspend fun readBindingAttribute(): BindingAttribute { + 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}") - } + 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) { - "Binding attribute not found in response" - } + } + + requireNotNull(attributeData) { "Binding 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(BindingClusterTargetStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(BindingClusterTargetStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return BindingAttribute(decodedValue) } suspend fun writeBindingAttribute( value: List, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startArray(AnonymousTag) - for (item in value.iterator()) { - item.toTlv(AnonymousTag, tlvWriter) - } - tlvWriter.endArray() + for (item in value.iterator()) { + item.toTlv(AnonymousTag, tlvWriter) + } + tlvWriter.endArray() val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -214,53 +172,56 @@ suspend fun readBindingAttribute(): BindingAttribute {val ATTRIBUTE_ID: UInt = 0 throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeBindingAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(BindingAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + BindingAttributeSubscriptionState.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) { - "Binding attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Binding 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(BindingClusterTargetStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(BindingClusterTargetStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(BindingAttributeSubscriptionState.Success(decodedValue)) } @@ -268,97 +229,96 @@ suspend fun readBindingAttribute(): BindingAttribute {val ATTRIBUTE_ID: UInt = 0 emit(BindingAttributeSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -366,97 +326,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -464,97 +423,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -562,97 +518,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -660,81 +613,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -746,80 +694,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -832,7 +777,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/BooleanStateCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/BooleanStateCluster.kt index 0c44c4bb081d4a..f7b13245077204 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/BooleanStateCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/BooleanStateCluster.kt @@ -17,173 +17,135 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.BooleanSubscriptionState import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState -import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse -import matter.controller.model.AttributePath -import matter.controller.model.CommandPath +import matter.controller.UShortSubscriptionState import matter.controller.cluster.structs.* +import matter.controller.model.AttributePath import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader -import matter.tlv.TlvWriter -class BooleanStateCluster(private val controller: MatterController, private val endpointId: UShort) {class GeneratedCommandListAttribute( - val value: List - ) +class BooleanStateCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } -suspend fun readStateValueAttribute(): Boolean {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } + + suspend fun readStateValueAttribute(): Boolean { + 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}") - } + 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) { - "Statevalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Statevalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Boolean = tlvReader.getBoolean(AnonymousTag) - return decodedValue } suspend fun subscribeStateValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Statevalue attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Statevalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -195,97 +157,96 @@ suspend fun readStateValueAttribute(): Boolean {val ATTRIBUTE_ID: UInt = 0u emit(BooleanSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -293,97 +254,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -391,97 +351,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -489,97 +446,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -587,81 +541,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -673,80 +622,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -759,7 +705,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/BooleanStateConfigurationCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/BooleanStateConfigurationCluster.kt index a92edf5556e383..f38f944df17693 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/BooleanStateConfigurationCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/BooleanStateConfigurationCluster.kt @@ -17,208 +17,177 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class BooleanStateConfigurationCluster(private val controller: MatterController, private val endpointId: UShort) {class GeneratedCommandListAttribute( - val value: List - ) +class BooleanStateConfigurationCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun suppressAlarm(alarmsToSuppress: UByte - ,timedInvokeTimeout: Duration? = null) { + suspend fun suppressAlarm(alarmsToSuppress: UByte, timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_ALARMS_TO_SUPPRESS_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_ALARMS_TO_SUPPRESS_REQ), alarmsToSuppress) + tlvWriter.put(ContextSpecificTag(TAG_ALARMS_TO_SUPPRESS_REQ), alarmsToSuppress) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun enableDisableAlarm(alarmsToEnableDisable: UByte - ,timedInvokeTimeout: Duration? = null) { + suspend fun enableDisableAlarm( + alarmsToEnableDisable: UByte, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 1u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_ALARMS_TO_ENABLE_DISABLE_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_ALARMS_TO_ENABLE_DISABLE_REQ), alarmsToEnableDisable) + tlvWriter.put(ContextSpecificTag(TAG_ALARMS_TO_ENABLE_DISABLE_REQ), alarmsToEnableDisable) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } -suspend fun readCurrentSensitivityLevelAttribute(): 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) - ) - + + suspend fun readCurrentSensitivityLevelAttribute(): 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}") - } + 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) { - "Currentsensitivitylevel attribute not found in response" - } + } + + requireNotNull(attributeData) { "Currentsensitivitylevel 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun writeCurrentSensitivityLevelAttribute( value: UByte, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -239,831 +208,798 @@ suspend fun readCurrentSensitivityLevelAttribute(): UByte? {val ATTRIBUTE_ID: UI throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeCurrentSensitivityLevelAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Currentsensitivitylevel attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Currentsensitivitylevel 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)) - } - + 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 readSupportedSensitivityLevelsAttribute(): 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) - ) - + + suspend fun readSupportedSensitivityLevelsAttribute(): 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}") - } + 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) { - "Supportedsensitivitylevels attribute not found in response" - } + } + + requireNotNull(attributeData) { "Supportedsensitivitylevels 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeSupportedSensitivityLevelsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Supportedsensitivitylevels attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Supportedsensitivitylevels 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)) - } - + 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 readDefaultSensitivityLevelAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readDefaultSensitivityLevelAttribute(): UByte? { + 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}") - } + 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) { - "Defaultsensitivitylevel attribute not found in response" - } + } + + requireNotNull(attributeData) { "Defaultsensitivitylevel 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeDefaultSensitivityLevelAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Defaultsensitivitylevel attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Defaultsensitivitylevel 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)) - } - + 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 readAlarmsActiveAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readAlarmsActiveAttribute(): UByte? { + 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}") - } + 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) { - "Alarmsactive attribute not found in response" - } + } + + requireNotNull(attributeData) { "Alarmsactive 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeAlarmsActiveAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Alarmsactive attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Alarmsactive 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)) - } - + 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 readAlarmsSuppressedAttribute(): 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) - ) - + + suspend fun readAlarmsSuppressedAttribute(): 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}") - } + 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) { - "Alarmssuppressed attribute not found in response" - } + } + + requireNotNull(attributeData) { "Alarmssuppressed 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeAlarmsSuppressedAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Alarmssuppressed attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Alarmssuppressed 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)) - } - + 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 readAlarmsEnabledAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 5u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readAlarmsEnabledAttribute(): UByte? { + 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}") - } + 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) { - "Alarmsenabled attribute not found in response" - } + } + + requireNotNull(attributeData) { "Alarmsenabled 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeAlarmsEnabledAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Alarmsenabled attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Alarmsenabled 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)) - } - + 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 readAlarmsSupportedAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 6u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readAlarmsSupportedAttribute(): UByte? { + 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}") - } + 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) { - "Alarmssupported attribute not found in response" - } + } + + requireNotNull(attributeData) { "Alarmssupported 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeAlarmsSupportedAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Alarmssupported attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Alarmssupported 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)) - } - + 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 readSensorFaultAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 7u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readSensorFaultAttribute(): UShort? { + 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}") - } + 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) { - "Sensorfault attribute not found in response" - } + } + + requireNotNull(attributeData) { "Sensorfault 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeSensorFaultAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Sensorfault attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Sensorfault 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)) - } - + 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 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1071,97 +1007,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1169,97 +1104,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1267,97 +1199,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1365,81 +1294,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1451,80 +1375,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1537,7 +1458,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/BridgedDeviceBasicInformationCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/BridgedDeviceBasicInformationCluster.kt index 837b3588937ed6..8e56362d8da349 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/BridgedDeviceBasicInformationCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/BridgedDeviceBasicInformationCluster.kt @@ -17,587 +17,528 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration 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.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest +import matter.controller.StringSubscriptionState import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState -import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class BridgedDeviceBasicInformationCluster(private val controller: MatterController, private val endpointId: UShort) {class ProductAppearanceAttribute( +class BridgedDeviceBasicInformationCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class ProductAppearanceAttribute( val value: BridgedDeviceBasicInformationClusterProductAppearanceStruct? ) sealed class ProductAppearanceAttributeSubscriptionState { - data class Success( - val value: BridgedDeviceBasicInformationClusterProductAppearanceStruct? - ) : ProductAppearanceAttributeSubscriptionState() - + data class Success(val value: BridgedDeviceBasicInformationClusterProductAppearanceStruct?) : + ProductAppearanceAttributeSubscriptionState() + data class Error(val exception: Exception) : ProductAppearanceAttributeSubscriptionState() - object SubscriptionEstablished : ProductAppearanceAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : ProductAppearanceAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun keepActive(stayActiveDuration: UInt - ,timedInvokeTimeout: Duration? = null) { + suspend fun keepActive(stayActiveDuration: UInt, timedInvokeTimeout: Duration? = null) { val commandId: UInt = 128u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_STAY_ACTIVE_DURATION_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_STAY_ACTIVE_DURATION_REQ), stayActiveDuration) + tlvWriter.put(ContextSpecificTag(TAG_STAY_ACTIVE_DURATION_REQ), stayActiveDuration) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } -suspend fun readVendorNameAttribute(): String? {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readVendorNameAttribute(): String? { + 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}") - } + 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) { - "Vendorname attribute not found in response" - } + } + + requireNotNull(attributeData) { "Vendorname attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeVendorNameAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StringSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StringSubscriptionState.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) { - "Vendorname attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Vendorname attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(StringSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(StringSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readVendorIDAttribute(): 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) - ) - + + suspend fun readVendorIDAttribute(): 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}") - } + 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) { - "Vendorid attribute not found in response" - } + } + + requireNotNull(attributeData) { "Vendorid 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeVendorIDAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Vendorid attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Vendorid 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readProductNameAttribute(): String? {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readProductNameAttribute(): String? { + 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}") - } + 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) { - "Productname attribute not found in response" - } + } + + requireNotNull(attributeData) { "Productname attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeProductNameAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StringSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StringSubscriptionState.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) { - "Productname attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Productname attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(StringSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(StringSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readProductIDAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 4u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readProductIDAttribute(): UShort? { + 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}") - } + 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) { - "Productid attribute not found in response" - } + } + + requireNotNull(attributeData) { "Productid 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeProductIDAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Productid attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Productid 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNodeLabelAttribute(): String? {val ATTRIBUTE_ID: UInt = 5u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readNodeLabelAttribute(): String? { + 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}") - } + 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) { - "Nodelabel attribute not found in response" - } + } + + requireNotNull(attributeData) { "Nodelabel attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } return decodedValue } - suspend fun writeNodeLabelAttribute( - value: String, - timedWriteTimeout: Duration? = null) { + suspend fun writeNodeLabelAttribute(value: String, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 5u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -618,1009 +559,960 @@ suspend fun readNodeLabelAttribute(): String? {val ATTRIBUTE_ID: UInt = 5u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNodeLabelAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StringSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StringSubscriptionState.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) { - "Nodelabel attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Nodelabel attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(StringSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(StringSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readHardwareVersionAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 7u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readHardwareVersionAttribute(): UShort? { + 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}") - } + 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) { - "Hardwareversion attribute not found in response" - } + } + + requireNotNull(attributeData) { "Hardwareversion 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeHardwareVersionAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Hardwareversion attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Hardwareversion 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readHardwareVersionStringAttribute(): String? {val ATTRIBUTE_ID: UInt = 8u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readHardwareVersionStringAttribute(): String? { + val ATTRIBUTE_ID: UInt = 8u + + 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}") - } + 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) { - "Hardwareversionstring attribute not found in response" - } + } + + requireNotNull(attributeData) { "Hardwareversionstring attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeHardwareVersionStringAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StringSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StringSubscriptionState.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) { - "Hardwareversionstring attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Hardwareversionstring attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(StringSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(StringSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readSoftwareVersionAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 9u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readSoftwareVersionAttribute(): UInt? { + val ATTRIBUTE_ID: UInt = 9u + + 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}") - } + 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) { - "Softwareversion attribute not found in response" - } + } + + requireNotNull(attributeData) { "Softwareversion attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeSoftwareVersionAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Softwareversion attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Softwareversion attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readSoftwareVersionStringAttribute(): String? {val ATTRIBUTE_ID: UInt = 10u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readSoftwareVersionStringAttribute(): String? { + val ATTRIBUTE_ID: UInt = 10u + + 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}") - } + 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) { - "Softwareversionstring attribute not found in response" - } + } + + requireNotNull(attributeData) { "Softwareversionstring attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeSoftwareVersionStringAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StringSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StringSubscriptionState.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) { - "Softwareversionstring attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Softwareversionstring attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(StringSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(StringSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readManufacturingDateAttribute(): String? {val ATTRIBUTE_ID: UInt = 11u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readManufacturingDateAttribute(): String? { + val ATTRIBUTE_ID: UInt = 11u + + 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}") - } + 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) { - "Manufacturingdate attribute not found in response" - } + } + + requireNotNull(attributeData) { "Manufacturingdate attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeManufacturingDateAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 11u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StringSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StringSubscriptionState.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) { - "Manufacturingdate attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Manufacturingdate attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(StringSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(StringSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPartNumberAttribute(): String? {val ATTRIBUTE_ID: UInt = 12u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readPartNumberAttribute(): String? { + val ATTRIBUTE_ID: UInt = 12u + + 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}") - } + 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) { - "Partnumber attribute not found in response" - } + } + + requireNotNull(attributeData) { "Partnumber attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribePartNumberAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 12u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StringSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StringSubscriptionState.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) { - "Partnumber attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Partnumber attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(StringSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(StringSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readProductURLAttribute(): String? {val ATTRIBUTE_ID: UInt = 13u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readProductURLAttribute(): String? { + val ATTRIBUTE_ID: UInt = 13u + + 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}") - } + 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) { - "Producturl attribute not found in response" - } + } + + requireNotNull(attributeData) { "Producturl attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeProductURLAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 13u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StringSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StringSubscriptionState.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) { - "Producturl attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Producturl attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(StringSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(StringSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readProductLabelAttribute(): String? {val ATTRIBUTE_ID: UInt = 14u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readProductLabelAttribute(): String? { + val ATTRIBUTE_ID: UInt = 14u + + 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}") - } + 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) { - "Productlabel attribute not found in response" - } + } + + requireNotNull(attributeData) { "Productlabel attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeProductLabelAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 14u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StringSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StringSubscriptionState.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) { - "Productlabel attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Productlabel attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(StringSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(StringSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readSerialNumberAttribute(): String? {val ATTRIBUTE_ID: UInt = 15u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readSerialNumberAttribute(): String? { + val ATTRIBUTE_ID: UInt = 15u + + 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}") - } + 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) { - "Serialnumber attribute not found in response" - } + } + + requireNotNull(attributeData) { "Serialnumber attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeSerialNumberAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 15u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StringSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StringSubscriptionState.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) { - "Serialnumber attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Serialnumber attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(StringSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(StringSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readReachableAttribute(): Boolean {val ATTRIBUTE_ID: UInt = 17u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readReachableAttribute(): Boolean { + val ATTRIBUTE_ID: UInt = 17u + + 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}") - } + 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) { - "Reachable attribute not found in response" - } + } + + requireNotNull(attributeData) { "Reachable attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Boolean = tlvReader.getBoolean(AnonymousTag) - return decodedValue } suspend fun subscribeReachableAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 17u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Reachable attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Reachable attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -1632,81 +1524,76 @@ suspend fun readReachableAttribute(): Boolean {val ATTRIBUTE_ID: UInt = 17u emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readUniqueIDAttribute(): String {val ATTRIBUTE_ID: UInt = 18u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readUniqueIDAttribute(): String { + val ATTRIBUTE_ID: UInt = 18u + + 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}") - } + 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) { - "Uniqueid attribute not found in response" - } + } + + requireNotNull(attributeData) { "Uniqueid attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: String = tlvReader.getString(AnonymousTag) - return decodedValue } suspend fun subscribeUniqueIDAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 18u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StringSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StringSubscriptionState.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) { - "Uniqueid attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Uniqueid attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -1718,194 +1605,192 @@ suspend fun readUniqueIDAttribute(): String {val ATTRIBUTE_ID: UInt = 18u emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readProductAppearanceAttribute(): ProductAppearanceAttribute {val ATTRIBUTE_ID: UInt = 20u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readProductAppearanceAttribute(): ProductAppearanceAttribute { + val ATTRIBUTE_ID: UInt = 20u + + 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}") - } + 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) { - "Productappearance attribute not found in response" - } + } + + requireNotNull(attributeData) { "Productappearance attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: BridgedDeviceBasicInformationClusterProductAppearanceStruct? = if (tlvReader.isNextTag(AnonymousTag)) { - BridgedDeviceBasicInformationClusterProductAppearanceStruct.fromTlv(AnonymousTag, tlvReader) - } else { - null - } - + val decodedValue: BridgedDeviceBasicInformationClusterProductAppearanceStruct? = + if (tlvReader.isNextTag(AnonymousTag)) { + BridgedDeviceBasicInformationClusterProductAppearanceStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } return ProductAppearanceAttribute(decodedValue) } suspend fun subscribeProductAppearanceAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 20u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ProductAppearanceAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ProductAppearanceAttributeSubscriptionState.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) { - "Productappearance attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Productappearance attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: BridgedDeviceBasicInformationClusterProductAppearanceStruct? = if (tlvReader.isNextTag(AnonymousTag)) { - BridgedDeviceBasicInformationClusterProductAppearanceStruct.fromTlv(AnonymousTag, tlvReader) - } else { - null - } - - decodedValue?.let { - emit(ProductAppearanceAttributeSubscriptionState.Success(it)) - } - + val decodedValue: BridgedDeviceBasicInformationClusterProductAppearanceStruct? = + if (tlvReader.isNextTag(AnonymousTag)) { + BridgedDeviceBasicInformationClusterProductAppearanceStruct.fromTlv( + AnonymousTag, + tlvReader, + ) + } else { + null + } + + decodedValue?.let { emit(ProductAppearanceAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ProductAppearanceAttributeSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1913,97 +1798,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -2011,97 +1895,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -2109,97 +1990,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -2207,81 +2085,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -2293,80 +2166,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -2379,7 +2249,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/CarbonDioxideConcentrationMeasurementCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/CarbonDioxideConcentrationMeasurementCluster.kt index 32fbbb01553d32..c3353d6a7a7f8d 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/CarbonDioxideConcentrationMeasurementCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/CarbonDioxideConcentrationMeasurementCluster.kt @@ -17,1371 +17,1273 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.FloatSubscriptionState import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse -import matter.controller.model.AttributePath -import matter.controller.model.CommandPath +import matter.controller.UShortSubscriptionState import matter.controller.cluster.structs.* +import matter.controller.model.AttributePath import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader -import matter.tlv.TlvWriter -class CarbonDioxideConcentrationMeasurementCluster(private val controller: MatterController, private val endpointId: UShort) {class MeasuredValueAttribute( - val value: Float? - ) +class CarbonDioxideConcentrationMeasurementCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class MeasuredValueAttribute(val value: Float?) sealed class MeasuredValueAttributeSubscriptionState { - data class Success( - val value: Float? - ) : MeasuredValueAttributeSubscriptionState() - + data class Success(val value: Float?) : MeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() - } -class MinMeasuredValueAttribute( - val value: Float? - ) + object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() + } + + class MinMeasuredValueAttribute(val value: Float?) sealed class MinMeasuredValueAttributeSubscriptionState { - data class Success( - val value: Float? - ) : MinMeasuredValueAttributeSubscriptionState() - + data class Success(val value: Float?) : MinMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MinMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() - } -class MaxMeasuredValueAttribute( - val value: Float? - ) + object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() + } + + class MaxMeasuredValueAttribute(val value: Float?) sealed class MaxMeasuredValueAttributeSubscriptionState { - data class Success( - val value: Float? - ) : MaxMeasuredValueAttributeSubscriptionState() - + data class Success(val value: Float?) : MaxMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MaxMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() - } -class PeakMeasuredValueAttribute( - val value: Float? - ) + object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() + } + + class PeakMeasuredValueAttribute(val value: Float?) sealed class PeakMeasuredValueAttributeSubscriptionState { - data class Success( - val value: Float? - ) : PeakMeasuredValueAttributeSubscriptionState() - + data class Success(val value: Float?) : PeakMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : PeakMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : PeakMeasuredValueAttributeSubscriptionState() - } -class AverageMeasuredValueAttribute( - val value: Float? - ) + object SubscriptionEstablished : PeakMeasuredValueAttributeSubscriptionState() + } + + class AverageMeasuredValueAttribute(val value: Float?) sealed class AverageMeasuredValueAttributeSubscriptionState { - data class Success( - val value: Float? - ) : AverageMeasuredValueAttributeSubscriptionState() - + data class Success(val value: Float?) : AverageMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : AverageMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : AverageMeasuredValueAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : AverageMeasuredValueAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } -suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } + + suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute { + 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}") - } + 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) { - "Measuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Measuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return MeasuredValueAttribute(decodedValue) } suspend fun subscribeMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MeasuredValueAttributeSubscriptionState.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) { - "Measuredvalue attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Measuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute { + 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}") - } + 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) { - "Minmeasuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Minmeasuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return MinMeasuredValueAttribute(decodedValue) } suspend fun subscribeMinMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MinMeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MinMeasuredValueAttributeSubscriptionState.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) { - "Minmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Minmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MinMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute { + 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}") - } + 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) { - "Maxmeasuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Maxmeasuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return MaxMeasuredValueAttribute(decodedValue) } suspend fun subscribeMaxMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MaxMeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MaxMeasuredValueAttributeSubscriptionState.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) { - "Maxmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Maxmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MaxMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPeakMeasuredValueAttribute(): PeakMeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readPeakMeasuredValueAttribute(): PeakMeasuredValueAttribute { + 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}") - } + 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) { - "Peakmeasuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Peakmeasuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return PeakMeasuredValueAttribute(decodedValue) } suspend fun subscribePeakMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(PeakMeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + PeakMeasuredValueAttributeSubscriptionState.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) { - "Peakmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Peakmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(PeakMeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(PeakMeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(PeakMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPeakMeasuredValueWindowAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 4u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readPeakMeasuredValueWindowAttribute(): UInt? { + 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}") - } + 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) { - "Peakmeasuredvaluewindow attribute not found in response" - } + } + + requireNotNull(attributeData) { "Peakmeasuredvaluewindow attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribePeakMeasuredValueWindowAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Peakmeasuredvaluewindow attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Peakmeasuredvaluewindow attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAverageMeasuredValueAttribute(): AverageMeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 5u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readAverageMeasuredValueAttribute(): AverageMeasuredValueAttribute { + 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}") - } + 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) { - "Averagemeasuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Averagemeasuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return AverageMeasuredValueAttribute(decodedValue) } suspend fun subscribeAverageMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(AverageMeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + AverageMeasuredValueAttributeSubscriptionState.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) { - "Averagemeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Averagemeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(AverageMeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(AverageMeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(AverageMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAverageMeasuredValueWindowAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 6u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readAverageMeasuredValueWindowAttribute(): UInt? { + 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}") - } + 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) { - "Averagemeasuredvaluewindow attribute not found in response" - } + } + + requireNotNull(attributeData) { "Averagemeasuredvaluewindow attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeAverageMeasuredValueWindowAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Averagemeasuredvaluewindow attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Averagemeasuredvaluewindow attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readUncertaintyAttribute(): Float? {val ATTRIBUTE_ID: UInt = 7u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readUncertaintyAttribute(): Float? { + 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}") - } + 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) { - "Uncertainty attribute not found in response" - } + } + + requireNotNull(attributeData) { "Uncertainty attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - + val decodedValue: Float? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeUncertaintyAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(FloatSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + FloatSubscriptionState.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) { - "Uncertainty attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Uncertainty attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(FloatSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(FloatSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(FloatSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMeasurementUnitAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 8u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMeasurementUnitAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 8u + + 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}") - } + 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) { - "Measurementunit attribute not found in response" - } + } + + requireNotNull(attributeData) { "Measurementunit 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeMeasurementUnitAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Measurementunit attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Measurementunit 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)) - } - + 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 readMeasurementMediumAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 9u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMeasurementMediumAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 9u + + 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}") - } + 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) { - "Measurementmedium attribute not found in response" - } + } + + requireNotNull(attributeData) { "Measurementmedium 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeMeasurementMediumAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Measurementmedium attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Measurementmedium 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)) - } - + 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 readLevelValueAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 10u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readLevelValueAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 10u + + 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}") - } + 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) { - "Levelvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Levelvalue 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeLevelValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Levelvalue attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Levelvalue 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)) - } - + 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 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1389,97 +1291,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1487,97 +1388,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1585,97 +1483,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1683,81 +1578,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1769,80 +1659,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1855,11 +1742,12 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { - private val logger = Logger.getLogger(CarbonDioxideConcentrationMeasurementCluster::class.java.name) + private val logger = + Logger.getLogger(CarbonDioxideConcentrationMeasurementCluster::class.java.name) const val CLUSTER_ID: UInt = 1037u } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/CarbonMonoxideConcentrationMeasurementCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/CarbonMonoxideConcentrationMeasurementCluster.kt index c97c2f69df0087..559ccd6f86ca26 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/CarbonMonoxideConcentrationMeasurementCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/CarbonMonoxideConcentrationMeasurementCluster.kt @@ -17,1371 +17,1273 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.FloatSubscriptionState import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse -import matter.controller.model.AttributePath -import matter.controller.model.CommandPath +import matter.controller.UShortSubscriptionState import matter.controller.cluster.structs.* +import matter.controller.model.AttributePath import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader -import matter.tlv.TlvWriter -class CarbonMonoxideConcentrationMeasurementCluster(private val controller: MatterController, private val endpointId: UShort) {class MeasuredValueAttribute( - val value: Float? - ) +class CarbonMonoxideConcentrationMeasurementCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class MeasuredValueAttribute(val value: Float?) sealed class MeasuredValueAttributeSubscriptionState { - data class Success( - val value: Float? - ) : MeasuredValueAttributeSubscriptionState() - + data class Success(val value: Float?) : MeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() - } -class MinMeasuredValueAttribute( - val value: Float? - ) + object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() + } + + class MinMeasuredValueAttribute(val value: Float?) sealed class MinMeasuredValueAttributeSubscriptionState { - data class Success( - val value: Float? - ) : MinMeasuredValueAttributeSubscriptionState() - + data class Success(val value: Float?) : MinMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MinMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() - } -class MaxMeasuredValueAttribute( - val value: Float? - ) + object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() + } + + class MaxMeasuredValueAttribute(val value: Float?) sealed class MaxMeasuredValueAttributeSubscriptionState { - data class Success( - val value: Float? - ) : MaxMeasuredValueAttributeSubscriptionState() - + data class Success(val value: Float?) : MaxMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MaxMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() - } -class PeakMeasuredValueAttribute( - val value: Float? - ) + object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() + } + + class PeakMeasuredValueAttribute(val value: Float?) sealed class PeakMeasuredValueAttributeSubscriptionState { - data class Success( - val value: Float? - ) : PeakMeasuredValueAttributeSubscriptionState() - + data class Success(val value: Float?) : PeakMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : PeakMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : PeakMeasuredValueAttributeSubscriptionState() - } -class AverageMeasuredValueAttribute( - val value: Float? - ) + object SubscriptionEstablished : PeakMeasuredValueAttributeSubscriptionState() + } + + class AverageMeasuredValueAttribute(val value: Float?) sealed class AverageMeasuredValueAttributeSubscriptionState { - data class Success( - val value: Float? - ) : AverageMeasuredValueAttributeSubscriptionState() - + data class Success(val value: Float?) : AverageMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : AverageMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : AverageMeasuredValueAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : AverageMeasuredValueAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } -suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } + + suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute { + 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}") - } + 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) { - "Measuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Measuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return MeasuredValueAttribute(decodedValue) } suspend fun subscribeMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MeasuredValueAttributeSubscriptionState.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) { - "Measuredvalue attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Measuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute { + 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}") - } + 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) { - "Minmeasuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Minmeasuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return MinMeasuredValueAttribute(decodedValue) } suspend fun subscribeMinMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MinMeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MinMeasuredValueAttributeSubscriptionState.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) { - "Minmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Minmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MinMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute { + 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}") - } + 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) { - "Maxmeasuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Maxmeasuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return MaxMeasuredValueAttribute(decodedValue) } suspend fun subscribeMaxMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MaxMeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MaxMeasuredValueAttributeSubscriptionState.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) { - "Maxmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Maxmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MaxMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPeakMeasuredValueAttribute(): PeakMeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readPeakMeasuredValueAttribute(): PeakMeasuredValueAttribute { + 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}") - } + 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) { - "Peakmeasuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Peakmeasuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return PeakMeasuredValueAttribute(decodedValue) } suspend fun subscribePeakMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(PeakMeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + PeakMeasuredValueAttributeSubscriptionState.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) { - "Peakmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Peakmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(PeakMeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(PeakMeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(PeakMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPeakMeasuredValueWindowAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 4u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readPeakMeasuredValueWindowAttribute(): UInt? { + 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}") - } + 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) { - "Peakmeasuredvaluewindow attribute not found in response" - } + } + + requireNotNull(attributeData) { "Peakmeasuredvaluewindow attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribePeakMeasuredValueWindowAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Peakmeasuredvaluewindow attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Peakmeasuredvaluewindow attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAverageMeasuredValueAttribute(): AverageMeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 5u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readAverageMeasuredValueAttribute(): AverageMeasuredValueAttribute { + 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}") - } + 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) { - "Averagemeasuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Averagemeasuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return AverageMeasuredValueAttribute(decodedValue) } suspend fun subscribeAverageMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(AverageMeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + AverageMeasuredValueAttributeSubscriptionState.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) { - "Averagemeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Averagemeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(AverageMeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(AverageMeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(AverageMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAverageMeasuredValueWindowAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 6u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readAverageMeasuredValueWindowAttribute(): UInt? { + 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}") - } + 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) { - "Averagemeasuredvaluewindow attribute not found in response" - } + } + + requireNotNull(attributeData) { "Averagemeasuredvaluewindow attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeAverageMeasuredValueWindowAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Averagemeasuredvaluewindow attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Averagemeasuredvaluewindow attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readUncertaintyAttribute(): Float? {val ATTRIBUTE_ID: UInt = 7u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readUncertaintyAttribute(): Float? { + 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}") - } + 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) { - "Uncertainty attribute not found in response" - } + } + + requireNotNull(attributeData) { "Uncertainty attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - + val decodedValue: Float? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeUncertaintyAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(FloatSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + FloatSubscriptionState.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) { - "Uncertainty attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Uncertainty attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(FloatSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(FloatSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(FloatSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMeasurementUnitAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 8u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMeasurementUnitAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 8u + + 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}") - } + 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) { - "Measurementunit attribute not found in response" - } + } + + requireNotNull(attributeData) { "Measurementunit 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeMeasurementUnitAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Measurementunit attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Measurementunit 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)) - } - + 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 readMeasurementMediumAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 9u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMeasurementMediumAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 9u + + 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}") - } + 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) { - "Measurementmedium attribute not found in response" - } + } + + requireNotNull(attributeData) { "Measurementmedium 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeMeasurementMediumAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Measurementmedium attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Measurementmedium 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)) - } - + 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 readLevelValueAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 10u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readLevelValueAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 10u + + 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}") - } + 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) { - "Levelvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Levelvalue 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeLevelValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Levelvalue attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Levelvalue 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)) - } - + 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 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1389,97 +1291,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1487,97 +1388,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1585,97 +1483,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1683,81 +1578,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1769,80 +1659,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1855,11 +1742,12 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { - private val logger = Logger.getLogger(CarbonMonoxideConcentrationMeasurementCluster::class.java.name) + private val logger = + Logger.getLogger(CarbonMonoxideConcentrationMeasurementCluster::class.java.name) const val CLUSTER_ID: UInt = 1036u } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/ChannelCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/ChannelCluster.kt index f3bee01c8e2643..67eccfdb2126b3 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/ChannelCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/ChannelCluster.kt @@ -17,166 +17,127 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState -import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.UShortSubscriptionState +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter class ChannelCluster(private val controller: MatterController, private val endpointId: UShort) { - class ChangeChannelResponse( - val status: UByte, - val data: String? - ) + class ChangeChannelResponse(val status: UByte, val data: String?) class ProgramGuideResponse( - val paging: ChannelClusterChannelPagingStruct, - val programList: List - ) -class ChannelListAttribute( - val value: List? + val paging: ChannelClusterChannelPagingStruct, + val programList: List, ) + class ChannelListAttribute(val value: List?) + sealed class ChannelListAttributeSubscriptionState { - data class Success( - val value: List? - ) : ChannelListAttributeSubscriptionState() - + data class Success(val value: List?) : + ChannelListAttributeSubscriptionState() + data class Error(val exception: Exception) : ChannelListAttributeSubscriptionState() - object SubscriptionEstablished : ChannelListAttributeSubscriptionState() - } -class LineupAttribute( - val value: ChannelClusterLineupInfoStruct? - ) + object SubscriptionEstablished : ChannelListAttributeSubscriptionState() + } + + class LineupAttribute(val value: ChannelClusterLineupInfoStruct?) sealed class LineupAttributeSubscriptionState { - data class Success( - val value: ChannelClusterLineupInfoStruct? - ) : LineupAttributeSubscriptionState() - + data class Success(val value: ChannelClusterLineupInfoStruct?) : + LineupAttributeSubscriptionState() + data class Error(val exception: Exception) : LineupAttributeSubscriptionState() - object SubscriptionEstablished : LineupAttributeSubscriptionState() - } -class CurrentChannelAttribute( - val value: ChannelClusterChannelInfoStruct? - ) + object SubscriptionEstablished : LineupAttributeSubscriptionState() + } + + class CurrentChannelAttribute(val value: ChannelClusterChannelInfoStruct?) sealed class CurrentChannelAttributeSubscriptionState { - data class Success( - val value: ChannelClusterChannelInfoStruct? - ) : CurrentChannelAttributeSubscriptionState() - + data class Success(val value: ChannelClusterChannelInfoStruct?) : + CurrentChannelAttributeSubscriptionState() + data class Error(val exception: Exception) : CurrentChannelAttributeSubscriptionState() - object SubscriptionEstablished : CurrentChannelAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : CurrentChannelAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun changeChannel(match: String - ,timedInvokeTimeout: Duration? = null): ChangeChannelResponse { + suspend fun changeChannel( + match: String, + timedInvokeTimeout: Duration? = null, + ): ChangeChannelResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_MATCH_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_MATCH_REQ), match) + tlvWriter.put(ContextSpecificTag(TAG_MATCH_REQ), match) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -186,55 +147,48 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_DATA: Int = 1 var data_decoded: String? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_DATA)) {data_decoded = + if (tag == ContextSpecificTag(TAG_STATUS)) { + status_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_DATA)) { + data_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - }} - - - else { + tlvReader.getString(tag) + } else { + null + } + } + } else { tlvReader.skipElement() } } - - if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - - - tlvReader.exitContainer() - return ChangeChannelResponse( - status_decoded, - data_decoded - ) + return ChangeChannelResponse(status_decoded, data_decoded) } - suspend fun changeChannelByNumber(majorNumber: UShort - ,minorNumber: UShort - ,timedInvokeTimeout: Duration? = null) { + suspend fun changeChannelByNumber( + majorNumber: UShort, + minorNumber: UShort, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 2u val tlvWriter = TlvWriter() @@ -244,64 +198,61 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_MAJOR_NUMBER_REQ), majorNumber) val TAG_MINOR_NUMBER_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_MINOR_NUMBER_REQ), minorNumber) + tlvWriter.put(ContextSpecificTag(TAG_MINOR_NUMBER_REQ), minorNumber) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun skipChannel(count: Short - ,timedInvokeTimeout: Duration? = null) { + suspend fun skipChannel(count: Short, timedInvokeTimeout: Duration? = null) { val commandId: UInt = 3u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_COUNT_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_COUNT_REQ), count) + tlvWriter.put(ContextSpecificTag(TAG_COUNT_REQ), count) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun getProgramGuide(startTime: UInt? - ,endTime: UInt? - ,channelList: List? - ,pageToken: ChannelClusterPageTokenStruct? - ,recordingFlag: UInt? - ,externalIDList: List? - ,data: ByteArray? - ,timedInvokeTimeout: Duration? = null): ProgramGuideResponse { + suspend fun getProgramGuide( + startTime: UInt?, + endTime: UInt?, + channelList: List?, + pageToken: ChannelClusterPageTokenStruct?, + recordingFlag: UInt?, + externalIDList: List?, + data: ByteArray?, + timedInvokeTimeout: Duration? = null, + ): ProgramGuideResponse { val commandId: UInt = 4u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_START_TIME_REQ: Int = 0 - startTime?.let { - tlvWriter.put(ContextSpecificTag(TAG_START_TIME_REQ), startTime) - } + startTime?.let { tlvWriter.put(ContextSpecificTag(TAG_START_TIME_REQ), startTime) } val TAG_END_TIME_REQ: Int = 1 - endTime?.let { - tlvWriter.put(ContextSpecificTag(TAG_END_TIME_REQ), endTime) - } + endTime?.let { tlvWriter.put(ContextSpecificTag(TAG_END_TIME_REQ), endTime) } val TAG_CHANNEL_LIST_REQ: Int = 2 channelList?.let { @@ -313,14 +264,10 @@ class AttributeListAttribute( } val TAG_PAGE_TOKEN_REQ: Int = 3 - pageToken?.let { - pageToken.toTlv(ContextSpecificTag(TAG_PAGE_TOKEN_REQ), tlvWriter) - } + pageToken?.let { pageToken.toTlv(ContextSpecificTag(TAG_PAGE_TOKEN_REQ), tlvWriter) } val TAG_RECORDING_FLAG_REQ: Int = 4 - recordingFlag?.let { - tlvWriter.put(ContextSpecificTag(TAG_RECORDING_FLAG_REQ), recordingFlag) - } + recordingFlag?.let { tlvWriter.put(ContextSpecificTag(TAG_RECORDING_FLAG_REQ), recordingFlag) } val TAG_EXTERNAL_ID_LIST_REQ: Int = 5 externalIDList?.let { @@ -332,16 +279,14 @@ class AttributeListAttribute( } val TAG_DATA_REQ: Int = 6 - data?.let { - tlvWriter.put(ContextSpecificTag(TAG_DATA_REQ), data) - } + data?.let { tlvWriter.put(ContextSpecificTag(TAG_DATA_REQ), data) } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -351,56 +296,51 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_PAGING: Int = 0 var paging_decoded: ChannelClusterChannelPagingStruct? = null - + val TAG_PROGRAM_LIST: Int = 1 var programList_decoded: List? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_PAGING)) {paging_decoded = ChannelClusterChannelPagingStruct.fromTlv(tag, tlvReader)} - - if (tag == ContextSpecificTag(TAG_PROGRAM_LIST)) {programList_decoded = buildList { - tlvReader.enterArray(tag) - while(!tlvReader.isEndOfContainer()) { - add(ChannelClusterProgramStruct.fromTlv(AnonymousTag, tlvReader)) + if (tag == ContextSpecificTag(TAG_PAGING)) { + paging_decoded = ChannelClusterChannelPagingStruct.fromTlv(tag, tlvReader) } - tlvReader.exitContainer() - }} - - else { + if (tag == ContextSpecificTag(TAG_PROGRAM_LIST)) { + programList_decoded = + buildList { + tlvReader.enterArray(tag) + while (!tlvReader.isEndOfContainer()) { + add(ChannelClusterProgramStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { tlvReader.skipElement() } } - - if (paging_decoded == null) { - throw IllegalStateException("paging not found in TLV") + throw IllegalStateException("paging not found in TLV") } - - + if (programList_decoded == null) { - throw IllegalStateException("programList not found in TLV") + throw IllegalStateException("programList not found in TLV") } - tlvReader.exitContainer() - return ProgramGuideResponse( - paging_decoded, - programList_decoded - ) + return ProgramGuideResponse(paging_decoded, programList_decoded) } - suspend fun recordProgram(programIdentifier: String - ,shouldRecordSeries: Boolean - ,externalIDList: List - ,data: ByteArray - ,timedInvokeTimeout: Duration? = null) { + suspend fun recordProgram( + programIdentifier: String, + shouldRecordSeries: Boolean, + externalIDList: List, + data: ByteArray, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 6u val tlvWriter = TlvWriter() @@ -414,31 +354,33 @@ class AttributeListAttribute( val TAG_EXTERNAL_ID_LIST_REQ: Int = 2 tlvWriter.startArray(ContextSpecificTag(TAG_EXTERNAL_ID_LIST_REQ)) - for (item in externalIDList.iterator()) { - item.toTlv(AnonymousTag, tlvWriter) - } - tlvWriter.endArray() + for (item in externalIDList.iterator()) { + item.toTlv(AnonymousTag, tlvWriter) + } + tlvWriter.endArray() val TAG_DATA_REQ: Int = 3 - tlvWriter.put(ContextSpecificTag(TAG_DATA_REQ), data) + tlvWriter.put(ContextSpecificTag(TAG_DATA_REQ), data) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun cancelRecordProgram(programIdentifier: String - ,shouldRecordSeries: Boolean - ,externalIDList: List - ,data: ByteArray - ,timedInvokeTimeout: Duration? = null) { + suspend fun cancelRecordProgram( + programIdentifier: String, + shouldRecordSeries: Boolean, + externalIDList: List, + data: ByteArray, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 7u val tlvWriter = TlvWriter() @@ -452,437 +394,420 @@ class AttributeListAttribute( val TAG_EXTERNAL_ID_LIST_REQ: Int = 2 tlvWriter.startArray(ContextSpecificTag(TAG_EXTERNAL_ID_LIST_REQ)) - for (item in externalIDList.iterator()) { - item.toTlv(AnonymousTag, tlvWriter) - } - tlvWriter.endArray() + for (item in externalIDList.iterator()) { + item.toTlv(AnonymousTag, tlvWriter) + } + tlvWriter.endArray() val TAG_DATA_REQ: Int = 3 - tlvWriter.put(ContextSpecificTag(TAG_DATA_REQ), data) + tlvWriter.put(ContextSpecificTag(TAG_DATA_REQ), data) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } -suspend fun readChannelListAttribute(): ChannelListAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readChannelListAttribute(): ChannelListAttribute { + 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}") - } + 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) { - "Channellist attribute not found in response" - } + } + + requireNotNull(attributeData) { "Channellist attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(ChannelClusterChannelInfoStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(ChannelClusterChannelInfoStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null } - tlvReader.exitContainer() - } - } else { - null - } - return ChannelListAttribute(decodedValue) } suspend fun subscribeChannelListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ChannelListAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ChannelListAttributeSubscriptionState.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) { - "Channellist attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Channellist attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(ChannelClusterChannelInfoStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { - emit(ChannelListAttributeSubscriptionState.Success(it)) - } - + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(ChannelClusterChannelInfoStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { emit(ChannelListAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ChannelListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readLineupAttribute(): LineupAttribute {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readLineupAttribute(): LineupAttribute { + 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}") - } + 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) { - "Lineup attribute not found in response" - } + } + + requireNotNull(attributeData) { "Lineup attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ChannelClusterLineupInfoStruct? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - ChannelClusterLineupInfoStruct.fromTlv(AnonymousTag, tlvReader) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: ChannelClusterLineupInfoStruct? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + ChannelClusterLineupInfoStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return LineupAttribute(decodedValue) } suspend fun subscribeLineupAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(LineupAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + LineupAttributeSubscriptionState.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) { - "Lineup attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Lineup attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ChannelClusterLineupInfoStruct? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - ChannelClusterLineupInfoStruct.fromTlv(AnonymousTag, tlvReader) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(LineupAttributeSubscriptionState.Success(it)) - } - + val decodedValue: ChannelClusterLineupInfoStruct? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + ChannelClusterLineupInfoStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(LineupAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(LineupAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCurrentChannelAttribute(): CurrentChannelAttribute {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readCurrentChannelAttribute(): CurrentChannelAttribute { + 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}") - } + 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) { - "Currentchannel attribute not found in response" - } + } + + requireNotNull(attributeData) { "Currentchannel attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ChannelClusterChannelInfoStruct? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - ChannelClusterChannelInfoStruct.fromTlv(AnonymousTag, tlvReader) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: ChannelClusterChannelInfoStruct? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + ChannelClusterChannelInfoStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return CurrentChannelAttribute(decodedValue) } suspend fun subscribeCurrentChannelAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(CurrentChannelAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + CurrentChannelAttributeSubscriptionState.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) { - "Currentchannel attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Currentchannel attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ChannelClusterChannelInfoStruct? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - ChannelClusterChannelInfoStruct.fromTlv(AnonymousTag, tlvReader) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(CurrentChannelAttributeSubscriptionState.Success(it)) - } - + val decodedValue: ChannelClusterChannelInfoStruct? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + ChannelClusterChannelInfoStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(CurrentChannelAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(CurrentChannelAttributeSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -890,97 +815,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -988,97 +912,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1086,97 +1007,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1184,81 +1102,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1270,80 +1183,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1356,7 +1266,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/ColorControlCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/ColorControlCluster.kt index 22dd04f551f5f8..bded0dfd041f7d 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/ColorControlCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/ColorControlCluster.kt @@ -17,250 +17,197 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest +import matter.controller.StringSubscriptionState import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class ColorControlCluster(private val controller: MatterController, private val endpointId: UShort) {class NumberOfPrimariesAttribute( - val value: UByte? - ) +class ColorControlCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class NumberOfPrimariesAttribute(val value: UByte?) sealed class NumberOfPrimariesAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : NumberOfPrimariesAttributeSubscriptionState() - + data class Success(val value: UByte?) : NumberOfPrimariesAttributeSubscriptionState() + data class Error(val exception: Exception) : NumberOfPrimariesAttributeSubscriptionState() - object SubscriptionEstablished : NumberOfPrimariesAttributeSubscriptionState() - } -class Primary1IntensityAttribute( - val value: UByte? - ) + object SubscriptionEstablished : NumberOfPrimariesAttributeSubscriptionState() + } + + class Primary1IntensityAttribute(val value: UByte?) sealed class Primary1IntensityAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : Primary1IntensityAttributeSubscriptionState() - + data class Success(val value: UByte?) : Primary1IntensityAttributeSubscriptionState() + data class Error(val exception: Exception) : Primary1IntensityAttributeSubscriptionState() - object SubscriptionEstablished : Primary1IntensityAttributeSubscriptionState() - } -class Primary2IntensityAttribute( - val value: UByte? - ) + object SubscriptionEstablished : Primary1IntensityAttributeSubscriptionState() + } + + class Primary2IntensityAttribute(val value: UByte?) sealed class Primary2IntensityAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : Primary2IntensityAttributeSubscriptionState() - + data class Success(val value: UByte?) : Primary2IntensityAttributeSubscriptionState() + data class Error(val exception: Exception) : Primary2IntensityAttributeSubscriptionState() - object SubscriptionEstablished : Primary2IntensityAttributeSubscriptionState() - } -class Primary3IntensityAttribute( - val value: UByte? - ) + object SubscriptionEstablished : Primary2IntensityAttributeSubscriptionState() + } + + class Primary3IntensityAttribute(val value: UByte?) sealed class Primary3IntensityAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : Primary3IntensityAttributeSubscriptionState() - + data class Success(val value: UByte?) : Primary3IntensityAttributeSubscriptionState() + data class Error(val exception: Exception) : Primary3IntensityAttributeSubscriptionState() - object SubscriptionEstablished : Primary3IntensityAttributeSubscriptionState() - } -class Primary4IntensityAttribute( - val value: UByte? - ) + object SubscriptionEstablished : Primary3IntensityAttributeSubscriptionState() + } + + class Primary4IntensityAttribute(val value: UByte?) sealed class Primary4IntensityAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : Primary4IntensityAttributeSubscriptionState() - + data class Success(val value: UByte?) : Primary4IntensityAttributeSubscriptionState() + data class Error(val exception: Exception) : Primary4IntensityAttributeSubscriptionState() - object SubscriptionEstablished : Primary4IntensityAttributeSubscriptionState() - } -class Primary5IntensityAttribute( - val value: UByte? - ) + object SubscriptionEstablished : Primary4IntensityAttributeSubscriptionState() + } + + class Primary5IntensityAttribute(val value: UByte?) sealed class Primary5IntensityAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : Primary5IntensityAttributeSubscriptionState() - + data class Success(val value: UByte?) : Primary5IntensityAttributeSubscriptionState() + data class Error(val exception: Exception) : Primary5IntensityAttributeSubscriptionState() - object SubscriptionEstablished : Primary5IntensityAttributeSubscriptionState() - } -class Primary6IntensityAttribute( - val value: UByte? - ) + object SubscriptionEstablished : Primary5IntensityAttributeSubscriptionState() + } + + class Primary6IntensityAttribute(val value: UByte?) sealed class Primary6IntensityAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : Primary6IntensityAttributeSubscriptionState() - + data class Success(val value: UByte?) : Primary6IntensityAttributeSubscriptionState() + data class Error(val exception: Exception) : Primary6IntensityAttributeSubscriptionState() - object SubscriptionEstablished : Primary6IntensityAttributeSubscriptionState() - } -class ColorPointRIntensityAttribute( - val value: UByte? - ) + object SubscriptionEstablished : Primary6IntensityAttributeSubscriptionState() + } + + class ColorPointRIntensityAttribute(val value: UByte?) sealed class ColorPointRIntensityAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : ColorPointRIntensityAttributeSubscriptionState() - + data class Success(val value: UByte?) : ColorPointRIntensityAttributeSubscriptionState() + data class Error(val exception: Exception) : ColorPointRIntensityAttributeSubscriptionState() - object SubscriptionEstablished : ColorPointRIntensityAttributeSubscriptionState() - } -class ColorPointGIntensityAttribute( - val value: UByte? - ) + object SubscriptionEstablished : ColorPointRIntensityAttributeSubscriptionState() + } + + class ColorPointGIntensityAttribute(val value: UByte?) sealed class ColorPointGIntensityAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : ColorPointGIntensityAttributeSubscriptionState() - + data class Success(val value: UByte?) : ColorPointGIntensityAttributeSubscriptionState() + data class Error(val exception: Exception) : ColorPointGIntensityAttributeSubscriptionState() - object SubscriptionEstablished : ColorPointGIntensityAttributeSubscriptionState() - } -class ColorPointBIntensityAttribute( - val value: UByte? - ) + object SubscriptionEstablished : ColorPointGIntensityAttributeSubscriptionState() + } + + class ColorPointBIntensityAttribute(val value: UByte?) sealed class ColorPointBIntensityAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : ColorPointBIntensityAttributeSubscriptionState() - + data class Success(val value: UByte?) : ColorPointBIntensityAttributeSubscriptionState() + data class Error(val exception: Exception) : ColorPointBIntensityAttributeSubscriptionState() - object SubscriptionEstablished : ColorPointBIntensityAttributeSubscriptionState() - } -class StartUpColorTemperatureMiredsAttribute( - val value: UShort? - ) + object SubscriptionEstablished : ColorPointBIntensityAttributeSubscriptionState() + } + + class StartUpColorTemperatureMiredsAttribute(val value: UShort?) sealed class StartUpColorTemperatureMiredsAttributeSubscriptionState { - data class Success( - val value: UShort? - ) : StartUpColorTemperatureMiredsAttributeSubscriptionState() - - data class Error(val exception: Exception) : StartUpColorTemperatureMiredsAttributeSubscriptionState() - - object SubscriptionEstablished : StartUpColorTemperatureMiredsAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + data class Success(val value: UShort?) : + StartUpColorTemperatureMiredsAttributeSubscriptionState() + + data class Error(val exception: Exception) : + StartUpColorTemperatureMiredsAttributeSubscriptionState() + + object SubscriptionEstablished : StartUpColorTemperatureMiredsAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun moveToHue(hue: UByte - ,direction: UByte - ,transitionTime: UShort - ,optionsMask: UByte - ,optionsOverride: UByte - ,timedInvokeTimeout: Duration? = null) { + suspend fun moveToHue( + hue: UByte, + direction: UByte, + transitionTime: UShort, + optionsMask: UByte, + optionsOverride: UByte, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 0u val tlvWriter = TlvWriter() @@ -279,25 +226,27 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 4 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun moveHue(moveMode: UByte - ,rate: UByte - ,optionsMask: UByte - ,optionsOverride: UByte - ,timedInvokeTimeout: Duration? = null) { + suspend fun moveHue( + moveMode: UByte, + rate: UByte, + optionsMask: UByte, + optionsOverride: UByte, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 1u val tlvWriter = TlvWriter() @@ -313,26 +262,28 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 3 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun stepHue(stepMode: UByte - ,stepSize: UByte - ,transitionTime: UByte - ,optionsMask: UByte - ,optionsOverride: UByte - ,timedInvokeTimeout: Duration? = null) { + suspend fun stepHue( + stepMode: UByte, + stepSize: UByte, + transitionTime: UByte, + optionsMask: UByte, + optionsOverride: UByte, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 2u val tlvWriter = TlvWriter() @@ -351,25 +302,27 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 4 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun moveToSaturation(saturation: UByte - ,transitionTime: UShort - ,optionsMask: UByte - ,optionsOverride: UByte - ,timedInvokeTimeout: Duration? = null) { + suspend fun moveToSaturation( + saturation: UByte, + transitionTime: UShort, + optionsMask: UByte, + optionsOverride: UByte, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 3u val tlvWriter = TlvWriter() @@ -385,25 +338,27 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 3 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun moveSaturation(moveMode: UByte - ,rate: UByte - ,optionsMask: UByte - ,optionsOverride: UByte - ,timedInvokeTimeout: Duration? = null) { + suspend fun moveSaturation( + moveMode: UByte, + rate: UByte, + optionsMask: UByte, + optionsOverride: UByte, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 4u val tlvWriter = TlvWriter() @@ -419,26 +374,28 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 3 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun stepSaturation(stepMode: UByte - ,stepSize: UByte - ,transitionTime: UByte - ,optionsMask: UByte - ,optionsOverride: UByte - ,timedInvokeTimeout: Duration? = null) { + suspend fun stepSaturation( + stepMode: UByte, + stepSize: UByte, + transitionTime: UByte, + optionsMask: UByte, + optionsOverride: UByte, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 5u val tlvWriter = TlvWriter() @@ -457,26 +414,28 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 4 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun moveToHueAndSaturation(hue: UByte - ,saturation: UByte - ,transitionTime: UShort - ,optionsMask: UByte - ,optionsOverride: UByte - ,timedInvokeTimeout: Duration? = null) { + suspend fun moveToHueAndSaturation( + hue: UByte, + saturation: UByte, + transitionTime: UShort, + optionsMask: UByte, + optionsOverride: UByte, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 6u val tlvWriter = TlvWriter() @@ -495,26 +454,28 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 4 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun moveToColor(colorX: UShort - ,colorY: UShort - ,transitionTime: UShort - ,optionsMask: UByte - ,optionsOverride: UByte - ,timedInvokeTimeout: Duration? = null) { + suspend fun moveToColor( + colorX: UShort, + colorY: UShort, + transitionTime: UShort, + optionsMask: UByte, + optionsOverride: UByte, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 7u val tlvWriter = TlvWriter() @@ -533,25 +494,27 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 4 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun moveColor(rateX: Short - ,rateY: Short - ,optionsMask: UByte - ,optionsOverride: UByte - ,timedInvokeTimeout: Duration? = null) { + suspend fun moveColor( + rateX: Short, + rateY: Short, + optionsMask: UByte, + optionsOverride: UByte, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 8u val tlvWriter = TlvWriter() @@ -567,26 +530,28 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 3 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun stepColor(stepX: Short - ,stepY: Short - ,transitionTime: UShort - ,optionsMask: UByte - ,optionsOverride: UByte - ,timedInvokeTimeout: Duration? = null) { + suspend fun stepColor( + stepX: Short, + stepY: Short, + transitionTime: UShort, + optionsMask: UByte, + optionsOverride: UByte, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 9u val tlvWriter = TlvWriter() @@ -605,25 +570,27 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 4 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun moveToColorTemperature(colorTemperatureMireds: UShort - ,transitionTime: UShort - ,optionsMask: UByte - ,optionsOverride: UByte - ,timedInvokeTimeout: Duration? = null) { + suspend fun moveToColorTemperature( + colorTemperatureMireds: UShort, + transitionTime: UShort, + optionsMask: UByte, + optionsOverride: UByte, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 10u val tlvWriter = TlvWriter() @@ -639,26 +606,28 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 3 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun enhancedMoveToHue(enhancedHue: UShort - ,direction: UByte - ,transitionTime: UShort - ,optionsMask: UByte - ,optionsOverride: UByte - ,timedInvokeTimeout: Duration? = null) { + suspend fun enhancedMoveToHue( + enhancedHue: UShort, + direction: UByte, + transitionTime: UShort, + optionsMask: UByte, + optionsOverride: UByte, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 64u val tlvWriter = TlvWriter() @@ -677,25 +646,27 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 4 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun enhancedMoveHue(moveMode: UByte - ,rate: UShort - ,optionsMask: UByte - ,optionsOverride: UByte - ,timedInvokeTimeout: Duration? = null) { + suspend fun enhancedMoveHue( + moveMode: UByte, + rate: UShort, + optionsMask: UByte, + optionsOverride: UByte, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 65u val tlvWriter = TlvWriter() @@ -711,26 +682,28 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 3 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun enhancedStepHue(stepMode: UByte - ,stepSize: UShort - ,transitionTime: UShort - ,optionsMask: UByte - ,optionsOverride: UByte - ,timedInvokeTimeout: Duration? = null) { + suspend fun enhancedStepHue( + stepMode: UByte, + stepSize: UShort, + transitionTime: UShort, + optionsMask: UByte, + optionsOverride: UByte, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 66u val tlvWriter = TlvWriter() @@ -749,26 +722,28 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 4 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun enhancedMoveToHueAndSaturation(enhancedHue: UShort - ,saturation: UByte - ,transitionTime: UShort - ,optionsMask: UByte - ,optionsOverride: UByte - ,timedInvokeTimeout: Duration? = null) { + suspend fun enhancedMoveToHueAndSaturation( + enhancedHue: UShort, + saturation: UByte, + transitionTime: UShort, + optionsMask: UByte, + optionsOverride: UByte, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 67u val tlvWriter = TlvWriter() @@ -787,28 +762,30 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 4 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun colorLoopSet(updateFlags: UByte - ,action: UByte - ,direction: UByte - ,time: UShort - ,startHue: UShort - ,optionsMask: UByte - ,optionsOverride: UByte - ,timedInvokeTimeout: Duration? = null) { + suspend fun colorLoopSet( + updateFlags: UByte, + action: UByte, + direction: UByte, + time: UShort, + startHue: UShort, + optionsMask: UByte, + optionsOverride: UByte, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 68u val tlvWriter = TlvWriter() @@ -833,23 +810,25 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 6 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun stopMoveStep(optionsMask: UByte - ,optionsOverride: UByte - ,timedInvokeTimeout: Duration? = null) { + suspend fun stopMoveStep( + optionsMask: UByte, + optionsOverride: UByte, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 71u val tlvWriter = TlvWriter() @@ -859,27 +838,29 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun moveColorTemperature(moveMode: UByte - ,rate: UShort - ,colorTemperatureMinimumMireds: UShort - ,colorTemperatureMaximumMireds: UShort - ,optionsMask: UByte - ,optionsOverride: UByte - ,timedInvokeTimeout: Duration? = null) { + suspend fun moveColorTemperature( + moveMode: UByte, + rate: UShort, + colorTemperatureMinimumMireds: UShort, + colorTemperatureMaximumMireds: UShort, + optionsMask: UByte, + optionsOverride: UByte, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 75u val tlvWriter = TlvWriter() @@ -892,37 +873,45 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_RATE_REQ), rate) val TAG_COLOR_TEMPERATURE_MINIMUM_MIREDS_REQ: Int = 2 - tlvWriter.put(ContextSpecificTag(TAG_COLOR_TEMPERATURE_MINIMUM_MIREDS_REQ), colorTemperatureMinimumMireds) + tlvWriter.put( + ContextSpecificTag(TAG_COLOR_TEMPERATURE_MINIMUM_MIREDS_REQ), + colorTemperatureMinimumMireds, + ) val TAG_COLOR_TEMPERATURE_MAXIMUM_MIREDS_REQ: Int = 3 - tlvWriter.put(ContextSpecificTag(TAG_COLOR_TEMPERATURE_MAXIMUM_MIREDS_REQ), colorTemperatureMaximumMireds) + tlvWriter.put( + ContextSpecificTag(TAG_COLOR_TEMPERATURE_MAXIMUM_MIREDS_REQ), + colorTemperatureMaximumMireds, + ) val TAG_OPTIONS_MASK_REQ: Int = 4 tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 5 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun stepColorTemperature(stepMode: UByte - ,stepSize: UShort - ,transitionTime: UShort - ,colorTemperatureMinimumMireds: UShort - ,colorTemperatureMaximumMireds: UShort - ,optionsMask: UByte - ,optionsOverride: UByte - ,timedInvokeTimeout: Duration? = null) { + suspend fun stepColorTemperature( + stepMode: UByte, + stepSize: UShort, + transitionTime: UShort, + colorTemperatureMinimumMireds: UShort, + colorTemperatureMaximumMireds: UShort, + optionsMask: UByte, + optionsOverride: UByte, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 76u val tlvWriter = TlvWriter() @@ -938,877 +927,838 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_TRANSITION_TIME_REQ), transitionTime) val TAG_COLOR_TEMPERATURE_MINIMUM_MIREDS_REQ: Int = 3 - tlvWriter.put(ContextSpecificTag(TAG_COLOR_TEMPERATURE_MINIMUM_MIREDS_REQ), colorTemperatureMinimumMireds) + tlvWriter.put( + ContextSpecificTag(TAG_COLOR_TEMPERATURE_MINIMUM_MIREDS_REQ), + colorTemperatureMinimumMireds, + ) val TAG_COLOR_TEMPERATURE_MAXIMUM_MIREDS_REQ: Int = 4 - tlvWriter.put(ContextSpecificTag(TAG_COLOR_TEMPERATURE_MAXIMUM_MIREDS_REQ), colorTemperatureMaximumMireds) + tlvWriter.put( + ContextSpecificTag(TAG_COLOR_TEMPERATURE_MAXIMUM_MIREDS_REQ), + colorTemperatureMaximumMireds, + ) val TAG_OPTIONS_MASK_REQ: Int = 5 tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 6 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } -suspend fun readCurrentHueAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 0u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readCurrentHueAttribute(): 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 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}") - } + 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) { - "Currenthue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Currenthue 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeCurrentHueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Currenthue attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Currenthue 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCurrentSaturationAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 1u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readCurrentSaturationAttribute(): 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 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}") - } + 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) { - "Currentsaturation attribute not found in response" - } + } + + requireNotNull(attributeData) { "Currentsaturation 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeCurrentSaturationAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Currentsaturation attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Currentsaturation 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRemainingTimeAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRemainingTimeAttribute(): 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 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}") - } + 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) { - "Remainingtime attribute not found in response" - } + } + + requireNotNull(attributeData) { "Remainingtime 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeRemainingTimeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Remainingtime attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Remainingtime 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCurrentXAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 3u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readCurrentXAttribute(): UShort? { + 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 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}") - } + 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) { - "Currentx attribute not found in response" - } + } + + requireNotNull(attributeData) { "Currentx 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeCurrentXAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Currentx attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Currentx 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCurrentYAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 4u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readCurrentYAttribute(): UShort? { + 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 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}") - } + 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) { - "Currenty attribute not found in response" - } + } + + requireNotNull(attributeData) { "Currenty 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeCurrentYAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Currenty attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Currenty 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readDriftCompensationAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 5u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readDriftCompensationAttribute(): UByte? { + 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 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}") - } + 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) { - "Driftcompensation attribute not found in response" - } + } + + requireNotNull(attributeData) { "Driftcompensation 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeDriftCompensationAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Driftcompensation attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Driftcompensation 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCompensationTextAttribute(): String? {val ATTRIBUTE_ID: UInt = 6u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readCompensationTextAttribute(): String? { + 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 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}") - } + 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) { - "Compensationtext attribute not found in response" - } + } + + requireNotNull(attributeData) { "Compensationtext attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeCompensationTextAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StringSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StringSubscriptionState.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) { - "Compensationtext attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Compensationtext attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(StringSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(StringSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readColorTemperatureMiredsAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 7u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readColorTemperatureMiredsAttribute(): UShort? { + 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 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}") - } + 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) { - "Colortemperaturemireds attribute not found in response" - } + } + + requireNotNull(attributeData) { "Colortemperaturemireds 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeColorTemperatureMiredsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Colortemperaturemireds attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Colortemperaturemireds 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readColorModeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 8u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readColorModeAttribute(): UByte { + val ATTRIBUTE_ID: UInt = 8u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Colormode attribute not found in response" - } + } + + requireNotNull(attributeData) { "Colormode 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 subscribeColorModeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Colormode attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Colormode attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -1820,68 +1770,57 @@ suspend fun readColorModeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 8u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readOptionsAttribute(): UByte {val ATTRIBUTE_ID: UInt = 15u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readOptionsAttribute(): UByte { + val ATTRIBUTE_ID: UInt = 15u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Options attribute not found in response" - } + } + + requireNotNull(attributeData) { "Options 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 writeOptionsAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeOptionsAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 15u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -1902,43 +1841,45 @@ suspend fun readOptionsAttribute(): UByte {val ATTRIBUTE_ID: UInt = 15u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeOptionsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 15u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Options attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Options attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -1950,1977 +1891,1867 @@ suspend fun readOptionsAttribute(): UByte {val ATTRIBUTE_ID: UInt = 15u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNumberOfPrimariesAttribute(): NumberOfPrimariesAttribute {val ATTRIBUTE_ID: UInt = 16u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNumberOfPrimariesAttribute(): NumberOfPrimariesAttribute { + val ATTRIBUTE_ID: UInt = 16u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Numberofprimaries attribute not found in response" - } + } + + requireNotNull(attributeData) { "Numberofprimaries attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return NumberOfPrimariesAttribute(decodedValue) } suspend fun subscribeNumberOfPrimariesAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(NumberOfPrimariesAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + NumberOfPrimariesAttributeSubscriptionState.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) { - "Numberofprimaries attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Numberofprimaries 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.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(NumberOfPrimariesAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(NumberOfPrimariesAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(NumberOfPrimariesAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPrimary1XAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 17u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readPrimary1XAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 17u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Primary1x attribute not found in response" - } + } + + requireNotNull(attributeData) { "Primary1x 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribePrimary1XAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 17u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Primary1x attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Primary1x 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPrimary1YAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 18u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readPrimary1YAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 18u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Primary1y attribute not found in response" - } + } + + requireNotNull(attributeData) { "Primary1y 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribePrimary1YAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 18u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Primary1y attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Primary1y 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPrimary1IntensityAttribute(): Primary1IntensityAttribute {val ATTRIBUTE_ID: UInt = 19u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readPrimary1IntensityAttribute(): Primary1IntensityAttribute { + val ATTRIBUTE_ID: UInt = 19u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Primary1intensity attribute not found in response" - } + } + + requireNotNull(attributeData) { "Primary1intensity attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return Primary1IntensityAttribute(decodedValue) } suspend fun subscribePrimary1IntensityAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 19u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(Primary1IntensityAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + Primary1IntensityAttributeSubscriptionState.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) { - "Primary1intensity attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Primary1intensity 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(Primary1IntensityAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(Primary1IntensityAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(Primary1IntensityAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPrimary2XAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 21u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readPrimary2XAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 21u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Primary2x attribute not found in response" - } + } + + requireNotNull(attributeData) { "Primary2x 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribePrimary2XAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 21u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Primary2x attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Primary2x 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPrimary2YAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 22u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readPrimary2YAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 22u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Primary2y attribute not found in response" - } + } + + requireNotNull(attributeData) { "Primary2y 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribePrimary2YAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 22u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Primary2y attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Primary2y 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPrimary2IntensityAttribute(): Primary2IntensityAttribute {val ATTRIBUTE_ID: UInt = 23u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readPrimary2IntensityAttribute(): Primary2IntensityAttribute { + val ATTRIBUTE_ID: UInt = 23u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Primary2intensity attribute not found in response" - } + } + + requireNotNull(attributeData) { "Primary2intensity attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return Primary2IntensityAttribute(decodedValue) } suspend fun subscribePrimary2IntensityAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 23u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(Primary2IntensityAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + Primary2IntensityAttributeSubscriptionState.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) { - "Primary2intensity attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Primary2intensity 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(Primary2IntensityAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(Primary2IntensityAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(Primary2IntensityAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPrimary3XAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 25u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readPrimary3XAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 25u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Primary3x attribute not found in response" - } + } + + requireNotNull(attributeData) { "Primary3x 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribePrimary3XAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 25u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Primary3x attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Primary3x 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPrimary3YAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 26u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readPrimary3YAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 26u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Primary3y attribute not found in response" - } + } + + requireNotNull(attributeData) { "Primary3y 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribePrimary3YAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 26u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Primary3y attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Primary3y 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPrimary3IntensityAttribute(): Primary3IntensityAttribute {val ATTRIBUTE_ID: UInt = 27u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readPrimary3IntensityAttribute(): Primary3IntensityAttribute { + val ATTRIBUTE_ID: UInt = 27u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Primary3intensity attribute not found in response" - } + } + + requireNotNull(attributeData) { "Primary3intensity attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return Primary3IntensityAttribute(decodedValue) } suspend fun subscribePrimary3IntensityAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 27u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(Primary3IntensityAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + Primary3IntensityAttributeSubscriptionState.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) { - "Primary3intensity attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Primary3intensity 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(Primary3IntensityAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(Primary3IntensityAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(Primary3IntensityAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPrimary4XAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 32u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readPrimary4XAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 32u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Primary4x attribute not found in response" - } + } + + requireNotNull(attributeData) { "Primary4x 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribePrimary4XAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 32u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Primary4x attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Primary4x 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPrimary4YAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 33u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readPrimary4YAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 33u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Primary4y attribute not found in response" - } + } + + requireNotNull(attributeData) { "Primary4y 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribePrimary4YAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 33u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Primary4y attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Primary4y 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPrimary4IntensityAttribute(): Primary4IntensityAttribute {val ATTRIBUTE_ID: UInt = 34u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readPrimary4IntensityAttribute(): Primary4IntensityAttribute { + val ATTRIBUTE_ID: UInt = 34u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Primary4intensity attribute not found in response" - } + } + + requireNotNull(attributeData) { "Primary4intensity attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return Primary4IntensityAttribute(decodedValue) } suspend fun subscribePrimary4IntensityAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 34u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(Primary4IntensityAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + Primary4IntensityAttributeSubscriptionState.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) { - "Primary4intensity attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Primary4intensity 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(Primary4IntensityAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(Primary4IntensityAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(Primary4IntensityAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPrimary5XAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 36u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readPrimary5XAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 36u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Primary5x attribute not found in response" - } + } + + requireNotNull(attributeData) { "Primary5x 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribePrimary5XAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 36u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Primary5x attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Primary5x 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPrimary5YAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 37u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readPrimary5YAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 37u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Primary5y attribute not found in response" - } + } + + requireNotNull(attributeData) { "Primary5y 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribePrimary5YAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 37u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Primary5y attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Primary5y 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPrimary5IntensityAttribute(): Primary5IntensityAttribute {val ATTRIBUTE_ID: UInt = 38u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readPrimary5IntensityAttribute(): Primary5IntensityAttribute { + val ATTRIBUTE_ID: UInt = 38u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Primary5intensity attribute not found in response" - } + } + + requireNotNull(attributeData) { "Primary5intensity attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return Primary5IntensityAttribute(decodedValue) } suspend fun subscribePrimary5IntensityAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 38u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(Primary5IntensityAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + Primary5IntensityAttributeSubscriptionState.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) { - "Primary5intensity attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Primary5intensity 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(Primary5IntensityAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(Primary5IntensityAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(Primary5IntensityAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPrimary6XAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 40u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readPrimary6XAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 40u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Primary6x attribute not found in response" - } + } + + requireNotNull(attributeData) { "Primary6x 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribePrimary6XAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 40u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Primary6x attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Primary6x 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPrimary6YAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 41u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readPrimary6YAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 41u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Primary6y attribute not found in response" - } + } + + requireNotNull(attributeData) { "Primary6y 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribePrimary6YAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 41u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Primary6y attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Primary6y 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPrimary6IntensityAttribute(): Primary6IntensityAttribute {val ATTRIBUTE_ID: UInt = 42u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readPrimary6IntensityAttribute(): Primary6IntensityAttribute { + val ATTRIBUTE_ID: UInt = 42u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Primary6intensity attribute not found in response" - } + } + + requireNotNull(attributeData) { "Primary6intensity attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return Primary6IntensityAttribute(decodedValue) } suspend fun subscribePrimary6IntensityAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 42u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(Primary6IntensityAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + Primary6IntensityAttributeSubscriptionState.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) { - "Primary6intensity attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Primary6intensity 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(Primary6IntensityAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(Primary6IntensityAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(Primary6IntensityAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readWhitePointXAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 48u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readWhitePointXAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 48u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Whitepointx attribute not found in response" - } + } + + requireNotNull(attributeData) { "Whitepointx 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } - suspend fun writeWhitePointXAttribute( - value: UShort, - timedWriteTimeout: Duration? = null) { + suspend fun writeWhitePointXAttribute(value: UShort, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 48u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -3941,127 +3772,117 @@ suspend fun readWhitePointXAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 48u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeWhitePointXAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 48u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Whitepointx attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Whitepointx 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readWhitePointYAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 49u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readWhitePointYAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 49u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Whitepointy attribute not found in response" - } + } + + requireNotNull(attributeData) { "Whitepointy 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } - suspend fun writeWhitePointYAttribute( - value: UShort, - timedWriteTimeout: Duration? = null) { + suspend fun writeWhitePointYAttribute(value: UShort, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 49u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -4082,127 +3903,117 @@ suspend fun readWhitePointYAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 49u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeWhitePointYAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 49u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Whitepointy attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Whitepointy 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readColorPointRXAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 50u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readColorPointRXAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 50u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Colorpointrx attribute not found in response" - } + } + + requireNotNull(attributeData) { "Colorpointrx 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } - suspend fun writeColorPointRXAttribute( - value: UShort, - timedWriteTimeout: Duration? = null) { + suspend fun writeColorPointRXAttribute(value: UShort, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 50u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -4223,127 +4034,117 @@ suspend fun readColorPointRXAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 50u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeColorPointRXAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 50u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Colorpointrx attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Colorpointrx 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readColorPointRYAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 51u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readColorPointRYAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 51u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Colorpointry attribute not found in response" - } + } + + requireNotNull(attributeData) { "Colorpointry 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } - suspend fun writeColorPointRYAttribute( - value: UShort, - timedWriteTimeout: Duration? = null) { + suspend fun writeColorPointRYAttribute(value: UShort, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 51u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -4364,132 +4165,125 @@ suspend fun readColorPointRYAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 51u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeColorPointRYAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 51u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Colorpointry attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Colorpointry 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readColorPointRIntensityAttribute(): ColorPointRIntensityAttribute {val ATTRIBUTE_ID: UInt = 52u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readColorPointRIntensityAttribute(): ColorPointRIntensityAttribute { + val ATTRIBUTE_ID: UInt = 52u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Colorpointrintensity attribute not found in response" - } + } + + requireNotNull(attributeData) { "Colorpointrintensity attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return ColorPointRIntensityAttribute(decodedValue) } suspend fun writeColorPointRIntensityAttribute( value: UByte, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 52u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -4510,132 +4304,124 @@ suspend fun readColorPointRIntensityAttribute(): ColorPointRIntensityAttribute { throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeColorPointRIntensityAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 52u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ColorPointRIntensityAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ColorPointRIntensityAttributeSubscriptionState.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) { - "Colorpointrintensity attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Colorpointrintensity 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(ColorPointRIntensityAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(ColorPointRIntensityAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ColorPointRIntensityAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readColorPointGXAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 54u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readColorPointGXAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 54u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Colorpointgx attribute not found in response" - } + } + + requireNotNull(attributeData) { "Colorpointgx 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } - suspend fun writeColorPointGXAttribute( - value: UShort, - timedWriteTimeout: Duration? = null) { + suspend fun writeColorPointGXAttribute(value: UShort, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 54u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -4656,127 +4442,117 @@ suspend fun readColorPointGXAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 54u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeColorPointGXAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 54u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Colorpointgx attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Colorpointgx 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readColorPointGYAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 55u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readColorPointGYAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 55u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Colorpointgy attribute not found in response" - } + } + + requireNotNull(attributeData) { "Colorpointgy 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } - suspend fun writeColorPointGYAttribute( - value: UShort, - timedWriteTimeout: Duration? = null) { + suspend fun writeColorPointGYAttribute(value: UShort, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 55u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -4797,132 +4573,125 @@ suspend fun readColorPointGYAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 55u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeColorPointGYAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 55u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Colorpointgy attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Colorpointgy 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readColorPointGIntensityAttribute(): ColorPointGIntensityAttribute {val ATTRIBUTE_ID: UInt = 56u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readColorPointGIntensityAttribute(): ColorPointGIntensityAttribute { + val ATTRIBUTE_ID: UInt = 56u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Colorpointgintensity attribute not found in response" - } + } + + requireNotNull(attributeData) { "Colorpointgintensity attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return ColorPointGIntensityAttribute(decodedValue) } suspend fun writeColorPointGIntensityAttribute( value: UByte, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 56u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -4943,132 +4712,124 @@ suspend fun readColorPointGIntensityAttribute(): ColorPointGIntensityAttribute { throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeColorPointGIntensityAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 56u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ColorPointGIntensityAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ColorPointGIntensityAttributeSubscriptionState.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) { - "Colorpointgintensity attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Colorpointgintensity 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(ColorPointGIntensityAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(ColorPointGIntensityAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ColorPointGIntensityAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readColorPointBXAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 58u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readColorPointBXAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 58u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Colorpointbx attribute not found in response" - } + } + + requireNotNull(attributeData) { "Colorpointbx 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } - suspend fun writeColorPointBXAttribute( - value: UShort, - timedWriteTimeout: Duration? = null) { + suspend fun writeColorPointBXAttribute(value: UShort, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 58u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -5089,127 +4850,117 @@ suspend fun readColorPointBXAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 58u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeColorPointBXAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 58u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Colorpointbx attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Colorpointbx 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readColorPointBYAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 59u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readColorPointBYAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 59u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Colorpointby attribute not found in response" - } + } + + requireNotNull(attributeData) { "Colorpointby 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } - suspend fun writeColorPointBYAttribute( - value: UShort, - timedWriteTimeout: Duration? = null) { + suspend fun writeColorPointBYAttribute(value: UShort, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 59u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -5230,132 +4981,125 @@ suspend fun readColorPointBYAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 59u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeColorPointBYAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 59u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Colorpointby attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Colorpointby 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readColorPointBIntensityAttribute(): ColorPointBIntensityAttribute {val ATTRIBUTE_ID: UInt = 60u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readColorPointBIntensityAttribute(): ColorPointBIntensityAttribute { + val ATTRIBUTE_ID: UInt = 60u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Colorpointbintensity attribute not found in response" - } + } + + requireNotNull(attributeData) { "Colorpointbintensity attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return ColorPointBIntensityAttribute(decodedValue) } suspend fun writeColorPointBIntensityAttribute( value: UByte, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 60u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -5376,237 +5120,232 @@ suspend fun readColorPointBIntensityAttribute(): ColorPointBIntensityAttribute { throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeColorPointBIntensityAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 60u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ColorPointBIntensityAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ColorPointBIntensityAttributeSubscriptionState.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) { - "Colorpointbintensity attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Colorpointbintensity 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(ColorPointBIntensityAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(ColorPointBIntensityAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ColorPointBIntensityAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readEnhancedCurrentHueAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 16384u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readEnhancedCurrentHueAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 16384u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Enhancedcurrenthue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Enhancedcurrenthue 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeEnhancedCurrentHueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16384u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Enhancedcurrenthue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Enhancedcurrenthue 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readEnhancedColorModeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 16385u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readEnhancedColorModeAttribute(): UByte { + val ATTRIBUTE_ID: UInt = 16385u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Enhancedcolormode attribute not found in response" - } + } + + requireNotNull(attributeData) { "Enhancedcolormode 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 subscribeEnhancedColorModeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16385u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Enhancedcolormode attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Enhancedcolormode attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -5619,565 +5358,540 @@ suspend fun readEnhancedColorModeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 16 emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readColorLoopActiveAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 16386u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readColorLoopActiveAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 16386u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Colorloopactive attribute not found in response" - } + } + + requireNotNull(attributeData) { "Colorloopactive 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeColorLoopActiveAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16386u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Colorloopactive attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Colorloopactive 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readColorLoopDirectionAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 16387u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readColorLoopDirectionAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 16387u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Colorloopdirection attribute not found in response" - } + } + + requireNotNull(attributeData) { "Colorloopdirection 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeColorLoopDirectionAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16387u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Colorloopdirection attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Colorloopdirection 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readColorLoopTimeAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 16388u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readColorLoopTimeAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 16388u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Colorlooptime attribute not found in response" - } + } + + requireNotNull(attributeData) { "Colorlooptime 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeColorLoopTimeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16388u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Colorlooptime attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Colorlooptime 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readColorLoopStartEnhancedHueAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 16389u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readColorLoopStartEnhancedHueAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 16389u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Colorloopstartenhancedhue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Colorloopstartenhancedhue 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeColorLoopStartEnhancedHueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16389u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Colorloopstartenhancedhue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Colorloopstartenhancedhue 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readColorLoopStoredEnhancedHueAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 16390u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readColorLoopStoredEnhancedHueAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 16390u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Colorloopstoredenhancedhue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Colorloopstoredenhancedhue 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeColorLoopStoredEnhancedHueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16390u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Colorloopstoredenhancedhue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Colorloopstoredenhancedhue 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readColorCapabilitiesAttribute(): UShort {val ATTRIBUTE_ID: UInt = 16394u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readColorCapabilitiesAttribute(): UShort { + val ATTRIBUTE_ID: UInt = 16394u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Colorcapabilities attribute not found in response" - } + } + + requireNotNull(attributeData) { "Colorcapabilities 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 subscribeColorCapabilitiesAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16394u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Colorcapabilities attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Colorcapabilities attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -6190,368 +5904,353 @@ suspend fun readColorCapabilitiesAttribute(): UShort {val ATTRIBUTE_ID: UInt = 1 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readColorTempPhysicalMinMiredsAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 16395u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readColorTempPhysicalMinMiredsAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 16395u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Colortempphysicalminmireds attribute not found in response" - } + } + + requireNotNull(attributeData) { "Colortempphysicalminmireds 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeColorTempPhysicalMinMiredsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16395u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Colortempphysicalminmireds attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Colortempphysicalminmireds 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readColorTempPhysicalMaxMiredsAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 16396u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readColorTempPhysicalMaxMiredsAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 16396u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Colortempphysicalmaxmireds attribute not found in response" - } + } + + requireNotNull(attributeData) { "Colortempphysicalmaxmireds 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeColorTempPhysicalMaxMiredsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16396u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Colortempphysicalmaxmireds attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Colortempphysicalmaxmireds 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCoupleColorTempToLevelMinMiredsAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 16397u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readCoupleColorTempToLevelMinMiredsAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 16397u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Couplecolortemptolevelminmireds attribute not found in response" + } + + requireNotNull(attributeData) { + "Couplecolortemptolevelminmireds 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeCoupleColorTempToLevelMinMiredsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16397u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Couplecolortemptolevelminmireds attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Couplecolortemptolevelminmireds 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readStartUpColorTemperatureMiredsAttribute(): StartUpColorTemperatureMiredsAttribute {val ATTRIBUTE_ID: UInt = 16400u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readStartUpColorTemperatureMiredsAttribute(): StartUpColorTemperatureMiredsAttribute { + val ATTRIBUTE_ID: UInt = 16400u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Startupcolortemperaturemireds attribute not found in response" + } + + requireNotNull(attributeData) { + "Startupcolortemperaturemireds attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return StartUpColorTemperatureMiredsAttribute(decodedValue) } suspend fun writeStartUpColorTemperatureMiredsAttribute( value: UShort, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 16400u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -6572,157 +6271,160 @@ suspend fun readStartUpColorTemperatureMiredsAttribute(): StartUpColorTemperatur throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeStartUpColorTemperatureMiredsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16400u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StartUpColorTemperatureMiredsAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StartUpColorTemperatureMiredsAttributeSubscriptionState.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) { - "Startupcolortemperaturemireds attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Startupcolortemperaturemireds 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } decodedValue?.let { emit(StartUpColorTemperatureMiredsAttributeSubscriptionState.Success(it)) } - } SubscriptionState.SubscriptionEstablished -> { emit(StartUpColorTemperatureMiredsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65528u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -6730,97 +6432,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { emit(GeneratedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65529u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -6828,97 +6529,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va emit(AcceptedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt = 65530u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -6926,97 +6624,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt emit(EventListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ID: UInt = 65531u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -7024,81 +6719,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ emit(AttributeListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -7110,80 +6800,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 65533u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -7196,7 +6883,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/CommissionerControlCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/CommissionerControlCluster.kt index e9308706f47f15..2daf2b464e948f 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/CommissionerControlCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/CommissionerControlCluster.kt @@ -17,114 +17,87 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState -import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.UShortSubscriptionState +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class CommissionerControlCluster(private val controller: MatterController, private val endpointId: UShort) { +class CommissionerControlCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { class ReverseOpenCommissioningWindow( - val commissioningTimeout: UShort, - val PAKEPasscodeVerifier: ByteArray, - val discriminator: UShort, - val iterations: UInt, - val salt: ByteArray - ) -class GeneratedCommandListAttribute( - val value: List + val commissioningTimeout: UShort, + val PAKEPasscodeVerifier: ByteArray, + val discriminator: UShort, + val iterations: UInt, + val salt: ByteArray, ) + class GeneratedCommandListAttribute(val value: List) + sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun requestCommissioningApproval(requestId: ULong - ,vendorId: UShort - ,productId: UShort - ,label: String? - ,timedInvokeTimeout: Duration? = null) { + suspend fun requestCommissioningApproval( + requestId: ULong, + vendorId: UShort, + productId: UShort, + label: String?, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 0u val tlvWriter = TlvWriter() @@ -140,27 +113,27 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_PRODUCT_ID_REQ), productId) val TAG_LABEL_REQ: Int = 3 - label?.let { - tlvWriter.put(ContextSpecificTag(TAG_LABEL_REQ), label) - } + label?.let { tlvWriter.put(ContextSpecificTag(TAG_LABEL_REQ), label) } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun commissionNode(requestId: ULong - ,responseTimeoutSeconds: UShort - ,ipAddress: ByteArray? - ,port: UShort? - ,timedInvokeTimeout: Duration? = null): ReverseOpenCommissioningWindow { + suspend fun commissionNode( + requestId: ULong, + responseTimeoutSeconds: UShort, + ipAddress: ByteArray?, + port: UShort?, + timedInvokeTimeout: Duration? = null, + ): ReverseOpenCommissioningWindow { val commandId: UInt = 1u val tlvWriter = TlvWriter() @@ -173,21 +146,17 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_RESPONSE_TIMEOUT_SECONDS_REQ), responseTimeoutSeconds) val TAG_IP_ADDRESS_REQ: Int = 2 - ipAddress?.let { - tlvWriter.put(ContextSpecificTag(TAG_IP_ADDRESS_REQ), ipAddress) - } + ipAddress?.let { tlvWriter.put(ContextSpecificTag(TAG_IP_ADDRESS_REQ), ipAddress) } val TAG_PORT_REQ: Int = 3 - port?.let { - tlvWriter.put(ContextSpecificTag(TAG_PORT_REQ), port) - } + port?.let { tlvWriter.put(ContextSpecificTag(TAG_PORT_REQ), port) } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -197,66 +166,64 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_COMMISSIONING_TIMEOUT: Int = 0 var commissioningTimeout_decoded: UShort? = null - + val TAG_PAKE_PASSCODE_VERIFIER: Int = 1 var PAKEPasscodeVerifier_decoded: ByteArray? = null - + val TAG_DISCRIMINATOR: Int = 2 var discriminator_decoded: UShort? = null - + val TAG_ITERATIONS: Int = 3 var iterations_decoded: UInt? = null - + val TAG_SALT: Int = 4 var salt_decoded: ByteArray? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_COMMISSIONING_TIMEOUT)) {commissioningTimeout_decoded = tlvReader.getUShort(tag)} - - if (tag == ContextSpecificTag(TAG_PAKE_PASSCODE_VERIFIER)) {PAKEPasscodeVerifier_decoded = tlvReader.getByteArray(tag)} - - if (tag == ContextSpecificTag(TAG_DISCRIMINATOR)) {discriminator_decoded = tlvReader.getUShort(tag)} - - if (tag == ContextSpecificTag(TAG_ITERATIONS)) {iterations_decoded = tlvReader.getUInt(tag)} - - if (tag == ContextSpecificTag(TAG_SALT)) {salt_decoded = tlvReader.getByteArray(tag)} - - - else { + if (tag == ContextSpecificTag(TAG_COMMISSIONING_TIMEOUT)) { + commissioningTimeout_decoded = tlvReader.getUShort(tag) + } + + if (tag == ContextSpecificTag(TAG_PAKE_PASSCODE_VERIFIER)) { + PAKEPasscodeVerifier_decoded = tlvReader.getByteArray(tag) + } + + if (tag == ContextSpecificTag(TAG_DISCRIMINATOR)) { + discriminator_decoded = tlvReader.getUShort(tag) + } + + if (tag == ContextSpecificTag(TAG_ITERATIONS)) { + iterations_decoded = tlvReader.getUInt(tag) + } + + if (tag == ContextSpecificTag(TAG_SALT)) { + salt_decoded = tlvReader.getByteArray(tag) + } else { tlvReader.skipElement() } } - - if (commissioningTimeout_decoded == null) { - throw IllegalStateException("commissioningTimeout not found in TLV") + throw IllegalStateException("commissioningTimeout not found in TLV") } - - + if (PAKEPasscodeVerifier_decoded == null) { - throw IllegalStateException("PAKEPasscodeVerifier not found in TLV") + throw IllegalStateException("PAKEPasscodeVerifier not found in TLV") } - - + if (discriminator_decoded == null) { - throw IllegalStateException("discriminator not found in TLV") + throw IllegalStateException("discriminator not found in TLV") } - - + if (iterations_decoded == null) { - throw IllegalStateException("iterations not found in TLV") + throw IllegalStateException("iterations not found in TLV") } - - + if (salt_decoded == null) { - throw IllegalStateException("salt not found in TLV") + throw IllegalStateException("salt not found in TLV") } - tlvReader.exitContainer() @@ -265,81 +232,78 @@ class AttributeListAttribute( PAKEPasscodeVerifier_decoded, discriminator_decoded, iterations_decoded, - salt_decoded + salt_decoded, ) } -suspend fun readSupportedDeviceCategoriesAttribute(): UInt {val ATTRIBUTE_ID: UInt = 0u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readSupportedDeviceCategoriesAttribute(): UInt { + 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 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}") - } + 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) { - "Supporteddevicecategories attribute not found in response" - } + } + + requireNotNull(attributeData) { "Supporteddevicecategories 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 subscribeSupportedDeviceCategoriesAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Supporteddevicecategories attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Supporteddevicecategories attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -352,97 +316,96 @@ suspend fun readSupportedDeviceCategoriesAttribute(): UInt {val ATTRIBUTE_ID: UI emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65528u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -450,97 +413,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { emit(GeneratedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65529u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -548,97 +510,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va emit(AcceptedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt = 65530u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -646,97 +605,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt emit(EventListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ID: UInt = 65531u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -744,81 +700,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ emit(AttributeListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -830,80 +781,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 65533u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -916,7 +864,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/ContentAppObserverCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/ContentAppObserverCluster.kt index 034e54bd0d2c5a..bd87b2cef85d47 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/ContentAppObserverCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/ContentAppObserverCluster.kt @@ -17,129 +17,96 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState -import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.UShortSubscriptionState +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class ContentAppObserverCluster(private val controller: MatterController, private val endpointId: UShort) { - class ContentAppMessageResponse( - val status: UByte, - val data: String?, - val encodingHint: String? - ) -class GeneratedCommandListAttribute( - val value: List - ) +class ContentAppObserverCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class ContentAppMessageResponse(val status: UByte, val data: String?, val encodingHint: String?) + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun contentAppMessage(data: String? - ,encodingHint: String - ,timedInvokeTimeout: Duration? = null): ContentAppMessageResponse { + suspend fun contentAppMessage( + data: String?, + encodingHint: String, + timedInvokeTimeout: Duration? = null, + ): ContentAppMessageResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_DATA_REQ: Int = 0 - data?.let { - tlvWriter.put(ContextSpecificTag(TAG_DATA_REQ), data) - } + data?.let { tlvWriter.put(ContextSpecificTag(TAG_DATA_REQ), data) } val TAG_ENCODING_HINT_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_ENCODING_HINT_REQ), encodingHint) + tlvWriter.put(ContextSpecificTag(TAG_ENCODING_HINT_REQ), encodingHint) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -149,158 +116,147 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_DATA: Int = 1 var data_decoded: String? = null - + val TAG_ENCODING_HINT: Int = 2 var encodingHint_decoded: String? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_DATA)) {data_decoded = + if (tag == ContextSpecificTag(TAG_STATUS)) { + status_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_DATA)) { + data_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - }} - - if (tag == ContextSpecificTag(TAG_ENCODING_HINT)) {encodingHint_decoded = + tlvReader.getString(tag) + } else { + null + } + } + } + + if (tag == ContextSpecificTag(TAG_ENCODING_HINT)) { + encodingHint_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - }} - - - else { + tlvReader.getString(tag) + } else { + null + } + } + } else { tlvReader.skipElement() } } - - if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - - - - - tlvReader.exitContainer() - return ContentAppMessageResponse( - status_decoded, - data_decoded, - encodingHint_decoded - ) + return ContentAppMessageResponse(status_decoded, data_decoded, encodingHint_decoded) } -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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -308,97 +264,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -406,97 +361,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -504,97 +456,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -602,81 +551,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -688,80 +632,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -774,7 +715,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/ContentControlCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/ContentControlCluster.kt index b9ba76f30449a3..c2a44834d09481 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/ContentControlCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/ContentControlCluster.kt @@ -17,153 +17,117 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration 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.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest +import matter.controller.StringSubscriptionState import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState -import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.UShortSubscriptionState +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class ContentControlCluster(private val controller: MatterController, private val endpointId: UShort) { - class ResetPINResponse( - val PINCode: String - ) -class OnDemandRatingsAttribute( - val value: List? - ) +class ContentControlCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class ResetPINResponse(val PINCode: String) + + class OnDemandRatingsAttribute(val value: List?) sealed class OnDemandRatingsAttributeSubscriptionState { - data class Success( - val value: List? - ) : OnDemandRatingsAttributeSubscriptionState() - + data class Success(val value: List?) : + OnDemandRatingsAttributeSubscriptionState() + data class Error(val exception: Exception) : OnDemandRatingsAttributeSubscriptionState() - object SubscriptionEstablished : OnDemandRatingsAttributeSubscriptionState() - } -class ScheduledContentRatingsAttribute( - val value: List? - ) + object SubscriptionEstablished : OnDemandRatingsAttributeSubscriptionState() + } + + class ScheduledContentRatingsAttribute(val value: List?) sealed class ScheduledContentRatingsAttributeSubscriptionState { - data class Success( - val value: List? - ) : ScheduledContentRatingsAttributeSubscriptionState() - - data class Error(val exception: Exception) : ScheduledContentRatingsAttributeSubscriptionState() - - object SubscriptionEstablished : ScheduledContentRatingsAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + data class Success(val value: List?) : + ScheduledContentRatingsAttributeSubscriptionState() + + data class Error(val exception: Exception) : + ScheduledContentRatingsAttributeSubscriptionState() + + object SubscriptionEstablished : ScheduledContentRatingsAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun updatePIN(oldPIN: String? - ,newPIN: String - ,timedInvokeTimeout: Duration? = null) { + suspend fun updatePIN(oldPIN: String?, newPIN: String, timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_OLD_PIN_REQ: Int = 0 - oldPIN?.let { - tlvWriter.put(ContextSpecificTag(TAG_OLD_PIN_REQ), oldPIN) - } + oldPIN?.let { tlvWriter.put(ContextSpecificTag(TAG_OLD_PIN_REQ), oldPIN) } val TAG_NEW_PIN_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_NEW_PIN_REQ), newPIN) + tlvWriter.put(ContextSpecificTag(TAG_NEW_PIN_REQ), newPIN) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -174,14 +138,14 @@ class AttributeListAttribute( val commandId: UInt = 1u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -191,46 +155,38 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_PIN_CODE: Int = 0 var PINCode_decoded: String? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_PIN_CODE)) {PINCode_decoded = tlvReader.getString(tag)} - - - else { + if (tag == ContextSpecificTag(TAG_PIN_CODE)) { + PINCode_decoded = tlvReader.getString(tag) + } else { tlvReader.skipElement() } } - - if (PINCode_decoded == null) { - throw IllegalStateException("PINCode not found in TLV") + throw IllegalStateException("PINCode not found in TLV") } - tlvReader.exitContainer() - return ResetPINResponse( - PINCode_decoded - ) + return ResetPINResponse(PINCode_decoded) } suspend fun enable(timedInvokeTimeout: Duration? = null) { val commandId: UInt = 3u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -241,66 +197,63 @@ class AttributeListAttribute( val commandId: UInt = 4u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun addBonusTime(PINCode: String? - ,bonusTime: UInt? - ,timedInvokeTimeout: Duration? = null) { + suspend fun addBonusTime( + PINCode: String?, + bonusTime: UInt?, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 5u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_PIN_CODE_REQ: Int = 0 - PINCode?.let { - tlvWriter.put(ContextSpecificTag(TAG_PIN_CODE_REQ), PINCode) - } + PINCode?.let { tlvWriter.put(ContextSpecificTag(TAG_PIN_CODE_REQ), PINCode) } val TAG_BONUS_TIME_REQ: Int = 1 - bonusTime?.let { - tlvWriter.put(ContextSpecificTag(TAG_BONUS_TIME_REQ), bonusTime) - } + bonusTime?.let { tlvWriter.put(ContextSpecificTag(TAG_BONUS_TIME_REQ), bonusTime) } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun setScreenDailyTime(screenTime: UInt - ,timedInvokeTimeout: Duration? = null) { + suspend fun setScreenDailyTime(screenTime: UInt, timedInvokeTimeout: Duration? = null) { val commandId: UInt = 6u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_SCREEN_TIME_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_SCREEN_TIME_REQ), screenTime) + tlvWriter.put(ContextSpecificTag(TAG_SCREEN_TIME_REQ), screenTime) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -311,14 +264,14 @@ class AttributeListAttribute( val commandId: UInt = 7u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -329,136 +282,132 @@ class AttributeListAttribute( val commandId: UInt = 8u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun setOnDemandRatingThreshold(rating: String - ,timedInvokeTimeout: Duration? = null) { + suspend fun setOnDemandRatingThreshold(rating: String, timedInvokeTimeout: Duration? = null) { val commandId: UInt = 9u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_RATING_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_RATING_REQ), rating) + tlvWriter.put(ContextSpecificTag(TAG_RATING_REQ), rating) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun setScheduledContentRatingThreshold(rating: String - ,timedInvokeTimeout: Duration? = null) { + suspend fun setScheduledContentRatingThreshold( + rating: String, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 10u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_RATING_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_RATING_REQ), rating) + tlvWriter.put(ContextSpecificTag(TAG_RATING_REQ), rating) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } -suspend fun readEnabledAttribute(): Boolean {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readEnabledAttribute(): Boolean { + 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}") - } + 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) { - "Enabled attribute not found in response" - } + } + + requireNotNull(attributeData) { "Enabled attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Boolean = tlvReader.getBoolean(AnonymousTag) - return decodedValue } suspend fun subscribeEnabledAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Enabled attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Enabled attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -470,687 +419,660 @@ suspend fun readEnabledAttribute(): Boolean {val ATTRIBUTE_ID: UInt = 0u emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readOnDemandRatingsAttribute(): OnDemandRatingsAttribute {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readOnDemandRatingsAttribute(): OnDemandRatingsAttribute { + 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}") - } + 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) { - "Ondemandratings attribute not found in response" - } + } + + requireNotNull(attributeData) { "Ondemandratings attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(ContentControlClusterRatingNameStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(ContentControlClusterRatingNameStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null } - tlvReader.exitContainer() - } - } else { - null - } - return OnDemandRatingsAttribute(decodedValue) } suspend fun subscribeOnDemandRatingsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(OnDemandRatingsAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + OnDemandRatingsAttributeSubscriptionState.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) { - "Ondemandratings attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Ondemandratings attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(ContentControlClusterRatingNameStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { - emit(OnDemandRatingsAttributeSubscriptionState.Success(it)) - } - + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(ContentControlClusterRatingNameStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { emit(OnDemandRatingsAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(OnDemandRatingsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readOnDemandRatingThresholdAttribute(): String? {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readOnDemandRatingThresholdAttribute(): String? { + 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}") - } + 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) { - "Ondemandratingthreshold attribute not found in response" - } + } + + requireNotNull(attributeData) { "Ondemandratingthreshold attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeOnDemandRatingThresholdAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StringSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StringSubscriptionState.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) { - "Ondemandratingthreshold attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Ondemandratingthreshold attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(StringSubscriptionState.Success(it)) - } - + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(StringSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readScheduledContentRatingsAttribute(): ScheduledContentRatingsAttribute {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readScheduledContentRatingsAttribute(): ScheduledContentRatingsAttribute { + 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}") - } + 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) { - "Scheduledcontentratings attribute not found in response" - } + } + + requireNotNull(attributeData) { "Scheduledcontentratings attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(ContentControlClusterRatingNameStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(ContentControlClusterRatingNameStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null } - tlvReader.exitContainer() - } - } else { - null - } - return ScheduledContentRatingsAttribute(decodedValue) } suspend fun subscribeScheduledContentRatingsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ScheduledContentRatingsAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ScheduledContentRatingsAttributeSubscriptionState.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) { - "Scheduledcontentratings attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Scheduledcontentratings attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(ContentControlClusterRatingNameStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { - emit(ScheduledContentRatingsAttributeSubscriptionState.Success(it)) - } - + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(ContentControlClusterRatingNameStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { emit(ScheduledContentRatingsAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ScheduledContentRatingsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readScheduledContentRatingThresholdAttribute(): String? {val ATTRIBUTE_ID: UInt = 4u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readScheduledContentRatingThresholdAttribute(): String? { + 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}") - } + 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) { - "Scheduledcontentratingthreshold attribute not found in response" + } + + requireNotNull(attributeData) { + "Scheduledcontentratingthreshold attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeScheduledContentRatingThresholdAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StringSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StringSubscriptionState.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) { - "Scheduledcontentratingthreshold attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Scheduledcontentratingthreshold attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(StringSubscriptionState.Success(it)) - } - + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(StringSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readScreenDailyTimeAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 5u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readScreenDailyTimeAttribute(): UInt? { + 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}") - } + 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) { - "Screendailytime attribute not found in response" - } + } + + requireNotNull(attributeData) { "Screendailytime attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeScreenDailyTimeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Screendailytime attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Screendailytime attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRemainingScreenTimeAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 6u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readRemainingScreenTimeAttribute(): UInt? { + 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}") - } + 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) { - "Remainingscreentime attribute not found in response" - } + } + + requireNotNull(attributeData) { "Remainingscreentime attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeRemainingScreenTimeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Remainingscreentime attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Remainingscreentime attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readBlockUnratedAttribute(): Boolean {val ATTRIBUTE_ID: UInt = 7u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readBlockUnratedAttribute(): Boolean { + 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}") - } + 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) { - "Blockunrated attribute not found in response" - } + } + + requireNotNull(attributeData) { "Blockunrated attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Boolean = tlvReader.getBoolean(AnonymousTag) - return decodedValue } suspend fun subscribeBlockUnratedAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Blockunrated attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Blockunrated attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -1162,97 +1084,96 @@ suspend fun readBlockUnratedAttribute(): Boolean {val ATTRIBUTE_ID: UInt = 7u emit(BooleanSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1260,97 +1181,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1358,97 +1278,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1456,97 +1373,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1554,81 +1468,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1640,80 +1549,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1726,7 +1632,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/ContentLauncherCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/ContentLauncherCluster.kt index 0e0f98b0995f7b..ae0b6d4935427f 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/ContentLauncherCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/ContentLauncherCluster.kt @@ -17,125 +17,92 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState -import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.UShortSubscriptionState +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class ContentLauncherCluster(private val controller: MatterController, private val endpointId: UShort) { - class LauncherResponse( - val status: UByte, - val data: String? - ) -class AcceptHeaderAttribute( - val value: List? - ) +class ContentLauncherCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class LauncherResponse(val status: UByte, val data: String?) + + class AcceptHeaderAttribute(val value: List?) sealed class AcceptHeaderAttributeSubscriptionState { - data class Success( - val value: List? - ) : AcceptHeaderAttributeSubscriptionState() - + data class Success(val value: List?) : AcceptHeaderAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptHeaderAttributeSubscriptionState() - object SubscriptionEstablished : AcceptHeaderAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptHeaderAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun launchContent(search: ContentLauncherClusterContentSearchStruct - ,autoPlay: Boolean - ,data: String? - ,playbackPreferences: ContentLauncherClusterPlaybackPreferencesStruct? - ,useCurrentContext: Boolean? - ,timedInvokeTimeout: Duration? = null): LauncherResponse { + suspend fun launchContent( + search: ContentLauncherClusterContentSearchStruct, + autoPlay: Boolean, + data: String?, + playbackPreferences: ContentLauncherClusterPlaybackPreferencesStruct?, + useCurrentContext: Boolean?, + timedInvokeTimeout: Duration? = null, + ): LauncherResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() @@ -148,9 +115,7 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_AUTO_PLAY_REQ), autoPlay) val TAG_DATA_REQ: Int = 2 - data?.let { - tlvWriter.put(ContextSpecificTag(TAG_DATA_REQ), data) - } + data?.let { tlvWriter.put(ContextSpecificTag(TAG_DATA_REQ), data) } val TAG_PLAYBACK_PREFERENCES_REQ: Int = 3 playbackPreferences?.let { @@ -160,14 +125,14 @@ class AttributeListAttribute( val TAG_USE_CURRENT_CONTEXT_REQ: Int = 4 useCurrentContext?.let { tlvWriter.put(ContextSpecificTag(TAG_USE_CURRENT_CONTEXT_REQ), useCurrentContext) - } + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -177,56 +142,49 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_DATA: Int = 1 var data_decoded: String? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_DATA)) {data_decoded = + if (tag == ContextSpecificTag(TAG_STATUS)) { + status_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_DATA)) { + data_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - }} - - - else { + tlvReader.getString(tag) + } else { + null + } + } + } else { tlvReader.skipElement() } } - - if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - - - tlvReader.exitContainer() - return LauncherResponse( - status_decoded, - data_decoded - ) + return LauncherResponse(status_decoded, data_decoded) } - suspend fun launchURL(contentURL: String - ,displayString: String? - ,brandingInformation: ContentLauncherClusterBrandingInformationStruct? - ,timedInvokeTimeout: Duration? = null): LauncherResponse { + suspend fun launchURL( + contentURL: String, + displayString: String?, + brandingInformation: ContentLauncherClusterBrandingInformationStruct?, + timedInvokeTimeout: Duration? = null, + ): LauncherResponse { val commandId: UInt = 1u val tlvWriter = TlvWriter() @@ -236,21 +194,19 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_CONTENT_URL_REQ), contentURL) val TAG_DISPLAY_STRING_REQ: Int = 1 - displayString?.let { - tlvWriter.put(ContextSpecificTag(TAG_DISPLAY_STRING_REQ), displayString) - } + displayString?.let { tlvWriter.put(ContextSpecificTag(TAG_DISPLAY_STRING_REQ), displayString) } val TAG_BRANDING_INFORMATION_REQ: Int = 2 brandingInformation?.let { brandingInformation.toTlv(ContextSpecificTag(TAG_BRANDING_INFORMATION_REQ), tlvWriter) - } + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -260,346 +216,326 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_DATA: Int = 1 var data_decoded: String? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_DATA)) {data_decoded = + if (tag == ContextSpecificTag(TAG_STATUS)) { + status_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_DATA)) { + data_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - }} - - - else { + tlvReader.getString(tag) + } else { + null + } + } + } else { tlvReader.skipElement() } } - - if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - - - tlvReader.exitContainer() - return LauncherResponse( - status_decoded, - data_decoded - ) + return LauncherResponse(status_decoded, data_decoded) } -suspend fun readAcceptHeaderAttribute(): AcceptHeaderAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readAcceptHeaderAttribute(): AcceptHeaderAttribute { + 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}") - } + 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) { - "Acceptheader attribute not found in response" - } + } + + requireNotNull(attributeData) { "Acceptheader attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getString(AnonymousTag)) + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getString(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null } - tlvReader.exitContainer() - } - } else { - null - } - return AcceptHeaderAttribute(decodedValue) } suspend fun subscribeAcceptHeaderAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(AcceptHeaderAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + AcceptHeaderAttributeSubscriptionState.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) { - "Acceptheader attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Acceptheader attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getString(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { - emit(AcceptHeaderAttributeSubscriptionState.Success(it)) - } - + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getString(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { emit(AcceptHeaderAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(AcceptHeaderAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readSupportedStreamingProtocolsAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readSupportedStreamingProtocolsAttribute(): UInt? { + 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}") - } + 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) { - "Supportedstreamingprotocols attribute not found in response" - } + } + + requireNotNull(attributeData) { "Supportedstreamingprotocols attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeSupportedStreamingProtocolsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Supportedstreamingprotocols attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Supportedstreamingprotocols attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -607,97 +543,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -705,97 +640,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -803,97 +735,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -901,81 +830,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -987,80 +911,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1073,7 +994,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/DemandResponseLoadControlCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/DemandResponseLoadControlCluster.kt index 3ada4bef66c3cf..ea72cd4cd78068 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/DemandResponseLoadControlCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/DemandResponseLoadControlCluster.kt @@ -17,209 +17,190 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class DemandResponseLoadControlCluster(private val controller: MatterController, private val endpointId: UShort) {class LoadControlProgramsAttribute( +class DemandResponseLoadControlCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class LoadControlProgramsAttribute( val value: List ) sealed class LoadControlProgramsAttributeSubscriptionState { - data class Success( - val value: List - ) : LoadControlProgramsAttributeSubscriptionState() - + data class Success(val value: List) : + LoadControlProgramsAttributeSubscriptionState() + data class Error(val exception: Exception) : LoadControlProgramsAttributeSubscriptionState() - object SubscriptionEstablished : LoadControlProgramsAttributeSubscriptionState() - } -class EventsAttribute( - val value: List - ) + object SubscriptionEstablished : LoadControlProgramsAttributeSubscriptionState() + } + + class EventsAttribute(val value: List) sealed class EventsAttributeSubscriptionState { - data class Success( - val value: List - ) : EventsAttributeSubscriptionState() - + data class Success(val value: List) : + EventsAttributeSubscriptionState() + data class Error(val exception: Exception) : EventsAttributeSubscriptionState() - object SubscriptionEstablished : EventsAttributeSubscriptionState() - } -class ActiveEventsAttribute( + object SubscriptionEstablished : EventsAttributeSubscriptionState() + } + + class ActiveEventsAttribute( val value: List ) sealed class ActiveEventsAttributeSubscriptionState { - data class Success( - val value: List - ) : ActiveEventsAttributeSubscriptionState() - + data class Success(val value: List) : + ActiveEventsAttributeSubscriptionState() + data class Error(val exception: Exception) : ActiveEventsAttributeSubscriptionState() - object SubscriptionEstablished : ActiveEventsAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : ActiveEventsAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun registerLoadControlProgramRequest(loadControlProgram: DemandResponseLoadControlClusterLoadControlProgramStruct - ,timedInvokeTimeout: Duration? = null) { + suspend fun registerLoadControlProgramRequest( + loadControlProgram: DemandResponseLoadControlClusterLoadControlProgramStruct, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_LOAD_CONTROL_PROGRAM_REQ: Int = 0 - loadControlProgram.toTlv(ContextSpecificTag(TAG_LOAD_CONTROL_PROGRAM_REQ), tlvWriter) + loadControlProgram.toTlv(ContextSpecificTag(TAG_LOAD_CONTROL_PROGRAM_REQ), tlvWriter) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun unregisterLoadControlProgramRequest(loadControlProgramID: ByteArray - ,timedInvokeTimeout: Duration? = null) { + suspend fun unregisterLoadControlProgramRequest( + loadControlProgramID: ByteArray, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 1u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_LOAD_CONTROL_PROGRAM_ID_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_LOAD_CONTROL_PROGRAM_ID_REQ), loadControlProgramID) + tlvWriter.put(ContextSpecificTag(TAG_LOAD_CONTROL_PROGRAM_ID_REQ), loadControlProgramID) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun addLoadControlEventRequest(event: DemandResponseLoadControlClusterLoadControlEventStruct - ,timedInvokeTimeout: Duration? = null) { + suspend fun addLoadControlEventRequest( + event: DemandResponseLoadControlClusterLoadControlEventStruct, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 2u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_EVENT_REQ: Int = 0 - event.toTlv(ContextSpecificTag(TAG_EVENT_REQ), tlvWriter) + event.toTlv(ContextSpecificTag(TAG_EVENT_REQ), tlvWriter) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun removeLoadControlEventRequest(eventID: ByteArray - ,cancelControl: UShort - ,timedInvokeTimeout: Duration? = null) { + suspend fun removeLoadControlEventRequest( + eventID: ByteArray, + cancelControl: UShort, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 3u val tlvWriter = TlvWriter() @@ -229,14 +210,14 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_EVENT_ID_REQ), eventID) val TAG_CANCEL_CONTROL_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_CANCEL_CONTROL_REQ), cancelControl) + tlvWriter.put(ContextSpecificTag(TAG_CANCEL_CONTROL_REQ), cancelControl) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -247,108 +228,117 @@ class AttributeListAttribute( val commandId: UInt = 4u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } -suspend fun readLoadControlProgramsAttribute(): LoadControlProgramsAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readLoadControlProgramsAttribute(): LoadControlProgramsAttribute { + 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}") - } + 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) { - "Loadcontrolprograms attribute not found in response" - } + } + + requireNotNull(attributeData) { "Loadcontrolprograms 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(DemandResponseLoadControlClusterLoadControlProgramStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add( + DemandResponseLoadControlClusterLoadControlProgramStruct.fromTlv( + AnonymousTag, + tlvReader, + ) + ) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return LoadControlProgramsAttribute(decodedValue) } suspend fun subscribeLoadControlProgramsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(LoadControlProgramsAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + LoadControlProgramsAttributeSubscriptionState.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) { - "Loadcontrolprograms attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Loadcontrolprograms 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(DemandResponseLoadControlClusterLoadControlProgramStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add( + DemandResponseLoadControlClusterLoadControlProgramStruct.fromTlv( + AnonymousTag, + tlvReader, + ) + ) + } + tlvReader.exitContainer() + } emit(LoadControlProgramsAttributeSubscriptionState.Success(decodedValue)) } @@ -356,80 +346,77 @@ suspend fun readLoadControlProgramsAttribute(): LoadControlProgramsAttribute {va emit(LoadControlProgramsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNumberOfLoadControlProgramsAttribute(): 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) - ) - + + suspend fun readNumberOfLoadControlProgramsAttribute(): 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}") - } + 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) { - "Numberofloadcontrolprograms attribute not found in response" - } + } + + requireNotNull(attributeData) { "Numberofloadcontrolprograms 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 subscribeNumberOfLoadControlProgramsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Numberofloadcontrolprograms attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Numberofloadcontrolprograms attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -442,97 +429,101 @@ suspend fun readNumberOfLoadControlProgramsAttribute(): UByte {val ATTRIBUTE_ID: emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readEventsAttribute(): EventsAttribute {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readEventsAttribute(): EventsAttribute { + 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}") - } + 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) { - "Events attribute not found in response" - } + } + + requireNotNull(attributeData) { "Events 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(DemandResponseLoadControlClusterLoadControlEventStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add( + DemandResponseLoadControlClusterLoadControlEventStruct.fromTlv(AnonymousTag, tlvReader) + ) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventsAttribute(decodedValue) } suspend fun subscribeEventsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(EventsAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + EventsAttributeSubscriptionState.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) { - "Events attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Events 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(DemandResponseLoadControlClusterLoadControlEventStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add( + DemandResponseLoadControlClusterLoadControlEventStruct.fromTlv( + AnonymousTag, + tlvReader, + ) + ) + } + tlvReader.exitContainer() + } emit(EventsAttributeSubscriptionState.Success(decodedValue)) } @@ -540,97 +531,101 @@ suspend fun readEventsAttribute(): EventsAttribute {val ATTRIBUTE_ID: UInt = 2u emit(EventsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readActiveEventsAttribute(): ActiveEventsAttribute {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readActiveEventsAttribute(): ActiveEventsAttribute { + 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}") - } + 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) { - "Activeevents attribute not found in response" - } + } + + requireNotNull(attributeData) { "Activeevents 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(DemandResponseLoadControlClusterLoadControlEventStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add( + DemandResponseLoadControlClusterLoadControlEventStruct.fromTlv(AnonymousTag, tlvReader) + ) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return ActiveEventsAttribute(decodedValue) } suspend fun subscribeActiveEventsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ActiveEventsAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ActiveEventsAttributeSubscriptionState.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) { - "Activeevents attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Activeevents 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(DemandResponseLoadControlClusterLoadControlEventStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add( + DemandResponseLoadControlClusterLoadControlEventStruct.fromTlv( + AnonymousTag, + tlvReader, + ) + ) + } + tlvReader.exitContainer() + } emit(ActiveEventsAttributeSubscriptionState.Success(decodedValue)) } @@ -638,80 +633,77 @@ suspend fun readActiveEventsAttribute(): ActiveEventsAttribute {val ATTRIBUTE_ID emit(ActiveEventsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNumberOfEventsPerProgramAttribute(): 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) - ) - + + suspend fun readNumberOfEventsPerProgramAttribute(): 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}") - } + 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) { - "Numberofeventsperprogram attribute not found in response" - } + } + + requireNotNull(attributeData) { "Numberofeventsperprogram 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 subscribeNumberOfEventsPerProgramAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Numberofeventsperprogram attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Numberofeventsperprogram attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -724,80 +716,77 @@ suspend fun readNumberOfEventsPerProgramAttribute(): UByte {val ATTRIBUTE_ID: UI emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNumberOfTransitionsAttribute(): UByte {val ATTRIBUTE_ID: UInt = 5u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readNumberOfTransitionsAttribute(): UByte { + 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}") - } + 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) { - "Numberoftransitions attribute not found in response" - } + } + + requireNotNull(attributeData) { "Numberoftransitions 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 subscribeNumberOfTransitionsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Numberoftransitions attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Numberoftransitions attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -810,68 +799,57 @@ suspend fun readNumberOfTransitionsAttribute(): UByte {val ATTRIBUTE_ID: UInt = emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readDefaultRandomStartAttribute(): UByte {val ATTRIBUTE_ID: UInt = 6u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readDefaultRandomStartAttribute(): UByte { + 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}") - } + 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) { - "Defaultrandomstart attribute not found in response" - } + } + + requireNotNull(attributeData) { "Defaultrandomstart 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 writeDefaultRandomStartAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeDefaultRandomStartAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 6u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -892,42 +870,46 @@ suspend fun readDefaultRandomStartAttribute(): UByte {val ATTRIBUTE_ID: UInt = 6 throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeDefaultRandomStartAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Defaultrandomstart attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Defaultrandomstart attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -940,68 +922,60 @@ suspend fun readDefaultRandomStartAttribute(): UByte {val ATTRIBUTE_ID: UInt = 6 emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readDefaultRandomDurationAttribute(): UByte {val ATTRIBUTE_ID: UInt = 7u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readDefaultRandomDurationAttribute(): UByte { + 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}") - } + 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) { - "Defaultrandomduration attribute not found in response" - } + } + + requireNotNull(attributeData) { "Defaultrandomduration 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 writeDefaultRandomDurationAttribute( value: UByte, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 7u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -1022,42 +996,46 @@ suspend fun readDefaultRandomDurationAttribute(): UByte {val ATTRIBUTE_ID: UInt throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeDefaultRandomDurationAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Defaultrandomduration attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Defaultrandomduration attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -1070,97 +1048,96 @@ suspend fun readDefaultRandomDurationAttribute(): UByte {val ATTRIBUTE_ID: UInt emit(UByteSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1168,97 +1145,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1266,97 +1242,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1364,97 +1337,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1462,81 +1432,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1548,80 +1513,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1634,7 +1596,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/DescriptorCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/DescriptorCluster.kt index e5b5a887fd60b2..0ef479e85a94fc 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/DescriptorCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/DescriptorCluster.kt @@ -17,254 +17,203 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState -import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse -import matter.controller.model.AttributePath -import matter.controller.model.CommandPath +import matter.controller.UShortSubscriptionState import matter.controller.cluster.structs.* +import matter.controller.model.AttributePath import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader -import matter.tlv.TlvWriter -class DescriptorCluster(private val controller: MatterController, private val endpointId: UShort) {class DeviceTypeListAttribute( - val value: List - ) +class DescriptorCluster(private val controller: MatterController, private val endpointId: UShort) { + class DeviceTypeListAttribute(val value: List) sealed class DeviceTypeListAttributeSubscriptionState { - data class Success( - val value: List - ) : DeviceTypeListAttributeSubscriptionState() - + data class Success(val value: List) : + DeviceTypeListAttributeSubscriptionState() + data class Error(val exception: Exception) : DeviceTypeListAttributeSubscriptionState() - object SubscriptionEstablished : DeviceTypeListAttributeSubscriptionState() - } -class ServerListAttribute( - val value: List - ) + object SubscriptionEstablished : DeviceTypeListAttributeSubscriptionState() + } + + class ServerListAttribute(val value: List) sealed class ServerListAttributeSubscriptionState { - data class Success( - val value: List - ) : ServerListAttributeSubscriptionState() - + data class Success(val value: List) : ServerListAttributeSubscriptionState() + data class Error(val exception: Exception) : ServerListAttributeSubscriptionState() - object SubscriptionEstablished : ServerListAttributeSubscriptionState() - } -class ClientListAttribute( - val value: List - ) + object SubscriptionEstablished : ServerListAttributeSubscriptionState() + } + + class ClientListAttribute(val value: List) sealed class ClientListAttributeSubscriptionState { - data class Success( - val value: List - ) : ClientListAttributeSubscriptionState() - + data class Success(val value: List) : ClientListAttributeSubscriptionState() + data class Error(val exception: Exception) : ClientListAttributeSubscriptionState() - object SubscriptionEstablished : ClientListAttributeSubscriptionState() - } -class PartsListAttribute( - val value: List - ) + object SubscriptionEstablished : ClientListAttributeSubscriptionState() + } + + class PartsListAttribute(val value: List) sealed class PartsListAttributeSubscriptionState { - data class Success( - val value: List - ) : PartsListAttributeSubscriptionState() - + data class Success(val value: List) : PartsListAttributeSubscriptionState() + data class Error(val exception: Exception) : PartsListAttributeSubscriptionState() - object SubscriptionEstablished : PartsListAttributeSubscriptionState() - } -class TagListAttribute( - val value: List? - ) + object SubscriptionEstablished : PartsListAttributeSubscriptionState() + } + + class TagListAttribute(val value: List?) sealed class TagListAttributeSubscriptionState { - data class Success( - val value: List? - ) : TagListAttributeSubscriptionState() - + data class Success(val value: List?) : + TagListAttributeSubscriptionState() + data class Error(val exception: Exception) : TagListAttributeSubscriptionState() - object SubscriptionEstablished : TagListAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : TagListAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } -suspend fun readDeviceTypeListAttribute(): DeviceTypeListAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } + + suspend fun readDeviceTypeListAttribute(): DeviceTypeListAttribute { + 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}") - } + 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) { - "Devicetypelist attribute not found in response" - } + } + + requireNotNull(attributeData) { "Devicetypelist 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(DescriptorClusterDeviceTypeStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(DescriptorClusterDeviceTypeStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return DeviceTypeListAttribute(decodedValue) } suspend fun subscribeDeviceTypeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(DeviceTypeListAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + DeviceTypeListAttributeSubscriptionState.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) { - "Devicetypelist attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Devicetypelist 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(DescriptorClusterDeviceTypeStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(DescriptorClusterDeviceTypeStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(DeviceTypeListAttributeSubscriptionState.Success(decodedValue)) } @@ -272,97 +221,94 @@ suspend fun readDeviceTypeListAttribute(): DeviceTypeListAttribute {val ATTRIBUT emit(DeviceTypeListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readServerListAttribute(): ServerListAttribute {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readServerListAttribute(): ServerListAttribute { + 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}") - } + 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) { - "Serverlist attribute not found in response" - } + } + + requireNotNull(attributeData) { "Serverlist 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return ServerListAttribute(decodedValue) } suspend fun subscribeServerListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ServerListAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ServerListAttributeSubscriptionState.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) { - "Serverlist attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Serverlist 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(ServerListAttributeSubscriptionState.Success(decodedValue)) } @@ -370,97 +316,94 @@ suspend fun readServerListAttribute(): ServerListAttribute {val ATTRIBUTE_ID: UI emit(ServerListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readClientListAttribute(): ClientListAttribute {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readClientListAttribute(): ClientListAttribute { + 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}") - } + 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) { - "Clientlist attribute not found in response" - } + } + + requireNotNull(attributeData) { "Clientlist 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return ClientListAttribute(decodedValue) } suspend fun subscribeClientListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ClientListAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ClientListAttributeSubscriptionState.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) { - "Clientlist attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Clientlist 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(ClientListAttributeSubscriptionState.Success(decodedValue)) } @@ -468,97 +411,94 @@ suspend fun readClientListAttribute(): ClientListAttribute {val ATTRIBUTE_ID: UI emit(ClientListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPartsListAttribute(): PartsListAttribute {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readPartsListAttribute(): PartsListAttribute { + 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}") - } + 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) { - "Partslist attribute not found in response" - } + } + + requireNotNull(attributeData) { "Partslist 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.getUShort(AnonymousTag)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUShort(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return PartsListAttribute(decodedValue) } suspend fun subscribePartsListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(PartsListAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + PartsListAttributeSubscriptionState.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) { - "Partslist attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Partslist 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.getUShort(AnonymousTag)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUShort(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(PartsListAttributeSubscriptionState.Success(decodedValue)) } @@ -566,206 +506,199 @@ suspend fun readPartsListAttribute(): PartsListAttribute {val ATTRIBUTE_ID: UInt emit(PartsListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readTagListAttribute(): TagListAttribute {val ATTRIBUTE_ID: UInt = 4u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readTagListAttribute(): TagListAttribute { + 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}") - } + 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) { - "Taglist attribute not found in response" - } + } + + requireNotNull(attributeData) { "Taglist attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(DescriptorClusterSemanticTagStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(DescriptorClusterSemanticTagStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null } - tlvReader.exitContainer() - } - } else { - null - } - return TagListAttribute(decodedValue) } suspend fun subscribeTagListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(TagListAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + TagListAttributeSubscriptionState.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) { - "Taglist attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Taglist attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(DescriptorClusterSemanticTagStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { - emit(TagListAttributeSubscriptionState.Success(it)) - } - + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(DescriptorClusterSemanticTagStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { emit(TagListAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(TagListAttributeSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -773,97 +706,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -871,97 +803,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -969,97 +898,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1067,81 +993,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1153,80 +1074,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1239,7 +1157,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/DeviceEnergyManagementCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/DeviceEnergyManagementCluster.kt index 92e778b73b7fe1..455b52d4d0853b 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/DeviceEnergyManagementCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/DeviceEnergyManagementCluster.kt @@ -17,131 +17,106 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration 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.LongSubscriptionState import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.UShortSubscriptionState +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class DeviceEnergyManagementCluster(private val controller: MatterController, private val endpointId: UShort) {class PowerAdjustmentCapabilityAttribute( +class DeviceEnergyManagementCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class PowerAdjustmentCapabilityAttribute( val value: DeviceEnergyManagementClusterPowerAdjustCapabilityStruct? ) sealed class PowerAdjustmentCapabilityAttributeSubscriptionState { - data class Success( - val value: DeviceEnergyManagementClusterPowerAdjustCapabilityStruct? - ) : PowerAdjustmentCapabilityAttributeSubscriptionState() - - data class Error(val exception: Exception) : PowerAdjustmentCapabilityAttributeSubscriptionState() - - object SubscriptionEstablished : PowerAdjustmentCapabilityAttributeSubscriptionState() - } -class ForecastAttribute( - val value: DeviceEnergyManagementClusterForecastStruct? - ) + data class Success(val value: DeviceEnergyManagementClusterPowerAdjustCapabilityStruct?) : + PowerAdjustmentCapabilityAttributeSubscriptionState() + + data class Error(val exception: Exception) : + PowerAdjustmentCapabilityAttributeSubscriptionState() + + object SubscriptionEstablished : PowerAdjustmentCapabilityAttributeSubscriptionState() + } + + class ForecastAttribute(val value: DeviceEnergyManagementClusterForecastStruct?) sealed class ForecastAttributeSubscriptionState { - data class Success( - val value: DeviceEnergyManagementClusterForecastStruct? - ) : ForecastAttributeSubscriptionState() - + data class Success(val value: DeviceEnergyManagementClusterForecastStruct?) : + ForecastAttributeSubscriptionState() + data class Error(val exception: Exception) : ForecastAttributeSubscriptionState() - object SubscriptionEstablished : ForecastAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : ForecastAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun powerAdjustRequest(power: Long - ,duration: UInt - ,cause: UByte - ,timedInvokeTimeout: Duration? = null) { + suspend fun powerAdjustRequest( + power: Long, + duration: UInt, + cause: UByte, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 0u val tlvWriter = TlvWriter() @@ -154,14 +129,14 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_DURATION_REQ), duration) val TAG_CAUSE_REQ: Int = 2 - tlvWriter.put(ContextSpecificTag(TAG_CAUSE_REQ), cause) + tlvWriter.put(ContextSpecificTag(TAG_CAUSE_REQ), cause) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -172,23 +147,25 @@ class AttributeListAttribute( val commandId: UInt = 1u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun startTimeAdjustRequest(requestedStartTime: UInt - ,cause: UByte - ,timedInvokeTimeout: Duration? = null) { + suspend fun startTimeAdjustRequest( + requestedStartTime: UInt, + cause: UByte, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 2u val tlvWriter = TlvWriter() @@ -198,23 +175,21 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_REQUESTED_START_TIME_REQ), requestedStartTime) val TAG_CAUSE_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_CAUSE_REQ), cause) + tlvWriter.put(ContextSpecificTag(TAG_CAUSE_REQ), cause) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun pauseRequest(duration: UInt - ,cause: UByte - ,timedInvokeTimeout: Duration? = null) { + suspend fun pauseRequest(duration: UInt, cause: UByte, timedInvokeTimeout: Duration? = null) { val commandId: UInt = 3u val tlvWriter = TlvWriter() @@ -224,14 +199,14 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_DURATION_REQ), duration) val TAG_CAUSE_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_CAUSE_REQ), cause) + tlvWriter.put(ContextSpecificTag(TAG_CAUSE_REQ), cause) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -242,24 +217,26 @@ class AttributeListAttribute( val commandId: UInt = 4u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun modifyForecastRequest(forecastID: UInt - ,slotAdjustments: List - ,cause: UByte - ,timedInvokeTimeout: Duration? = null) { + suspend fun modifyForecastRequest( + forecastID: UInt, + slotAdjustments: List, + cause: UByte, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 5u val tlvWriter = TlvWriter() @@ -270,29 +247,31 @@ class AttributeListAttribute( val TAG_SLOT_ADJUSTMENTS_REQ: Int = 1 tlvWriter.startArray(ContextSpecificTag(TAG_SLOT_ADJUSTMENTS_REQ)) - for (item in slotAdjustments.iterator()) { - item.toTlv(AnonymousTag, tlvWriter) - } - tlvWriter.endArray() + for (item in slotAdjustments.iterator()) { + item.toTlv(AnonymousTag, tlvWriter) + } + tlvWriter.endArray() val TAG_CAUSE_REQ: Int = 2 - tlvWriter.put(ContextSpecificTag(TAG_CAUSE_REQ), cause) + tlvWriter.put(ContextSpecificTag(TAG_CAUSE_REQ), cause) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun requestConstraintBasedForecast(constraints: List - ,cause: UByte - ,timedInvokeTimeout: Duration? = null) { + suspend fun requestConstraintBasedForecast( + constraints: List, + cause: UByte, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 6u val tlvWriter = TlvWriter() @@ -300,20 +279,20 @@ class AttributeListAttribute( val TAG_CONSTRAINTS_REQ: Int = 0 tlvWriter.startArray(ContextSpecificTag(TAG_CONSTRAINTS_REQ)) - for (item in constraints.iterator()) { - item.toTlv(AnonymousTag, tlvWriter) - } - tlvWriter.endArray() + for (item in constraints.iterator()) { + item.toTlv(AnonymousTag, tlvWriter) + } + tlvWriter.endArray() val TAG_CAUSE_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_CAUSE_REQ), cause) + tlvWriter.put(ContextSpecificTag(TAG_CAUSE_REQ), cause) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -324,92 +303,87 @@ class AttributeListAttribute( val commandId: UInt = 7u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } -suspend fun readESATypeAttribute(): 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) - ) - + + suspend fun readESATypeAttribute(): 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}") - } + 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) { - "Esatype attribute not found in response" - } + } + + requireNotNull(attributeData) { "Esatype 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 subscribeESATypeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Esatype attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Esatype attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -421,80 +395,77 @@ suspend fun readESATypeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 0u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readESACanGenerateAttribute(): Boolean {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readESACanGenerateAttribute(): Boolean { + 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}") - } + 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) { - "Esacangenerate attribute not found in response" - } + } + + requireNotNull(attributeData) { "Esacangenerate attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Boolean = tlvReader.getBoolean(AnonymousTag) - return decodedValue } suspend fun subscribeESACanGenerateAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Esacangenerate attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Esacangenerate attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -507,81 +478,76 @@ suspend fun readESACanGenerateAttribute(): Boolean {val ATTRIBUTE_ID: UInt = 1u emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readESAStateAttribute(): UByte {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readESAStateAttribute(): UByte { + 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}") - } + 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) { - "Esastate attribute not found in response" - } + } + + requireNotNull(attributeData) { "Esastate 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 subscribeESAStateAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Esastate attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Esastate attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -593,81 +559,76 @@ suspend fun readESAStateAttribute(): UByte {val ATTRIBUTE_ID: UInt = 2u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAbsMinPowerAttribute(): Long {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readAbsMinPowerAttribute(): Long { + 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}") - } + 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) { - "Absminpower attribute not found in response" - } + } + + requireNotNull(attributeData) { "Absminpower attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Long = tlvReader.getLong(AnonymousTag) - return decodedValue } suspend fun subscribeAbsMinPowerAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(LongSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + LongSubscriptionState.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) { - "Absminpower attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Absminpower attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -679,81 +640,76 @@ suspend fun readAbsMinPowerAttribute(): Long {val ATTRIBUTE_ID: UInt = 3u emit(LongSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAbsMaxPowerAttribute(): Long {val ATTRIBUTE_ID: UInt = 4u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readAbsMaxPowerAttribute(): Long { + 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}") - } + 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) { - "Absmaxpower attribute not found in response" - } + } + + requireNotNull(attributeData) { "Absmaxpower attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Long = tlvReader.getLong(AnonymousTag) - return decodedValue } suspend fun subscribeAbsMaxPowerAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(LongSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + LongSubscriptionState.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) { - "Absmaxpower attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Absmaxpower attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -765,408 +721,396 @@ suspend fun readAbsMaxPowerAttribute(): Long {val ATTRIBUTE_ID: UInt = 4u emit(LongSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPowerAdjustmentCapabilityAttribute(): PowerAdjustmentCapabilityAttribute {val ATTRIBUTE_ID: UInt = 5u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readPowerAdjustmentCapabilityAttribute(): PowerAdjustmentCapabilityAttribute { + 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}") - } + 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) { - "Poweradjustmentcapability attribute not found in response" - } + } + + requireNotNull(attributeData) { "Poweradjustmentcapability attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: DeviceEnergyManagementClusterPowerAdjustCapabilityStruct? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - DeviceEnergyManagementClusterPowerAdjustCapabilityStruct.fromTlv(AnonymousTag, tlvReader) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: DeviceEnergyManagementClusterPowerAdjustCapabilityStruct? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + DeviceEnergyManagementClusterPowerAdjustCapabilityStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return PowerAdjustmentCapabilityAttribute(decodedValue) } suspend fun subscribePowerAdjustmentCapabilityAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(PowerAdjustmentCapabilityAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + PowerAdjustmentCapabilityAttributeSubscriptionState.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) { - "Poweradjustmentcapability attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Poweradjustmentcapability attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: DeviceEnergyManagementClusterPowerAdjustCapabilityStruct? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - DeviceEnergyManagementClusterPowerAdjustCapabilityStruct.fromTlv(AnonymousTag, tlvReader) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: DeviceEnergyManagementClusterPowerAdjustCapabilityStruct? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + DeviceEnergyManagementClusterPowerAdjustCapabilityStruct.fromTlv( + AnonymousTag, + tlvReader, + ) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } decodedValue?.let { emit(PowerAdjustmentCapabilityAttributeSubscriptionState.Success(it)) } - } SubscriptionState.SubscriptionEstablished -> { emit(PowerAdjustmentCapabilityAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readForecastAttribute(): ForecastAttribute {val ATTRIBUTE_ID: UInt = 6u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readForecastAttribute(): ForecastAttribute { + 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}") - } + 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) { - "Forecast attribute not found in response" - } + } + + requireNotNull(attributeData) { "Forecast attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: DeviceEnergyManagementClusterForecastStruct? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - DeviceEnergyManagementClusterForecastStruct.fromTlv(AnonymousTag, tlvReader) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: DeviceEnergyManagementClusterForecastStruct? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + DeviceEnergyManagementClusterForecastStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return ForecastAttribute(decodedValue) } suspend fun subscribeForecastAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ForecastAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ForecastAttributeSubscriptionState.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) { - "Forecast attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Forecast attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: DeviceEnergyManagementClusterForecastStruct? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - DeviceEnergyManagementClusterForecastStruct.fromTlv(AnonymousTag, tlvReader) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(ForecastAttributeSubscriptionState.Success(it)) - } - + val decodedValue: DeviceEnergyManagementClusterForecastStruct? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + DeviceEnergyManagementClusterForecastStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(ForecastAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ForecastAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readOptOutStateAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 7u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readOptOutStateAttribute(): UByte? { + 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}") - } + 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) { - "Optoutstate attribute not found in response" - } + } + + requireNotNull(attributeData) { "Optoutstate 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeOptOutStateAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Optoutstate attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Optoutstate 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)) - } - + 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 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1174,97 +1118,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1272,97 +1215,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1370,97 +1310,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1468,81 +1405,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1554,80 +1486,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1640,7 +1569,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/DeviceEnergyManagementModeCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/DeviceEnergyManagementModeCluster.kt index 7754d2662184b2..657941cb3f0964 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/DeviceEnergyManagementModeCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/DeviceEnergyManagementModeCluster.kt @@ -17,161 +17,127 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class DeviceEnergyManagementModeCluster(private val controller: MatterController, private val endpointId: UShort) { - class ChangeToModeResponse( - val status: UByte, - val statusText: String? - ) -class SupportedModesAttribute( - val value: List - ) +class DeviceEnergyManagementModeCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class ChangeToModeResponse(val status: UByte, val statusText: String?) + + class SupportedModesAttribute(val value: List) sealed class SupportedModesAttributeSubscriptionState { - data class Success( - val value: List - ) : SupportedModesAttributeSubscriptionState() - + data class Success(val value: List) : + SupportedModesAttributeSubscriptionState() + data class Error(val exception: Exception) : SupportedModesAttributeSubscriptionState() - object SubscriptionEstablished : SupportedModesAttributeSubscriptionState() - } -class StartUpModeAttribute( - val value: UByte? - ) + object SubscriptionEstablished : SupportedModesAttributeSubscriptionState() + } + + class StartUpModeAttribute(val value: UByte?) sealed class StartUpModeAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : StartUpModeAttributeSubscriptionState() - + data class Success(val value: UByte?) : StartUpModeAttributeSubscriptionState() + data class Error(val exception: Exception) : StartUpModeAttributeSubscriptionState() - object SubscriptionEstablished : StartUpModeAttributeSubscriptionState() - } -class OnModeAttribute( - val value: UByte? - ) + object SubscriptionEstablished : StartUpModeAttributeSubscriptionState() + } + + class OnModeAttribute(val value: UByte?) sealed class OnModeAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : OnModeAttributeSubscriptionState() - + data class Success(val value: UByte?) : OnModeAttributeSubscriptionState() + data class Error(val exception: Exception) : OnModeAttributeSubscriptionState() - object SubscriptionEstablished : OnModeAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : OnModeAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun changeToMode(newMode: UByte - ,timedInvokeTimeout: Duration? = null): ChangeToModeResponse { + suspend fun changeToMode( + newMode: UByte, + timedInvokeTimeout: Duration? = null, + ): ChangeToModeResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_NEW_MODE_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_NEW_MODE_REQ), newMode) + tlvWriter.put(ContextSpecificTag(TAG_NEW_MODE_REQ), newMode) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -181,140 +147,132 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_STATUS_TEXT: Int = 1 var statusText_decoded: String? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_STATUS_TEXT)) {statusText_decoded = + if (tag == ContextSpecificTag(TAG_STATUS)) { + status_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_STATUS_TEXT)) { + statusText_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - }} - - - else { + tlvReader.getString(tag) + } else { + null + } + } + } else { tlvReader.skipElement() } } - - if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - - - tlvReader.exitContainer() - return ChangeToModeResponse( - status_decoded, - statusText_decoded - ) + return ChangeToModeResponse(status_decoded, statusText_decoded) } -suspend fun readSupportedModesAttribute(): SupportedModesAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readSupportedModesAttribute(): SupportedModesAttribute { + 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}") - } + 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) { - "Supportedmodes attribute not found in response" - } + } + + requireNotNull(attributeData) { "Supportedmodes 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(DeviceEnergyManagementModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(DeviceEnergyManagementModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return SupportedModesAttribute(decodedValue) } suspend fun subscribeSupportedModesAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(SupportedModesAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + SupportedModesAttributeSubscriptionState.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) { - "Supportedmodes attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Supportedmodes 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(DeviceEnergyManagementModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add( + DeviceEnergyManagementModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader) + ) + } + tlvReader.exitContainer() + } emit(SupportedModesAttributeSubscriptionState.Success(decodedValue)) } @@ -322,81 +280,76 @@ suspend fun readSupportedModesAttribute(): SupportedModesAttribute {val ATTRIBUT emit(SupportedModesAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCurrentModeAttribute(): 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) - ) - + + suspend fun readCurrentModeAttribute(): 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}") - } + 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) { - "Currentmode attribute not found in response" - } + } + + requireNotNull(attributeData) { "Currentmode 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 subscribeCurrentModeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Currentmode attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Currentmode attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -408,77 +361,67 @@ suspend fun readCurrentModeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 1u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readStartUpModeAttribute(): StartUpModeAttribute {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readStartUpModeAttribute(): StartUpModeAttribute { + 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}") - } + 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) { - "Startupmode attribute not found in response" - } + } + + requireNotNull(attributeData) { "Startupmode attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return StartUpModeAttribute(decodedValue) } - suspend fun writeStartUpModeAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeStartUpModeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 2u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -499,137 +442,127 @@ suspend fun readStartUpModeAttribute(): StartUpModeAttribute {val ATTRIBUTE_ID: throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeStartUpModeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StartUpModeAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StartUpModeAttributeSubscriptionState.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) { - "Startupmode attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Startupmode 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(StartUpModeAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(StartUpModeAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(StartUpModeAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readOnModeAttribute(): OnModeAttribute {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readOnModeAttribute(): OnModeAttribute { + 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}") - } + 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) { - "Onmode attribute not found in response" - } + } + + requireNotNull(attributeData) { "Onmode attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return OnModeAttribute(decodedValue) } - suspend fun writeOnModeAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeOnModeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 3u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -650,157 +583,156 @@ suspend fun readOnModeAttribute(): OnModeAttribute {val ATTRIBUTE_ID: UInt = 3u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeOnModeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(OnModeAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + OnModeAttributeSubscriptionState.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) { - "Onmode attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Onmode 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(OnModeAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(OnModeAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(OnModeAttributeSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -808,97 +740,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -906,97 +837,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1004,97 +932,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1102,81 +1027,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1188,80 +1108,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1274,7 +1191,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/DiagnosticLogsCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/DiagnosticLogsCluster.kt index 21693574406ef4..fb4d455810d966 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/DiagnosticLogsCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/DiagnosticLogsCluster.kt @@ -17,112 +17,85 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState -import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.UShortSubscriptionState +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class DiagnosticLogsCluster(private val controller: MatterController, private val endpointId: UShort) { +class DiagnosticLogsCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { class RetrieveLogsResponse( - val status: UByte, - val logContent: ByteArray, - val UTCTimeStamp: ULong?, - val timeSinceBoot: ULong? - ) -class GeneratedCommandListAttribute( - val value: List + val status: UByte, + val logContent: ByteArray, + val UTCTimeStamp: ULong?, + val timeSinceBoot: ULong?, ) + class GeneratedCommandListAttribute(val value: List) + sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun retrieveLogsRequest(intent: UByte - ,requestedProtocol: UByte - ,transferFileDesignator: String? - ,timedInvokeTimeout: Duration? = null): RetrieveLogsResponse { + suspend fun retrieveLogsRequest( + intent: UByte, + requestedProtocol: UByte, + transferFileDesignator: String?, + timedInvokeTimeout: Duration? = null, + ): RetrieveLogsResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() @@ -137,14 +110,14 @@ class AttributeListAttribute( val TAG_TRANSFER_FILE_DESIGNATOR_REQ: Int = 2 transferFileDesignator?.let { tlvWriter.put(ContextSpecificTag(TAG_TRANSFER_FILE_DESIGNATOR_REQ), transferFileDesignator) - } + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -154,70 +127,65 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_LOG_CONTENT: Int = 1 var logContent_decoded: ByteArray? = null - + val TAG_UTC_TIME_STAMP: Int = 2 var UTCTimeStamp_decoded: ULong? = null - + val TAG_TIME_SINCE_BOOT: Int = 3 var timeSinceBoot_decoded: ULong? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_LOG_CONTENT)) {logContent_decoded = tlvReader.getByteArray(tag)} - - if (tag == ContextSpecificTag(TAG_UTC_TIME_STAMP)) {UTCTimeStamp_decoded = + if (tag == ContextSpecificTag(TAG_STATUS)) { + status_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_LOG_CONTENT)) { + logContent_decoded = tlvReader.getByteArray(tag) + } + + if (tag == ContextSpecificTag(TAG_UTC_TIME_STAMP)) { + UTCTimeStamp_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getULong(tag) - } else { - null - } - }} - - if (tag == ContextSpecificTag(TAG_TIME_SINCE_BOOT)) {timeSinceBoot_decoded = + tlvReader.getULong(tag) + } else { + null + } + } + } + + if (tag == ContextSpecificTag(TAG_TIME_SINCE_BOOT)) { + timeSinceBoot_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getULong(tag) - } else { - null - } - }} - - - else { + tlvReader.getULong(tag) + } else { + null + } + } + } else { tlvReader.skipElement() } } - - if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - - + if (logContent_decoded == null) { - throw IllegalStateException("logContent not found in TLV") + throw IllegalStateException("logContent not found in TLV") } - - - - - tlvReader.exitContainer() @@ -225,98 +193,97 @@ class AttributeListAttribute( status_decoded, logContent_decoded, UTCTimeStamp_decoded, - timeSinceBoot_decoded + timeSinceBoot_decoded, ) } -suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65528u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -324,97 +291,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { emit(GeneratedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65529u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -422,97 +388,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va emit(AcceptedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt = 65530u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -520,97 +483,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt emit(EventListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ID: UInt = 65531u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -618,81 +578,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ emit(AttributeListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -704,80 +659,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 65533u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -790,7 +742,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/DishwasherAlarmCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/DishwasherAlarmCluster.kt index 75b1724e213003..2082aec247699e 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/DishwasherAlarmCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/DishwasherAlarmCluster.kt @@ -17,217 +17,181 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState -import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.UShortSubscriptionState +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class DishwasherAlarmCluster(private val controller: MatterController, private val endpointId: UShort) {class GeneratedCommandListAttribute( - val value: List - ) +class DishwasherAlarmCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun reset(alarms: UInt - ,timedInvokeTimeout: Duration? = null) { + suspend fun reset(alarms: UInt, timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_ALARMS_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_ALARMS_REQ), alarms) + tlvWriter.put(ContextSpecificTag(TAG_ALARMS_REQ), alarms) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun modifyEnabledAlarms(mask: UInt - ,timedInvokeTimeout: Duration? = null) { + suspend fun modifyEnabledAlarms(mask: UInt, timedInvokeTimeout: Duration? = null) { val commandId: UInt = 1u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_MASK_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_MASK_REQ), mask) + tlvWriter.put(ContextSpecificTag(TAG_MASK_REQ), mask) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } -suspend fun readMaskAttribute(): UInt {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMaskAttribute(): UInt { + 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}") - } + 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) { - "Mask attribute not found in response" - } + } + + requireNotNull(attributeData) { "Mask 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 subscribeMaskAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Mask attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Mask attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -239,178 +203,167 @@ suspend fun readMaskAttribute(): UInt {val ATTRIBUTE_ID: UInt = 0u emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readLatchAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readLatchAttribute(): UInt? { + 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}") - } + 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) { - "Latch attribute not found in response" - } + } + + requireNotNull(attributeData) { "Latch attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeLatchAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Latch attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Latch attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readStateAttribute(): UInt {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readStateAttribute(): UInt { + 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}") - } + 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) { - "State attribute not found in response" - } + } + + requireNotNull(attributeData) { "State 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 subscribeStateAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "State attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "State attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -422,81 +375,76 @@ suspend fun readStateAttribute(): UInt {val ATTRIBUTE_ID: UInt = 2u emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readSupportedAttribute(): UInt {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readSupportedAttribute(): UInt { + 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}") - } + 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) { - "Supported attribute not found in response" - } + } + + requireNotNull(attributeData) { "Supported 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 subscribeSupportedAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Supported attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Supported attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -508,97 +456,96 @@ suspend fun readSupportedAttribute(): UInt {val ATTRIBUTE_ID: UInt = 3u emit(UIntSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -606,97 +553,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -704,97 +650,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -802,97 +745,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -900,81 +840,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -986,80 +921,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1072,7 +1004,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/DishwasherModeCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/DishwasherModeCluster.kt index b9223830ec6740..4d57444fe65fba 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/DishwasherModeCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/DishwasherModeCluster.kt @@ -17,161 +17,127 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class DishwasherModeCluster(private val controller: MatterController, private val endpointId: UShort) { - class ChangeToModeResponse( - val status: UByte, - val statusText: String? - ) -class SupportedModesAttribute( - val value: List - ) +class DishwasherModeCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class ChangeToModeResponse(val status: UByte, val statusText: String?) + + class SupportedModesAttribute(val value: List) sealed class SupportedModesAttributeSubscriptionState { - data class Success( - val value: List - ) : SupportedModesAttributeSubscriptionState() - + data class Success(val value: List) : + SupportedModesAttributeSubscriptionState() + data class Error(val exception: Exception) : SupportedModesAttributeSubscriptionState() - object SubscriptionEstablished : SupportedModesAttributeSubscriptionState() - } -class StartUpModeAttribute( - val value: UByte? - ) + object SubscriptionEstablished : SupportedModesAttributeSubscriptionState() + } + + class StartUpModeAttribute(val value: UByte?) sealed class StartUpModeAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : StartUpModeAttributeSubscriptionState() - + data class Success(val value: UByte?) : StartUpModeAttributeSubscriptionState() + data class Error(val exception: Exception) : StartUpModeAttributeSubscriptionState() - object SubscriptionEstablished : StartUpModeAttributeSubscriptionState() - } -class OnModeAttribute( - val value: UByte? - ) + object SubscriptionEstablished : StartUpModeAttributeSubscriptionState() + } + + class OnModeAttribute(val value: UByte?) sealed class OnModeAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : OnModeAttributeSubscriptionState() - + data class Success(val value: UByte?) : OnModeAttributeSubscriptionState() + data class Error(val exception: Exception) : OnModeAttributeSubscriptionState() - object SubscriptionEstablished : OnModeAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : OnModeAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun changeToMode(newMode: UByte - ,timedInvokeTimeout: Duration? = null): ChangeToModeResponse { + suspend fun changeToMode( + newMode: UByte, + timedInvokeTimeout: Duration? = null, + ): ChangeToModeResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_NEW_MODE_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_NEW_MODE_REQ), newMode) + tlvWriter.put(ContextSpecificTag(TAG_NEW_MODE_REQ), newMode) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -181,140 +147,130 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_STATUS_TEXT: Int = 1 var statusText_decoded: String? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_STATUS_TEXT)) {statusText_decoded = + if (tag == ContextSpecificTag(TAG_STATUS)) { + status_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_STATUS_TEXT)) { + statusText_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - }} - - - else { + tlvReader.getString(tag) + } else { + null + } + } + } else { tlvReader.skipElement() } } - - if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - - - tlvReader.exitContainer() - return ChangeToModeResponse( - status_decoded, - statusText_decoded - ) + return ChangeToModeResponse(status_decoded, statusText_decoded) } -suspend fun readSupportedModesAttribute(): SupportedModesAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readSupportedModesAttribute(): SupportedModesAttribute { + 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}") - } + 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) { - "Supportedmodes attribute not found in response" - } + } + + requireNotNull(attributeData) { "Supportedmodes 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(DishwasherModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(DishwasherModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return SupportedModesAttribute(decodedValue) } suspend fun subscribeSupportedModesAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(SupportedModesAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + SupportedModesAttributeSubscriptionState.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) { - "Supportedmodes attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Supportedmodes 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(DishwasherModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(DishwasherModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(SupportedModesAttributeSubscriptionState.Success(decodedValue)) } @@ -322,81 +278,76 @@ suspend fun readSupportedModesAttribute(): SupportedModesAttribute {val ATTRIBUT emit(SupportedModesAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCurrentModeAttribute(): 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) - ) - + + suspend fun readCurrentModeAttribute(): 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}") - } + 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) { - "Currentmode attribute not found in response" - } + } + + requireNotNull(attributeData) { "Currentmode 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 subscribeCurrentModeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Currentmode attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Currentmode attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -408,77 +359,67 @@ suspend fun readCurrentModeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 1u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readStartUpModeAttribute(): StartUpModeAttribute {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readStartUpModeAttribute(): StartUpModeAttribute { + 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}") - } + 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) { - "Startupmode attribute not found in response" - } + } + + requireNotNull(attributeData) { "Startupmode attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return StartUpModeAttribute(decodedValue) } - suspend fun writeStartUpModeAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeStartUpModeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 2u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -499,137 +440,127 @@ suspend fun readStartUpModeAttribute(): StartUpModeAttribute {val ATTRIBUTE_ID: throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeStartUpModeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StartUpModeAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StartUpModeAttributeSubscriptionState.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) { - "Startupmode attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Startupmode 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(StartUpModeAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(StartUpModeAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(StartUpModeAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readOnModeAttribute(): OnModeAttribute {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readOnModeAttribute(): OnModeAttribute { + 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}") - } + 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) { - "Onmode attribute not found in response" - } + } + + requireNotNull(attributeData) { "Onmode attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return OnModeAttribute(decodedValue) } - suspend fun writeOnModeAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeOnModeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 3u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -650,157 +581,156 @@ suspend fun readOnModeAttribute(): OnModeAttribute {val ATTRIBUTE_ID: UInt = 3u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeOnModeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(OnModeAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + OnModeAttributeSubscriptionState.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) { - "Onmode attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Onmode 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(OnModeAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(OnModeAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(OnModeAttributeSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -808,97 +738,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -906,97 +835,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1004,97 +930,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1102,81 +1025,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1188,80 +1106,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1274,7 +1189,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/DoorLockCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/DoorLockCluster.kt index 41016b4a66ccb9..ff0525a58d8c27 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/DoorLockCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/DoorLockCluster.kt @@ -17,297 +17,257 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.BooleanSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest +import matter.controller.StringSubscriptionState import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter class DoorLockCluster(private val controller: MatterController, private val endpointId: UShort) { class GetWeekDayScheduleResponse( - val weekDayIndex: UByte, - val userIndex: UShort, - val status: UByte, - val daysMask: UByte?, - val startHour: UByte?, - val startMinute: UByte?, - val endHour: UByte?, - val endMinute: UByte? + val weekDayIndex: UByte, + val userIndex: UShort, + val status: UByte, + val daysMask: UByte?, + val startHour: UByte?, + val startMinute: UByte?, + val endHour: UByte?, + val endMinute: UByte?, ) class GetYearDayScheduleResponse( - val yearDayIndex: UByte, - val userIndex: UShort, - val status: UByte, - val localStartTime: UInt?, - val localEndTime: UInt? + val yearDayIndex: UByte, + val userIndex: UShort, + val status: UByte, + val localStartTime: UInt?, + val localEndTime: UInt?, ) class GetHolidayScheduleResponse( - val holidayIndex: UByte, - val status: UByte, - val localStartTime: UInt?, - val localEndTime: UInt?, - val operatingMode: UByte? + val holidayIndex: UByte, + val status: UByte, + val localStartTime: UInt?, + val localEndTime: UInt?, + val operatingMode: UByte?, ) class GetUserResponse( - val userIndex: UShort, - val userName: String?, - val userUniqueID: UInt?, - val userStatus: UByte?, - val userType: UByte?, - val credentialRule: UByte?, - val credentials: List?, - val creatorFabricIndex: UByte?, - val lastModifiedFabricIndex: UByte?, - val nextUserIndex: UShort? + val userIndex: UShort, + val userName: String?, + val userUniqueID: UInt?, + val userStatus: UByte?, + val userType: UByte?, + val credentialRule: UByte?, + val credentials: List?, + val creatorFabricIndex: UByte?, + val lastModifiedFabricIndex: UByte?, + val nextUserIndex: UShort?, ) class SetCredentialResponse( - val status: UByte, - val userIndex: UShort?, - val nextCredentialIndex: UShort? + val status: UByte, + val userIndex: UShort?, + val nextCredentialIndex: UShort?, ) class GetCredentialStatusResponse( - val credentialExists: Boolean, - val userIndex: UShort?, - val creatorFabricIndex: UByte?, - val lastModifiedFabricIndex: UByte?, - val nextCredentialIndex: UShort? - ) -class LockStateAttribute( - val value: UByte? + val credentialExists: Boolean, + val userIndex: UShort?, + val creatorFabricIndex: UByte?, + val lastModifiedFabricIndex: UByte?, + val nextCredentialIndex: UShort?, ) + class LockStateAttribute(val value: UByte?) + sealed class LockStateAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : LockStateAttributeSubscriptionState() - + data class Success(val value: UByte?) : LockStateAttributeSubscriptionState() + data class Error(val exception: Exception) : LockStateAttributeSubscriptionState() - object SubscriptionEstablished : LockStateAttributeSubscriptionState() - } -class DoorStateAttribute( - val value: UByte? - ) + object SubscriptionEstablished : LockStateAttributeSubscriptionState() + } + + class DoorStateAttribute(val value: UByte?) sealed class DoorStateAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : DoorStateAttributeSubscriptionState() - + data class Success(val value: UByte?) : DoorStateAttributeSubscriptionState() + data class Error(val exception: Exception) : DoorStateAttributeSubscriptionState() - object SubscriptionEstablished : DoorStateAttributeSubscriptionState() - } -class AliroReaderVerificationKeyAttribute( - val value: ByteArray? - ) + object SubscriptionEstablished : DoorStateAttributeSubscriptionState() + } + + class AliroReaderVerificationKeyAttribute(val value: ByteArray?) sealed class AliroReaderVerificationKeyAttributeSubscriptionState { - data class Success( - val value: ByteArray? - ) : AliroReaderVerificationKeyAttributeSubscriptionState() - - data class Error(val exception: Exception) : AliroReaderVerificationKeyAttributeSubscriptionState() - - object SubscriptionEstablished : AliroReaderVerificationKeyAttributeSubscriptionState() - } -class AliroReaderGroupIdentifierAttribute( - val value: ByteArray? - ) + data class Success(val value: ByteArray?) : + AliroReaderVerificationKeyAttributeSubscriptionState() + + data class Error(val exception: Exception) : + AliroReaderVerificationKeyAttributeSubscriptionState() + + object SubscriptionEstablished : AliroReaderVerificationKeyAttributeSubscriptionState() + } + + class AliroReaderGroupIdentifierAttribute(val value: ByteArray?) sealed class AliroReaderGroupIdentifierAttributeSubscriptionState { - data class Success( - val value: ByteArray? - ) : AliroReaderGroupIdentifierAttributeSubscriptionState() - - data class Error(val exception: Exception) : AliroReaderGroupIdentifierAttributeSubscriptionState() - - object SubscriptionEstablished : AliroReaderGroupIdentifierAttributeSubscriptionState() - } -class AliroExpeditedTransactionSupportedProtocolVersionsAttribute( - val value: List? - ) + data class Success(val value: ByteArray?) : + AliroReaderGroupIdentifierAttributeSubscriptionState() + + data class Error(val exception: Exception) : + AliroReaderGroupIdentifierAttributeSubscriptionState() + + object SubscriptionEstablished : AliroReaderGroupIdentifierAttributeSubscriptionState() + } + + class AliroExpeditedTransactionSupportedProtocolVersionsAttribute(val value: List?) sealed class AliroExpeditedTransactionSupportedProtocolVersionsAttributeSubscriptionState { - data class Success( - val value: List? - ) : AliroExpeditedTransactionSupportedProtocolVersionsAttributeSubscriptionState() - - data class Error(val exception: Exception) : AliroExpeditedTransactionSupportedProtocolVersionsAttributeSubscriptionState() - - object SubscriptionEstablished : AliroExpeditedTransactionSupportedProtocolVersionsAttributeSubscriptionState() - } -class AliroGroupResolvingKeyAttribute( - val value: ByteArray? - ) + data class Success(val value: List?) : + AliroExpeditedTransactionSupportedProtocolVersionsAttributeSubscriptionState() + + data class Error(val exception: Exception) : + AliroExpeditedTransactionSupportedProtocolVersionsAttributeSubscriptionState() + + object SubscriptionEstablished : + AliroExpeditedTransactionSupportedProtocolVersionsAttributeSubscriptionState() + } + + class AliroGroupResolvingKeyAttribute(val value: ByteArray?) sealed class AliroGroupResolvingKeyAttributeSubscriptionState { - data class Success( - val value: ByteArray? - ) : AliroGroupResolvingKeyAttributeSubscriptionState() - + data class Success(val value: ByteArray?) : AliroGroupResolvingKeyAttributeSubscriptionState() + data class Error(val exception: Exception) : AliroGroupResolvingKeyAttributeSubscriptionState() - object SubscriptionEstablished : AliroGroupResolvingKeyAttributeSubscriptionState() - } -class AliroSupportedBLEUWBProtocolVersionsAttribute( - val value: List? - ) + object SubscriptionEstablished : AliroGroupResolvingKeyAttributeSubscriptionState() + } + + class AliroSupportedBLEUWBProtocolVersionsAttribute(val value: List?) sealed class AliroSupportedBLEUWBProtocolVersionsAttributeSubscriptionState { - data class Success( - val value: List? - ) : AliroSupportedBLEUWBProtocolVersionsAttributeSubscriptionState() - - data class Error(val exception: Exception) : AliroSupportedBLEUWBProtocolVersionsAttributeSubscriptionState() - - object SubscriptionEstablished : AliroSupportedBLEUWBProtocolVersionsAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + data class Success(val value: List?) : + AliroSupportedBLEUWBProtocolVersionsAttributeSubscriptionState() + + data class Error(val exception: Exception) : + AliroSupportedBLEUWBProtocolVersionsAttributeSubscriptionState() + + object SubscriptionEstablished : + AliroSupportedBLEUWBProtocolVersionsAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun lockDoor(PINCode: ByteArray? - ,timedInvokeTimeout: Duration) { + suspend fun lockDoor(PINCode: ByteArray?, timedInvokeTimeout: Duration) { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_PIN_CODE_REQ: Int = 0 - PINCode?.let { - tlvWriter.put(ContextSpecificTag(TAG_PIN_CODE_REQ), PINCode) - } + PINCode?.let { tlvWriter.put(ContextSpecificTag(TAG_PIN_CODE_REQ), PINCode) } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun unlockDoor(PINCode: ByteArray? - ,timedInvokeTimeout: Duration) { + suspend fun unlockDoor(PINCode: ByteArray?, timedInvokeTimeout: Duration) { val commandId: UInt = 1u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_PIN_CODE_REQ: Int = 0 - PINCode?.let { - tlvWriter.put(ContextSpecificTag(TAG_PIN_CODE_REQ), PINCode) - } + PINCode?.let { tlvWriter.put(ContextSpecificTag(TAG_PIN_CODE_REQ), PINCode) } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun unlockWithTimeout(timeout: UShort - ,PINCode: ByteArray? - ,timedInvokeTimeout: Duration) { + suspend fun unlockWithTimeout( + timeout: UShort, + PINCode: ByteArray?, + timedInvokeTimeout: Duration, + ) { val commandId: UInt = 3u val tlvWriter = TlvWriter() @@ -317,30 +277,30 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_TIMEOUT_REQ), timeout) val TAG_PIN_CODE_REQ: Int = 1 - PINCode?.let { - tlvWriter.put(ContextSpecificTag(TAG_PIN_CODE_REQ), PINCode) - } + PINCode?.let { tlvWriter.put(ContextSpecificTag(TAG_PIN_CODE_REQ), PINCode) } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun setWeekDaySchedule(weekDayIndex: UByte - ,userIndex: UShort - ,daysMask: UByte - ,startHour: UByte - ,startMinute: UByte - ,endHour: UByte - ,endMinute: UByte - ,timedInvokeTimeout: Duration? = null) { + suspend fun setWeekDaySchedule( + weekDayIndex: UByte, + userIndex: UShort, + daysMask: UByte, + startHour: UByte, + startMinute: UByte, + endHour: UByte, + endMinute: UByte, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 11u val tlvWriter = TlvWriter() @@ -365,23 +325,25 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_END_HOUR_REQ), endHour) val TAG_END_MINUTE_REQ: Int = 6 - tlvWriter.put(ContextSpecificTag(TAG_END_MINUTE_REQ), endMinute) + tlvWriter.put(ContextSpecificTag(TAG_END_MINUTE_REQ), endMinute) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun getWeekDaySchedule(weekDayIndex: UByte - ,userIndex: UShort - ,timedInvokeTimeout: Duration? = null): GetWeekDayScheduleResponse { + suspend fun getWeekDaySchedule( + weekDayIndex: UByte, + userIndex: UShort, + timedInvokeTimeout: Duration? = null, + ): GetWeekDayScheduleResponse { val commandId: UInt = 12u val tlvWriter = TlvWriter() @@ -391,14 +353,14 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_WEEK_DAY_INDEX_REQ), weekDayIndex) val TAG_USER_INDEX_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_USER_INDEX_REQ), userIndex) + tlvWriter.put(ContextSpecificTag(TAG_USER_INDEX_REQ), userIndex) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -408,131 +370,127 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_WEEK_DAY_INDEX: Int = 0 var weekDayIndex_decoded: UByte? = null - + val TAG_USER_INDEX: Int = 1 var userIndex_decoded: UShort? = null - + val TAG_STATUS: Int = 2 var status_decoded: UByte? = null - + val TAG_DAYS_MASK: Int = 3 var daysMask_decoded: UByte? = null - + val TAG_START_HOUR: Int = 4 var startHour_decoded: UByte? = null - + val TAG_START_MINUTE: Int = 5 var startMinute_decoded: UByte? = null - + val TAG_END_HOUR: Int = 6 var endHour_decoded: UByte? = null - + val TAG_END_MINUTE: Int = 7 var endMinute_decoded: UByte? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_WEEK_DAY_INDEX)) {weekDayIndex_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_USER_INDEX)) {userIndex_decoded = tlvReader.getUShort(tag)} - - if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_DAYS_MASK)) {daysMask_decoded = + if (tag == ContextSpecificTag(TAG_WEEK_DAY_INDEX)) { + weekDayIndex_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_USER_INDEX)) { + userIndex_decoded = tlvReader.getUShort(tag) + } + + if (tag == ContextSpecificTag(TAG_STATUS)) { + status_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_DAYS_MASK)) { + daysMask_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getUByte(tag) - } else { - null - } - }} - - if (tag == ContextSpecificTag(TAG_START_HOUR)) {startHour_decoded = + tlvReader.getUByte(tag) + } else { + null + } + } + } + + if (tag == ContextSpecificTag(TAG_START_HOUR)) { + startHour_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getUByte(tag) - } else { - null - } - }} - - if (tag == ContextSpecificTag(TAG_START_MINUTE)) {startMinute_decoded = + tlvReader.getUByte(tag) + } else { + null + } + } + } + + if (tag == ContextSpecificTag(TAG_START_MINUTE)) { + startMinute_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getUByte(tag) - } else { - null - } - }} - - if (tag == ContextSpecificTag(TAG_END_HOUR)) {endHour_decoded = + tlvReader.getUByte(tag) + } else { + null + } + } + } + + if (tag == ContextSpecificTag(TAG_END_HOUR)) { + endHour_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getUByte(tag) - } else { - null - } - }} - - if (tag == ContextSpecificTag(TAG_END_MINUTE)) {endMinute_decoded = + tlvReader.getUByte(tag) + } else { + null + } + } + } + + if (tag == ContextSpecificTag(TAG_END_MINUTE)) { + endMinute_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getUByte(tag) - } else { - null - } - }} - - - else { + tlvReader.getUByte(tag) + } else { + null + } + } + } else { tlvReader.skipElement() } } - - if (weekDayIndex_decoded == null) { - throw IllegalStateException("weekDayIndex not found in TLV") + throw IllegalStateException("weekDayIndex not found in TLV") } - - + if (userIndex_decoded == null) { - throw IllegalStateException("userIndex not found in TLV") + throw IllegalStateException("userIndex not found in TLV") } - - + if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") - } - - - - - - - - - - - + throw IllegalStateException("status not found in TLV") + } tlvReader.exitContainer() @@ -544,13 +502,15 @@ class AttributeListAttribute( startHour_decoded, startMinute_decoded, endHour_decoded, - endMinute_decoded + endMinute_decoded, ) } - suspend fun clearWeekDaySchedule(weekDayIndex: UByte - ,userIndex: UShort - ,timedInvokeTimeout: Duration? = null) { + suspend fun clearWeekDaySchedule( + weekDayIndex: UByte, + userIndex: UShort, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 13u val tlvWriter = TlvWriter() @@ -560,25 +520,27 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_WEEK_DAY_INDEX_REQ), weekDayIndex) val TAG_USER_INDEX_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_USER_INDEX_REQ), userIndex) + tlvWriter.put(ContextSpecificTag(TAG_USER_INDEX_REQ), userIndex) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun setYearDaySchedule(yearDayIndex: UByte - ,userIndex: UShort - ,localStartTime: UInt - ,localEndTime: UInt - ,timedInvokeTimeout: Duration? = null) { + suspend fun setYearDaySchedule( + yearDayIndex: UByte, + userIndex: UShort, + localStartTime: UInt, + localEndTime: UInt, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 14u val tlvWriter = TlvWriter() @@ -594,23 +556,25 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_LOCAL_START_TIME_REQ), localStartTime) val TAG_LOCAL_END_TIME_REQ: Int = 3 - tlvWriter.put(ContextSpecificTag(TAG_LOCAL_END_TIME_REQ), localEndTime) + tlvWriter.put(ContextSpecificTag(TAG_LOCAL_END_TIME_REQ), localEndTime) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun getYearDaySchedule(yearDayIndex: UByte - ,userIndex: UShort - ,timedInvokeTimeout: Duration? = null): GetYearDayScheduleResponse { + suspend fun getYearDaySchedule( + yearDayIndex: UByte, + userIndex: UShort, + timedInvokeTimeout: Duration? = null, + ): GetYearDayScheduleResponse { val commandId: UInt = 15u val tlvWriter = TlvWriter() @@ -620,14 +584,14 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_YEAR_DAY_INDEX_REQ), yearDayIndex) val TAG_USER_INDEX_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_USER_INDEX_REQ), userIndex) + tlvWriter.put(ContextSpecificTag(TAG_USER_INDEX_REQ), userIndex) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -637,80 +601,76 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_YEAR_DAY_INDEX: Int = 0 var yearDayIndex_decoded: UByte? = null - + val TAG_USER_INDEX: Int = 1 var userIndex_decoded: UShort? = null - + val TAG_STATUS: Int = 2 var status_decoded: UByte? = null - + val TAG_LOCAL_START_TIME: Int = 3 var localStartTime_decoded: UInt? = null - + val TAG_LOCAL_END_TIME: Int = 4 var localEndTime_decoded: UInt? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_YEAR_DAY_INDEX)) {yearDayIndex_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_USER_INDEX)) {userIndex_decoded = tlvReader.getUShort(tag)} - - if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_LOCAL_START_TIME)) {localStartTime_decoded = + if (tag == ContextSpecificTag(TAG_YEAR_DAY_INDEX)) { + yearDayIndex_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_USER_INDEX)) { + userIndex_decoded = tlvReader.getUShort(tag) + } + + if (tag == ContextSpecificTag(TAG_STATUS)) { + status_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_LOCAL_START_TIME)) { + localStartTime_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getUInt(tag) - } else { - null - } - }} - - if (tag == ContextSpecificTag(TAG_LOCAL_END_TIME)) {localEndTime_decoded = + tlvReader.getUInt(tag) + } else { + null + } + } + } + + if (tag == ContextSpecificTag(TAG_LOCAL_END_TIME)) { + localEndTime_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getUInt(tag) - } else { - null - } - }} - - - else { + tlvReader.getUInt(tag) + } else { + null + } + } + } else { tlvReader.skipElement() } } - - if (yearDayIndex_decoded == null) { - throw IllegalStateException("yearDayIndex not found in TLV") + throw IllegalStateException("yearDayIndex not found in TLV") } - - + if (userIndex_decoded == null) { - throw IllegalStateException("userIndex not found in TLV") + throw IllegalStateException("userIndex not found in TLV") } - - + if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - - - - - tlvReader.exitContainer() @@ -719,13 +679,15 @@ class AttributeListAttribute( userIndex_decoded, status_decoded, localStartTime_decoded, - localEndTime_decoded + localEndTime_decoded, ) } - suspend fun clearYearDaySchedule(yearDayIndex: UByte - ,userIndex: UShort - ,timedInvokeTimeout: Duration? = null) { + suspend fun clearYearDaySchedule( + yearDayIndex: UByte, + userIndex: UShort, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 16u val tlvWriter = TlvWriter() @@ -735,25 +697,27 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_YEAR_DAY_INDEX_REQ), yearDayIndex) val TAG_USER_INDEX_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_USER_INDEX_REQ), userIndex) + tlvWriter.put(ContextSpecificTag(TAG_USER_INDEX_REQ), userIndex) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun setHolidaySchedule(holidayIndex: UByte - ,localStartTime: UInt - ,localEndTime: UInt - ,operatingMode: UByte - ,timedInvokeTimeout: Duration? = null) { + suspend fun setHolidaySchedule( + holidayIndex: UByte, + localStartTime: UInt, + localEndTime: UInt, + operatingMode: UByte, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 17u val tlvWriter = TlvWriter() @@ -769,36 +733,38 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_LOCAL_END_TIME_REQ), localEndTime) val TAG_OPERATING_MODE_REQ: Int = 3 - tlvWriter.put(ContextSpecificTag(TAG_OPERATING_MODE_REQ), operatingMode) + tlvWriter.put(ContextSpecificTag(TAG_OPERATING_MODE_REQ), operatingMode) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun getHolidaySchedule(holidayIndex: UByte - ,timedInvokeTimeout: Duration? = null): GetHolidayScheduleResponse { + suspend fun getHolidaySchedule( + holidayIndex: UByte, + timedInvokeTimeout: Duration? = null, + ): GetHolidayScheduleResponse { val commandId: UInt = 18u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_HOLIDAY_INDEX_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_HOLIDAY_INDEX_REQ), holidayIndex) + tlvWriter.put(ContextSpecificTag(TAG_HOLIDAY_INDEX_REQ), holidayIndex) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -808,87 +774,82 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_HOLIDAY_INDEX: Int = 0 var holidayIndex_decoded: UByte? = null - + val TAG_STATUS: Int = 1 var status_decoded: UByte? = null - + val TAG_LOCAL_START_TIME: Int = 2 var localStartTime_decoded: UInt? = null - + val TAG_LOCAL_END_TIME: Int = 3 var localEndTime_decoded: UInt? = null - + val TAG_OPERATING_MODE: Int = 4 var operatingMode_decoded: UByte? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_HOLIDAY_INDEX)) {holidayIndex_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_LOCAL_START_TIME)) {localStartTime_decoded = + if (tag == ContextSpecificTag(TAG_HOLIDAY_INDEX)) { + holidayIndex_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_STATUS)) { + status_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_LOCAL_START_TIME)) { + localStartTime_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getUInt(tag) - } else { - null - } - }} - - if (tag == ContextSpecificTag(TAG_LOCAL_END_TIME)) {localEndTime_decoded = + tlvReader.getUInt(tag) + } else { + null + } + } + } + + if (tag == ContextSpecificTag(TAG_LOCAL_END_TIME)) { + localEndTime_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getUInt(tag) - } else { - null - } - }} - - if (tag == ContextSpecificTag(TAG_OPERATING_MODE)) {operatingMode_decoded = + tlvReader.getUInt(tag) + } else { + null + } + } + } + + if (tag == ContextSpecificTag(TAG_OPERATING_MODE)) { + operatingMode_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getUByte(tag) - } else { - null - } - }} - - - else { + tlvReader.getUByte(tag) + } else { + null + } + } + } else { tlvReader.skipElement() } } - - if (holidayIndex_decoded == null) { - throw IllegalStateException("holidayIndex not found in TLV") + throw IllegalStateException("holidayIndex not found in TLV") } - - + if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - - - - - - - tlvReader.exitContainer() @@ -897,40 +858,41 @@ class AttributeListAttribute( status_decoded, localStartTime_decoded, localEndTime_decoded, - operatingMode_decoded + operatingMode_decoded, ) } - suspend fun clearHolidaySchedule(holidayIndex: UByte - ,timedInvokeTimeout: Duration? = null) { + suspend fun clearHolidaySchedule(holidayIndex: UByte, timedInvokeTimeout: Duration? = null) { val commandId: UInt = 19u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_HOLIDAY_INDEX_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_HOLIDAY_INDEX_REQ), holidayIndex) + tlvWriter.put(ContextSpecificTag(TAG_HOLIDAY_INDEX_REQ), holidayIndex) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun setUser(operationType: UByte - ,userIndex: UShort - ,userName: String? - ,userUniqueID: UInt? - ,userStatus: UByte? - ,userType: UByte? - ,credentialRule: UByte? - ,timedInvokeTimeout: Duration) { + suspend fun setUser( + operationType: UByte, + userIndex: UShort, + userName: String?, + userUniqueID: UInt?, + userStatus: UByte?, + userType: UByte?, + credentialRule: UByte?, + timedInvokeTimeout: Duration, + ) { val commandId: UInt = 26u val tlvWriter = TlvWriter() @@ -943,58 +905,49 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_USER_INDEX_REQ), userIndex) val TAG_USER_NAME_REQ: Int = 2 - userName?.let { - tlvWriter.put(ContextSpecificTag(TAG_USER_NAME_REQ), userName) - } + userName?.let { tlvWriter.put(ContextSpecificTag(TAG_USER_NAME_REQ), userName) } val TAG_USER_UNIQUE_ID_REQ: Int = 3 - userUniqueID?.let { - tlvWriter.put(ContextSpecificTag(TAG_USER_UNIQUE_ID_REQ), userUniqueID) - } + userUniqueID?.let { tlvWriter.put(ContextSpecificTag(TAG_USER_UNIQUE_ID_REQ), userUniqueID) } val TAG_USER_STATUS_REQ: Int = 4 - userStatus?.let { - tlvWriter.put(ContextSpecificTag(TAG_USER_STATUS_REQ), userStatus) - } + userStatus?.let { tlvWriter.put(ContextSpecificTag(TAG_USER_STATUS_REQ), userStatus) } val TAG_USER_TYPE_REQ: Int = 5 - userType?.let { - tlvWriter.put(ContextSpecificTag(TAG_USER_TYPE_REQ), userType) - } + userType?.let { tlvWriter.put(ContextSpecificTag(TAG_USER_TYPE_REQ), userType) } val TAG_CREDENTIAL_RULE_REQ: Int = 6 credentialRule?.let { tlvWriter.put(ContextSpecificTag(TAG_CREDENTIAL_RULE_REQ), credentialRule) - } + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun getUser(userIndex: UShort - ,timedInvokeTimeout: Duration? = null): GetUserResponse { + suspend fun getUser(userIndex: UShort, timedInvokeTimeout: Duration? = null): GetUserResponse { val commandId: UInt = 27u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_USER_INDEX_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_USER_INDEX_REQ), userIndex) + tlvWriter.put(ContextSpecificTag(TAG_USER_INDEX_REQ), userIndex) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -1004,194 +957,188 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_USER_INDEX: Int = 0 var userIndex_decoded: UShort? = null - + val TAG_USER_NAME: Int = 1 var userName_decoded: String? = null - + val TAG_USER_UNIQUE_ID: Int = 2 var userUniqueID_decoded: UInt? = null - + val TAG_USER_STATUS: Int = 3 var userStatus_decoded: UByte? = null - + val TAG_USER_TYPE: Int = 4 var userType_decoded: UByte? = null - + val TAG_CREDENTIAL_RULE: Int = 5 var credentialRule_decoded: UByte? = null - + val TAG_CREDENTIALS: Int = 6 var credentials_decoded: List? = null - + val TAG_CREATOR_FABRIC_INDEX: Int = 7 var creatorFabricIndex_decoded: UByte? = null - + val TAG_LAST_MODIFIED_FABRIC_INDEX: Int = 8 var lastModifiedFabricIndex_decoded: UByte? = null - + val TAG_NEXT_USER_INDEX: Int = 9 var nextUserIndex_decoded: UShort? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_USER_INDEX)) {userIndex_decoded = tlvReader.getUShort(tag)} - - if (tag == ContextSpecificTag(TAG_USER_NAME)) {userName_decoded = + if (tag == ContextSpecificTag(TAG_USER_INDEX)) { + userIndex_decoded = tlvReader.getUShort(tag) + } + + if (tag == ContextSpecificTag(TAG_USER_NAME)) { + userName_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (!tlvReader.isNull()) { - tlvReader.getString(tag) - } else { - tlvReader.getNull(tag) - null - } - }} - - if (tag == ContextSpecificTag(TAG_USER_UNIQUE_ID)) {userUniqueID_decoded = + tlvReader.getString(tag) + } else { + tlvReader.getNull(tag) + null + } + } + } + + if (tag == ContextSpecificTag(TAG_USER_UNIQUE_ID)) { + userUniqueID_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (!tlvReader.isNull()) { - tlvReader.getUInt(tag) - } else { - tlvReader.getNull(tag) - null - } - }} - - if (tag == ContextSpecificTag(TAG_USER_STATUS)) {userStatus_decoded = + tlvReader.getUInt(tag) + } else { + tlvReader.getNull(tag) + null + } + } + } + + if (tag == ContextSpecificTag(TAG_USER_STATUS)) { + userStatus_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (!tlvReader.isNull()) { - tlvReader.getUByte(tag) - } else { - tlvReader.getNull(tag) - null - } - }} - - if (tag == ContextSpecificTag(TAG_USER_TYPE)) {userType_decoded = + tlvReader.getUByte(tag) + } else { + tlvReader.getNull(tag) + null + } + } + } + + if (tag == ContextSpecificTag(TAG_USER_TYPE)) { + userType_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (!tlvReader.isNull()) { - tlvReader.getUByte(tag) - } else { - tlvReader.getNull(tag) - null - } - }} - - if (tag == ContextSpecificTag(TAG_CREDENTIAL_RULE)) {credentialRule_decoded = + tlvReader.getUByte(tag) + } else { + tlvReader.getNull(tag) + null + } + } + } + + if (tag == ContextSpecificTag(TAG_CREDENTIAL_RULE)) { + credentialRule_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (!tlvReader.isNull()) { - tlvReader.getUByte(tag) - } else { - tlvReader.getNull(tag) - null - } - }} - - if (tag == ContextSpecificTag(TAG_CREDENTIALS)) {credentials_decoded = + tlvReader.getUByte(tag) + } else { + tlvReader.getNull(tag) + null + } + } + } + + if (tag == ContextSpecificTag(TAG_CREDENTIALS)) { + credentials_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (!tlvReader.isNull()) { - buildList { - tlvReader.enterArray(tag) - while(!tlvReader.isEndOfContainer()) { - add(DoorLockClusterCredentialStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - tlvReader.getNull(tag) - null - } - }} - - if (tag == ContextSpecificTag(TAG_CREATOR_FABRIC_INDEX)) {creatorFabricIndex_decoded = + buildList { + tlvReader.enterArray(tag) + while (!tlvReader.isEndOfContainer()) { + add(DoorLockClusterCredentialStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + tlvReader.getNull(tag) + null + } + } + } + + if (tag == ContextSpecificTag(TAG_CREATOR_FABRIC_INDEX)) { + creatorFabricIndex_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (!tlvReader.isNull()) { - tlvReader.getUByte(tag) - } else { - tlvReader.getNull(tag) - null - } - }} - - if (tag == ContextSpecificTag(TAG_LAST_MODIFIED_FABRIC_INDEX)) {lastModifiedFabricIndex_decoded = + tlvReader.getUByte(tag) + } else { + tlvReader.getNull(tag) + null + } + } + } + + if (tag == ContextSpecificTag(TAG_LAST_MODIFIED_FABRIC_INDEX)) { + lastModifiedFabricIndex_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (!tlvReader.isNull()) { - tlvReader.getUByte(tag) - } else { - tlvReader.getNull(tag) - null - } - }} - - if (tag == ContextSpecificTag(TAG_NEXT_USER_INDEX)) {nextUserIndex_decoded = + tlvReader.getUByte(tag) + } else { + tlvReader.getNull(tag) + null + } + } + } + + if (tag == ContextSpecificTag(TAG_NEXT_USER_INDEX)) { + nextUserIndex_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (!tlvReader.isNull()) { - tlvReader.getUShort(tag) - } else { - tlvReader.getNull(tag) - null - } - }} - - - else { + tlvReader.getUShort(tag) + } else { + tlvReader.getNull(tag) + null + } + } + } else { tlvReader.skipElement() } } - - if (userIndex_decoded == null) { - throw IllegalStateException("userIndex not found in TLV") - } - - - - - - - - - - - - - - - - - - - + throw IllegalStateException("userIndex not found in TLV") + } tlvReader.exitContainer() @@ -1205,39 +1152,40 @@ class AttributeListAttribute( credentials_decoded, creatorFabricIndex_decoded, lastModifiedFabricIndex_decoded, - nextUserIndex_decoded + nextUserIndex_decoded, ) } - suspend fun clearUser(userIndex: UShort - ,timedInvokeTimeout: Duration) { + suspend fun clearUser(userIndex: UShort, timedInvokeTimeout: Duration) { val commandId: UInt = 29u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_USER_INDEX_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_USER_INDEX_REQ), userIndex) + tlvWriter.put(ContextSpecificTag(TAG_USER_INDEX_REQ), userIndex) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun setCredential(operationType: UByte - ,credential: DoorLockClusterCredentialStruct - ,credentialData: ByteArray - ,userIndex: UShort? - ,userStatus: UByte? - ,userType: UByte? - ,timedInvokeTimeout: Duration): SetCredentialResponse { + suspend fun setCredential( + operationType: UByte, + credential: DoorLockClusterCredentialStruct, + credentialData: ByteArray, + userIndex: UShort?, + userStatus: UByte?, + userType: UByte?, + timedInvokeTimeout: Duration, + ): SetCredentialResponse { val commandId: UInt = 34u val tlvWriter = TlvWriter() @@ -1253,26 +1201,20 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_CREDENTIAL_DATA_REQ), credentialData) val TAG_USER_INDEX_REQ: Int = 3 - userIndex?.let { - tlvWriter.put(ContextSpecificTag(TAG_USER_INDEX_REQ), userIndex) - } + userIndex?.let { tlvWriter.put(ContextSpecificTag(TAG_USER_INDEX_REQ), userIndex) } val TAG_USER_STATUS_REQ: Int = 4 - userStatus?.let { - tlvWriter.put(ContextSpecificTag(TAG_USER_STATUS_REQ), userStatus) - } + userStatus?.let { tlvWriter.put(ContextSpecificTag(TAG_USER_STATUS_REQ), userStatus) } val TAG_USER_TYPE_REQ: Int = 5 - userType?.let { - tlvWriter.put(ContextSpecificTag(TAG_USER_TYPE_REQ), userType) - } + userType?.let { tlvWriter.put(ContextSpecificTag(TAG_USER_TYPE_REQ), userType) } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -1282,88 +1224,80 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_USER_INDEX: Int = 1 var userIndex_decoded: UShort? = null - + val TAG_NEXT_CREDENTIAL_INDEX: Int = 2 var nextCredentialIndex_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_USER_INDEX)) {userIndex_decoded = + if (tag == ContextSpecificTag(TAG_STATUS)) { + status_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_USER_INDEX)) { + userIndex_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (!tlvReader.isNull()) { - tlvReader.getUShort(tag) - } else { - tlvReader.getNull(tag) - null - } - }} - - if (tag == ContextSpecificTag(TAG_NEXT_CREDENTIAL_INDEX)) {nextCredentialIndex_decoded = + tlvReader.getUShort(tag) + } else { + tlvReader.getNull(tag) + null + } + } + } + + if (tag == ContextSpecificTag(TAG_NEXT_CREDENTIAL_INDEX)) { + nextCredentialIndex_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (!tlvReader.isNull()) { - tlvReader.getUShort(tag) - } else { - tlvReader.getNull(tag) - null - } - }} - - - else { + tlvReader.getUShort(tag) + } else { + tlvReader.getNull(tag) + null + } + } + } else { tlvReader.skipElement() } } - - if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - - - - - tlvReader.exitContainer() - return SetCredentialResponse( - status_decoded, - userIndex_decoded, - nextCredentialIndex_decoded - ) + return SetCredentialResponse(status_decoded, userIndex_decoded, nextCredentialIndex_decoded) } - suspend fun getCredentialStatus(credential: DoorLockClusterCredentialStruct - ,timedInvokeTimeout: Duration? = null): GetCredentialStatusResponse { + suspend fun getCredentialStatus( + credential: DoorLockClusterCredentialStruct, + timedInvokeTimeout: Duration? = null, + ): GetCredentialStatusResponse { val commandId: UInt = 36u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_CREDENTIAL_REQ: Int = 0 - credential.toTlv(ContextSpecificTag(TAG_CREDENTIAL_REQ), tlvWriter) + credential.toTlv(ContextSpecificTag(TAG_CREDENTIAL_REQ), tlvWriter) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -1373,98 +1307,92 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_CREDENTIAL_EXISTS: Int = 0 var credentialExists_decoded: Boolean? = null - + val TAG_USER_INDEX: Int = 1 var userIndex_decoded: UShort? = null - + val TAG_CREATOR_FABRIC_INDEX: Int = 2 var creatorFabricIndex_decoded: UByte? = null - + val TAG_LAST_MODIFIED_FABRIC_INDEX: Int = 3 var lastModifiedFabricIndex_decoded: UByte? = null - + val TAG_NEXT_CREDENTIAL_INDEX: Int = 4 var nextCredentialIndex_decoded: UShort? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_CREDENTIAL_EXISTS)) {credentialExists_decoded = tlvReader.getBoolean(tag)} - - if (tag == ContextSpecificTag(TAG_USER_INDEX)) {userIndex_decoded = + if (tag == ContextSpecificTag(TAG_CREDENTIAL_EXISTS)) { + credentialExists_decoded = tlvReader.getBoolean(tag) + } + + if (tag == ContextSpecificTag(TAG_USER_INDEX)) { + userIndex_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (!tlvReader.isNull()) { - tlvReader.getUShort(tag) - } else { - tlvReader.getNull(tag) - null - } - }} - - if (tag == ContextSpecificTag(TAG_CREATOR_FABRIC_INDEX)) {creatorFabricIndex_decoded = + tlvReader.getUShort(tag) + } else { + tlvReader.getNull(tag) + null + } + } + } + + if (tag == ContextSpecificTag(TAG_CREATOR_FABRIC_INDEX)) { + creatorFabricIndex_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (!tlvReader.isNull()) { - tlvReader.getUByte(tag) - } else { - tlvReader.getNull(tag) - null - } - }} - - if (tag == ContextSpecificTag(TAG_LAST_MODIFIED_FABRIC_INDEX)) {lastModifiedFabricIndex_decoded = + tlvReader.getUByte(tag) + } else { + tlvReader.getNull(tag) + null + } + } + } + + if (tag == ContextSpecificTag(TAG_LAST_MODIFIED_FABRIC_INDEX)) { + lastModifiedFabricIndex_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (!tlvReader.isNull()) { - tlvReader.getUByte(tag) - } else { - tlvReader.getNull(tag) - null - } - }} - - if (tag == ContextSpecificTag(TAG_NEXT_CREDENTIAL_INDEX)) {nextCredentialIndex_decoded = + tlvReader.getUByte(tag) + } else { + tlvReader.getNull(tag) + null + } + } + } + + if (tag == ContextSpecificTag(TAG_NEXT_CREDENTIAL_INDEX)) { + nextCredentialIndex_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (!tlvReader.isNull()) { - tlvReader.getUShort(tag) - } else { - tlvReader.getNull(tag) - null - } - }} - - - else { + tlvReader.getUShort(tag) + } else { + tlvReader.getNull(tag) + null + } + } + } else { tlvReader.skipElement() } } - - if (credentialExists_decoded == null) { - throw IllegalStateException("credentialExists not found in TLV") - } - - - - - - - - - + throw IllegalStateException("credentialExists not found in TLV") + } tlvReader.exitContainer() @@ -1473,63 +1401,62 @@ class AttributeListAttribute( userIndex_decoded, creatorFabricIndex_decoded, lastModifiedFabricIndex_decoded, - nextCredentialIndex_decoded + nextCredentialIndex_decoded, ) } - suspend fun clearCredential(credential: DoorLockClusterCredentialStruct? - ,timedInvokeTimeout: Duration) { + suspend fun clearCredential( + credential: DoorLockClusterCredentialStruct?, + timedInvokeTimeout: Duration, + ) { val commandId: UInt = 38u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_CREDENTIAL_REQ: Int = 0 - credential?.let { - credential.toTlv(ContextSpecificTag(TAG_CREDENTIAL_REQ), tlvWriter) - } + credential?.let { credential.toTlv(ContextSpecificTag(TAG_CREDENTIAL_REQ), tlvWriter) } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun unboltDoor(PINCode: ByteArray? - ,timedInvokeTimeout: Duration) { + suspend fun unboltDoor(PINCode: ByteArray?, timedInvokeTimeout: Duration) { val commandId: UInt = 39u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_PIN_CODE_REQ: Int = 0 - PINCode?.let { - tlvWriter.put(ContextSpecificTag(TAG_PIN_CODE_REQ), PINCode) - } + PINCode?.let { tlvWriter.put(ContextSpecificTag(TAG_PIN_CODE_REQ), PINCode) } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun setAliroReaderConfig(signingKey: ByteArray - ,verificationKey: ByteArray - ,groupIdentifier: ByteArray - ,groupResolvingKey: ByteArray? - ,timedInvokeTimeout: Duration) { + suspend fun setAliroReaderConfig( + signingKey: ByteArray, + verificationKey: ByteArray, + groupIdentifier: ByteArray, + groupResolvingKey: ByteArray?, + timedInvokeTimeout: Duration, + ) { val commandId: UInt = 40u val tlvWriter = TlvWriter() @@ -1547,14 +1474,14 @@ class AttributeListAttribute( val TAG_GROUP_RESOLVING_KEY_REQ: Int = 3 groupResolvingKey?.let { tlvWriter.put(ContextSpecificTag(TAG_GROUP_RESOLVING_KEY_REQ), groupResolvingKey) - } + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -1565,191 +1492,180 @@ class AttributeListAttribute( val commandId: UInt = 41u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } -suspend fun readLockStateAttribute(): LockStateAttribute {val ATTRIBUTE_ID: UInt = 0u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readLockStateAttribute(): LockStateAttribute { + 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 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}") - } + 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) { - "Lockstate attribute not found in response" - } + } + + requireNotNull(attributeData) { "Lockstate attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return LockStateAttribute(decodedValue) } suspend fun subscribeLockStateAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(LockStateAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + LockStateAttributeSubscriptionState.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) { - "Lockstate attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Lockstate 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.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(LockStateAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(LockStateAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(LockStateAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readLockTypeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 1u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readLockTypeAttribute(): 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 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}") - } + 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) { - "Locktype attribute not found in response" - } + } + + requireNotNull(attributeData) { "Locktype 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 subscribeLockTypeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Locktype attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Locktype attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -1761,80 +1677,77 @@ suspend fun readLockTypeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 1u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readActuatorEnabledAttribute(): Boolean {val ATTRIBUTE_ID: UInt = 2u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readActuatorEnabledAttribute(): Boolean { + val ATTRIBUTE_ID: UInt = 2u - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - - val response = controller.read(readRequest) + 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}") - } + 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) { - "Actuatorenabled attribute not found in response" - } + } + + requireNotNull(attributeData) { "Actuatorenabled attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Boolean = tlvReader.getBoolean(AnonymousTag) - return decodedValue } suspend fun subscribeActuatorEnabledAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Actuatorenabled attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Actuatorenabled attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -1847,179 +1760,163 @@ suspend fun readActuatorEnabledAttribute(): Boolean {val ATTRIBUTE_ID: UInt = 2u emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readDoorStateAttribute(): DoorStateAttribute {val ATTRIBUTE_ID: UInt = 3u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readDoorStateAttribute(): DoorStateAttribute { + 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 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}") - } + 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) { - "Doorstate attribute not found in response" - } + } + + requireNotNull(attributeData) { "Doorstate attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return DoorStateAttribute(decodedValue) } suspend fun subscribeDoorStateAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(DoorStateAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + DoorStateAttributeSubscriptionState.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) { - "Doorstate attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Doorstate 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(DoorStateAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(DoorStateAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(DoorStateAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readDoorOpenEventsAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 4u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readDoorOpenEventsAttribute(): UInt? { + 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 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}") - } + 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) { - "Dooropenevents attribute not found in response" - } + } + + requireNotNull(attributeData) { "Dooropenevents attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } - suspend fun writeDoorOpenEventsAttribute( - value: UInt, - timedWriteTimeout: Duration? = null) { + suspend fun writeDoorOpenEventsAttribute(value: UInt, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 4u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -2040,127 +1937,119 @@ suspend fun readDoorOpenEventsAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 4u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeDoorOpenEventsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Dooropenevents attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Dooropenevents attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readDoorClosedEventsAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 5u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readDoorClosedEventsAttribute(): UInt? { + 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 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}") - } + 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) { - "Doorclosedevents attribute not found in response" - } + } + + requireNotNull(attributeData) { "Doorclosedevents attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } - suspend fun writeDoorClosedEventsAttribute( - value: UInt, - timedWriteTimeout: Duration? = null) { + suspend fun writeDoorClosedEventsAttribute(value: UInt, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 5u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -2181,127 +2070,119 @@ suspend fun readDoorClosedEventsAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 5u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeDoorClosedEventsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Doorclosedevents attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Doorclosedevents attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readOpenPeriodAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 6u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readOpenPeriodAttribute(): 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 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}") - } + 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) { - "Openperiod attribute not found in response" - } + } + + requireNotNull(attributeData) { "Openperiod 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } - suspend fun writeOpenPeriodAttribute( - value: UShort, - timedWriteTimeout: Duration? = null) { + suspend fun writeOpenPeriodAttribute(value: UShort, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 6u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -2322,1291 +2203,1241 @@ suspend fun readOpenPeriodAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 6u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeOpenPeriodAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Openperiod attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Openperiod 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNumberOfTotalUsersSupportedAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 17u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNumberOfTotalUsersSupportedAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 17u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Numberoftotaluserssupported attribute not found in response" - } + } + + requireNotNull(attributeData) { "Numberoftotaluserssupported 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeNumberOfTotalUsersSupportedAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 17u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Numberoftotaluserssupported attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Numberoftotaluserssupported 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNumberOfPINUsersSupportedAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 18u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNumberOfPINUsersSupportedAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 18u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Numberofpinuserssupported attribute not found in response" - } + } + + requireNotNull(attributeData) { "Numberofpinuserssupported 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeNumberOfPINUsersSupportedAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 18u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Numberofpinuserssupported attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Numberofpinuserssupported 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNumberOfRFIDUsersSupportedAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 19u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNumberOfRFIDUsersSupportedAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 19u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Numberofrfiduserssupported attribute not found in response" - } + } + + requireNotNull(attributeData) { "Numberofrfiduserssupported 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeNumberOfRFIDUsersSupportedAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 19u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Numberofrfiduserssupported attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Numberofrfiduserssupported 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNumberOfWeekDaySchedulesSupportedPerUserAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 20u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNumberOfWeekDaySchedulesSupportedPerUserAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 20u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Numberofweekdayschedulessupportedperuser attribute not found in response" + } + + requireNotNull(attributeData) { + "Numberofweekdayschedulessupportedperuser 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeNumberOfWeekDaySchedulesSupportedPerUserAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 20u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Numberofweekdayschedulessupportedperuser attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Numberofweekdayschedulessupportedperuser 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNumberOfYearDaySchedulesSupportedPerUserAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 21u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNumberOfYearDaySchedulesSupportedPerUserAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 21u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Numberofyeardayschedulessupportedperuser attribute not found in response" + } + + requireNotNull(attributeData) { + "Numberofyeardayschedulessupportedperuser 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeNumberOfYearDaySchedulesSupportedPerUserAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 21u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Numberofyeardayschedulessupportedperuser attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Numberofyeardayschedulessupportedperuser 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNumberOfHolidaySchedulesSupportedAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 22u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNumberOfHolidaySchedulesSupportedAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 22u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Numberofholidayschedulessupported attribute not found in response" + } + + requireNotNull(attributeData) { + "Numberofholidayschedulessupported 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeNumberOfHolidaySchedulesSupportedAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 22u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Numberofholidayschedulessupported attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Numberofholidayschedulessupported 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMaxPINCodeLengthAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 23u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readMaxPINCodeLengthAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 23u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Maxpincodelength attribute not found in response" - } + } + + requireNotNull(attributeData) { "Maxpincodelength 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeMaxPINCodeLengthAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 23u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Maxpincodelength attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Maxpincodelength 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMinPINCodeLengthAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 24u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readMinPINCodeLengthAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 24u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Minpincodelength attribute not found in response" - } + } + + requireNotNull(attributeData) { "Minpincodelength 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeMinPINCodeLengthAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 24u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Minpincodelength attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Minpincodelength 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMaxRFIDCodeLengthAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 25u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readMaxRFIDCodeLengthAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 25u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Maxrfidcodelength attribute not found in response" - } + } + + requireNotNull(attributeData) { "Maxrfidcodelength 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeMaxRFIDCodeLengthAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 25u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Maxrfidcodelength attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Maxrfidcodelength 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMinRFIDCodeLengthAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 26u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readMinRFIDCodeLengthAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 26u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Minrfidcodelength attribute not found in response" - } + } + + requireNotNull(attributeData) { "Minrfidcodelength 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeMinRFIDCodeLengthAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 26u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Minrfidcodelength attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Minrfidcodelength 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCredentialRulesSupportAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 27u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readCredentialRulesSupportAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 27u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Credentialrulessupport attribute not found in response" - } + } + + requireNotNull(attributeData) { "Credentialrulessupport 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeCredentialRulesSupportAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 27u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Credentialrulessupport attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Credentialrulessupport 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNumberOfCredentialsSupportedPerUserAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 28u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNumberOfCredentialsSupportedPerUserAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 28u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Numberofcredentialssupportedperuser attribute not found in response" + } + + requireNotNull(attributeData) { + "Numberofcredentialssupportedperuser 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeNumberOfCredentialsSupportedPerUserAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 28u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Numberofcredentialssupportedperuser attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Numberofcredentialssupportedperuser 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readLanguageAttribute(): String? {val ATTRIBUTE_ID: UInt = 33u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readLanguageAttribute(): String? { + val ATTRIBUTE_ID: UInt = 33u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Language attribute not found in response" - } + } + + requireNotNull(attributeData) { "Language attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } return decodedValue } - suspend fun writeLanguageAttribute( - value: String, - timedWriteTimeout: Duration? = null) { + suspend fun writeLanguageAttribute(value: String, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 33u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -3627,127 +3458,117 @@ suspend fun readLanguageAttribute(): String? {val ATTRIBUTE_ID: UInt = 33u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeLanguageAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 33u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StringSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StringSubscriptionState.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) { - "Language attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Language attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(StringSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(StringSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readLEDSettingsAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 34u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readLEDSettingsAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 34u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Ledsettings attribute not found in response" - } + } + + requireNotNull(attributeData) { "Ledsettings 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } - suspend fun writeLEDSettingsAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeLEDSettingsAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 34u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -3768,127 +3589,117 @@ suspend fun readLEDSettingsAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 34u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeLEDSettingsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 34u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Ledsettings attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Ledsettings 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAutoRelockTimeAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 35u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readAutoRelockTimeAttribute(): UInt? { + val ATTRIBUTE_ID: UInt = 35u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Autorelocktime attribute not found in response" - } + } + + requireNotNull(attributeData) { "Autorelocktime attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } - suspend fun writeAutoRelockTimeAttribute( - value: UInt, - timedWriteTimeout: Duration? = null) { + suspend fun writeAutoRelockTimeAttribute(value: UInt, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 35u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -3909,127 +3720,119 @@ suspend fun readAutoRelockTimeAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 35u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeAutoRelockTimeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 35u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Autorelocktime attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Autorelocktime attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readSoundVolumeAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 36u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readSoundVolumeAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 36u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Soundvolume attribute not found in response" - } + } + + requireNotNull(attributeData) { "Soundvolume 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } - suspend fun writeSoundVolumeAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeSoundVolumeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 36u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -4050,123 +3853,112 @@ suspend fun readSoundVolumeAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 36u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeSoundVolumeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 36u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Soundvolume attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Soundvolume 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readOperatingModeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 37u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readOperatingModeAttribute(): UByte { + val ATTRIBUTE_ID: UInt = 37u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Operatingmode attribute not found in response" - } + } + + requireNotNull(attributeData) { "Operatingmode 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 writeOperatingModeAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeOperatingModeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 37u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -4187,43 +3979,45 @@ suspend fun readOperatingModeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 37u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeOperatingModeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 37u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Operatingmode attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Operatingmode attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -4235,80 +4029,77 @@ suspend fun readOperatingModeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 37u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readSupportedOperatingModesAttribute(): UShort {val ATTRIBUTE_ID: UInt = 38u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readSupportedOperatingModesAttribute(): UShort { + val ATTRIBUTE_ID: UInt = 38u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Supportedoperatingmodes attribute not found in response" - } + } + + requireNotNull(attributeData) { "Supportedoperatingmodes 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 subscribeSupportedOperatingModesAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 38u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Supportedoperatingmodes attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Supportedoperatingmodes attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -4321,169 +4112,158 @@ suspend fun readSupportedOperatingModesAttribute(): UShort {val ATTRIBUTE_ID: UI emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readDefaultConfigurationRegisterAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 39u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readDefaultConfigurationRegisterAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 39u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Defaultconfigurationregister attribute not found in response" - } + } + + requireNotNull(attributeData) { "Defaultconfigurationregister 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeDefaultConfigurationRegisterAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 39u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Defaultconfigurationregister attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Defaultconfigurationregister 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readEnableLocalProgrammingAttribute(): Boolean? {val ATTRIBUTE_ID: UInt = 40u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readEnableLocalProgrammingAttribute(): Boolean? { + val ATTRIBUTE_ID: UInt = 40u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Enablelocalprogramming attribute not found in response" - } + } + + requireNotNull(attributeData) { "Enablelocalprogramming 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 - } - + val decodedValue: Boolean? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } return decodedValue } suspend fun writeEnableLocalProgrammingAttribute( value: Boolean, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 40u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -4504,127 +4284,122 @@ suspend fun readEnableLocalProgrammingAttribute(): Boolean? {val ATTRIBUTE_ID: U throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeEnableLocalProgrammingAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 40u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Enablelocalprogramming attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Enablelocalprogramming 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 - } + val decodedValue: Boolean? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(BooleanSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(BooleanSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readEnableOneTouchLockingAttribute(): Boolean? {val ATTRIBUTE_ID: UInt = 41u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readEnableOneTouchLockingAttribute(): Boolean? { + val ATTRIBUTE_ID: UInt = 41u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Enableonetouchlocking attribute not found in response" - } + } + + requireNotNull(attributeData) { "Enableonetouchlocking 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 - } - + val decodedValue: Boolean? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } return decodedValue } suspend fun writeEnableOneTouchLockingAttribute( value: Boolean, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 41u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -4645,127 +4420,122 @@ suspend fun readEnableOneTouchLockingAttribute(): Boolean? {val ATTRIBUTE_ID: UI throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeEnableOneTouchLockingAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 41u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Enableonetouchlocking attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Enableonetouchlocking 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 - } + val decodedValue: Boolean? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(BooleanSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(BooleanSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readEnableInsideStatusLEDAttribute(): Boolean? {val ATTRIBUTE_ID: UInt = 42u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readEnableInsideStatusLEDAttribute(): Boolean? { + val ATTRIBUTE_ID: UInt = 42u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Enableinsidestatusled attribute not found in response" - } + } + + requireNotNull(attributeData) { "Enableinsidestatusled 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 - } - + val decodedValue: Boolean? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } return decodedValue } suspend fun writeEnableInsideStatusLEDAttribute( value: Boolean, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 42u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -4786,127 +4556,122 @@ suspend fun readEnableInsideStatusLEDAttribute(): Boolean? {val ATTRIBUTE_ID: UI throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeEnableInsideStatusLEDAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 42u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Enableinsidestatusled attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Enableinsidestatusled 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 - } + val decodedValue: Boolean? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(BooleanSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(BooleanSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readEnablePrivacyModeButtonAttribute(): Boolean? {val ATTRIBUTE_ID: UInt = 43u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readEnablePrivacyModeButtonAttribute(): Boolean? { + val ATTRIBUTE_ID: UInt = 43u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Enableprivacymodebutton attribute not found in response" - } + } + + requireNotNull(attributeData) { "Enableprivacymodebutton 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 - } - + val decodedValue: Boolean? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } return decodedValue } suspend fun writeEnablePrivacyModeButtonAttribute( value: Boolean, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 43u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -4927,127 +4692,122 @@ suspend fun readEnablePrivacyModeButtonAttribute(): Boolean? {val ATTRIBUTE_ID: throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeEnablePrivacyModeButtonAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 43u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Enableprivacymodebutton attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Enableprivacymodebutton 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 - } + val decodedValue: Boolean? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(BooleanSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(BooleanSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readLocalProgrammingFeaturesAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 44u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readLocalProgrammingFeaturesAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 44u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Localprogrammingfeatures attribute not found in response" - } + } + + requireNotNull(attributeData) { "Localprogrammingfeatures 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun writeLocalProgrammingFeaturesAttribute( value: UByte, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 44u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -5068,127 +4828,119 @@ suspend fun readLocalProgrammingFeaturesAttribute(): UByte? {val ATTRIBUTE_ID: U throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeLocalProgrammingFeaturesAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 44u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Localprogrammingfeatures attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Localprogrammingfeatures 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readWrongCodeEntryLimitAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 48u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readWrongCodeEntryLimitAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 48u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Wrongcodeentrylimit attribute not found in response" - } + } + + requireNotNull(attributeData) { "Wrongcodeentrylimit 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } - suspend fun writeWrongCodeEntryLimitAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeWrongCodeEntryLimitAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 48u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -5209,127 +4961,122 @@ suspend fun readWrongCodeEntryLimitAttribute(): UByte? {val ATTRIBUTE_ID: UInt = throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeWrongCodeEntryLimitAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 48u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Wrongcodeentrylimit attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Wrongcodeentrylimit 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readUserCodeTemporaryDisableTimeAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 49u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readUserCodeTemporaryDisableTimeAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 49u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Usercodetemporarydisabletime attribute not found in response" - } + } + + requireNotNull(attributeData) { "Usercodetemporarydisabletime 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun writeUserCodeTemporaryDisableTimeAttribute( value: UByte, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 49u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -5350,127 +5097,119 @@ suspend fun readUserCodeTemporaryDisableTimeAttribute(): UByte? {val ATTRIBUTE_I throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeUserCodeTemporaryDisableTimeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 49u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Usercodetemporarydisabletime attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Usercodetemporarydisabletime 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readSendPINOverTheAirAttribute(): Boolean? {val ATTRIBUTE_ID: UInt = 50u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readSendPINOverTheAirAttribute(): Boolean? { + val ATTRIBUTE_ID: UInt = 50u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Sendpinovertheair attribute not found in response" - } + } + + requireNotNull(attributeData) { "Sendpinovertheair 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 - } - + val decodedValue: Boolean? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } return decodedValue } - suspend fun writeSendPINOverTheAirAttribute( - value: Boolean, - timedWriteTimeout: Duration? = null) { + suspend fun writeSendPINOverTheAirAttribute(value: Boolean, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 50u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -5491,127 +5230,122 @@ suspend fun readSendPINOverTheAirAttribute(): Boolean? {val ATTRIBUTE_ID: UInt = throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeSendPINOverTheAirAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 50u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Sendpinovertheair attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Sendpinovertheair 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 - } + val decodedValue: Boolean? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(BooleanSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(BooleanSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRequirePINforRemoteOperationAttribute(): Boolean? {val ATTRIBUTE_ID: UInt = 51u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRequirePINforRemoteOperationAttribute(): Boolean? { + val ATTRIBUTE_ID: UInt = 51u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Requirepinforremoteoperation attribute not found in response" - } + } + + requireNotNull(attributeData) { "Requirepinforremoteoperation 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 - } - + val decodedValue: Boolean? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } return decodedValue } suspend fun writeRequirePINforRemoteOperationAttribute( value: Boolean, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 51u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -5632,127 +5366,122 @@ suspend fun readRequirePINforRemoteOperationAttribute(): Boolean? {val ATTRIBUTE throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeRequirePINforRemoteOperationAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 51u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Requirepinforremoteoperation attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Requirepinforremoteoperation 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 - } + val decodedValue: Boolean? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(BooleanSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(BooleanSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readExpiringUserTimeoutAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 53u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readExpiringUserTimeoutAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 53u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Expiringusertimeout attribute not found in response" - } + } + + requireNotNull(attributeData) { "Expiringusertimeout 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun writeExpiringUserTimeoutAttribute( value: UShort, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 53u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -5773,1079 +5502,1073 @@ suspend fun readExpiringUserTimeoutAttribute(): UShort? {val ATTRIBUTE_ID: UInt throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeExpiringUserTimeoutAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 53u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Expiringusertimeout attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Expiringusertimeout 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAliroReaderVerificationKeyAttribute(): AliroReaderVerificationKeyAttribute {val ATTRIBUTE_ID: UInt = 128u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readAliroReaderVerificationKeyAttribute(): AliroReaderVerificationKeyAttribute { + val ATTRIBUTE_ID: UInt = 128u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Aliroreaderverificationkey attribute not found in response" - } + } + + requireNotNull(attributeData) { "Aliroreaderverificationkey attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByteArray(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: ByteArray? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByteArray(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return AliroReaderVerificationKeyAttribute(decodedValue) } suspend fun subscribeAliroReaderVerificationKeyAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 128u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(AliroReaderVerificationKeyAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + AliroReaderVerificationKeyAttributeSubscriptionState.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) { - "Aliroreaderverificationkey attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Aliroreaderverificationkey attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByteArray(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ByteArray? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByteArray(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } decodedValue?.let { emit(AliroReaderVerificationKeyAttributeSubscriptionState.Success(it)) } - } SubscriptionState.SubscriptionEstablished -> { emit(AliroReaderVerificationKeyAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAliroReaderGroupIdentifierAttribute(): AliroReaderGroupIdentifierAttribute {val ATTRIBUTE_ID: UInt = 129u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readAliroReaderGroupIdentifierAttribute(): AliroReaderGroupIdentifierAttribute { + val ATTRIBUTE_ID: UInt = 129u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Aliroreadergroupidentifier attribute not found in response" - } + } + + requireNotNull(attributeData) { "Aliroreadergroupidentifier attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByteArray(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: ByteArray? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByteArray(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return AliroReaderGroupIdentifierAttribute(decodedValue) } suspend fun subscribeAliroReaderGroupIdentifierAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 129u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(AliroReaderGroupIdentifierAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + AliroReaderGroupIdentifierAttributeSubscriptionState.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) { - "Aliroreadergroupidentifier attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Aliroreadergroupidentifier attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByteArray(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ByteArray? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByteArray(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } decodedValue?.let { emit(AliroReaderGroupIdentifierAttributeSubscriptionState.Success(it)) } - } SubscriptionState.SubscriptionEstablished -> { emit(AliroReaderGroupIdentifierAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAliroReaderGroupSubIdentifierAttribute(): ByteArray? {val ATTRIBUTE_ID: UInt = 130u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readAliroReaderGroupSubIdentifierAttribute(): ByteArray? { + val ATTRIBUTE_ID: UInt = 130u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Aliroreadergroupsubidentifier attribute not found in response" + } + + requireNotNull(attributeData) { + "Aliroreadergroupsubidentifier attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByteArray(AnonymousTag) - } else { - null - } - + val decodedValue: ByteArray? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByteArray(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeAliroReaderGroupSubIdentifierAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 130u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ByteArraySubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ByteArraySubscriptionState.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) { - "Aliroreadergroupsubidentifier attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Aliroreadergroupsubidentifier attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByteArray(AnonymousTag) - } else { - null - } + val decodedValue: ByteArray? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByteArray(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ByteArraySubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ByteArraySubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ByteArraySubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAliroExpeditedTransactionSupportedProtocolVersionsAttribute(): AliroExpeditedTransactionSupportedProtocolVersionsAttribute {val ATTRIBUTE_ID: UInt = 131u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readAliroExpeditedTransactionSupportedProtocolVersionsAttribute(): + AliroExpeditedTransactionSupportedProtocolVersionsAttribute { + val ATTRIBUTE_ID: UInt = 131u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Aliroexpeditedtransactionsupportedprotocolversions attribute not found in response" + } + + requireNotNull(attributeData) { + "Aliroexpeditedtransactionsupportedprotocolversions attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getByteArray(AnonymousTag)) + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getByteArray(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null } - tlvReader.exitContainer() - } - } else { - null - } - return AliroExpeditedTransactionSupportedProtocolVersionsAttribute(decodedValue) } suspend fun subscribeAliroExpeditedTransactionSupportedProtocolVersionsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 131u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(AliroExpeditedTransactionSupportedProtocolVersionsAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + AliroExpeditedTransactionSupportedProtocolVersionsAttributeSubscriptionState.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) { - "Aliroexpeditedtransactionsupportedprotocolversions attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Aliroexpeditedtransactionsupportedprotocolversions attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getByteArray(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null - } + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getByteArray(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null + } decodedValue?.let { - emit(AliroExpeditedTransactionSupportedProtocolVersionsAttributeSubscriptionState.Success(it)) + emit( + AliroExpeditedTransactionSupportedProtocolVersionsAttributeSubscriptionState.Success( + it + ) + ) } - } SubscriptionState.SubscriptionEstablished -> { - emit(AliroExpeditedTransactionSupportedProtocolVersionsAttributeSubscriptionState.SubscriptionEstablished) + emit( + AliroExpeditedTransactionSupportedProtocolVersionsAttributeSubscriptionState + .SubscriptionEstablished + ) } } - } + } } -suspend fun readAliroGroupResolvingKeyAttribute(): AliroGroupResolvingKeyAttribute {val ATTRIBUTE_ID: UInt = 132u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readAliroGroupResolvingKeyAttribute(): AliroGroupResolvingKeyAttribute { + val ATTRIBUTE_ID: UInt = 132u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Alirogroupresolvingkey attribute not found in response" - } + } + + requireNotNull(attributeData) { "Alirogroupresolvingkey attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByteArray(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: ByteArray? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByteArray(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return AliroGroupResolvingKeyAttribute(decodedValue) } suspend fun subscribeAliroGroupResolvingKeyAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 132u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(AliroGroupResolvingKeyAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + AliroGroupResolvingKeyAttributeSubscriptionState.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) { - "Alirogroupresolvingkey attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Alirogroupresolvingkey attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByteArray(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(AliroGroupResolvingKeyAttributeSubscriptionState.Success(it)) - } - + val decodedValue: ByteArray? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByteArray(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(AliroGroupResolvingKeyAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(AliroGroupResolvingKeyAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAliroSupportedBLEUWBProtocolVersionsAttribute(): AliroSupportedBLEUWBProtocolVersionsAttribute {val ATTRIBUTE_ID: UInt = 133u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readAliroSupportedBLEUWBProtocolVersionsAttribute(): + AliroSupportedBLEUWBProtocolVersionsAttribute { + val ATTRIBUTE_ID: UInt = 133u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Alirosupportedbleuwbprotocolversions attribute not found in response" + } + + requireNotNull(attributeData) { + "Alirosupportedbleuwbprotocolversions attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getByteArray(AnonymousTag)) + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getByteArray(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null } - tlvReader.exitContainer() - } - } else { - null - } - return AliroSupportedBLEUWBProtocolVersionsAttribute(decodedValue) } suspend fun subscribeAliroSupportedBLEUWBProtocolVersionsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 133u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(AliroSupportedBLEUWBProtocolVersionsAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + AliroSupportedBLEUWBProtocolVersionsAttributeSubscriptionState.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) { - "Alirosupportedbleuwbprotocolversions attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Alirosupportedbleuwbprotocolversions attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getByteArray(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null - } + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getByteArray(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null + } decodedValue?.let { emit(AliroSupportedBLEUWBProtocolVersionsAttributeSubscriptionState.Success(it)) } - } SubscriptionState.SubscriptionEstablished -> { - emit(AliroSupportedBLEUWBProtocolVersionsAttributeSubscriptionState.SubscriptionEstablished) + emit( + AliroSupportedBLEUWBProtocolVersionsAttributeSubscriptionState.SubscriptionEstablished + ) } } - } + } } -suspend fun readAliroBLEAdvertisingVersionAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 134u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readAliroBLEAdvertisingVersionAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 134u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Alirobleadvertisingversion attribute not found in response" - } + } + + requireNotNull(attributeData) { "Alirobleadvertisingversion 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeAliroBLEAdvertisingVersionAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 134u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Alirobleadvertisingversion attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Alirobleadvertisingversion 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNumberOfAliroCredentialIssuerKeysSupportedAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 135u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNumberOfAliroCredentialIssuerKeysSupportedAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 135u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Numberofalirocredentialissuerkeyssupported attribute not found in response" + } + + requireNotNull(attributeData) { + "Numberofalirocredentialissuerkeyssupported 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeNumberOfAliroCredentialIssuerKeysSupportedAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 135u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Numberofalirocredentialissuerkeyssupported attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Numberofalirocredentialissuerkeyssupported 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNumberOfAliroEndpointKeysSupportedAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 136u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNumberOfAliroEndpointKeysSupportedAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 136u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Numberofaliroendpointkeyssupported attribute not found in response" + } + + requireNotNull(attributeData) { + "Numberofaliroendpointkeyssupported 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeNumberOfAliroEndpointKeysSupportedAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 136u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Numberofaliroendpointkeyssupported attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Numberofaliroendpointkeyssupported 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65528u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -6853,97 +6576,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { emit(GeneratedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65529u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -6951,97 +6673,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va emit(AcceptedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt = 65530u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -7049,97 +6768,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt emit(EventListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ID: UInt = 65531u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -7147,81 +6863,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ emit(AttributeListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -7233,80 +6944,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 65533u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -7319,7 +7027,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/EcosystemInformationCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/EcosystemInformationCluster.kt index cbf93654da7199..5dfa4a7f8067ef 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/EcosystemInformationCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/EcosystemInformationCluster.kt @@ -17,335 +17,291 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState -import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse -import matter.controller.model.AttributePath -import matter.controller.model.CommandPath +import matter.controller.UShortSubscriptionState import matter.controller.cluster.structs.* +import matter.controller.model.AttributePath import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader -import matter.tlv.TlvWriter -class EcosystemInformationCluster(private val controller: MatterController, private val endpointId: UShort) {class RemovedOnAttribute( - val value: ULong? - ) +class EcosystemInformationCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class RemovedOnAttribute(val value: ULong?) sealed class RemovedOnAttributeSubscriptionState { - data class Success( - val value: ULong? - ) : RemovedOnAttributeSubscriptionState() - + data class Success(val value: ULong?) : RemovedOnAttributeSubscriptionState() + data class Error(val exception: Exception) : RemovedOnAttributeSubscriptionState() - object SubscriptionEstablished : RemovedOnAttributeSubscriptionState() - } -class DeviceDirectoryAttribute( - val value: List - ) + object SubscriptionEstablished : RemovedOnAttributeSubscriptionState() + } + + class DeviceDirectoryAttribute(val value: List) sealed class DeviceDirectoryAttributeSubscriptionState { - data class Success( - val value: List - ) : DeviceDirectoryAttributeSubscriptionState() - + data class Success(val value: List) : + DeviceDirectoryAttributeSubscriptionState() + data class Error(val exception: Exception) : DeviceDirectoryAttributeSubscriptionState() - object SubscriptionEstablished : DeviceDirectoryAttributeSubscriptionState() - } -class LocationDirectoryAttribute( + object SubscriptionEstablished : DeviceDirectoryAttributeSubscriptionState() + } + + class LocationDirectoryAttribute( val value: List ) sealed class LocationDirectoryAttributeSubscriptionState { - data class Success( - val value: List - ) : LocationDirectoryAttributeSubscriptionState() - + data class Success(val value: List) : + LocationDirectoryAttributeSubscriptionState() + data class Error(val exception: Exception) : LocationDirectoryAttributeSubscriptionState() - object SubscriptionEstablished : LocationDirectoryAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : LocationDirectoryAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } -suspend fun readRemovedOnAttribute(): RemovedOnAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } + + suspend fun readRemovedOnAttribute(): RemovedOnAttribute { + 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}") - } + 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) { - "Removedon attribute not found in response" - } + } + + requireNotNull(attributeData) { "Removedon 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 - } - + val decodedValue: ULong? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return RemovedOnAttribute(decodedValue) } suspend fun subscribeRemovedOnAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(RemovedOnAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + RemovedOnAttributeSubscriptionState.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) { - "Removedon attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Removedon 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(RemovedOnAttributeSubscriptionState.Success(it)) - } - + val decodedValue: ULong? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(RemovedOnAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(RemovedOnAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readDeviceDirectoryAttribute(): DeviceDirectoryAttribute {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readDeviceDirectoryAttribute(): DeviceDirectoryAttribute { + 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}") - } + 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) { - "Devicedirectory attribute not found in response" - } + } + + requireNotNull(attributeData) { "Devicedirectory 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(EcosystemInformationClusterEcosystemDeviceStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(EcosystemInformationClusterEcosystemDeviceStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return DeviceDirectoryAttribute(decodedValue) } suspend fun subscribeDeviceDirectoryAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(DeviceDirectoryAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + DeviceDirectoryAttributeSubscriptionState.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) { - "Devicedirectory attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Devicedirectory 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(EcosystemInformationClusterEcosystemDeviceStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add( + EcosystemInformationClusterEcosystemDeviceStruct.fromTlv(AnonymousTag, tlvReader) + ) + } + tlvReader.exitContainer() + } emit(DeviceDirectoryAttributeSubscriptionState.Success(decodedValue)) } @@ -353,97 +309,101 @@ suspend fun readDeviceDirectoryAttribute(): DeviceDirectoryAttribute {val ATTRIB emit(DeviceDirectoryAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readLocationDirectoryAttribute(): LocationDirectoryAttribute {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readLocationDirectoryAttribute(): LocationDirectoryAttribute { + 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}") - } + 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) { - "Locationdirectory attribute not found in response" - } + } + + requireNotNull(attributeData) { "Locationdirectory 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(EcosystemInformationClusterEcosystemLocationStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(EcosystemInformationClusterEcosystemLocationStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return LocationDirectoryAttribute(decodedValue) } suspend fun subscribeLocationDirectoryAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(LocationDirectoryAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + LocationDirectoryAttributeSubscriptionState.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) { - "Locationdirectory attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Locationdirectory 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(EcosystemInformationClusterEcosystemLocationStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add( + EcosystemInformationClusterEcosystemLocationStruct.fromTlv( + AnonymousTag, + tlvReader, + ) + ) + } + tlvReader.exitContainer() + } emit(LocationDirectoryAttributeSubscriptionState.Success(decodedValue)) } @@ -451,97 +411,96 @@ suspend fun readLocationDirectoryAttribute(): LocationDirectoryAttribute {val AT emit(LocationDirectoryAttributeSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -549,97 +508,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -647,97 +605,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -745,97 +700,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -843,81 +795,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -929,80 +876,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1015,7 +959,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/ElectricalEnergyMeasurementCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/ElectricalEnergyMeasurementCluster.kt index e8ee567241b398..e23cc2d91b6c98 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/ElectricalEnergyMeasurementCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/ElectricalEnergyMeasurementCluster.kt @@ -17,255 +17,221 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState -import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse -import matter.controller.model.AttributePath -import matter.controller.model.CommandPath +import matter.controller.UShortSubscriptionState import matter.controller.cluster.structs.* +import matter.controller.model.AttributePath import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader -import matter.tlv.TlvWriter -class ElectricalEnergyMeasurementCluster(private val controller: MatterController, private val endpointId: UShort) {class AccuracyAttribute( - val value: ElectricalEnergyMeasurementClusterMeasurementAccuracyStruct - ) +class ElectricalEnergyMeasurementCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class AccuracyAttribute(val value: ElectricalEnergyMeasurementClusterMeasurementAccuracyStruct) sealed class AccuracyAttributeSubscriptionState { - data class Success( - val value: ElectricalEnergyMeasurementClusterMeasurementAccuracyStruct - ) : AccuracyAttributeSubscriptionState() - + data class Success(val value: ElectricalEnergyMeasurementClusterMeasurementAccuracyStruct) : + AccuracyAttributeSubscriptionState() + data class Error(val exception: Exception) : AccuracyAttributeSubscriptionState() - object SubscriptionEstablished : AccuracyAttributeSubscriptionState() - } -class CumulativeEnergyImportedAttribute( + object SubscriptionEstablished : AccuracyAttributeSubscriptionState() + } + + class CumulativeEnergyImportedAttribute( val value: ElectricalEnergyMeasurementClusterEnergyMeasurementStruct? ) sealed class CumulativeEnergyImportedAttributeSubscriptionState { - data class Success( - val value: ElectricalEnergyMeasurementClusterEnergyMeasurementStruct? - ) : CumulativeEnergyImportedAttributeSubscriptionState() - - data class Error(val exception: Exception) : CumulativeEnergyImportedAttributeSubscriptionState() + data class Success(val value: ElectricalEnergyMeasurementClusterEnergyMeasurementStruct?) : + CumulativeEnergyImportedAttributeSubscriptionState() - object SubscriptionEstablished : CumulativeEnergyImportedAttributeSubscriptionState() - } -class CumulativeEnergyExportedAttribute( + data class Error(val exception: Exception) : + CumulativeEnergyImportedAttributeSubscriptionState() + + object SubscriptionEstablished : CumulativeEnergyImportedAttributeSubscriptionState() + } + + class CumulativeEnergyExportedAttribute( val value: ElectricalEnergyMeasurementClusterEnergyMeasurementStruct? ) sealed class CumulativeEnergyExportedAttributeSubscriptionState { - data class Success( - val value: ElectricalEnergyMeasurementClusterEnergyMeasurementStruct? - ) : CumulativeEnergyExportedAttributeSubscriptionState() - - data class Error(val exception: Exception) : CumulativeEnergyExportedAttributeSubscriptionState() + data class Success(val value: ElectricalEnergyMeasurementClusterEnergyMeasurementStruct?) : + CumulativeEnergyExportedAttributeSubscriptionState() - object SubscriptionEstablished : CumulativeEnergyExportedAttributeSubscriptionState() - } -class PeriodicEnergyImportedAttribute( + data class Error(val exception: Exception) : + CumulativeEnergyExportedAttributeSubscriptionState() + + object SubscriptionEstablished : CumulativeEnergyExportedAttributeSubscriptionState() + } + + class PeriodicEnergyImportedAttribute( val value: ElectricalEnergyMeasurementClusterEnergyMeasurementStruct? ) sealed class PeriodicEnergyImportedAttributeSubscriptionState { - data class Success( - val value: ElectricalEnergyMeasurementClusterEnergyMeasurementStruct? - ) : PeriodicEnergyImportedAttributeSubscriptionState() - + data class Success(val value: ElectricalEnergyMeasurementClusterEnergyMeasurementStruct?) : + PeriodicEnergyImportedAttributeSubscriptionState() + data class Error(val exception: Exception) : PeriodicEnergyImportedAttributeSubscriptionState() - object SubscriptionEstablished : PeriodicEnergyImportedAttributeSubscriptionState() - } -class PeriodicEnergyExportedAttribute( + object SubscriptionEstablished : PeriodicEnergyImportedAttributeSubscriptionState() + } + + class PeriodicEnergyExportedAttribute( val value: ElectricalEnergyMeasurementClusterEnergyMeasurementStruct? ) sealed class PeriodicEnergyExportedAttributeSubscriptionState { - data class Success( - val value: ElectricalEnergyMeasurementClusterEnergyMeasurementStruct? - ) : PeriodicEnergyExportedAttributeSubscriptionState() - + data class Success(val value: ElectricalEnergyMeasurementClusterEnergyMeasurementStruct?) : + PeriodicEnergyExportedAttributeSubscriptionState() + data class Error(val exception: Exception) : PeriodicEnergyExportedAttributeSubscriptionState() - object SubscriptionEstablished : PeriodicEnergyExportedAttributeSubscriptionState() - } -class CumulativeEnergyResetAttribute( + object SubscriptionEstablished : PeriodicEnergyExportedAttributeSubscriptionState() + } + + class CumulativeEnergyResetAttribute( val value: ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct? ) sealed class CumulativeEnergyResetAttributeSubscriptionState { - data class Success( - val value: ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct? - ) : CumulativeEnergyResetAttributeSubscriptionState() - + data class Success(val value: ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct?) : + CumulativeEnergyResetAttributeSubscriptionState() + data class Error(val exception: Exception) : CumulativeEnergyResetAttributeSubscriptionState() - object SubscriptionEstablished : CumulativeEnergyResetAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : CumulativeEnergyResetAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } -suspend fun readAccuracyAttribute(): AccuracyAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } + + suspend fun readAccuracyAttribute(): AccuracyAttribute { + 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}") - } + 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) { - "Accuracy attribute not found in response" - } + } + + 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) - + val decodedValue: ElectricalEnergyMeasurementClusterMeasurementAccuracyStruct = + ElectricalEnergyMeasurementClusterMeasurementAccuracyStruct.fromTlv(AnonymousTag, tlvReader) return AccuracyAttribute(decodedValue) } suspend fun subscribeAccuracyAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(AccuracyAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + AccuracyAttributeSubscriptionState.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) { - "Accuracy attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Accuracy attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ElectricalEnergyMeasurementClusterMeasurementAccuracyStruct = ElectricalEnergyMeasurementClusterMeasurementAccuracyStruct.fromTlv(AnonymousTag, tlvReader) + val decodedValue: ElectricalEnergyMeasurementClusterMeasurementAccuracyStruct = + ElectricalEnergyMeasurementClusterMeasurementAccuracyStruct.fromTlv( + AnonymousTag, + tlvReader, + ) emit(AccuracyAttributeSubscriptionState.Success(decodedValue)) } @@ -273,632 +239,629 @@ suspend fun readAccuracyAttribute(): AccuracyAttribute {val ATTRIBUTE_ID: UInt = emit(AccuracyAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCumulativeEnergyImportedAttribute(): CumulativeEnergyImportedAttribute {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readCumulativeEnergyImportedAttribute(): CumulativeEnergyImportedAttribute { + 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}") - } + 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" - } + } + + 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 - } - + 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 subscribeCumulativeEnergyImportedAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(CumulativeEnergyImportedAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + CumulativeEnergyImportedAttributeSubscriptionState.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) { - "Cumulativeenergyimported attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Cumulativeenergyimported attribute not found in Node State update" } // 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 - } - - decodedValue?.let { - emit(CumulativeEnergyImportedAttributeSubscriptionState.Success(it)) - } - + val decodedValue: ElectricalEnergyMeasurementClusterEnergyMeasurementStruct? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + ElectricalEnergyMeasurementClusterEnergyMeasurementStruct.fromTlv( + AnonymousTag, + tlvReader, + ) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(CumulativeEnergyImportedAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(CumulativeEnergyImportedAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCumulativeEnergyExportedAttribute(): CumulativeEnergyExportedAttribute {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readCumulativeEnergyExportedAttribute(): CumulativeEnergyExportedAttribute { + 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}") - } + 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) { - "Cumulativeenergyexported attribute not found in response" - } + } + + 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 - } - + 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 subscribeCumulativeEnergyExportedAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(CumulativeEnergyExportedAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + CumulativeEnergyExportedAttributeSubscriptionState.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) { - "Cumulativeenergyexported attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Cumulativeenergyexported attribute not found in Node State update" } // 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 - } - - decodedValue?.let { - emit(CumulativeEnergyExportedAttributeSubscriptionState.Success(it)) - } - + val decodedValue: ElectricalEnergyMeasurementClusterEnergyMeasurementStruct? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + ElectricalEnergyMeasurementClusterEnergyMeasurementStruct.fromTlv( + AnonymousTag, + tlvReader, + ) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(CumulativeEnergyExportedAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(CumulativeEnergyExportedAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPeriodicEnergyImportedAttribute(): PeriodicEnergyImportedAttribute {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readPeriodicEnergyImportedAttribute(): PeriodicEnergyImportedAttribute { + 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}") - } + 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) { - "Periodicenergyimported attribute not found in response" - } + } + + 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 - } - + 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 subscribePeriodicEnergyImportedAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(PeriodicEnergyImportedAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + PeriodicEnergyImportedAttributeSubscriptionState.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) { - "Periodicenergyimported attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Periodicenergyimported attribute not found in Node State update" } // 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 - } - - decodedValue?.let { - emit(PeriodicEnergyImportedAttributeSubscriptionState.Success(it)) - } - + val decodedValue: ElectricalEnergyMeasurementClusterEnergyMeasurementStruct? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + ElectricalEnergyMeasurementClusterEnergyMeasurementStruct.fromTlv( + AnonymousTag, + tlvReader, + ) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(PeriodicEnergyImportedAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(PeriodicEnergyImportedAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPeriodicEnergyExportedAttribute(): PeriodicEnergyExportedAttribute {val ATTRIBUTE_ID: UInt = 4u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readPeriodicEnergyExportedAttribute(): PeriodicEnergyExportedAttribute { + 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}") - } + 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" - } + } + + 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 - } - + 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 subscribePeriodicEnergyExportedAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(PeriodicEnergyExportedAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + PeriodicEnergyExportedAttributeSubscriptionState.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) { - "Periodicenergyexported attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Periodicenergyexported attribute not found in Node State update" } // 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 - } - - decodedValue?.let { - emit(PeriodicEnergyExportedAttributeSubscriptionState.Success(it)) - } - + val decodedValue: ElectricalEnergyMeasurementClusterEnergyMeasurementStruct? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + ElectricalEnergyMeasurementClusterEnergyMeasurementStruct.fromTlv( + AnonymousTag, + tlvReader, + ) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(PeriodicEnergyExportedAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(PeriodicEnergyExportedAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCumulativeEnergyResetAttribute(): CumulativeEnergyResetAttribute {val ATTRIBUTE_ID: UInt = 5u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readCumulativeEnergyResetAttribute(): CumulativeEnergyResetAttribute { + 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}") - } + 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) { - "Cumulativeenergyreset attribute not found in response" - } + } + + requireNotNull(attributeData) { "Cumulativeenergyreset attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct.fromTlv(AnonymousTag, tlvReader) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct.fromTlv( + AnonymousTag, + tlvReader, + ) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return CumulativeEnergyResetAttribute(decodedValue) } suspend fun subscribeCumulativeEnergyResetAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(CumulativeEnergyResetAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + CumulativeEnergyResetAttributeSubscriptionState.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) { - "Cumulativeenergyreset attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Cumulativeenergyreset attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct.fromTlv(AnonymousTag, tlvReader) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(CumulativeEnergyResetAttributeSubscriptionState.Success(it)) - } - + val decodedValue: ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct.fromTlv( + AnonymousTag, + tlvReader, + ) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(CumulativeEnergyResetAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(CumulativeEnergyResetAttributeSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -906,97 +869,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1004,97 +966,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1102,97 +1061,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1200,81 +1156,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1286,80 +1237,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1372,7 +1320,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/ElectricalMeasurementCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/ElectricalMeasurementCluster.kt index 0fec4dc6624459..7c564d94f7738c 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/ElectricalMeasurementCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/ElectricalMeasurementCluster.kt @@ -17,123 +17,103 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.ByteSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest +import matter.controller.ShortSubscriptionState import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class ElectricalMeasurementCluster(private val controller: MatterController, private val endpointId: UShort) {class GeneratedCommandListAttribute( - val value: List - ) +class ElectricalMeasurementCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } suspend fun getProfileInfoCommand(timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun getMeasurementProfileCommand(attributeId: UShort - ,startTime: UInt - ,numberOfIntervals: UByte - ,timedInvokeTimeout: Duration? = null) { + suspend fun getMeasurementProfileCommand( + attributeId: UShort, + startTime: UInt, + numberOfIntervals: UByte, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 1u val tlvWriter = TlvWriter() @@ -146,5709 +126,5444 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_START_TIME_REQ), startTime) val TAG_NUMBER_OF_INTERVALS_REQ: Int = 2 - tlvWriter.put(ContextSpecificTag(TAG_NUMBER_OF_INTERVALS_REQ), numberOfIntervals) + tlvWriter.put(ContextSpecificTag(TAG_NUMBER_OF_INTERVALS_REQ), numberOfIntervals) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } -suspend fun readMeasurementTypeAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 0u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readMeasurementTypeAttribute(): UInt? { + 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 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}") - } + 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) { - "Measurementtype attribute not found in response" - } + } + + requireNotNull(attributeData) { "Measurementtype attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeMeasurementTypeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Measurementtype attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Measurementtype attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readDcVoltageAttribute(): Short? {val ATTRIBUTE_ID: UInt = 256u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readDcVoltageAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 256u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Dcvoltage attribute not found in response" - } + } + + requireNotNull(attributeData) { "Dcvoltage attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeDcVoltageAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 256u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Dcvoltage attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Dcvoltage attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readDcVoltageMinAttribute(): Short? {val ATTRIBUTE_ID: UInt = 257u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readDcVoltageMinAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 257u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Dcvoltagemin attribute not found in response" - } + } + + requireNotNull(attributeData) { "Dcvoltagemin attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeDcVoltageMinAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 257u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Dcvoltagemin attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Dcvoltagemin attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readDcVoltageMaxAttribute(): Short? {val ATTRIBUTE_ID: UInt = 258u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readDcVoltageMaxAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 258u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Dcvoltagemax attribute not found in response" - } + } + + requireNotNull(attributeData) { "Dcvoltagemax attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeDcVoltageMaxAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 258u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Dcvoltagemax attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Dcvoltagemax attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readDcCurrentAttribute(): Short? {val ATTRIBUTE_ID: UInt = 259u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readDcCurrentAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 259u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Dccurrent attribute not found in response" - } + } + + requireNotNull(attributeData) { "Dccurrent attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeDcCurrentAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 259u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Dccurrent attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Dccurrent attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readDcCurrentMinAttribute(): Short? {val ATTRIBUTE_ID: UInt = 260u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readDcCurrentMinAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 260u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Dccurrentmin attribute not found in response" - } + } + + requireNotNull(attributeData) { "Dccurrentmin attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeDcCurrentMinAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 260u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Dccurrentmin attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Dccurrentmin attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readDcCurrentMaxAttribute(): Short? {val ATTRIBUTE_ID: UInt = 261u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readDcCurrentMaxAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 261u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Dccurrentmax attribute not found in response" - } + } + + requireNotNull(attributeData) { "Dccurrentmax attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeDcCurrentMaxAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 261u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Dccurrentmax attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Dccurrentmax attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readDcPowerAttribute(): Short? {val ATTRIBUTE_ID: UInt = 262u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readDcPowerAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 262u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Dcpower attribute not found in response" - } + } + + requireNotNull(attributeData) { "Dcpower attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeDcPowerAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 262u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Dcpower attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Dcpower attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readDcPowerMinAttribute(): Short? {val ATTRIBUTE_ID: UInt = 263u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readDcPowerMinAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 263u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Dcpowermin attribute not found in response" - } + } + + requireNotNull(attributeData) { "Dcpowermin attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeDcPowerMinAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 263u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Dcpowermin attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Dcpowermin attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readDcPowerMaxAttribute(): Short? {val ATTRIBUTE_ID: UInt = 264u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readDcPowerMaxAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 264u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Dcpowermax attribute not found in response" - } + } + + requireNotNull(attributeData) { "Dcpowermax attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeDcPowerMaxAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 264u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Dcpowermax attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Dcpowermax attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readDcVoltageMultiplierAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 512u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readDcVoltageMultiplierAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 512u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Dcvoltagemultiplier attribute not found in response" - } + } + + requireNotNull(attributeData) { "Dcvoltagemultiplier 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeDcVoltageMultiplierAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 512u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Dcvoltagemultiplier attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Dcvoltagemultiplier 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readDcVoltageDivisorAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 513u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readDcVoltageDivisorAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 513u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Dcvoltagedivisor attribute not found in response" - } + } + + requireNotNull(attributeData) { "Dcvoltagedivisor 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeDcVoltageDivisorAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 513u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Dcvoltagedivisor attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Dcvoltagedivisor 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readDcCurrentMultiplierAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 514u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readDcCurrentMultiplierAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 514u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Dccurrentmultiplier attribute not found in response" - } + } + + requireNotNull(attributeData) { "Dccurrentmultiplier 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeDcCurrentMultiplierAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 514u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Dccurrentmultiplier attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Dccurrentmultiplier 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readDcCurrentDivisorAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 515u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readDcCurrentDivisorAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 515u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Dccurrentdivisor attribute not found in response" - } + } + + requireNotNull(attributeData) { "Dccurrentdivisor 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeDcCurrentDivisorAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 515u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Dccurrentdivisor attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Dccurrentdivisor 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readDcPowerMultiplierAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 516u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readDcPowerMultiplierAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 516u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Dcpowermultiplier attribute not found in response" - } + } + + requireNotNull(attributeData) { "Dcpowermultiplier 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeDcPowerMultiplierAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 516u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Dcpowermultiplier attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Dcpowermultiplier 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readDcPowerDivisorAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 517u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readDcPowerDivisorAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 517u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Dcpowerdivisor attribute not found in response" - } + } + + requireNotNull(attributeData) { "Dcpowerdivisor 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeDcPowerDivisorAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 517u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Dcpowerdivisor attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Dcpowerdivisor 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAcFrequencyAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 768u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readAcFrequencyAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 768u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Acfrequency attribute not found in response" - } + } + + requireNotNull(attributeData) { "Acfrequency 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeAcFrequencyAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 768u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Acfrequency attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Acfrequency 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAcFrequencyMinAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 769u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readAcFrequencyMinAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 769u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Acfrequencymin attribute not found in response" - } + } + + requireNotNull(attributeData) { "Acfrequencymin 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeAcFrequencyMinAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 769u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Acfrequencymin attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Acfrequencymin 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAcFrequencyMaxAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 770u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readAcFrequencyMaxAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 770u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Acfrequencymax attribute not found in response" - } + } + + requireNotNull(attributeData) { "Acfrequencymax 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeAcFrequencyMaxAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 770u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Acfrequencymax attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Acfrequencymax 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNeutralCurrentAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 771u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNeutralCurrentAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 771u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Neutralcurrent attribute not found in response" - } + } + + requireNotNull(attributeData) { "Neutralcurrent 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeNeutralCurrentAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 771u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Neutralcurrent attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Neutralcurrent 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readTotalActivePowerAttribute(): Int? {val ATTRIBUTE_ID: UInt = 772u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readTotalActivePowerAttribute(): Int? { + val ATTRIBUTE_ID: UInt = 772u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Totalactivepower attribute not found in response" - } + } + + requireNotNull(attributeData) { "Totalactivepower attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Int? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getInt(AnonymousTag) - } else { - null - } - + val decodedValue: Int? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeTotalActivePowerAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 772u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(IntSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + IntSubscriptionState.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) { - "Totalactivepower attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Totalactivepower attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Int? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getInt(AnonymousTag) - } else { - null - } + val decodedValue: Int? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getInt(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(IntSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(IntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(IntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readTotalReactivePowerAttribute(): Int? {val ATTRIBUTE_ID: UInt = 773u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readTotalReactivePowerAttribute(): Int? { + val ATTRIBUTE_ID: UInt = 773u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Totalreactivepower attribute not found in response" - } + } + + requireNotNull(attributeData) { "Totalreactivepower attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Int? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getInt(AnonymousTag) - } else { - null - } - + val decodedValue: Int? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeTotalReactivePowerAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 773u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(IntSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + IntSubscriptionState.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) { - "Totalreactivepower attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Totalreactivepower attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Int? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getInt(AnonymousTag) - } else { - null - } + val decodedValue: Int? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getInt(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(IntSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(IntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(IntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readTotalApparentPowerAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 774u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readTotalApparentPowerAttribute(): UInt? { + val ATTRIBUTE_ID: UInt = 774u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Totalapparentpower attribute not found in response" - } + } + + requireNotNull(attributeData) { "Totalapparentpower attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeTotalApparentPowerAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 774u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Totalapparentpower attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Totalapparentpower attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMeasured1stHarmonicCurrentAttribute(): Short? {val ATTRIBUTE_ID: UInt = 775u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readMeasured1stHarmonicCurrentAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 775u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Measured1stharmoniccurrent attribute not found in response" - } + } + + requireNotNull(attributeData) { "Measured1stharmoniccurrent attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeMeasured1stHarmonicCurrentAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 775u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Measured1stharmoniccurrent attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Measured1stharmoniccurrent attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMeasured3rdHarmonicCurrentAttribute(): Short? {val ATTRIBUTE_ID: UInt = 776u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readMeasured3rdHarmonicCurrentAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 776u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Measured3rdharmoniccurrent attribute not found in response" - } + } + + requireNotNull(attributeData) { "Measured3rdharmoniccurrent attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeMeasured3rdHarmonicCurrentAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 776u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Measured3rdharmoniccurrent attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Measured3rdharmoniccurrent attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMeasured5thHarmonicCurrentAttribute(): Short? {val ATTRIBUTE_ID: UInt = 777u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readMeasured5thHarmonicCurrentAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 777u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Measured5thharmoniccurrent attribute not found in response" - } + } + + requireNotNull(attributeData) { "Measured5thharmoniccurrent attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeMeasured5thHarmonicCurrentAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 777u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Measured5thharmoniccurrent attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Measured5thharmoniccurrent attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMeasured7thHarmonicCurrentAttribute(): Short? {val ATTRIBUTE_ID: UInt = 778u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readMeasured7thHarmonicCurrentAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 778u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Measured7thharmoniccurrent attribute not found in response" - } + } + + requireNotNull(attributeData) { "Measured7thharmoniccurrent attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeMeasured7thHarmonicCurrentAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 778u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Measured7thharmoniccurrent attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Measured7thharmoniccurrent attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMeasured9thHarmonicCurrentAttribute(): Short? {val ATTRIBUTE_ID: UInt = 779u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readMeasured9thHarmonicCurrentAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 779u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Measured9thharmoniccurrent attribute not found in response" - } + } + + requireNotNull(attributeData) { "Measured9thharmoniccurrent attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeMeasured9thHarmonicCurrentAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 779u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Measured9thharmoniccurrent attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Measured9thharmoniccurrent attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMeasured11thHarmonicCurrentAttribute(): Short? {val ATTRIBUTE_ID: UInt = 780u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readMeasured11thHarmonicCurrentAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 780u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Measured11thharmoniccurrent attribute not found in response" - } + } + + requireNotNull(attributeData) { "Measured11thharmoniccurrent attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeMeasured11thHarmonicCurrentAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 780u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Measured11thharmoniccurrent attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Measured11thharmoniccurrent attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMeasuredPhase1stHarmonicCurrentAttribute(): Short? {val ATTRIBUTE_ID: UInt = 781u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readMeasuredPhase1stHarmonicCurrentAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 781u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Measuredphase1stharmoniccurrent attribute not found in response" + } + + requireNotNull(attributeData) { + "Measuredphase1stharmoniccurrent attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeMeasuredPhase1stHarmonicCurrentAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 781u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Measuredphase1stharmoniccurrent attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Measuredphase1stharmoniccurrent attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMeasuredPhase3rdHarmonicCurrentAttribute(): Short? {val ATTRIBUTE_ID: UInt = 782u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readMeasuredPhase3rdHarmonicCurrentAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 782u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Measuredphase3rdharmoniccurrent attribute not found in response" + } + + requireNotNull(attributeData) { + "Measuredphase3rdharmoniccurrent attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeMeasuredPhase3rdHarmonicCurrentAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 782u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Measuredphase3rdharmoniccurrent attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Measuredphase3rdharmoniccurrent attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMeasuredPhase5thHarmonicCurrentAttribute(): Short? {val ATTRIBUTE_ID: UInt = 783u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readMeasuredPhase5thHarmonicCurrentAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 783u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Measuredphase5thharmoniccurrent attribute not found in response" + } + + requireNotNull(attributeData) { + "Measuredphase5thharmoniccurrent attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeMeasuredPhase5thHarmonicCurrentAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 783u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Measuredphase5thharmoniccurrent attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Measuredphase5thharmoniccurrent attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMeasuredPhase7thHarmonicCurrentAttribute(): Short? {val ATTRIBUTE_ID: UInt = 784u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readMeasuredPhase7thHarmonicCurrentAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 784u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Measuredphase7thharmoniccurrent attribute not found in response" + } + + requireNotNull(attributeData) { + "Measuredphase7thharmoniccurrent attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeMeasuredPhase7thHarmonicCurrentAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 784u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Measuredphase7thharmoniccurrent attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Measuredphase7thharmoniccurrent attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMeasuredPhase9thHarmonicCurrentAttribute(): Short? {val ATTRIBUTE_ID: UInt = 785u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readMeasuredPhase9thHarmonicCurrentAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 785u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Measuredphase9thharmoniccurrent attribute not found in response" + } + + requireNotNull(attributeData) { + "Measuredphase9thharmoniccurrent attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeMeasuredPhase9thHarmonicCurrentAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 785u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Measuredphase9thharmoniccurrent attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Measuredphase9thharmoniccurrent attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMeasuredPhase11thHarmonicCurrentAttribute(): Short? {val ATTRIBUTE_ID: UInt = 786u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readMeasuredPhase11thHarmonicCurrentAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 786u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Measuredphase11thharmoniccurrent attribute not found in response" + } + + requireNotNull(attributeData) { + "Measuredphase11thharmoniccurrent attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeMeasuredPhase11thHarmonicCurrentAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 786u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Measuredphase11thharmoniccurrent attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Measuredphase11thharmoniccurrent attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAcFrequencyMultiplierAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 1024u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readAcFrequencyMultiplierAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 1024u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Acfrequencymultiplier attribute not found in response" - } + } + + requireNotNull(attributeData) { "Acfrequencymultiplier 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeAcFrequencyMultiplierAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1024u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Acfrequencymultiplier attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Acfrequencymultiplier 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAcFrequencyDivisorAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 1025u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readAcFrequencyDivisorAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 1025u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Acfrequencydivisor attribute not found in response" - } + } + + requireNotNull(attributeData) { "Acfrequencydivisor 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeAcFrequencyDivisorAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1025u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Acfrequencydivisor attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Acfrequencydivisor 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPowerMultiplierAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 1026u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readPowerMultiplierAttribute(): UInt? { + val ATTRIBUTE_ID: UInt = 1026u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Powermultiplier attribute not found in response" - } + } + + requireNotNull(attributeData) { "Powermultiplier attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribePowerMultiplierAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1026u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Powermultiplier attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Powermultiplier attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPowerDivisorAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 1027u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readPowerDivisorAttribute(): UInt? { + val ATTRIBUTE_ID: UInt = 1027u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Powerdivisor attribute not found in response" - } + } + + requireNotNull(attributeData) { "Powerdivisor attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribePowerDivisorAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1027u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Powerdivisor attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Powerdivisor attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readHarmonicCurrentMultiplierAttribute(): Byte? {val ATTRIBUTE_ID: UInt = 1028u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readHarmonicCurrentMultiplierAttribute(): Byte? { + val ATTRIBUTE_ID: UInt = 1028u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Harmoniccurrentmultiplier attribute not found in response" - } + } + + requireNotNull(attributeData) { "Harmoniccurrentmultiplier attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Byte? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByte(AnonymousTag) - } else { - null - } - + val decodedValue: Byte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeHarmonicCurrentMultiplierAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1028u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ByteSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ByteSubscriptionState.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) { - "Harmoniccurrentmultiplier attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Harmoniccurrentmultiplier attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Byte? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByte(AnonymousTag) - } else { - null - } + val decodedValue: Byte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPhaseHarmonicCurrentMultiplierAttribute(): Byte? {val ATTRIBUTE_ID: UInt = 1029u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readPhaseHarmonicCurrentMultiplierAttribute(): Byte? { + val ATTRIBUTE_ID: UInt = 1029u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Phaseharmoniccurrentmultiplier attribute not found in response" + } + + requireNotNull(attributeData) { + "Phaseharmoniccurrentmultiplier attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Byte? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByte(AnonymousTag) - } else { - null - } - + val decodedValue: Byte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribePhaseHarmonicCurrentMultiplierAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1029u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ByteSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ByteSubscriptionState.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) { - "Phaseharmoniccurrentmultiplier attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Phaseharmoniccurrentmultiplier attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Byte? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByte(AnonymousTag) - } else { - null - } + val decodedValue: Byte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readInstantaneousVoltageAttribute(): Short? {val ATTRIBUTE_ID: UInt = 1280u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readInstantaneousVoltageAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 1280u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Instantaneousvoltage attribute not found in response" - } + } + + requireNotNull(attributeData) { "Instantaneousvoltage attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeInstantaneousVoltageAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1280u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Instantaneousvoltage attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Instantaneousvoltage attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readInstantaneousLineCurrentAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 1281u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readInstantaneousLineCurrentAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 1281u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Instantaneouslinecurrent attribute not found in response" - } + } + + requireNotNull(attributeData) { "Instantaneouslinecurrent 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeInstantaneousLineCurrentAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1281u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Instantaneouslinecurrent attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Instantaneouslinecurrent 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readInstantaneousActiveCurrentAttribute(): Short? {val ATTRIBUTE_ID: UInt = 1282u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readInstantaneousActiveCurrentAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 1282u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Instantaneousactivecurrent attribute not found in response" - } + } + + requireNotNull(attributeData) { "Instantaneousactivecurrent attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeInstantaneousActiveCurrentAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1282u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Instantaneousactivecurrent attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Instantaneousactivecurrent attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readInstantaneousReactiveCurrentAttribute(): Short? {val ATTRIBUTE_ID: UInt = 1283u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readInstantaneousReactiveCurrentAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 1283u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Instantaneousreactivecurrent attribute not found in response" - } + } + + requireNotNull(attributeData) { "Instantaneousreactivecurrent attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeInstantaneousReactiveCurrentAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1283u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Instantaneousreactivecurrent attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Instantaneousreactivecurrent attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readInstantaneousPowerAttribute(): Short? {val ATTRIBUTE_ID: UInt = 1284u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readInstantaneousPowerAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 1284u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Instantaneouspower attribute not found in response" - } + } + + requireNotNull(attributeData) { "Instantaneouspower attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeInstantaneousPowerAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1284u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Instantaneouspower attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Instantaneouspower attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRmsVoltageAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 1285u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRmsVoltageAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 1285u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rmsvoltage attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rmsvoltage 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeRmsVoltageAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1285u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Rmsvoltage attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Rmsvoltage 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRmsVoltageMinAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 1286u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRmsVoltageMinAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 1286u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rmsvoltagemin attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rmsvoltagemin 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeRmsVoltageMinAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1286u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Rmsvoltagemin attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Rmsvoltagemin 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRmsVoltageMaxAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 1287u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRmsVoltageMaxAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 1287u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rmsvoltagemax attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rmsvoltagemax 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeRmsVoltageMaxAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1287u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Rmsvoltagemax attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Rmsvoltagemax 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRmsCurrentAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 1288u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRmsCurrentAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 1288u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rmscurrent attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rmscurrent 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeRmsCurrentAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1288u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Rmscurrent attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Rmscurrent 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRmsCurrentMinAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 1289u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRmsCurrentMinAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 1289u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rmscurrentmin attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rmscurrentmin 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeRmsCurrentMinAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1289u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Rmscurrentmin attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Rmscurrentmin 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRmsCurrentMaxAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 1290u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRmsCurrentMaxAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 1290u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rmscurrentmax attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rmscurrentmax 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeRmsCurrentMaxAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1290u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Rmscurrentmax attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Rmscurrentmax 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readActivePowerAttribute(): Short? {val ATTRIBUTE_ID: UInt = 1291u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readActivePowerAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 1291u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Activepower attribute not found in response" - } + } + + requireNotNull(attributeData) { "Activepower attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeActivePowerAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1291u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Activepower attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Activepower attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readActivePowerMinAttribute(): Short? {val ATTRIBUTE_ID: UInt = 1292u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readActivePowerMinAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 1292u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Activepowermin attribute not found in response" - } + } + + requireNotNull(attributeData) { "Activepowermin attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeActivePowerMinAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1292u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Activepowermin attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Activepowermin attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readActivePowerMaxAttribute(): Short? {val ATTRIBUTE_ID: UInt = 1293u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readActivePowerMaxAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 1293u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Activepowermax attribute not found in response" - } + } + + requireNotNull(attributeData) { "Activepowermax attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeActivePowerMaxAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1293u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Activepowermax attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Activepowermax attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readReactivePowerAttribute(): Short? {val ATTRIBUTE_ID: UInt = 1294u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readReactivePowerAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 1294u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Reactivepower attribute not found in response" - } + } + + requireNotNull(attributeData) { "Reactivepower attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeReactivePowerAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1294u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Reactivepower attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Reactivepower attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readApparentPowerAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 1295u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readApparentPowerAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 1295u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Apparentpower attribute not found in response" - } + } + + requireNotNull(attributeData) { "Apparentpower 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeApparentPowerAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1295u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Apparentpower attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Apparentpower 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPowerFactorAttribute(): Byte? {val ATTRIBUTE_ID: UInt = 1296u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readPowerFactorAttribute(): Byte? { + val ATTRIBUTE_ID: UInt = 1296u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Powerfactor attribute not found in response" - } + } + + requireNotNull(attributeData) { "Powerfactor attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Byte? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByte(AnonymousTag) - } else { - null - } - + val decodedValue: Byte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribePowerFactorAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1296u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ByteSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ByteSubscriptionState.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) { - "Powerfactor attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Powerfactor attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Byte? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByte(AnonymousTag) - } else { - null - } + val decodedValue: Byte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAverageRmsVoltageMeasurementPeriodAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 1297u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readAverageRmsVoltageMeasurementPeriodAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 1297u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Averagermsvoltagemeasurementperiod attribute not found in response" + } + + requireNotNull(attributeData) { + "Averagermsvoltagemeasurementperiod 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun writeAverageRmsVoltageMeasurementPeriodAttribute( value: UShort, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 1297u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -5869,127 +5584,124 @@ suspend fun readAverageRmsVoltageMeasurementPeriodAttribute(): UShort? {val ATTR throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeAverageRmsVoltageMeasurementPeriodAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1297u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Averagermsvoltagemeasurementperiod attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Averagermsvoltagemeasurementperiod 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAverageRmsUnderVoltageCounterAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 1299u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readAverageRmsUnderVoltageCounterAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 1299u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Averagermsundervoltagecounter attribute not found in response" + } + + requireNotNull(attributeData) { + "Averagermsundervoltagecounter 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun writeAverageRmsUnderVoltageCounterAttribute( value: UShort, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 1299u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -6010,127 +5722,122 @@ suspend fun readAverageRmsUnderVoltageCounterAttribute(): UShort? {val ATTRIBUTE throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeAverageRmsUnderVoltageCounterAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1299u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Averagermsundervoltagecounter attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Averagermsundervoltagecounter 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRmsExtremeOverVoltagePeriodAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 1300u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRmsExtremeOverVoltagePeriodAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 1300u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rmsextremeovervoltageperiod attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rmsextremeovervoltageperiod 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun writeRmsExtremeOverVoltagePeriodAttribute( value: UShort, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 1300u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -6151,127 +5858,122 @@ suspend fun readRmsExtremeOverVoltagePeriodAttribute(): UShort? {val ATTRIBUTE_I throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeRmsExtremeOverVoltagePeriodAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1300u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Rmsextremeovervoltageperiod attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Rmsextremeovervoltageperiod 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRmsExtremeUnderVoltagePeriodAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 1301u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRmsExtremeUnderVoltagePeriodAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 1301u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rmsextremeundervoltageperiod attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rmsextremeundervoltageperiod 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun writeRmsExtremeUnderVoltagePeriodAttribute( value: UShort, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 1301u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -6292,127 +5994,122 @@ suspend fun readRmsExtremeUnderVoltagePeriodAttribute(): UShort? {val ATTRIBUTE_ throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeRmsExtremeUnderVoltagePeriodAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1301u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Rmsextremeundervoltageperiod attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Rmsextremeundervoltageperiod 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRmsVoltageSagPeriodAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 1302u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRmsVoltageSagPeriodAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 1302u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rmsvoltagesagperiod attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rmsvoltagesagperiod 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun writeRmsVoltageSagPeriodAttribute( value: UShort, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 1302u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -6433,127 +6130,122 @@ suspend fun readRmsVoltageSagPeriodAttribute(): UShort? {val ATTRIBUTE_ID: UInt throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeRmsVoltageSagPeriodAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1302u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Rmsvoltagesagperiod attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Rmsvoltagesagperiod 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRmsVoltageSwellPeriodAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 1303u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRmsVoltageSwellPeriodAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 1303u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rmsvoltageswellperiod attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rmsvoltageswellperiod 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun writeRmsVoltageSwellPeriodAttribute( value: UShort, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 1303u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -6574,709 +6266,677 @@ suspend fun readRmsVoltageSwellPeriodAttribute(): UShort? {val ATTRIBUTE_ID: UIn throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeRmsVoltageSwellPeriodAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1303u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Rmsvoltageswellperiod attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Rmsvoltageswellperiod 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAcVoltageMultiplierAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 1536u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readAcVoltageMultiplierAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 1536u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Acvoltagemultiplier attribute not found in response" - } + } + + requireNotNull(attributeData) { "Acvoltagemultiplier 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeAcVoltageMultiplierAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1536u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Acvoltagemultiplier attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Acvoltagemultiplier 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAcVoltageDivisorAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 1537u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readAcVoltageDivisorAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 1537u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Acvoltagedivisor attribute not found in response" - } + } + + requireNotNull(attributeData) { "Acvoltagedivisor 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeAcVoltageDivisorAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1537u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Acvoltagedivisor attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Acvoltagedivisor 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAcCurrentMultiplierAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 1538u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readAcCurrentMultiplierAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 1538u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Accurrentmultiplier attribute not found in response" - } + } + + requireNotNull(attributeData) { "Accurrentmultiplier 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeAcCurrentMultiplierAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1538u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Accurrentmultiplier attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Accurrentmultiplier 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAcCurrentDivisorAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 1539u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readAcCurrentDivisorAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 1539u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Accurrentdivisor attribute not found in response" - } + } + + requireNotNull(attributeData) { "Accurrentdivisor 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeAcCurrentDivisorAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1539u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Accurrentdivisor attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Accurrentdivisor 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAcPowerMultiplierAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 1540u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readAcPowerMultiplierAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 1540u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Acpowermultiplier attribute not found in response" - } + } + + requireNotNull(attributeData) { "Acpowermultiplier 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeAcPowerMultiplierAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1540u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Acpowermultiplier attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Acpowermultiplier 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAcPowerDivisorAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 1541u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readAcPowerDivisorAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 1541u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Acpowerdivisor attribute not found in response" - } + } + + requireNotNull(attributeData) { "Acpowerdivisor 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeAcPowerDivisorAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1541u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Acpowerdivisor attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Acpowerdivisor 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readOverloadAlarmsMaskAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 1792u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readOverloadAlarmsMaskAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 1792u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Overloadalarmsmask attribute not found in response" - } + } + + requireNotNull(attributeData) { "Overloadalarmsmask 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } - suspend fun writeOverloadAlarmsMaskAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeOverloadAlarmsMaskAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 1792u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -7297,321 +6957,308 @@ suspend fun readOverloadAlarmsMaskAttribute(): UByte? {val ATTRIBUTE_ID: UInt = throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeOverloadAlarmsMaskAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1792u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Overloadalarmsmask attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Overloadalarmsmask 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readVoltageOverloadAttribute(): Short? {val ATTRIBUTE_ID: UInt = 1793u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readVoltageOverloadAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 1793u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Voltageoverload attribute not found in response" - } + } + + requireNotNull(attributeData) { "Voltageoverload attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeVoltageOverloadAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1793u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Voltageoverload attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Voltageoverload attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCurrentOverloadAttribute(): Short? {val ATTRIBUTE_ID: UInt = 1794u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readCurrentOverloadAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 1794u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Currentoverload attribute not found in response" - } + } + + requireNotNull(attributeData) { "Currentoverload attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeCurrentOverloadAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1794u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Currentoverload attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Currentoverload attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAcOverloadAlarmsMaskAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2048u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readAcOverloadAlarmsMaskAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 2048u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Acoverloadalarmsmask attribute not found in response" - } + } + + requireNotNull(attributeData) { "Acoverloadalarmsmask 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun writeAcOverloadAlarmsMaskAttribute( value: UShort, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 2048u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -7632,5390 +7279,5193 @@ suspend fun readAcOverloadAlarmsMaskAttribute(): UShort? {val ATTRIBUTE_ID: UInt throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeAcOverloadAlarmsMaskAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2048u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Acoverloadalarmsmask attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Acoverloadalarmsmask 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAcVoltageOverloadAttribute(): Short? {val ATTRIBUTE_ID: UInt = 2049u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readAcVoltageOverloadAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 2049u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Acvoltageoverload attribute not found in response" - } + } + + requireNotNull(attributeData) { "Acvoltageoverload attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeAcVoltageOverloadAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2049u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Acvoltageoverload attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Acvoltageoverload attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAcCurrentOverloadAttribute(): Short? {val ATTRIBUTE_ID: UInt = 2050u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readAcCurrentOverloadAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 2050u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Accurrentoverload attribute not found in response" - } + } + + requireNotNull(attributeData) { "Accurrentoverload attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeAcCurrentOverloadAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2050u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Accurrentoverload attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Accurrentoverload attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAcActivePowerOverloadAttribute(): Short? {val ATTRIBUTE_ID: UInt = 2051u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readAcActivePowerOverloadAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 2051u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Acactivepoweroverload attribute not found in response" - } + } + + requireNotNull(attributeData) { "Acactivepoweroverload attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeAcActivePowerOverloadAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2051u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Acactivepoweroverload attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Acactivepoweroverload attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAcReactivePowerOverloadAttribute(): Short? {val ATTRIBUTE_ID: UInt = 2052u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readAcReactivePowerOverloadAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 2052u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Acreactivepoweroverload attribute not found in response" - } + } + + requireNotNull(attributeData) { "Acreactivepoweroverload attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeAcReactivePowerOverloadAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2052u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Acreactivepoweroverload attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Acreactivepoweroverload attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAverageRmsOverVoltageAttribute(): Short? {val ATTRIBUTE_ID: UInt = 2053u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readAverageRmsOverVoltageAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 2053u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Averagermsovervoltage attribute not found in response" - } + } + + requireNotNull(attributeData) { "Averagermsovervoltage attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeAverageRmsOverVoltageAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2053u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Averagermsovervoltage attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Averagermsovervoltage attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAverageRmsUnderVoltageAttribute(): Short? {val ATTRIBUTE_ID: UInt = 2054u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readAverageRmsUnderVoltageAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 2054u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Averagermsundervoltage attribute not found in response" - } + } + + requireNotNull(attributeData) { "Averagermsundervoltage attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeAverageRmsUnderVoltageAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2054u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Averagermsundervoltage attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Averagermsundervoltage attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRmsExtremeOverVoltageAttribute(): Short? {val ATTRIBUTE_ID: UInt = 2055u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRmsExtremeOverVoltageAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 2055u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rmsextremeovervoltage attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rmsextremeovervoltage attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeRmsExtremeOverVoltageAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2055u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Rmsextremeovervoltage attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Rmsextremeovervoltage attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRmsExtremeUnderVoltageAttribute(): Short? {val ATTRIBUTE_ID: UInt = 2056u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRmsExtremeUnderVoltageAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 2056u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rmsextremeundervoltage attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rmsextremeundervoltage attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeRmsExtremeUnderVoltageAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2056u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Rmsextremeundervoltage attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Rmsextremeundervoltage attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRmsVoltageSagAttribute(): Short? {val ATTRIBUTE_ID: UInt = 2057u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRmsVoltageSagAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 2057u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rmsvoltagesag attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rmsvoltagesag attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeRmsVoltageSagAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2057u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Rmsvoltagesag attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Rmsvoltagesag attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRmsVoltageSwellAttribute(): Short? {val ATTRIBUTE_ID: UInt = 2058u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRmsVoltageSwellAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 2058u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rmsvoltageswell attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rmsvoltageswell attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeRmsVoltageSwellAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2058u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Rmsvoltageswell attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Rmsvoltageswell attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readLineCurrentPhaseBAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2305u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readLineCurrentPhaseBAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 2305u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Linecurrentphaseb attribute not found in response" - } + } + + requireNotNull(attributeData) { "Linecurrentphaseb 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeLineCurrentPhaseBAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2305u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Linecurrentphaseb attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Linecurrentphaseb 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readActiveCurrentPhaseBAttribute(): Short? {val ATTRIBUTE_ID: UInt = 2306u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readActiveCurrentPhaseBAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 2306u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Activecurrentphaseb attribute not found in response" - } + } + + requireNotNull(attributeData) { "Activecurrentphaseb attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeActiveCurrentPhaseBAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2306u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Activecurrentphaseb attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Activecurrentphaseb attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readReactiveCurrentPhaseBAttribute(): Short? {val ATTRIBUTE_ID: UInt = 2307u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readReactiveCurrentPhaseBAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 2307u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Reactivecurrentphaseb attribute not found in response" - } + } + + requireNotNull(attributeData) { "Reactivecurrentphaseb attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeReactiveCurrentPhaseBAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2307u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Reactivecurrentphaseb attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Reactivecurrentphaseb attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRmsVoltagePhaseBAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2309u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRmsVoltagePhaseBAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 2309u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rmsvoltagephaseb attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rmsvoltagephaseb 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeRmsVoltagePhaseBAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2309u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Rmsvoltagephaseb attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Rmsvoltagephaseb 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRmsVoltageMinPhaseBAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2310u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRmsVoltageMinPhaseBAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 2310u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rmsvoltageminphaseb attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rmsvoltageminphaseb 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeRmsVoltageMinPhaseBAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2310u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Rmsvoltageminphaseb attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Rmsvoltageminphaseb 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRmsVoltageMaxPhaseBAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2311u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRmsVoltageMaxPhaseBAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 2311u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rmsvoltagemaxphaseb attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rmsvoltagemaxphaseb 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeRmsVoltageMaxPhaseBAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2311u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Rmsvoltagemaxphaseb attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Rmsvoltagemaxphaseb 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRmsCurrentPhaseBAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2312u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRmsCurrentPhaseBAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 2312u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rmscurrentphaseb attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rmscurrentphaseb 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeRmsCurrentPhaseBAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2312u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Rmscurrentphaseb attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Rmscurrentphaseb 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRmsCurrentMinPhaseBAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2313u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRmsCurrentMinPhaseBAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 2313u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rmscurrentminphaseb attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rmscurrentminphaseb 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeRmsCurrentMinPhaseBAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2313u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Rmscurrentminphaseb attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Rmscurrentminphaseb 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRmsCurrentMaxPhaseBAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2314u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRmsCurrentMaxPhaseBAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 2314u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rmscurrentmaxphaseb attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rmscurrentmaxphaseb 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeRmsCurrentMaxPhaseBAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2314u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Rmscurrentmaxphaseb attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Rmscurrentmaxphaseb 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readActivePowerPhaseBAttribute(): Short? {val ATTRIBUTE_ID: UInt = 2315u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readActivePowerPhaseBAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 2315u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Activepowerphaseb attribute not found in response" - } + } + + requireNotNull(attributeData) { "Activepowerphaseb attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeActivePowerPhaseBAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2315u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Activepowerphaseb attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Activepowerphaseb attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readActivePowerMinPhaseBAttribute(): Short? {val ATTRIBUTE_ID: UInt = 2316u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readActivePowerMinPhaseBAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 2316u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Activepowerminphaseb attribute not found in response" - } + } + + requireNotNull(attributeData) { "Activepowerminphaseb attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeActivePowerMinPhaseBAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2316u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Activepowerminphaseb attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Activepowerminphaseb attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readActivePowerMaxPhaseBAttribute(): Short? {val ATTRIBUTE_ID: UInt = 2317u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readActivePowerMaxPhaseBAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 2317u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Activepowermaxphaseb attribute not found in response" - } + } + + requireNotNull(attributeData) { "Activepowermaxphaseb attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeActivePowerMaxPhaseBAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2317u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Activepowermaxphaseb attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Activepowermaxphaseb attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readReactivePowerPhaseBAttribute(): Short? {val ATTRIBUTE_ID: UInt = 2318u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readReactivePowerPhaseBAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 2318u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Reactivepowerphaseb attribute not found in response" - } + } + + requireNotNull(attributeData) { "Reactivepowerphaseb attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeReactivePowerPhaseBAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2318u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Reactivepowerphaseb attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Reactivepowerphaseb attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readApparentPowerPhaseBAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2319u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readApparentPowerPhaseBAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 2319u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Apparentpowerphaseb attribute not found in response" - } + } + + requireNotNull(attributeData) { "Apparentpowerphaseb 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeApparentPowerPhaseBAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2319u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Apparentpowerphaseb attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Apparentpowerphaseb 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPowerFactorPhaseBAttribute(): Byte? {val ATTRIBUTE_ID: UInt = 2320u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readPowerFactorPhaseBAttribute(): Byte? { + val ATTRIBUTE_ID: UInt = 2320u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Powerfactorphaseb attribute not found in response" - } + } + + requireNotNull(attributeData) { "Powerfactorphaseb attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Byte? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByte(AnonymousTag) - } else { - null - } - + val decodedValue: Byte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribePowerFactorPhaseBAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2320u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ByteSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ByteSubscriptionState.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) { - "Powerfactorphaseb attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Powerfactorphaseb attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Byte? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByte(AnonymousTag) - } else { - null - } + val decodedValue: Byte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAverageRmsVoltageMeasurementPeriodPhaseBAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2321u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readAverageRmsVoltageMeasurementPeriodPhaseBAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 2321u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Averagermsvoltagemeasurementperiodphaseb attribute not found in response" + } + + requireNotNull(attributeData) { + "Averagermsvoltagemeasurementperiodphaseb 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeAverageRmsVoltageMeasurementPeriodPhaseBAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2321u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Averagermsvoltagemeasurementperiodphaseb attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Averagermsvoltagemeasurementperiodphaseb 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAverageRmsOverVoltageCounterPhaseBAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2322u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readAverageRmsOverVoltageCounterPhaseBAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 2322u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Averagermsovervoltagecounterphaseb attribute not found in response" + } + + requireNotNull(attributeData) { + "Averagermsovervoltagecounterphaseb 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeAverageRmsOverVoltageCounterPhaseBAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2322u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Averagermsovervoltagecounterphaseb attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Averagermsovervoltagecounterphaseb 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAverageRmsUnderVoltageCounterPhaseBAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2323u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readAverageRmsUnderVoltageCounterPhaseBAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 2323u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Averagermsundervoltagecounterphaseb attribute not found in response" + } + + requireNotNull(attributeData) { + "Averagermsundervoltagecounterphaseb 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeAverageRmsUnderVoltageCounterPhaseBAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2323u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Averagermsundervoltagecounterphaseb attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Averagermsundervoltagecounterphaseb 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRmsExtremeOverVoltagePeriodPhaseBAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2324u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRmsExtremeOverVoltagePeriodPhaseBAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 2324u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rmsextremeovervoltageperiodphaseb attribute not found in response" + } + + requireNotNull(attributeData) { + "Rmsextremeovervoltageperiodphaseb 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeRmsExtremeOverVoltagePeriodPhaseBAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2324u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Rmsextremeovervoltageperiodphaseb attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Rmsextremeovervoltageperiodphaseb 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRmsExtremeUnderVoltagePeriodPhaseBAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2325u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRmsExtremeUnderVoltagePeriodPhaseBAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 2325u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rmsextremeundervoltageperiodphaseb attribute not found in response" + } + + requireNotNull(attributeData) { + "Rmsextremeundervoltageperiodphaseb 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeRmsExtremeUnderVoltagePeriodPhaseBAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2325u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Rmsextremeundervoltageperiodphaseb attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Rmsextremeundervoltageperiodphaseb 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRmsVoltageSagPeriodPhaseBAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2326u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRmsVoltageSagPeriodPhaseBAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 2326u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rmsvoltagesagperiodphaseb attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rmsvoltagesagperiodphaseb 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeRmsVoltageSagPeriodPhaseBAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2326u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Rmsvoltagesagperiodphaseb attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Rmsvoltagesagperiodphaseb 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRmsVoltageSwellPeriodPhaseBAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2327u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRmsVoltageSwellPeriodPhaseBAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 2327u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rmsvoltageswellperiodphaseb attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rmsvoltageswellperiodphaseb 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeRmsVoltageSwellPeriodPhaseBAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2327u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Rmsvoltageswellperiodphaseb attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Rmsvoltageswellperiodphaseb 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readLineCurrentPhaseCAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2561u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readLineCurrentPhaseCAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 2561u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Linecurrentphasec attribute not found in response" - } + } + + requireNotNull(attributeData) { "Linecurrentphasec 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeLineCurrentPhaseCAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2561u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Linecurrentphasec attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Linecurrentphasec 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readActiveCurrentPhaseCAttribute(): Short? {val ATTRIBUTE_ID: UInt = 2562u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readActiveCurrentPhaseCAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 2562u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Activecurrentphasec attribute not found in response" - } + } + + requireNotNull(attributeData) { "Activecurrentphasec attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeActiveCurrentPhaseCAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2562u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Activecurrentphasec attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Activecurrentphasec attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readReactiveCurrentPhaseCAttribute(): Short? {val ATTRIBUTE_ID: UInt = 2563u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readReactiveCurrentPhaseCAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 2563u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Reactivecurrentphasec attribute not found in response" - } + } + + requireNotNull(attributeData) { "Reactivecurrentphasec attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeReactiveCurrentPhaseCAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2563u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Reactivecurrentphasec attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Reactivecurrentphasec attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRmsVoltagePhaseCAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2565u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRmsVoltagePhaseCAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 2565u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rmsvoltagephasec attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rmsvoltagephasec 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeRmsVoltagePhaseCAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2565u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Rmsvoltagephasec attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Rmsvoltagephasec 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRmsVoltageMinPhaseCAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2566u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRmsVoltageMinPhaseCAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 2566u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rmsvoltageminphasec attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rmsvoltageminphasec 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeRmsVoltageMinPhaseCAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2566u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Rmsvoltageminphasec attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Rmsvoltageminphasec 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRmsVoltageMaxPhaseCAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2567u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRmsVoltageMaxPhaseCAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 2567u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rmsvoltagemaxphasec attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rmsvoltagemaxphasec 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeRmsVoltageMaxPhaseCAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2567u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Rmsvoltagemaxphasec attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Rmsvoltagemaxphasec 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRmsCurrentPhaseCAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2568u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRmsCurrentPhaseCAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 2568u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rmscurrentphasec attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rmscurrentphasec 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeRmsCurrentPhaseCAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2568u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Rmscurrentphasec attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Rmscurrentphasec 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRmsCurrentMinPhaseCAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2569u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRmsCurrentMinPhaseCAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 2569u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rmscurrentminphasec attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rmscurrentminphasec 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeRmsCurrentMinPhaseCAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2569u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Rmscurrentminphasec attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Rmscurrentminphasec 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRmsCurrentMaxPhaseCAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2570u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRmsCurrentMaxPhaseCAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 2570u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rmscurrentmaxphasec attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rmscurrentmaxphasec 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeRmsCurrentMaxPhaseCAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2570u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Rmscurrentmaxphasec attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Rmscurrentmaxphasec 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readActivePowerPhaseCAttribute(): Short? {val ATTRIBUTE_ID: UInt = 2571u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readActivePowerPhaseCAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 2571u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Activepowerphasec attribute not found in response" - } + } + + requireNotNull(attributeData) { "Activepowerphasec attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeActivePowerPhaseCAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2571u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Activepowerphasec attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Activepowerphasec attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readActivePowerMinPhaseCAttribute(): Short? {val ATTRIBUTE_ID: UInt = 2572u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readActivePowerMinPhaseCAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 2572u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Activepowerminphasec attribute not found in response" - } + } + + requireNotNull(attributeData) { "Activepowerminphasec attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeActivePowerMinPhaseCAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2572u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Activepowerminphasec attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Activepowerminphasec attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readActivePowerMaxPhaseCAttribute(): Short? {val ATTRIBUTE_ID: UInt = 2573u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readActivePowerMaxPhaseCAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 2573u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Activepowermaxphasec attribute not found in response" - } + } + + requireNotNull(attributeData) { "Activepowermaxphasec attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeActivePowerMaxPhaseCAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2573u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Activepowermaxphasec attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Activepowermaxphasec attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readReactivePowerPhaseCAttribute(): Short? {val ATTRIBUTE_ID: UInt = 2574u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readReactivePowerPhaseCAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 2574u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Reactivepowerphasec attribute not found in response" - } + } + + requireNotNull(attributeData) { "Reactivepowerphasec attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeReactivePowerPhaseCAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2574u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Reactivepowerphasec attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Reactivepowerphasec attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readApparentPowerPhaseCAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2575u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readApparentPowerPhaseCAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 2575u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Apparentpowerphasec attribute not found in response" - } + } + + requireNotNull(attributeData) { "Apparentpowerphasec 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeApparentPowerPhaseCAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2575u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Apparentpowerphasec attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Apparentpowerphasec 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPowerFactorPhaseCAttribute(): Byte? {val ATTRIBUTE_ID: UInt = 2576u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readPowerFactorPhaseCAttribute(): Byte? { + val ATTRIBUTE_ID: UInt = 2576u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Powerfactorphasec attribute not found in response" - } + } + + requireNotNull(attributeData) { "Powerfactorphasec attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Byte? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByte(AnonymousTag) - } else { - null - } - + val decodedValue: Byte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribePowerFactorPhaseCAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2576u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ByteSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ByteSubscriptionState.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) { - "Powerfactorphasec attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Powerfactorphasec attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Byte? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByte(AnonymousTag) - } else { - null - } + val decodedValue: Byte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAverageRmsVoltageMeasurementPeriodPhaseCAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2577u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readAverageRmsVoltageMeasurementPeriodPhaseCAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 2577u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Averagermsvoltagemeasurementperiodphasec attribute not found in response" + } + + requireNotNull(attributeData) { + "Averagermsvoltagemeasurementperiodphasec 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeAverageRmsVoltageMeasurementPeriodPhaseCAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2577u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Averagermsvoltagemeasurementperiodphasec attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Averagermsvoltagemeasurementperiodphasec 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAverageRmsOverVoltageCounterPhaseCAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2578u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readAverageRmsOverVoltageCounterPhaseCAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 2578u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Averagermsovervoltagecounterphasec attribute not found in response" + } + + requireNotNull(attributeData) { + "Averagermsovervoltagecounterphasec 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeAverageRmsOverVoltageCounterPhaseCAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2578u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Averagermsovervoltagecounterphasec attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Averagermsovervoltagecounterphasec 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAverageRmsUnderVoltageCounterPhaseCAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2579u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readAverageRmsUnderVoltageCounterPhaseCAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 2579u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Averagermsundervoltagecounterphasec attribute not found in response" + } + + requireNotNull(attributeData) { + "Averagermsundervoltagecounterphasec 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeAverageRmsUnderVoltageCounterPhaseCAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2579u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Averagermsundervoltagecounterphasec attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Averagermsundervoltagecounterphasec 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRmsExtremeOverVoltagePeriodPhaseCAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2580u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRmsExtremeOverVoltagePeriodPhaseCAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 2580u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rmsextremeovervoltageperiodphasec attribute not found in response" + } + + requireNotNull(attributeData) { + "Rmsextremeovervoltageperiodphasec 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeRmsExtremeOverVoltagePeriodPhaseCAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2580u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Rmsextremeovervoltageperiodphasec attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Rmsextremeovervoltageperiodphasec 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRmsExtremeUnderVoltagePeriodPhaseCAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2581u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRmsExtremeUnderVoltagePeriodPhaseCAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 2581u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rmsextremeundervoltageperiodphasec attribute not found in response" + } + + requireNotNull(attributeData) { + "Rmsextremeundervoltageperiodphasec 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeRmsExtremeUnderVoltagePeriodPhaseCAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2581u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Rmsextremeundervoltageperiodphasec attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Rmsextremeundervoltageperiodphasec 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRmsVoltageSagPeriodPhaseCAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2582u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRmsVoltageSagPeriodPhaseCAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 2582u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rmsvoltagesagperiodphasec attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rmsvoltagesagperiodphasec 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeRmsVoltageSagPeriodPhaseCAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2582u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Rmsvoltagesagperiodphasec attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Rmsvoltagesagperiodphasec 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRmsVoltageSwellPeriodPhaseCAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2583u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRmsVoltageSwellPeriodPhaseCAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 2583u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rmsvoltageswellperiodphasec attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rmsvoltageswellperiodphasec 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeRmsVoltageSwellPeriodPhaseCAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2583u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Rmsvoltageswellperiodphasec attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Rmsvoltageswellperiodphasec 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65528u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -13023,97 +12473,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { emit(GeneratedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65529u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -13121,97 +12570,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va emit(AcceptedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt = 65530u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -13219,97 +12665,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt emit(EventListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ID: UInt = 65531u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -13317,81 +12760,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ emit(AttributeListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -13403,80 +12841,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 65533u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -13489,7 +12924,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/ElectricalPowerMeasurementCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/ElectricalPowerMeasurementCluster.kt index 4856287ee65db5..98db5789b43596 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/ElectricalPowerMeasurementCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/ElectricalPowerMeasurementCluster.kt @@ -17,394 +17,318 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse -import matter.controller.model.AttributePath -import matter.controller.model.CommandPath +import matter.controller.UShortSubscriptionState import matter.controller.cluster.structs.* +import matter.controller.model.AttributePath import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader -import matter.tlv.TlvWriter -class ElectricalPowerMeasurementCluster(private val controller: MatterController, private val endpointId: UShort) {class AccuracyAttribute( +class ElectricalPowerMeasurementCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class AccuracyAttribute( val value: List ) sealed class AccuracyAttributeSubscriptionState { data class Success( - val value: List + val value: List ) : AccuracyAttributeSubscriptionState() - + data class Error(val exception: Exception) : AccuracyAttributeSubscriptionState() - object SubscriptionEstablished : AccuracyAttributeSubscriptionState() - } -class RangesAttribute( - val value: List? - ) + object SubscriptionEstablished : AccuracyAttributeSubscriptionState() + } + + class RangesAttribute(val value: List?) sealed class RangesAttributeSubscriptionState { - data class Success( - val value: List? - ) : RangesAttributeSubscriptionState() - + data class Success(val value: List?) : + RangesAttributeSubscriptionState() + data class Error(val exception: Exception) : RangesAttributeSubscriptionState() - object SubscriptionEstablished : RangesAttributeSubscriptionState() - } -class VoltageAttribute( - val value: Long? - ) + object SubscriptionEstablished : RangesAttributeSubscriptionState() + } + + class VoltageAttribute(val value: Long?) sealed class VoltageAttributeSubscriptionState { - data class Success( - val value: Long? - ) : VoltageAttributeSubscriptionState() - + data class Success(val value: Long?) : VoltageAttributeSubscriptionState() + data class Error(val exception: Exception) : VoltageAttributeSubscriptionState() - object SubscriptionEstablished : VoltageAttributeSubscriptionState() - } -class ActiveCurrentAttribute( - val value: Long? - ) + object SubscriptionEstablished : VoltageAttributeSubscriptionState() + } + + class ActiveCurrentAttribute(val value: Long?) sealed class ActiveCurrentAttributeSubscriptionState { - data class Success( - val value: Long? - ) : ActiveCurrentAttributeSubscriptionState() - + data class Success(val value: Long?) : ActiveCurrentAttributeSubscriptionState() + data class Error(val exception: Exception) : ActiveCurrentAttributeSubscriptionState() - object SubscriptionEstablished : ActiveCurrentAttributeSubscriptionState() - } -class ReactiveCurrentAttribute( - val value: Long? - ) + object SubscriptionEstablished : ActiveCurrentAttributeSubscriptionState() + } + + class ReactiveCurrentAttribute(val value: Long?) sealed class ReactiveCurrentAttributeSubscriptionState { - data class Success( - val value: Long? - ) : ReactiveCurrentAttributeSubscriptionState() - + data class Success(val value: Long?) : ReactiveCurrentAttributeSubscriptionState() + data class Error(val exception: Exception) : ReactiveCurrentAttributeSubscriptionState() - object SubscriptionEstablished : ReactiveCurrentAttributeSubscriptionState() - } -class ApparentCurrentAttribute( - val value: Long? - ) + object SubscriptionEstablished : ReactiveCurrentAttributeSubscriptionState() + } + + class ApparentCurrentAttribute(val value: Long?) sealed class ApparentCurrentAttributeSubscriptionState { - data class Success( - val value: Long? - ) : ApparentCurrentAttributeSubscriptionState() - + data class Success(val value: Long?) : ApparentCurrentAttributeSubscriptionState() + data class Error(val exception: Exception) : ApparentCurrentAttributeSubscriptionState() - object SubscriptionEstablished : ApparentCurrentAttributeSubscriptionState() - } -class ActivePowerAttribute( - val value: Long? - ) + object SubscriptionEstablished : ApparentCurrentAttributeSubscriptionState() + } + + class ActivePowerAttribute(val value: Long?) sealed class ActivePowerAttributeSubscriptionState { - data class Success( - val value: Long? - ) : ActivePowerAttributeSubscriptionState() - + data class Success(val value: Long?) : ActivePowerAttributeSubscriptionState() + data class Error(val exception: Exception) : ActivePowerAttributeSubscriptionState() - object SubscriptionEstablished : ActivePowerAttributeSubscriptionState() - } -class ReactivePowerAttribute( - val value: Long? - ) + object SubscriptionEstablished : ActivePowerAttributeSubscriptionState() + } + + class ReactivePowerAttribute(val value: Long?) sealed class ReactivePowerAttributeSubscriptionState { - data class Success( - val value: Long? - ) : ReactivePowerAttributeSubscriptionState() - + data class Success(val value: Long?) : ReactivePowerAttributeSubscriptionState() + data class Error(val exception: Exception) : ReactivePowerAttributeSubscriptionState() - object SubscriptionEstablished : ReactivePowerAttributeSubscriptionState() - } -class ApparentPowerAttribute( - val value: Long? - ) + object SubscriptionEstablished : ReactivePowerAttributeSubscriptionState() + } + + class ApparentPowerAttribute(val value: Long?) sealed class ApparentPowerAttributeSubscriptionState { - data class Success( - val value: Long? - ) : ApparentPowerAttributeSubscriptionState() - + data class Success(val value: Long?) : ApparentPowerAttributeSubscriptionState() + data class Error(val exception: Exception) : ApparentPowerAttributeSubscriptionState() - object SubscriptionEstablished : ApparentPowerAttributeSubscriptionState() - } -class RMSVoltageAttribute( - val value: Long? - ) + object SubscriptionEstablished : ApparentPowerAttributeSubscriptionState() + } + + class RMSVoltageAttribute(val value: Long?) sealed class RMSVoltageAttributeSubscriptionState { - data class Success( - val value: Long? - ) : RMSVoltageAttributeSubscriptionState() - + data class Success(val value: Long?) : RMSVoltageAttributeSubscriptionState() + data class Error(val exception: Exception) : RMSVoltageAttributeSubscriptionState() - object SubscriptionEstablished : RMSVoltageAttributeSubscriptionState() - } -class RMSCurrentAttribute( - val value: Long? - ) + object SubscriptionEstablished : RMSVoltageAttributeSubscriptionState() + } + + class RMSCurrentAttribute(val value: Long?) sealed class RMSCurrentAttributeSubscriptionState { - data class Success( - val value: Long? - ) : RMSCurrentAttributeSubscriptionState() - + data class Success(val value: Long?) : RMSCurrentAttributeSubscriptionState() + data class Error(val exception: Exception) : RMSCurrentAttributeSubscriptionState() - object SubscriptionEstablished : RMSCurrentAttributeSubscriptionState() - } -class RMSPowerAttribute( - val value: Long? - ) + object SubscriptionEstablished : RMSCurrentAttributeSubscriptionState() + } + + class RMSPowerAttribute(val value: Long?) sealed class RMSPowerAttributeSubscriptionState { - data class Success( - val value: Long? - ) : RMSPowerAttributeSubscriptionState() - + data class Success(val value: Long?) : RMSPowerAttributeSubscriptionState() + data class Error(val exception: Exception) : RMSPowerAttributeSubscriptionState() - object SubscriptionEstablished : RMSPowerAttributeSubscriptionState() - } -class FrequencyAttribute( - val value: Long? - ) + object SubscriptionEstablished : RMSPowerAttributeSubscriptionState() + } + + class FrequencyAttribute(val value: Long?) sealed class FrequencyAttributeSubscriptionState { - data class Success( - val value: Long? - ) : FrequencyAttributeSubscriptionState() - + data class Success(val value: Long?) : FrequencyAttributeSubscriptionState() + data class Error(val exception: Exception) : FrequencyAttributeSubscriptionState() - object SubscriptionEstablished : FrequencyAttributeSubscriptionState() - } -class HarmonicCurrentsAttribute( + object SubscriptionEstablished : FrequencyAttributeSubscriptionState() + } + + class HarmonicCurrentsAttribute( val value: List? ) sealed class HarmonicCurrentsAttributeSubscriptionState { data class Success( - val value: List? + val value: List? ) : HarmonicCurrentsAttributeSubscriptionState() - + data class Error(val exception: Exception) : HarmonicCurrentsAttributeSubscriptionState() - object SubscriptionEstablished : HarmonicCurrentsAttributeSubscriptionState() - } -class HarmonicPhasesAttribute( + object SubscriptionEstablished : HarmonicCurrentsAttributeSubscriptionState() + } + + class HarmonicPhasesAttribute( val value: List? ) sealed class HarmonicPhasesAttributeSubscriptionState { data class Success( - val value: List? + val value: List? ) : HarmonicPhasesAttributeSubscriptionState() - + data class Error(val exception: Exception) : HarmonicPhasesAttributeSubscriptionState() - object SubscriptionEstablished : HarmonicPhasesAttributeSubscriptionState() - } -class PowerFactorAttribute( - val value: Long? - ) + object SubscriptionEstablished : HarmonicPhasesAttributeSubscriptionState() + } + + class PowerFactorAttribute(val value: Long?) sealed class PowerFactorAttributeSubscriptionState { - data class Success( - val value: Long? - ) : PowerFactorAttributeSubscriptionState() - + data class Success(val value: Long?) : PowerFactorAttributeSubscriptionState() + data class Error(val exception: Exception) : PowerFactorAttributeSubscriptionState() - object SubscriptionEstablished : PowerFactorAttributeSubscriptionState() - } -class NeutralCurrentAttribute( - val value: Long? - ) + object SubscriptionEstablished : PowerFactorAttributeSubscriptionState() + } + + class NeutralCurrentAttribute(val value: Long?) sealed class NeutralCurrentAttributeSubscriptionState { - data class Success( - val value: Long? - ) : NeutralCurrentAttributeSubscriptionState() - + data class Success(val value: Long?) : NeutralCurrentAttributeSubscriptionState() + data class Error(val exception: Exception) : NeutralCurrentAttributeSubscriptionState() - object SubscriptionEstablished : NeutralCurrentAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : NeutralCurrentAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } -suspend fun readPowerModeAttribute(): 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) - ) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } + + suspend fun readPowerModeAttribute(): 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}") - } + 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) { - "Powermode attribute not found in response" - } + } + + requireNotNull(attributeData) { "Powermode 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 subscribePowerModeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Powermode attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Powermode attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -416,80 +340,77 @@ suspend fun readPowerModeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 0u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNumberOfMeasurementTypesAttribute(): UByte {val ATTRIBUTE_ID: UInt = 1u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNumberOfMeasurementTypesAttribute(): 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 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}") - } + 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) { - "Numberofmeasurementtypes attribute not found in response" - } + } + + requireNotNull(attributeData) { "Numberofmeasurementtypes 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 subscribeNumberOfMeasurementTypesAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Numberofmeasurementtypes attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Numberofmeasurementtypes attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -502,97 +423,104 @@ suspend fun readNumberOfMeasurementTypesAttribute(): UByte {val ATTRIBUTE_ID: UI emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAccuracyAttribute(): AccuracyAttribute {val ATTRIBUTE_ID: UInt = 2u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readAccuracyAttribute(): AccuracyAttribute { + 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 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}") - } + 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) { - "Accuracy attribute not found in response" - } + } + + requireNotNull(attributeData) { "Accuracy 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(ElectricalPowerMeasurementClusterMeasurementAccuracyStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add( + ElectricalPowerMeasurementClusterMeasurementAccuracyStruct.fromTlv( + AnonymousTag, + tlvReader, + ) + ) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AccuracyAttribute(decodedValue) } suspend fun subscribeAccuracyAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(AccuracyAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + AccuracyAttributeSubscriptionState.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) { - "Accuracy attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Accuracy 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(ElectricalPowerMeasurementClusterMeasurementAccuracyStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add( + ElectricalPowerMeasurementClusterMeasurementAccuracyStruct.fromTlv( + AnonymousTag, + tlvReader, + ) + ) + } + tlvReader.exitContainer() + } emit(AccuracyAttributeSubscriptionState.Success(decodedValue)) } @@ -600,1827 +528,1770 @@ suspend fun readAccuracyAttribute(): AccuracyAttribute {val ATTRIBUTE_ID: UInt = emit(AccuracyAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRangesAttribute(): RangesAttribute {val ATTRIBUTE_ID: UInt = 3u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRangesAttribute(): RangesAttribute { + 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 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}") - } + 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) { - "Ranges attribute not found in response" - } + } + + requireNotNull(attributeData) { "Ranges attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(ElectricalPowerMeasurementClusterMeasurementRangeStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add( + ElectricalPowerMeasurementClusterMeasurementRangeStruct.fromTlv( + AnonymousTag, + tlvReader, + ) + ) + } + tlvReader.exitContainer() + } + } else { + null } - tlvReader.exitContainer() - } - } else { - null - } - return RangesAttribute(decodedValue) } suspend fun subscribeRangesAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(RangesAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + RangesAttributeSubscriptionState.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) { - "Ranges attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Ranges attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(ElectricalPowerMeasurementClusterMeasurementRangeStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { - emit(RangesAttributeSubscriptionState.Success(it)) - } - + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add( + ElectricalPowerMeasurementClusterMeasurementRangeStruct.fromTlv( + AnonymousTag, + tlvReader, + ) + ) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { emit(RangesAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(RangesAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readVoltageAttribute(): VoltageAttribute {val ATTRIBUTE_ID: UInt = 4u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readVoltageAttribute(): VoltageAttribute { + 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 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}") - } + 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) { - "Voltage attribute not found in response" - } + } + + requireNotNull(attributeData) { "Voltage attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Long? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return VoltageAttribute(decodedValue) } suspend fun subscribeVoltageAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(VoltageAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + VoltageAttributeSubscriptionState.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) { - "Voltage attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Voltage attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(VoltageAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Long? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(VoltageAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(VoltageAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readActiveCurrentAttribute(): ActiveCurrentAttribute {val ATTRIBUTE_ID: UInt = 5u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readActiveCurrentAttribute(): ActiveCurrentAttribute { + 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 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}") - } + 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) { - "Activecurrent attribute not found in response" - } + } + + requireNotNull(attributeData) { "Activecurrent attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Long? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return ActiveCurrentAttribute(decodedValue) } suspend fun subscribeActiveCurrentAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ActiveCurrentAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ActiveCurrentAttributeSubscriptionState.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) { - "Activecurrent attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Activecurrent attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(ActiveCurrentAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Long? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(ActiveCurrentAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ActiveCurrentAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readReactiveCurrentAttribute(): ReactiveCurrentAttribute {val ATTRIBUTE_ID: UInt = 6u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readReactiveCurrentAttribute(): ReactiveCurrentAttribute { + 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 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}") - } + 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) { - "Reactivecurrent attribute not found in response" - } + } + + requireNotNull(attributeData) { "Reactivecurrent attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Long? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return ReactiveCurrentAttribute(decodedValue) } suspend fun subscribeReactiveCurrentAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ReactiveCurrentAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ReactiveCurrentAttributeSubscriptionState.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) { - "Reactivecurrent attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Reactivecurrent attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(ReactiveCurrentAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Long? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(ReactiveCurrentAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ReactiveCurrentAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readApparentCurrentAttribute(): ApparentCurrentAttribute {val ATTRIBUTE_ID: UInt = 7u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readApparentCurrentAttribute(): ApparentCurrentAttribute { + 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 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}") - } + 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) { - "Apparentcurrent attribute not found in response" - } + } + + requireNotNull(attributeData) { "Apparentcurrent attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Long? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return ApparentCurrentAttribute(decodedValue) } suspend fun subscribeApparentCurrentAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ApparentCurrentAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ApparentCurrentAttributeSubscriptionState.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) { - "Apparentcurrent attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Apparentcurrent attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(ApparentCurrentAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Long? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(ApparentCurrentAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ApparentCurrentAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readActivePowerAttribute(): ActivePowerAttribute {val ATTRIBUTE_ID: UInt = 8u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readActivePowerAttribute(): ActivePowerAttribute { + val ATTRIBUTE_ID: UInt = 8u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Activepower attribute not found in response" - } + } + + requireNotNull(attributeData) { "Activepower attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = if (!tlvReader.isNull()) { - tlvReader.getLong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Long? = + if (!tlvReader.isNull()) { + tlvReader.getLong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return ActivePowerAttribute(decodedValue) } suspend fun subscribeActivePowerAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ActivePowerAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ActivePowerAttributeSubscriptionState.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) { - "Activepower attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Activepower attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = if (!tlvReader.isNull()) { - tlvReader.getLong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Long? = + if (!tlvReader.isNull()) { + tlvReader.getLong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(ActivePowerAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ActivePowerAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ActivePowerAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readReactivePowerAttribute(): ReactivePowerAttribute {val ATTRIBUTE_ID: UInt = 9u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readReactivePowerAttribute(): ReactivePowerAttribute { + val ATTRIBUTE_ID: UInt = 9u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Reactivepower attribute not found in response" - } + } + + requireNotNull(attributeData) { "Reactivepower attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Long? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return ReactivePowerAttribute(decodedValue) } suspend fun subscribeReactivePowerAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ReactivePowerAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ReactivePowerAttributeSubscriptionState.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) { - "Reactivepower attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Reactivepower attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(ReactivePowerAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Long? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(ReactivePowerAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ReactivePowerAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readApparentPowerAttribute(): ApparentPowerAttribute {val ATTRIBUTE_ID: UInt = 10u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readApparentPowerAttribute(): ApparentPowerAttribute { + val ATTRIBUTE_ID: UInt = 10u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Apparentpower attribute not found in response" - } + } + + requireNotNull(attributeData) { "Apparentpower attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Long? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return ApparentPowerAttribute(decodedValue) } suspend fun subscribeApparentPowerAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ApparentPowerAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ApparentPowerAttributeSubscriptionState.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) { - "Apparentpower attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Apparentpower attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(ApparentPowerAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Long? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(ApparentPowerAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ApparentPowerAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRMSVoltageAttribute(): RMSVoltageAttribute {val ATTRIBUTE_ID: UInt = 11u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRMSVoltageAttribute(): RMSVoltageAttribute { + val ATTRIBUTE_ID: UInt = 11u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rmsvoltage attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rmsvoltage attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Long? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return RMSVoltageAttribute(decodedValue) } suspend fun subscribeRMSVoltageAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 11u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(RMSVoltageAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + RMSVoltageAttributeSubscriptionState.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) { - "Rmsvoltage attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Rmsvoltage attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(RMSVoltageAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Long? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(RMSVoltageAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(RMSVoltageAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRMSCurrentAttribute(): RMSCurrentAttribute {val ATTRIBUTE_ID: UInt = 12u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRMSCurrentAttribute(): RMSCurrentAttribute { + val ATTRIBUTE_ID: UInt = 12u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rmscurrent attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rmscurrent attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Long? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return RMSCurrentAttribute(decodedValue) } suspend fun subscribeRMSCurrentAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 12u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(RMSCurrentAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + RMSCurrentAttributeSubscriptionState.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) { - "Rmscurrent attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Rmscurrent attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(RMSCurrentAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Long? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(RMSCurrentAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(RMSCurrentAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRMSPowerAttribute(): RMSPowerAttribute {val ATTRIBUTE_ID: UInt = 13u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRMSPowerAttribute(): RMSPowerAttribute { + val ATTRIBUTE_ID: UInt = 13u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rmspower attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rmspower attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Long? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return RMSPowerAttribute(decodedValue) } suspend fun subscribeRMSPowerAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 13u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(RMSPowerAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + RMSPowerAttributeSubscriptionState.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) { - "Rmspower attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Rmspower attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(RMSPowerAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Long? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(RMSPowerAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(RMSPowerAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readFrequencyAttribute(): FrequencyAttribute {val ATTRIBUTE_ID: UInt = 14u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readFrequencyAttribute(): FrequencyAttribute { + val ATTRIBUTE_ID: UInt = 14u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Frequency attribute not found in response" - } + } + + requireNotNull(attributeData) { "Frequency attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Long? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return FrequencyAttribute(decodedValue) } suspend fun subscribeFrequencyAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 14u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(FrequencyAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + FrequencyAttributeSubscriptionState.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) { - "Frequency attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Frequency attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(FrequencyAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Long? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(FrequencyAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(FrequencyAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readHarmonicCurrentsAttribute(): HarmonicCurrentsAttribute {val ATTRIBUTE_ID: UInt = 15u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readHarmonicCurrentsAttribute(): HarmonicCurrentsAttribute { + val ATTRIBUTE_ID: UInt = 15u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Harmoniccurrents attribute not found in response" - } + } + + requireNotNull(attributeData) { "Harmoniccurrents attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(ElectricalPowerMeasurementClusterHarmonicMeasurementStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add( + ElectricalPowerMeasurementClusterHarmonicMeasurementStruct.fromTlv( + AnonymousTag, + tlvReader, + ) + ) + } + tlvReader.exitContainer() + } + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null } - tlvReader.exitContainer() - } - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - return HarmonicCurrentsAttribute(decodedValue) } suspend fun subscribeHarmonicCurrentsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 15u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(HarmonicCurrentsAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + HarmonicCurrentsAttributeSubscriptionState.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) { - "Harmoniccurrents attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Harmoniccurrents attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(ElectricalPowerMeasurementClusterHarmonicMeasurementStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(HarmonicCurrentsAttributeSubscriptionState.Success(it)) - } - + val decodedValue: List? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add( + ElectricalPowerMeasurementClusterHarmonicMeasurementStruct.fromTlv( + AnonymousTag, + tlvReader, + ) + ) + } + tlvReader.exitContainer() + } + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(HarmonicCurrentsAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(HarmonicCurrentsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readHarmonicPhasesAttribute(): HarmonicPhasesAttribute {val ATTRIBUTE_ID: UInt = 16u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readHarmonicPhasesAttribute(): HarmonicPhasesAttribute { + val ATTRIBUTE_ID: UInt = 16u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Harmonicphases attribute not found in response" - } + } + + requireNotNull(attributeData) { "Harmonicphases attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(ElectricalPowerMeasurementClusterHarmonicMeasurementStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add( + ElectricalPowerMeasurementClusterHarmonicMeasurementStruct.fromTlv( + AnonymousTag, + tlvReader, + ) + ) + } + tlvReader.exitContainer() + } + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null } - tlvReader.exitContainer() - } - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - return HarmonicPhasesAttribute(decodedValue) } suspend fun subscribeHarmonicPhasesAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(HarmonicPhasesAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + HarmonicPhasesAttributeSubscriptionState.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) { - "Harmonicphases attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Harmonicphases attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(ElectricalPowerMeasurementClusterHarmonicMeasurementStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(HarmonicPhasesAttributeSubscriptionState.Success(it)) - } - + val decodedValue: List? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add( + ElectricalPowerMeasurementClusterHarmonicMeasurementStruct.fromTlv( + AnonymousTag, + tlvReader, + ) + ) + } + tlvReader.exitContainer() + } + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(HarmonicPhasesAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(HarmonicPhasesAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPowerFactorAttribute(): PowerFactorAttribute {val ATTRIBUTE_ID: UInt = 17u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readPowerFactorAttribute(): PowerFactorAttribute { + val ATTRIBUTE_ID: UInt = 17u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Powerfactor attribute not found in response" - } + } + + requireNotNull(attributeData) { "Powerfactor attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Long? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return PowerFactorAttribute(decodedValue) } suspend fun subscribePowerFactorAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 17u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(PowerFactorAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + PowerFactorAttributeSubscriptionState.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) { - "Powerfactor attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Powerfactor attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(PowerFactorAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Long? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(PowerFactorAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(PowerFactorAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNeutralCurrentAttribute(): NeutralCurrentAttribute {val ATTRIBUTE_ID: UInt = 18u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNeutralCurrentAttribute(): NeutralCurrentAttribute { + val ATTRIBUTE_ID: UInt = 18u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Neutralcurrent attribute not found in response" - } + } + + requireNotNull(attributeData) { "Neutralcurrent attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Long? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return NeutralCurrentAttribute(decodedValue) } suspend fun subscribeNeutralCurrentAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 18u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(NeutralCurrentAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + NeutralCurrentAttributeSubscriptionState.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) { - "Neutralcurrent attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Neutralcurrent attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(NeutralCurrentAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Long? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(NeutralCurrentAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(NeutralCurrentAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65528u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -2428,97 +2299,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { emit(GeneratedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65529u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -2526,97 +2396,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va emit(AcceptedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt = 65530u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -2624,97 +2491,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt emit(EventListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ID: UInt = 65531u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -2722,81 +2586,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ emit(AttributeListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -2808,80 +2667,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 65533u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -2894,7 +2750,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/EnergyEvseCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/EnergyEvseCluster.kt index 0d532702cc4872..747300fe68f86c 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/EnergyEvseCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/EnergyEvseCluster.kt @@ -17,45 +17,30 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse +import matter.controller.LongSubscriptionState import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter @@ -63,276 +48,225 @@ class EnergyEvseCluster(private val controller: MatterController, private val en class GetTargetsResponse( val chargingTargetSchedules: List ) -class StateAttribute( - val value: UByte? - ) + + class StateAttribute(val value: UByte?) sealed class StateAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : StateAttributeSubscriptionState() - + data class Success(val value: UByte?) : StateAttributeSubscriptionState() + data class Error(val exception: Exception) : StateAttributeSubscriptionState() - object SubscriptionEstablished : StateAttributeSubscriptionState() - } -class ChargingEnabledUntilAttribute( - val value: UInt? - ) + object SubscriptionEstablished : StateAttributeSubscriptionState() + } + + class ChargingEnabledUntilAttribute(val value: UInt?) sealed class ChargingEnabledUntilAttributeSubscriptionState { - data class Success( - val value: UInt? - ) : ChargingEnabledUntilAttributeSubscriptionState() - + data class Success(val value: UInt?) : ChargingEnabledUntilAttributeSubscriptionState() + data class Error(val exception: Exception) : ChargingEnabledUntilAttributeSubscriptionState() - object SubscriptionEstablished : ChargingEnabledUntilAttributeSubscriptionState() - } -class DischargingEnabledUntilAttribute( - val value: UInt? - ) + object SubscriptionEstablished : ChargingEnabledUntilAttributeSubscriptionState() + } + + class DischargingEnabledUntilAttribute(val value: UInt?) sealed class DischargingEnabledUntilAttributeSubscriptionState { - data class Success( - val value: UInt? - ) : DischargingEnabledUntilAttributeSubscriptionState() - - data class Error(val exception: Exception) : DischargingEnabledUntilAttributeSubscriptionState() - - object SubscriptionEstablished : DischargingEnabledUntilAttributeSubscriptionState() - } -class NextChargeStartTimeAttribute( - val value: UInt? - ) + data class Success(val value: UInt?) : DischargingEnabledUntilAttributeSubscriptionState() + + data class Error(val exception: Exception) : + DischargingEnabledUntilAttributeSubscriptionState() + + object SubscriptionEstablished : DischargingEnabledUntilAttributeSubscriptionState() + } + + class NextChargeStartTimeAttribute(val value: UInt?) sealed class NextChargeStartTimeAttributeSubscriptionState { - data class Success( - val value: UInt? - ) : NextChargeStartTimeAttributeSubscriptionState() - + data class Success(val value: UInt?) : NextChargeStartTimeAttributeSubscriptionState() + data class Error(val exception: Exception) : NextChargeStartTimeAttributeSubscriptionState() - object SubscriptionEstablished : NextChargeStartTimeAttributeSubscriptionState() - } -class NextChargeTargetTimeAttribute( - val value: UInt? - ) + object SubscriptionEstablished : NextChargeStartTimeAttributeSubscriptionState() + } + + class NextChargeTargetTimeAttribute(val value: UInt?) sealed class NextChargeTargetTimeAttributeSubscriptionState { - data class Success( - val value: UInt? - ) : NextChargeTargetTimeAttributeSubscriptionState() - + data class Success(val value: UInt?) : NextChargeTargetTimeAttributeSubscriptionState() + data class Error(val exception: Exception) : NextChargeTargetTimeAttributeSubscriptionState() - object SubscriptionEstablished : NextChargeTargetTimeAttributeSubscriptionState() - } -class NextChargeRequiredEnergyAttribute( - val value: Long? - ) + object SubscriptionEstablished : NextChargeTargetTimeAttributeSubscriptionState() + } + + class NextChargeRequiredEnergyAttribute(val value: Long?) sealed class NextChargeRequiredEnergyAttributeSubscriptionState { - data class Success( - val value: Long? - ) : NextChargeRequiredEnergyAttributeSubscriptionState() - - data class Error(val exception: Exception) : NextChargeRequiredEnergyAttributeSubscriptionState() - - object SubscriptionEstablished : NextChargeRequiredEnergyAttributeSubscriptionState() - } -class NextChargeTargetSoCAttribute( - val value: UByte? - ) + data class Success(val value: Long?) : NextChargeRequiredEnergyAttributeSubscriptionState() + + data class Error(val exception: Exception) : + NextChargeRequiredEnergyAttributeSubscriptionState() + + object SubscriptionEstablished : NextChargeRequiredEnergyAttributeSubscriptionState() + } + + class NextChargeTargetSoCAttribute(val value: UByte?) sealed class NextChargeTargetSoCAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : NextChargeTargetSoCAttributeSubscriptionState() - + data class Success(val value: UByte?) : NextChargeTargetSoCAttributeSubscriptionState() + data class Error(val exception: Exception) : NextChargeTargetSoCAttributeSubscriptionState() - object SubscriptionEstablished : NextChargeTargetSoCAttributeSubscriptionState() - } -class ApproximateEVEfficiencyAttribute( - val value: UShort? - ) + object SubscriptionEstablished : NextChargeTargetSoCAttributeSubscriptionState() + } + + class ApproximateEVEfficiencyAttribute(val value: UShort?) sealed class ApproximateEVEfficiencyAttributeSubscriptionState { - data class Success( - val value: UShort? - ) : ApproximateEVEfficiencyAttributeSubscriptionState() - - data class Error(val exception: Exception) : ApproximateEVEfficiencyAttributeSubscriptionState() - - object SubscriptionEstablished : ApproximateEVEfficiencyAttributeSubscriptionState() - } -class StateOfChargeAttribute( - val value: UByte? - ) + data class Success(val value: UShort?) : ApproximateEVEfficiencyAttributeSubscriptionState() + + data class Error(val exception: Exception) : + ApproximateEVEfficiencyAttributeSubscriptionState() + + object SubscriptionEstablished : ApproximateEVEfficiencyAttributeSubscriptionState() + } + + class StateOfChargeAttribute(val value: UByte?) sealed class StateOfChargeAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : StateOfChargeAttributeSubscriptionState() - + data class Success(val value: UByte?) : StateOfChargeAttributeSubscriptionState() + data class Error(val exception: Exception) : StateOfChargeAttributeSubscriptionState() - object SubscriptionEstablished : StateOfChargeAttributeSubscriptionState() - } -class BatteryCapacityAttribute( - val value: Long? - ) + object SubscriptionEstablished : StateOfChargeAttributeSubscriptionState() + } + + class BatteryCapacityAttribute(val value: Long?) sealed class BatteryCapacityAttributeSubscriptionState { - data class Success( - val value: Long? - ) : BatteryCapacityAttributeSubscriptionState() - + data class Success(val value: Long?) : BatteryCapacityAttributeSubscriptionState() + data class Error(val exception: Exception) : BatteryCapacityAttributeSubscriptionState() - object SubscriptionEstablished : BatteryCapacityAttributeSubscriptionState() - } -class VehicleIDAttribute( - val value: String? - ) + object SubscriptionEstablished : BatteryCapacityAttributeSubscriptionState() + } + + class VehicleIDAttribute(val value: String?) sealed class VehicleIDAttributeSubscriptionState { - data class Success( - val value: String? - ) : VehicleIDAttributeSubscriptionState() - + data class Success(val value: String?) : VehicleIDAttributeSubscriptionState() + data class Error(val exception: Exception) : VehicleIDAttributeSubscriptionState() - object SubscriptionEstablished : VehicleIDAttributeSubscriptionState() - } -class SessionIDAttribute( - val value: UInt? - ) + object SubscriptionEstablished : VehicleIDAttributeSubscriptionState() + } + + class SessionIDAttribute(val value: UInt?) sealed class SessionIDAttributeSubscriptionState { - data class Success( - val value: UInt? - ) : SessionIDAttributeSubscriptionState() - + data class Success(val value: UInt?) : SessionIDAttributeSubscriptionState() + data class Error(val exception: Exception) : SessionIDAttributeSubscriptionState() - object SubscriptionEstablished : SessionIDAttributeSubscriptionState() - } -class SessionDurationAttribute( - val value: UInt? - ) + object SubscriptionEstablished : SessionIDAttributeSubscriptionState() + } + + class SessionDurationAttribute(val value: UInt?) sealed class SessionDurationAttributeSubscriptionState { - data class Success( - val value: UInt? - ) : SessionDurationAttributeSubscriptionState() - + data class Success(val value: UInt?) : SessionDurationAttributeSubscriptionState() + data class Error(val exception: Exception) : SessionDurationAttributeSubscriptionState() - object SubscriptionEstablished : SessionDurationAttributeSubscriptionState() - } -class SessionEnergyChargedAttribute( - val value: Long? - ) + object SubscriptionEstablished : SessionDurationAttributeSubscriptionState() + } + + class SessionEnergyChargedAttribute(val value: Long?) sealed class SessionEnergyChargedAttributeSubscriptionState { - data class Success( - val value: Long? - ) : SessionEnergyChargedAttributeSubscriptionState() - + data class Success(val value: Long?) : SessionEnergyChargedAttributeSubscriptionState() + data class Error(val exception: Exception) : SessionEnergyChargedAttributeSubscriptionState() - object SubscriptionEstablished : SessionEnergyChargedAttributeSubscriptionState() - } -class SessionEnergyDischargedAttribute( - val value: Long? - ) + object SubscriptionEstablished : SessionEnergyChargedAttributeSubscriptionState() + } + + class SessionEnergyDischargedAttribute(val value: Long?) sealed class SessionEnergyDischargedAttributeSubscriptionState { - data class Success( - val value: Long? - ) : SessionEnergyDischargedAttributeSubscriptionState() - - data class Error(val exception: Exception) : SessionEnergyDischargedAttributeSubscriptionState() - - object SubscriptionEstablished : SessionEnergyDischargedAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + data class Success(val value: Long?) : SessionEnergyDischargedAttributeSubscriptionState() + + data class Error(val exception: Exception) : + SessionEnergyDischargedAttributeSubscriptionState() + + object SubscriptionEstablished : SessionEnergyDischargedAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } suspend fun disable(timedInvokeTimeout: Duration) { val commandId: UInt = 1u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun enableCharging(chargingEnabledUntil: UInt? - ,minimumChargeCurrent: Long - ,maximumChargeCurrent: Long - ,timedInvokeTimeout: Duration) { + suspend fun enableCharging( + chargingEnabledUntil: UInt?, + minimumChargeCurrent: Long, + maximumChargeCurrent: Long, + timedInvokeTimeout: Duration, + ) { val commandId: UInt = 2u val tlvWriter = TlvWriter() @@ -347,23 +281,25 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_MINIMUM_CHARGE_CURRENT_REQ), minimumChargeCurrent) val TAG_MAXIMUM_CHARGE_CURRENT_REQ: Int = 2 - tlvWriter.put(ContextSpecificTag(TAG_MAXIMUM_CHARGE_CURRENT_REQ), maximumChargeCurrent) + tlvWriter.put(ContextSpecificTag(TAG_MAXIMUM_CHARGE_CURRENT_REQ), maximumChargeCurrent) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun enableDischarging(dischargingEnabledUntil: UInt? - ,maximumDischargeCurrent: Long - ,timedInvokeTimeout: Duration) { + suspend fun enableDischarging( + dischargingEnabledUntil: UInt?, + maximumDischargeCurrent: Long, + timedInvokeTimeout: Duration, + ) { val commandId: UInt = 3u val tlvWriter = TlvWriter() @@ -375,14 +311,14 @@ class AttributeListAttribute( } val TAG_MAXIMUM_DISCHARGE_CURRENT_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_MAXIMUM_DISCHARGE_CURRENT_REQ), maximumDischargeCurrent) + tlvWriter.put(ContextSpecificTag(TAG_MAXIMUM_DISCHARGE_CURRENT_REQ), maximumDischargeCurrent) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -393,22 +329,24 @@ class AttributeListAttribute( val commandId: UInt = 4u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun setTargets(chargingTargetSchedules: List - ,timedInvokeTimeout: Duration) { + suspend fun setTargets( + chargingTargetSchedules: List, + timedInvokeTimeout: Duration, + ) { val commandId: UInt = 5u val tlvWriter = TlvWriter() @@ -416,17 +354,17 @@ class AttributeListAttribute( val TAG_CHARGING_TARGET_SCHEDULES_REQ: Int = 0 tlvWriter.startArray(ContextSpecificTag(TAG_CHARGING_TARGET_SCHEDULES_REQ)) - for (item in chargingTargetSchedules.iterator()) { - item.toTlv(AnonymousTag, tlvWriter) - } - tlvWriter.endArray() + for (item in chargingTargetSchedules.iterator()) { + item.toTlv(AnonymousTag, tlvWriter) + } + tlvWriter.endArray() tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -437,14 +375,14 @@ class AttributeListAttribute( val commandId: UInt = 6u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -454,229 +392,211 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_CHARGING_TARGET_SCHEDULES: Int = 0 var chargingTargetSchedules_decoded: List? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_CHARGING_TARGET_SCHEDULES)) {chargingTargetSchedules_decoded = buildList { - tlvReader.enterArray(tag) - while(!tlvReader.isEndOfContainer()) { - add(EnergyEvseClusterChargingTargetScheduleStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - }} - - - else { + if (tag == ContextSpecificTag(TAG_CHARGING_TARGET_SCHEDULES)) { + chargingTargetSchedules_decoded = + buildList { + tlvReader.enterArray(tag) + while (!tlvReader.isEndOfContainer()) { + add(EnergyEvseClusterChargingTargetScheduleStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { tlvReader.skipElement() } } - - if (chargingTargetSchedules_decoded == null) { - throw IllegalStateException("chargingTargetSchedules not found in TLV") + throw IllegalStateException("chargingTargetSchedules not found in TLV") } - tlvReader.exitContainer() - return GetTargetsResponse( - chargingTargetSchedules_decoded - ) + return GetTargetsResponse(chargingTargetSchedules_decoded) } suspend fun clearTargets(timedInvokeTimeout: Duration) { val commandId: UInt = 7u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } -suspend fun readStateAttribute(): StateAttribute {val ATTRIBUTE_ID: UInt = 0u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readStateAttribute(): StateAttribute { + 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 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}") - } + 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) { - "State attribute not found in response" - } + } + + requireNotNull(attributeData) { "State attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return StateAttribute(decodedValue) } suspend fun subscribeStateAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StateAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StateAttributeSubscriptionState.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) { - "State attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "State 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.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(StateAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(StateAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(StateAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readSupplyStateAttribute(): UByte {val ATTRIBUTE_ID: UInt = 1u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readSupplyStateAttribute(): 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 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}") - } + 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) { - "Supplystate attribute not found in response" - } + } + + requireNotNull(attributeData) { "Supplystate 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 subscribeSupplyStateAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Supplystate attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Supplystate attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -688,81 +608,76 @@ suspend fun readSupplyStateAttribute(): UByte {val ATTRIBUTE_ID: UInt = 1u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readFaultStateAttribute(): UByte {val ATTRIBUTE_ID: UInt = 2u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readFaultStateAttribute(): UByte { + 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 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}") - } + 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) { - "Faultstate attribute not found in response" - } + } + + requireNotNull(attributeData) { "Faultstate 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 subscribeFaultStateAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Faultstate attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Faultstate attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -774,286 +689,275 @@ suspend fun readFaultStateAttribute(): UByte {val ATTRIBUTE_ID: UInt = 2u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readChargingEnabledUntilAttribute(): ChargingEnabledUntilAttribute {val ATTRIBUTE_ID: UInt = 3u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readChargingEnabledUntilAttribute(): ChargingEnabledUntilAttribute { + 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 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}") - } + 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) { - "Chargingenableduntil attribute not found in response" - } + } + + requireNotNull(attributeData) { "Chargingenableduntil attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - tlvReader.getUInt(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + tlvReader.getUInt(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return ChargingEnabledUntilAttribute(decodedValue) } suspend fun subscribeChargingEnabledUntilAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ChargingEnabledUntilAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ChargingEnabledUntilAttributeSubscriptionState.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) { - "Chargingenableduntil attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Chargingenableduntil attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - tlvReader.getUInt(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + tlvReader.getUInt(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(ChargingEnabledUntilAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ChargingEnabledUntilAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ChargingEnabledUntilAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readDischargingEnabledUntilAttribute(): DischargingEnabledUntilAttribute {val ATTRIBUTE_ID: UInt = 4u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readDischargingEnabledUntilAttribute(): DischargingEnabledUntilAttribute { + 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 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}") - } + 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) { - "Dischargingenableduntil attribute not found in response" - } + } + + requireNotNull(attributeData) { "Dischargingenableduntil attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return DischargingEnabledUntilAttribute(decodedValue) } suspend fun subscribeDischargingEnabledUntilAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(DischargingEnabledUntilAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + DischargingEnabledUntilAttributeSubscriptionState.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) { - "Dischargingenableduntil attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Dischargingenableduntil attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(DischargingEnabledUntilAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(DischargingEnabledUntilAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(DischargingEnabledUntilAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCircuitCapacityAttribute(): Long {val ATTRIBUTE_ID: UInt = 5u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readCircuitCapacityAttribute(): Long { + 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 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}") - } + 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) { - "Circuitcapacity attribute not found in response" - } + } + + requireNotNull(attributeData) { "Circuitcapacity attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Long = tlvReader.getLong(AnonymousTag) - return decodedValue } suspend fun subscribeCircuitCapacityAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(LongSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + LongSubscriptionState.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) { - "Circuitcapacity attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Circuitcapacity attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -1066,80 +970,77 @@ suspend fun readCircuitCapacityAttribute(): Long {val ATTRIBUTE_ID: UInt = 5u emit(LongSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMinimumChargeCurrentAttribute(): Long {val ATTRIBUTE_ID: UInt = 6u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readMinimumChargeCurrentAttribute(): Long { + 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 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}") - } + 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) { - "Minimumchargecurrent attribute not found in response" - } + } + + requireNotNull(attributeData) { "Minimumchargecurrent attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Long = tlvReader.getLong(AnonymousTag) - return decodedValue } suspend fun subscribeMinimumChargeCurrentAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(LongSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + LongSubscriptionState.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) { - "Minimumchargecurrent attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Minimumchargecurrent attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -1152,80 +1053,77 @@ suspend fun readMinimumChargeCurrentAttribute(): Long {val ATTRIBUTE_ID: UInt = emit(LongSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMaximumChargeCurrentAttribute(): Long {val ATTRIBUTE_ID: UInt = 7u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readMaximumChargeCurrentAttribute(): Long { + 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 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}") - } + 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) { - "Maximumchargecurrent attribute not found in response" - } + } + + requireNotNull(attributeData) { "Maximumchargecurrent attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Long = tlvReader.getLong(AnonymousTag) - return decodedValue } suspend fun subscribeMaximumChargeCurrentAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(LongSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + LongSubscriptionState.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) { - "Maximumchargecurrent attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Maximumchargecurrent attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -1238,169 +1136,158 @@ suspend fun readMaximumChargeCurrentAttribute(): Long {val ATTRIBUTE_ID: UInt = emit(LongSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMaximumDischargeCurrentAttribute(): Long? {val ATTRIBUTE_ID: UInt = 8u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readMaximumDischargeCurrentAttribute(): Long? { + val ATTRIBUTE_ID: UInt = 8u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Maximumdischargecurrent attribute not found in response" - } + } + + requireNotNull(attributeData) { "Maximumdischargecurrent attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - + val decodedValue: Long? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeMaximumDischargeCurrentAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(LongSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + LongSubscriptionState.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) { - "Maximumdischargecurrent attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Maximumdischargecurrent attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } + val decodedValue: Long? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(LongSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(LongSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(LongSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readUserMaximumChargeCurrentAttribute(): Long? {val ATTRIBUTE_ID: UInt = 9u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readUserMaximumChargeCurrentAttribute(): Long? { + val ATTRIBUTE_ID: UInt = 9u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Usermaximumchargecurrent attribute not found in response" - } + } + + requireNotNull(attributeData) { "Usermaximumchargecurrent attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - + val decodedValue: Long? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } return decodedValue } suspend fun writeUserMaximumChargeCurrentAttribute( value: Long, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 9u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -1421,127 +1308,122 @@ suspend fun readUserMaximumChargeCurrentAttribute(): Long? {val ATTRIBUTE_ID: UI throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeUserMaximumChargeCurrentAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(LongSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + LongSubscriptionState.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) { - "Usermaximumchargecurrent attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Usermaximumchargecurrent attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } + val decodedValue: Long? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(LongSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(LongSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(LongSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRandomizationDelayWindowAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 10u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRandomizationDelayWindowAttribute(): UInt? { + val ATTRIBUTE_ID: UInt = 10u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Randomizationdelaywindow attribute not found in response" - } + } + + requireNotNull(attributeData) { "Randomizationdelaywindow attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun writeRandomizationDelayWindowAttribute( value: UInt, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 10u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -1562,560 +1444,539 @@ suspend fun readRandomizationDelayWindowAttribute(): UInt? {val ATTRIBUTE_ID: UI throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeRandomizationDelayWindowAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Randomizationdelaywindow attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Randomizationdelaywindow attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNextChargeStartTimeAttribute(): NextChargeStartTimeAttribute {val ATTRIBUTE_ID: UInt = 35u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNextChargeStartTimeAttribute(): NextChargeStartTimeAttribute { + val ATTRIBUTE_ID: UInt = 35u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Nextchargestarttime attribute not found in response" - } + } + + requireNotNull(attributeData) { "Nextchargestarttime attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return NextChargeStartTimeAttribute(decodedValue) } suspend fun subscribeNextChargeStartTimeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 35u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(NextChargeStartTimeAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + NextChargeStartTimeAttributeSubscriptionState.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) { - "Nextchargestarttime attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Nextchargestarttime attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(NextChargeStartTimeAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(NextChargeStartTimeAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(NextChargeStartTimeAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNextChargeTargetTimeAttribute(): NextChargeTargetTimeAttribute {val ATTRIBUTE_ID: UInt = 36u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNextChargeTargetTimeAttribute(): NextChargeTargetTimeAttribute { + val ATTRIBUTE_ID: UInt = 36u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Nextchargetargettime attribute not found in response" - } + } + + requireNotNull(attributeData) { "Nextchargetargettime attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return NextChargeTargetTimeAttribute(decodedValue) } suspend fun subscribeNextChargeTargetTimeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 36u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(NextChargeTargetTimeAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + NextChargeTargetTimeAttributeSubscriptionState.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) { - "Nextchargetargettime attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Nextchargetargettime attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(NextChargeTargetTimeAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(NextChargeTargetTimeAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(NextChargeTargetTimeAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNextChargeRequiredEnergyAttribute(): NextChargeRequiredEnergyAttribute {val ATTRIBUTE_ID: UInt = 37u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNextChargeRequiredEnergyAttribute(): NextChargeRequiredEnergyAttribute { + val ATTRIBUTE_ID: UInt = 37u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Nextchargerequiredenergy attribute not found in response" - } + } + + requireNotNull(attributeData) { "Nextchargerequiredenergy attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Long? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return NextChargeRequiredEnergyAttribute(decodedValue) } suspend fun subscribeNextChargeRequiredEnergyAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 37u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(NextChargeRequiredEnergyAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + NextChargeRequiredEnergyAttributeSubscriptionState.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) { - "Nextchargerequiredenergy attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Nextchargerequiredenergy attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(NextChargeRequiredEnergyAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Long? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(NextChargeRequiredEnergyAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(NextChargeRequiredEnergyAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNextChargeTargetSoCAttribute(): NextChargeTargetSoCAttribute {val ATTRIBUTE_ID: UInt = 38u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNextChargeTargetSoCAttribute(): NextChargeTargetSoCAttribute { + val ATTRIBUTE_ID: UInt = 38u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Nextchargetargetsoc attribute not found in response" - } + } + + requireNotNull(attributeData) { "Nextchargetargetsoc attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return NextChargeTargetSoCAttribute(decodedValue) } suspend fun subscribeNextChargeTargetSoCAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 38u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(NextChargeTargetSoCAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + NextChargeTargetSoCAttributeSubscriptionState.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) { - "Nextchargetargetsoc attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Nextchargetargetsoc 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(NextChargeTargetSoCAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(NextChargeTargetSoCAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(NextChargeTargetSoCAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readApproximateEVEfficiencyAttribute(): ApproximateEVEfficiencyAttribute {val ATTRIBUTE_ID: UInt = 39u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readApproximateEVEfficiencyAttribute(): ApproximateEVEfficiencyAttribute { + val ATTRIBUTE_ID: UInt = 39u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Approximateevefficiency attribute not found in response" - } + } + + requireNotNull(attributeData) { "Approximateevefficiency attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return ApproximateEVEfficiencyAttribute(decodedValue) } suspend fun writeApproximateEVEfficiencyAttribute( value: UShort, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 39u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -2136,882 +1997,849 @@ suspend fun readApproximateEVEfficiencyAttribute(): ApproximateEVEfficiencyAttri throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeApproximateEVEfficiencyAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 39u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ApproximateEVEfficiencyAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ApproximateEVEfficiencyAttributeSubscriptionState.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) { - "Approximateevefficiency attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Approximateevefficiency 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(ApproximateEVEfficiencyAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(ApproximateEVEfficiencyAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ApproximateEVEfficiencyAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readStateOfChargeAttribute(): StateOfChargeAttribute {val ATTRIBUTE_ID: UInt = 48u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readStateOfChargeAttribute(): StateOfChargeAttribute { + val ATTRIBUTE_ID: UInt = 48u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Stateofcharge attribute not found in response" - } + } + + requireNotNull(attributeData) { "Stateofcharge attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return StateOfChargeAttribute(decodedValue) } suspend fun subscribeStateOfChargeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 48u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StateOfChargeAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StateOfChargeAttributeSubscriptionState.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) { - "Stateofcharge attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Stateofcharge 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(StateOfChargeAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(StateOfChargeAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(StateOfChargeAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readBatteryCapacityAttribute(): BatteryCapacityAttribute {val ATTRIBUTE_ID: UInt = 49u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readBatteryCapacityAttribute(): BatteryCapacityAttribute { + val ATTRIBUTE_ID: UInt = 49u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Batterycapacity attribute not found in response" - } + } + + requireNotNull(attributeData) { "Batterycapacity attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Long? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return BatteryCapacityAttribute(decodedValue) } suspend fun subscribeBatteryCapacityAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 49u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(BatteryCapacityAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + BatteryCapacityAttributeSubscriptionState.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) { - "Batterycapacity attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Batterycapacity attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(BatteryCapacityAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Long? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(BatteryCapacityAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(BatteryCapacityAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readVehicleIDAttribute(): VehicleIDAttribute {val ATTRIBUTE_ID: UInt = 50u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readVehicleIDAttribute(): VehicleIDAttribute { + val ATTRIBUTE_ID: UInt = 50u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Vehicleid attribute not found in response" - } + } + + requireNotNull(attributeData) { "Vehicleid attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: String? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return VehicleIDAttribute(decodedValue) } suspend fun subscribeVehicleIDAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 50u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(VehicleIDAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + VehicleIDAttributeSubscriptionState.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) { - "Vehicleid attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Vehicleid attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(VehicleIDAttributeSubscriptionState.Success(it)) - } - + val decodedValue: String? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(VehicleIDAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(VehicleIDAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readSessionIDAttribute(): SessionIDAttribute {val ATTRIBUTE_ID: UInt = 64u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readSessionIDAttribute(): SessionIDAttribute { + val ATTRIBUTE_ID: UInt = 64u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Sessionid attribute not found in response" - } + } + + requireNotNull(attributeData) { "Sessionid attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - tlvReader.getUInt(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + tlvReader.getUInt(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return SessionIDAttribute(decodedValue) } suspend fun subscribeSessionIDAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 64u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(SessionIDAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + SessionIDAttributeSubscriptionState.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) { - "Sessionid attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Sessionid attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - tlvReader.getUInt(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + tlvReader.getUInt(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(SessionIDAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(SessionIDAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(SessionIDAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readSessionDurationAttribute(): SessionDurationAttribute {val ATTRIBUTE_ID: UInt = 65u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readSessionDurationAttribute(): SessionDurationAttribute { + val ATTRIBUTE_ID: UInt = 65u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Sessionduration attribute not found in response" - } + } + + requireNotNull(attributeData) { "Sessionduration attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - tlvReader.getUInt(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + tlvReader.getUInt(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return SessionDurationAttribute(decodedValue) } suspend fun subscribeSessionDurationAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(SessionDurationAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + SessionDurationAttributeSubscriptionState.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) { - "Sessionduration attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Sessionduration attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - tlvReader.getUInt(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + tlvReader.getUInt(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(SessionDurationAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(SessionDurationAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(SessionDurationAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readSessionEnergyChargedAttribute(): SessionEnergyChargedAttribute {val ATTRIBUTE_ID: UInt = 66u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readSessionEnergyChargedAttribute(): SessionEnergyChargedAttribute { + val ATTRIBUTE_ID: UInt = 66u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Sessionenergycharged attribute not found in response" - } + } + + requireNotNull(attributeData) { "Sessionenergycharged attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = if (!tlvReader.isNull()) { - tlvReader.getLong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Long? = + if (!tlvReader.isNull()) { + tlvReader.getLong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return SessionEnergyChargedAttribute(decodedValue) } suspend fun subscribeSessionEnergyChargedAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 66u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(SessionEnergyChargedAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + SessionEnergyChargedAttributeSubscriptionState.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) { - "Sessionenergycharged attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Sessionenergycharged attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = if (!tlvReader.isNull()) { - tlvReader.getLong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Long? = + if (!tlvReader.isNull()) { + tlvReader.getLong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(SessionEnergyChargedAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(SessionEnergyChargedAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(SessionEnergyChargedAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readSessionEnergyDischargedAttribute(): SessionEnergyDischargedAttribute {val ATTRIBUTE_ID: UInt = 67u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readSessionEnergyDischargedAttribute(): SessionEnergyDischargedAttribute { + val ATTRIBUTE_ID: UInt = 67u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Sessionenergydischarged attribute not found in response" - } + } + + requireNotNull(attributeData) { "Sessionenergydischarged attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Long? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return SessionEnergyDischargedAttribute(decodedValue) } suspend fun subscribeSessionEnergyDischargedAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 67u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(SessionEnergyDischargedAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + SessionEnergyDischargedAttributeSubscriptionState.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) { - "Sessionenergydischarged attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Sessionenergydischarged attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(SessionEnergyDischargedAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Long? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(SessionEnergyDischargedAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(SessionEnergyDischargedAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65528u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -3019,97 +2847,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { emit(GeneratedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65529u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -3117,97 +2944,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va emit(AcceptedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt = 65530u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -3215,97 +3039,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt emit(EventListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ID: UInt = 65531u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -3313,81 +3134,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ emit(AttributeListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -3399,80 +3215,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 65533u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -3485,7 +3298,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/EnergyEvseModeCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/EnergyEvseModeCluster.kt index 43af7f34e08ac7..a854ec8d1f71b4 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/EnergyEvseModeCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/EnergyEvseModeCluster.kt @@ -17,161 +17,127 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class EnergyEvseModeCluster(private val controller: MatterController, private val endpointId: UShort) { - class ChangeToModeResponse( - val status: UByte, - val statusText: String? - ) -class SupportedModesAttribute( - val value: List - ) +class EnergyEvseModeCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class ChangeToModeResponse(val status: UByte, val statusText: String?) + + class SupportedModesAttribute(val value: List) sealed class SupportedModesAttributeSubscriptionState { - data class Success( - val value: List - ) : SupportedModesAttributeSubscriptionState() - + data class Success(val value: List) : + SupportedModesAttributeSubscriptionState() + data class Error(val exception: Exception) : SupportedModesAttributeSubscriptionState() - object SubscriptionEstablished : SupportedModesAttributeSubscriptionState() - } -class StartUpModeAttribute( - val value: UByte? - ) + object SubscriptionEstablished : SupportedModesAttributeSubscriptionState() + } + + class StartUpModeAttribute(val value: UByte?) sealed class StartUpModeAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : StartUpModeAttributeSubscriptionState() - + data class Success(val value: UByte?) : StartUpModeAttributeSubscriptionState() + data class Error(val exception: Exception) : StartUpModeAttributeSubscriptionState() - object SubscriptionEstablished : StartUpModeAttributeSubscriptionState() - } -class OnModeAttribute( - val value: UByte? - ) + object SubscriptionEstablished : StartUpModeAttributeSubscriptionState() + } + + class OnModeAttribute(val value: UByte?) sealed class OnModeAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : OnModeAttributeSubscriptionState() - + data class Success(val value: UByte?) : OnModeAttributeSubscriptionState() + data class Error(val exception: Exception) : OnModeAttributeSubscriptionState() - object SubscriptionEstablished : OnModeAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : OnModeAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun changeToMode(newMode: UByte - ,timedInvokeTimeout: Duration? = null): ChangeToModeResponse { + suspend fun changeToMode( + newMode: UByte, + timedInvokeTimeout: Duration? = null, + ): ChangeToModeResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_NEW_MODE_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_NEW_MODE_REQ), newMode) + tlvWriter.put(ContextSpecificTag(TAG_NEW_MODE_REQ), newMode) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -181,140 +147,130 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_STATUS_TEXT: Int = 1 var statusText_decoded: String? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_STATUS_TEXT)) {statusText_decoded = + if (tag == ContextSpecificTag(TAG_STATUS)) { + status_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_STATUS_TEXT)) { + statusText_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - }} - - - else { + tlvReader.getString(tag) + } else { + null + } + } + } else { tlvReader.skipElement() } } - - if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - - - tlvReader.exitContainer() - return ChangeToModeResponse( - status_decoded, - statusText_decoded - ) + return ChangeToModeResponse(status_decoded, statusText_decoded) } -suspend fun readSupportedModesAttribute(): SupportedModesAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readSupportedModesAttribute(): SupportedModesAttribute { + 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}") - } + 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) { - "Supportedmodes attribute not found in response" - } + } + + requireNotNull(attributeData) { "Supportedmodes 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(EnergyEvseModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(EnergyEvseModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return SupportedModesAttribute(decodedValue) } suspend fun subscribeSupportedModesAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(SupportedModesAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + SupportedModesAttributeSubscriptionState.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) { - "Supportedmodes attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Supportedmodes 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(EnergyEvseModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(EnergyEvseModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(SupportedModesAttributeSubscriptionState.Success(decodedValue)) } @@ -322,81 +278,76 @@ suspend fun readSupportedModesAttribute(): SupportedModesAttribute {val ATTRIBUT emit(SupportedModesAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCurrentModeAttribute(): 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) - ) - + + suspend fun readCurrentModeAttribute(): 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}") - } + 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) { - "Currentmode attribute not found in response" - } + } + + requireNotNull(attributeData) { "Currentmode 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 subscribeCurrentModeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Currentmode attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Currentmode attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -408,77 +359,67 @@ suspend fun readCurrentModeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 1u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readStartUpModeAttribute(): StartUpModeAttribute {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readStartUpModeAttribute(): StartUpModeAttribute { + 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}") - } + 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) { - "Startupmode attribute not found in response" - } + } + + requireNotNull(attributeData) { "Startupmode attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return StartUpModeAttribute(decodedValue) } - suspend fun writeStartUpModeAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeStartUpModeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 2u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -499,137 +440,127 @@ suspend fun readStartUpModeAttribute(): StartUpModeAttribute {val ATTRIBUTE_ID: throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeStartUpModeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StartUpModeAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StartUpModeAttributeSubscriptionState.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) { - "Startupmode attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Startupmode 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(StartUpModeAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(StartUpModeAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(StartUpModeAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readOnModeAttribute(): OnModeAttribute {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readOnModeAttribute(): OnModeAttribute { + 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}") - } + 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) { - "Onmode attribute not found in response" - } + } + + requireNotNull(attributeData) { "Onmode attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return OnModeAttribute(decodedValue) } - suspend fun writeOnModeAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeOnModeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 3u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -650,157 +581,156 @@ suspend fun readOnModeAttribute(): OnModeAttribute {val ATTRIBUTE_ID: UInt = 3u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeOnModeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(OnModeAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + OnModeAttributeSubscriptionState.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) { - "Onmode attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Onmode 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(OnModeAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(OnModeAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(OnModeAttributeSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -808,97 +738,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -906,97 +835,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1004,97 +930,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1102,81 +1025,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1188,80 +1106,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1274,7 +1189,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/EnergyPreferenceCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/EnergyPreferenceCluster.kt index 0ac2734058b8eb..7944f2640f66e1 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/EnergyPreferenceCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/EnergyPreferenceCluster.kt @@ -17,312 +17,266 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse -import matter.controller.model.AttributePath -import matter.controller.model.CommandPath import matter.controller.cluster.structs.* +import matter.controller.model.AttributePath import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class EnergyPreferenceCluster(private val controller: MatterController, private val endpointId: UShort) {class EnergyBalancesAttribute( - val value: List? - ) +class EnergyPreferenceCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class EnergyBalancesAttribute(val value: List?) sealed class EnergyBalancesAttributeSubscriptionState { - data class Success( - val value: List? - ) : EnergyBalancesAttributeSubscriptionState() - + data class Success(val value: List?) : + EnergyBalancesAttributeSubscriptionState() + data class Error(val exception: Exception) : EnergyBalancesAttributeSubscriptionState() - object SubscriptionEstablished : EnergyBalancesAttributeSubscriptionState() - } -class EnergyPrioritiesAttribute( - val value: List? - ) + object SubscriptionEstablished : EnergyBalancesAttributeSubscriptionState() + } + + class EnergyPrioritiesAttribute(val value: List?) sealed class EnergyPrioritiesAttributeSubscriptionState { - data class Success( - val value: List? - ) : EnergyPrioritiesAttributeSubscriptionState() - + data class Success(val value: List?) : EnergyPrioritiesAttributeSubscriptionState() + data class Error(val exception: Exception) : EnergyPrioritiesAttributeSubscriptionState() - object SubscriptionEstablished : EnergyPrioritiesAttributeSubscriptionState() - } -class LowPowerModeSensitivitiesAttribute( - val value: List? - ) + object SubscriptionEstablished : EnergyPrioritiesAttributeSubscriptionState() + } + + class LowPowerModeSensitivitiesAttribute(val value: List?) sealed class LowPowerModeSensitivitiesAttributeSubscriptionState { - data class Success( - val value: List? - ) : LowPowerModeSensitivitiesAttributeSubscriptionState() - - data class Error(val exception: Exception) : LowPowerModeSensitivitiesAttributeSubscriptionState() - - object SubscriptionEstablished : LowPowerModeSensitivitiesAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + data class Success(val value: List?) : + LowPowerModeSensitivitiesAttributeSubscriptionState() + + data class Error(val exception: Exception) : + LowPowerModeSensitivitiesAttributeSubscriptionState() + + object SubscriptionEstablished : LowPowerModeSensitivitiesAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } -suspend fun readEnergyBalancesAttribute(): EnergyBalancesAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } + + suspend fun readEnergyBalancesAttribute(): EnergyBalancesAttribute { + 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}") - } + 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) { - "Energybalances attribute not found in response" - } + } + + requireNotNull(attributeData) { "Energybalances attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(EnergyPreferenceClusterBalanceStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(EnergyPreferenceClusterBalanceStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null } - tlvReader.exitContainer() - } - } else { - null - } - return EnergyBalancesAttribute(decodedValue) } suspend fun subscribeEnergyBalancesAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(EnergyBalancesAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + EnergyBalancesAttributeSubscriptionState.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) { - "Energybalances attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Energybalances attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(EnergyPreferenceClusterBalanceStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { - emit(EnergyBalancesAttributeSubscriptionState.Success(it)) - } - + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(EnergyPreferenceClusterBalanceStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { emit(EnergyBalancesAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(EnergyBalancesAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCurrentEnergyBalanceAttribute(): 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) - ) - + + suspend fun readCurrentEnergyBalanceAttribute(): 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}") - } + 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) { - "Currentenergybalance attribute not found in response" - } + } + + requireNotNull(attributeData) { "Currentenergybalance 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun writeCurrentEnergyBalanceAttribute( value: UByte, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 1u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -343,345 +297,336 @@ suspend fun readCurrentEnergyBalanceAttribute(): UByte? {val ATTRIBUTE_ID: UInt throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeCurrentEnergyBalanceAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Currentenergybalance attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Currentenergybalance 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)) - } - + 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 readEnergyPrioritiesAttribute(): EnergyPrioritiesAttribute {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readEnergyPrioritiesAttribute(): EnergyPrioritiesAttribute { + 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}") - } + 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) { - "Energypriorities attribute not found in response" - } + } + + requireNotNull(attributeData) { "Energypriorities attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null } - tlvReader.exitContainer() - } - } else { - null - } - return EnergyPrioritiesAttribute(decodedValue) } suspend fun subscribeEnergyPrioritiesAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(EnergyPrioritiesAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + EnergyPrioritiesAttributeSubscriptionState.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) { - "Energypriorities attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Energypriorities attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { - emit(EnergyPrioritiesAttributeSubscriptionState.Success(it)) - } - + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { emit(EnergyPrioritiesAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(EnergyPrioritiesAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readLowPowerModeSensitivitiesAttribute(): LowPowerModeSensitivitiesAttribute {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readLowPowerModeSensitivitiesAttribute(): LowPowerModeSensitivitiesAttribute { + 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}") - } + 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) { - "Lowpowermodesensitivities attribute not found in response" - } + } + + requireNotNull(attributeData) { "Lowpowermodesensitivities attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(EnergyPreferenceClusterBalanceStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(EnergyPreferenceClusterBalanceStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null } - tlvReader.exitContainer() - } - } else { - null - } - return LowPowerModeSensitivitiesAttribute(decodedValue) } suspend fun subscribeLowPowerModeSensitivitiesAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(LowPowerModeSensitivitiesAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + LowPowerModeSensitivitiesAttributeSubscriptionState.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) { - "Lowpowermodesensitivities attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Lowpowermodesensitivities attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(EnergyPreferenceClusterBalanceStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null - } + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(EnergyPreferenceClusterBalanceStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null + } decodedValue?.let { emit(LowPowerModeSensitivitiesAttributeSubscriptionState.Success(it)) } - } SubscriptionState.SubscriptionEstablished -> { emit(LowPowerModeSensitivitiesAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCurrentLowPowerModeSensitivityAttribute(): 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) - ) - + + suspend fun readCurrentLowPowerModeSensitivityAttribute(): 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}") - } + 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) { - "Currentlowpowermodesensitivity attribute not found in response" + } + + requireNotNull(attributeData) { + "Currentlowpowermodesensitivity 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun writeCurrentLowPowerModeSensitivityAttribute( value: UByte, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 4u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -702,152 +647,153 @@ suspend fun readCurrentLowPowerModeSensitivityAttribute(): UByte? {val ATTRIBUTE throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeCurrentLowPowerModeSensitivityAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Currentlowpowermodesensitivity attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Currentlowpowermodesensitivity 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)) - } - + 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 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -855,97 +801,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -953,97 +898,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1051,97 +993,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1149,81 +1088,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1235,80 +1169,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1321,7 +1252,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/EthernetNetworkDiagnosticsCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/EthernetNetworkDiagnosticsCluster.kt index 296db7e7974d5b..219b842b46a746 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/EthernetNetworkDiagnosticsCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/EthernetNetworkDiagnosticsCluster.kt @@ -17,1149 +17,1060 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState -import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.UShortSubscriptionState +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class EthernetNetworkDiagnosticsCluster(private val controller: MatterController, private val endpointId: UShort) {class PHYRateAttribute( - val value: UByte? - ) +class EthernetNetworkDiagnosticsCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class PHYRateAttribute(val value: UByte?) sealed class PHYRateAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : PHYRateAttributeSubscriptionState() - + data class Success(val value: UByte?) : PHYRateAttributeSubscriptionState() + data class Error(val exception: Exception) : PHYRateAttributeSubscriptionState() - object SubscriptionEstablished : PHYRateAttributeSubscriptionState() - } -class FullDuplexAttribute( - val value: Boolean? - ) + object SubscriptionEstablished : PHYRateAttributeSubscriptionState() + } + + class FullDuplexAttribute(val value: Boolean?) sealed class FullDuplexAttributeSubscriptionState { - data class Success( - val value: Boolean? - ) : FullDuplexAttributeSubscriptionState() - + data class Success(val value: Boolean?) : FullDuplexAttributeSubscriptionState() + data class Error(val exception: Exception) : FullDuplexAttributeSubscriptionState() - object SubscriptionEstablished : FullDuplexAttributeSubscriptionState() - } -class CarrierDetectAttribute( - val value: Boolean? - ) + object SubscriptionEstablished : FullDuplexAttributeSubscriptionState() + } + + class CarrierDetectAttribute(val value: Boolean?) sealed class CarrierDetectAttributeSubscriptionState { - data class Success( - val value: Boolean? - ) : CarrierDetectAttributeSubscriptionState() - + data class Success(val value: Boolean?) : CarrierDetectAttributeSubscriptionState() + data class Error(val exception: Exception) : CarrierDetectAttributeSubscriptionState() - object SubscriptionEstablished : CarrierDetectAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : CarrierDetectAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } suspend fun resetCounts(timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } -suspend fun readPHYRateAttribute(): PHYRateAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readPHYRateAttribute(): PHYRateAttribute { + 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}") - } + 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) { - "Phyrate attribute not found in response" - } + } + + requireNotNull(attributeData) { "Phyrate attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return PHYRateAttribute(decodedValue) } suspend fun subscribePHYRateAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(PHYRateAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + PHYRateAttributeSubscriptionState.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) { - "Phyrate attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Phyrate 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(PHYRateAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(PHYRateAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(PHYRateAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readFullDuplexAttribute(): FullDuplexAttribute {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readFullDuplexAttribute(): FullDuplexAttribute { + 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}") - } + 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) { - "Fullduplex attribute not found in response" - } + } + + requireNotNull(attributeData) { "Fullduplex attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Boolean? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getBoolean(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Boolean? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return FullDuplexAttribute(decodedValue) } suspend fun subscribeFullDuplexAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(FullDuplexAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + FullDuplexAttributeSubscriptionState.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) { - "Fullduplex attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Fullduplex 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getBoolean(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(FullDuplexAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Boolean? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(FullDuplexAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(FullDuplexAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPacketRxCountAttribute(): ULong? {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readPacketRxCountAttribute(): ULong? { + 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}") - } + 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) { - "Packetrxcount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Packetrxcount attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ULong? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getULong(AnonymousTag) - } else { - null - } - + val decodedValue: ULong? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribePacketRxCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ULongSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ULongSubscriptionState.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) { - "Packetrxcount attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Packetrxcount 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.isNextTag(AnonymousTag)) { - tlvReader.getULong(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(ULongSubscriptionState.Success(it)) - } - + val decodedValue: ULong? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(ULongSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ULongSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPacketTxCountAttribute(): ULong? {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readPacketTxCountAttribute(): ULong? { + 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}") - } + 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) { - "Packettxcount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Packettxcount attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ULong? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getULong(AnonymousTag) - } else { - null - } - + val decodedValue: ULong? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribePacketTxCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ULongSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ULongSubscriptionState.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) { - "Packettxcount attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Packettxcount 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.isNextTag(AnonymousTag)) { - tlvReader.getULong(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(ULongSubscriptionState.Success(it)) - } - + val decodedValue: ULong? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(ULongSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ULongSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readTxErrCountAttribute(): ULong? {val ATTRIBUTE_ID: UInt = 4u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readTxErrCountAttribute(): ULong? { + 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}") - } + 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) { - "Txerrcount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Txerrcount attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ULong? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getULong(AnonymousTag) - } else { - null - } - + val decodedValue: ULong? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeTxErrCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ULongSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ULongSubscriptionState.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) { - "Txerrcount attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Txerrcount 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.isNextTag(AnonymousTag)) { - tlvReader.getULong(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(ULongSubscriptionState.Success(it)) - } - + val decodedValue: ULong? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(ULongSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ULongSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCollisionCountAttribute(): ULong? {val ATTRIBUTE_ID: UInt = 5u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readCollisionCountAttribute(): ULong? { + 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}") - } + 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) { - "Collisioncount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Collisioncount attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ULong? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getULong(AnonymousTag) - } else { - null - } - + val decodedValue: ULong? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeCollisionCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ULongSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ULongSubscriptionState.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) { - "Collisioncount attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Collisioncount 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.isNextTag(AnonymousTag)) { - tlvReader.getULong(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(ULongSubscriptionState.Success(it)) - } - + val decodedValue: ULong? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(ULongSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ULongSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readOverrunCountAttribute(): ULong? {val ATTRIBUTE_ID: UInt = 6u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readOverrunCountAttribute(): ULong? { + 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}") - } + 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) { - "Overruncount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Overruncount attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ULong? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getULong(AnonymousTag) - } else { - null - } - + val decodedValue: ULong? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeOverrunCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ULongSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ULongSubscriptionState.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) { - "Overruncount attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Overruncount 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.isNextTag(AnonymousTag)) { - tlvReader.getULong(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(ULongSubscriptionState.Success(it)) - } - + val decodedValue: ULong? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(ULongSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ULongSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCarrierDetectAttribute(): CarrierDetectAttribute {val ATTRIBUTE_ID: UInt = 7u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readCarrierDetectAttribute(): CarrierDetectAttribute { + 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}") - } + 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) { - "Carrierdetect attribute not found in response" - } + } + + requireNotNull(attributeData) { "Carrierdetect attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Boolean? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getBoolean(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Boolean? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return CarrierDetectAttribute(decodedValue) } suspend fun subscribeCarrierDetectAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(CarrierDetectAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + CarrierDetectAttributeSubscriptionState.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) { - "Carrierdetect attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Carrierdetect 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getBoolean(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(CarrierDetectAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Boolean? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(CarrierDetectAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(CarrierDetectAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readTimeSinceResetAttribute(): ULong? {val ATTRIBUTE_ID: UInt = 8u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readTimeSinceResetAttribute(): ULong? { + val ATTRIBUTE_ID: UInt = 8u + + 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}") - } + 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) { - "Timesincereset attribute not found in response" - } + } + + requireNotNull(attributeData) { "Timesincereset attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ULong? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getULong(AnonymousTag) - } else { - null - } - + val decodedValue: ULong? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeTimeSinceResetAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ULongSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ULongSubscriptionState.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) { - "Timesincereset attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Timesincereset 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.isNextTag(AnonymousTag)) { - tlvReader.getULong(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(ULongSubscriptionState.Success(it)) - } - + val decodedValue: ULong? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(ULongSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ULongSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1167,97 +1078,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1265,97 +1175,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1363,97 +1270,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1461,81 +1365,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1547,80 +1446,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1633,7 +1529,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/FanControlCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/FanControlCluster.kt index 6d0e58a6d5b9b2..7f29906d1bc0be 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/FanControlCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/FanControlCluster.kt @@ -17,131 +17,99 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class FanControlCluster(private val controller: MatterController, private val endpointId: UShort) {class PercentSettingAttribute( - val value: UByte? - ) +class FanControlCluster(private val controller: MatterController, private val endpointId: UShort) { + class PercentSettingAttribute(val value: UByte?) sealed class PercentSettingAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : PercentSettingAttributeSubscriptionState() - + data class Success(val value: UByte?) : PercentSettingAttributeSubscriptionState() + data class Error(val exception: Exception) : PercentSettingAttributeSubscriptionState() - object SubscriptionEstablished : PercentSettingAttributeSubscriptionState() - } -class SpeedSettingAttribute( - val value: UByte? - ) + object SubscriptionEstablished : PercentSettingAttributeSubscriptionState() + } + + class SpeedSettingAttribute(val value: UByte?) sealed class SpeedSettingAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : SpeedSettingAttributeSubscriptionState() - + data class Success(val value: UByte?) : SpeedSettingAttributeSubscriptionState() + data class Error(val exception: Exception) : SpeedSettingAttributeSubscriptionState() - object SubscriptionEstablished : SpeedSettingAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : SpeedSettingAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun step(direction: UByte - ,wrap: Boolean? - ,lowestOff: Boolean? - ,timedInvokeTimeout: Duration? = null) { + suspend fun step( + direction: UByte, + wrap: Boolean?, + lowestOff: Boolean?, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 0u val tlvWriter = TlvWriter() @@ -151,86 +119,71 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_DIRECTION_REQ), direction) val TAG_WRAP_REQ: Int = 1 - wrap?.let { - tlvWriter.put(ContextSpecificTag(TAG_WRAP_REQ), wrap) - } + wrap?.let { tlvWriter.put(ContextSpecificTag(TAG_WRAP_REQ), wrap) } val TAG_LOWEST_OFF_REQ: Int = 2 - lowestOff?.let { - tlvWriter.put(ContextSpecificTag(TAG_LOWEST_OFF_REQ), lowestOff) - } + lowestOff?.let { tlvWriter.put(ContextSpecificTag(TAG_LOWEST_OFF_REQ), lowestOff) } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } -suspend fun readFanModeAttribute(): 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) - ) - + + suspend fun readFanModeAttribute(): 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}") - } + 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) { - "Fanmode attribute not found in response" - } + } + + requireNotNull(attributeData) { "Fanmode 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 writeFanModeAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeFanModeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -251,43 +204,45 @@ suspend fun readFanModeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 0u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeFanModeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Fanmode attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Fanmode attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -299,80 +254,77 @@ suspend fun readFanModeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 0u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readFanModeSequenceAttribute(): 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) - ) - + + suspend fun readFanModeSequenceAttribute(): 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}") - } + 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) { - "Fanmodesequence attribute not found in response" - } + } + + requireNotNull(attributeData) { "Fanmodesequence 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 subscribeFanModeSequenceAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Fanmodesequence attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Fanmodesequence attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -385,73 +337,63 @@ suspend fun readFanModeSequenceAttribute(): UByte {val ATTRIBUTE_ID: UInt = 1u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPercentSettingAttribute(): PercentSettingAttribute {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readPercentSettingAttribute(): PercentSettingAttribute { + 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}") - } + 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) { - "Percentsetting attribute not found in response" - } + } + + requireNotNull(attributeData) { "Percentsetting attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return PercentSettingAttribute(decodedValue) } - suspend fun writePercentSettingAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writePercentSettingAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 2u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -472,136 +414,135 @@ suspend fun readPercentSettingAttribute(): PercentSettingAttribute {val ATTRIBUT throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribePercentSettingAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(PercentSettingAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + PercentSettingAttributeSubscriptionState.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) { - "Percentsetting attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Percentsetting 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.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(PercentSettingAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(PercentSettingAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(PercentSettingAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPercentCurrentAttribute(): UByte {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readPercentCurrentAttribute(): UByte { + 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}") - } + 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) { - "Percentcurrent attribute not found in response" - } + } + + requireNotNull(attributeData) { "Percentcurrent 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 subscribePercentCurrentAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Percentcurrent attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Percentcurrent attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -614,174 +555,158 @@ suspend fun readPercentCurrentAttribute(): UByte {val ATTRIBUTE_ID: UInt = 3u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readSpeedMaxAttribute(): 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) - ) - + + suspend fun readSpeedMaxAttribute(): 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}") - } + 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) { - "Speedmax attribute not found in response" - } + } + + requireNotNull(attributeData) { "Speedmax 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeSpeedMaxAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Speedmax attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Speedmax 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)) - } - + 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 readSpeedSettingAttribute(): SpeedSettingAttribute {val ATTRIBUTE_ID: UInt = 5u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readSpeedSettingAttribute(): SpeedSettingAttribute { + 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}") - } + 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) { - "Speedsetting attribute not found in response" - } + } + + requireNotNull(attributeData) { "Speedsetting attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return SpeedSettingAttribute(decodedValue) } - suspend fun writeSpeedSettingAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeSpeedSettingAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 5u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -802,326 +727,304 @@ suspend fun readSpeedSettingAttribute(): SpeedSettingAttribute {val ATTRIBUTE_ID throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeSpeedSettingAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(SpeedSettingAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + SpeedSettingAttributeSubscriptionState.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) { - "Speedsetting attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Speedsetting 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(SpeedSettingAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(SpeedSettingAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(SpeedSettingAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readSpeedCurrentAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 6u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readSpeedCurrentAttribute(): UByte? { + 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}") - } + 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) { - "Speedcurrent attribute not found in response" - } + } + + requireNotNull(attributeData) { "Speedcurrent 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeSpeedCurrentAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Speedcurrent attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Speedcurrent 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)) - } - + 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 readRockSupportAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 7u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readRockSupportAttribute(): UByte? { + 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}") - } + 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) { - "Rocksupport attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rocksupport 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeRockSupportAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Rocksupport attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Rocksupport 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)) - } - + 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 readRockSettingAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 8u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readRockSettingAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 8u + + 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}") - } + 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) { - "Rocksetting attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rocksetting 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } - suspend fun writeRockSettingAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeRockSettingAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 8u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -1142,224 +1045,208 @@ suspend fun readRockSettingAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 8u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeRockSettingAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Rocksetting attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Rocksetting 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)) - } - + 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 readWindSupportAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 9u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readWindSupportAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 9u + + 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}") - } + 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) { - "Windsupport attribute not found in response" - } + } + + requireNotNull(attributeData) { "Windsupport 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeWindSupportAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Windsupport attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Windsupport 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)) - } - + 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 readWindSettingAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 10u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readWindSettingAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 10u + + 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}") - } + 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) { - "Windsetting attribute not found in response" - } + } + + requireNotNull(attributeData) { "Windsetting 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } - suspend fun writeWindSettingAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeWindSettingAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 10u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -1380,127 +1267,117 @@ suspend fun readWindSettingAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 10u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeWindSettingAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Windsetting attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Windsetting 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)) - } - + 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 readAirflowDirectionAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 11u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readAirflowDirectionAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 11u + + 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}") - } + 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) { - "Airflowdirection attribute not found in response" - } + } + + requireNotNull(attributeData) { "Airflowdirection 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } - suspend fun writeAirflowDirectionAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeAirflowDirectionAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 11u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -1521,152 +1398,153 @@ suspend fun readAirflowDirectionAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 11 throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeAirflowDirectionAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 11u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Airflowdirection attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Airflowdirection 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)) - } - + 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 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1674,97 +1552,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1772,97 +1649,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1870,97 +1744,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1968,81 +1839,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -2054,80 +1920,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -2140,7 +2003,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/FaultInjectionCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/FaultInjectionCluster.kt index cd6627c787c57a..3543b5258d020a 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/FaultInjectionCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/FaultInjectionCluster.kt @@ -17,107 +17,80 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState -import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.UShortSubscriptionState +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class FaultInjectionCluster(private val controller: MatterController, private val endpointId: UShort) {class GeneratedCommandListAttribute( - val value: List - ) +class FaultInjectionCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun failAtFault(type: UByte - ,id: UInt - ,numCallsToSkip: UInt - ,numCallsToFail: UInt - ,takeMutex: Boolean - ,timedInvokeTimeout: Duration? = null) { + suspend fun failAtFault( + type: UByte, + id: UInt, + numCallsToSkip: UInt, + numCallsToFail: UInt, + takeMutex: Boolean, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 0u val tlvWriter = TlvWriter() @@ -136,24 +109,26 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_NUM_CALLS_TO_FAIL_REQ), numCallsToFail) val TAG_TAKE_MUTEX_REQ: Int = 4 - tlvWriter.put(ContextSpecificTag(TAG_TAKE_MUTEX_REQ), takeMutex) + tlvWriter.put(ContextSpecificTag(TAG_TAKE_MUTEX_REQ), takeMutex) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun failRandomlyAtFault(type: UByte - ,id: UInt - ,percentage: UByte - ,timedInvokeTimeout: Duration? = null) { + suspend fun failRandomlyAtFault( + type: UByte, + id: UInt, + percentage: UByte, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 1u val tlvWriter = TlvWriter() @@ -166,108 +141,107 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_ID_REQ), id) val TAG_PERCENTAGE_REQ: Int = 2 - tlvWriter.put(ContextSpecificTag(TAG_PERCENTAGE_REQ), percentage) + tlvWriter.put(ContextSpecificTag(TAG_PERCENTAGE_REQ), percentage) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } -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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -275,97 +249,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -373,97 +346,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -471,97 +441,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -569,81 +536,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -655,80 +617,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -741,7 +700,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/FixedLabelCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/FixedLabelCluster.kt index f36bab66f10935..0b246557c49442 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/FixedLabelCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/FixedLabelCluster.kt @@ -17,202 +17,160 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState -import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse -import matter.controller.model.AttributePath -import matter.controller.model.CommandPath +import matter.controller.UShortSubscriptionState import matter.controller.cluster.structs.* +import matter.controller.model.AttributePath import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader -import matter.tlv.TlvWriter -class FixedLabelCluster(private val controller: MatterController, private val endpointId: UShort) {class LabelListAttribute( - val value: List - ) +class FixedLabelCluster(private val controller: MatterController, private val endpointId: UShort) { + class LabelListAttribute(val value: List) sealed class LabelListAttributeSubscriptionState { - data class Success( - val value: List - ) : LabelListAttributeSubscriptionState() - + data class Success(val value: List) : + LabelListAttributeSubscriptionState() + data class Error(val exception: Exception) : LabelListAttributeSubscriptionState() - object SubscriptionEstablished : LabelListAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : LabelListAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } -suspend fun readLabelListAttribute(): LabelListAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } + + suspend fun readLabelListAttribute(): LabelListAttribute { + 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}") - } + 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) { - "Labellist attribute not found in response" - } + } + + requireNotNull(attributeData) { "Labellist 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(FixedLabelClusterLabelStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(FixedLabelClusterLabelStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return LabelListAttribute(decodedValue) } suspend fun subscribeLabelListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(LabelListAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + LabelListAttributeSubscriptionState.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) { - "Labellist attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Labellist 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(FixedLabelClusterLabelStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(FixedLabelClusterLabelStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(LabelListAttributeSubscriptionState.Success(decodedValue)) } @@ -220,97 +178,96 @@ suspend fun readLabelListAttribute(): LabelListAttribute {val ATTRIBUTE_ID: UInt emit(LabelListAttributeSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -318,97 +275,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -416,97 +372,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -514,97 +467,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -612,81 +562,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -698,80 +643,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -784,7 +726,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/FlowMeasurementCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/FlowMeasurementCluster.kt index 4987d915eb1c39..7587d7a243c65f 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/FlowMeasurementCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/FlowMeasurementCluster.kt @@ -17,622 +17,558 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState -import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse -import matter.controller.model.AttributePath -import matter.controller.model.CommandPath +import matter.controller.UShortSubscriptionState import matter.controller.cluster.structs.* +import matter.controller.model.AttributePath import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader -import matter.tlv.TlvWriter -class FlowMeasurementCluster(private val controller: MatterController, private val endpointId: UShort) {class MeasuredValueAttribute( - val value: UShort? - ) +class FlowMeasurementCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class MeasuredValueAttribute(val value: UShort?) sealed class MeasuredValueAttributeSubscriptionState { - data class Success( - val value: UShort? - ) : MeasuredValueAttributeSubscriptionState() - + data class Success(val value: UShort?) : MeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() - } -class MinMeasuredValueAttribute( - val value: UShort? - ) + object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() + } + + class MinMeasuredValueAttribute(val value: UShort?) sealed class MinMeasuredValueAttributeSubscriptionState { - data class Success( - val value: UShort? - ) : MinMeasuredValueAttributeSubscriptionState() - + data class Success(val value: UShort?) : MinMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MinMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() - } -class MaxMeasuredValueAttribute( - val value: UShort? - ) + object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() + } + + class MaxMeasuredValueAttribute(val value: UShort?) sealed class MaxMeasuredValueAttributeSubscriptionState { - data class Success( - val value: UShort? - ) : MaxMeasuredValueAttributeSubscriptionState() - + data class Success(val value: UShort?) : MaxMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MaxMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } -suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } + + suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute { + 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}") - } + 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) { - "Measuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Measuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = if (!tlvReader.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return MeasuredValueAttribute(decodedValue) } suspend fun subscribeMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MeasuredValueAttributeSubscriptionState.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) { - "Measuredvalue attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Measuredvalue 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.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute { + 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}") - } + 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) { - "Minmeasuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Minmeasuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = if (!tlvReader.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return MinMeasuredValueAttribute(decodedValue) } suspend fun subscribeMinMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MinMeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MinMeasuredValueAttributeSubscriptionState.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) { - "Minmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Minmeasuredvalue 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.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MinMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute { + 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}") - } + 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) { - "Maxmeasuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Maxmeasuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = if (!tlvReader.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return MaxMeasuredValueAttribute(decodedValue) } suspend fun subscribeMaxMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MaxMeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MaxMeasuredValueAttributeSubscriptionState.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) { - "Maxmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Maxmeasuredvalue 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.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MaxMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readToleranceAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readToleranceAttribute(): UShort? { + 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}") - } + 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) { - "Tolerance attribute not found in response" - } + } + + requireNotNull(attributeData) { "Tolerance 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeToleranceAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Tolerance attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Tolerance 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)) - } - + 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 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -640,97 +576,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -738,97 +673,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -836,97 +768,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -934,81 +863,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1020,80 +944,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1106,7 +1027,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/FormaldehydeConcentrationMeasurementCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/FormaldehydeConcentrationMeasurementCluster.kt index 472a14b09e3fea..40c38c1089e743 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/FormaldehydeConcentrationMeasurementCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/FormaldehydeConcentrationMeasurementCluster.kt @@ -17,1371 +17,1273 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.FloatSubscriptionState import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse -import matter.controller.model.AttributePath -import matter.controller.model.CommandPath +import matter.controller.UShortSubscriptionState import matter.controller.cluster.structs.* +import matter.controller.model.AttributePath import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader -import matter.tlv.TlvWriter -class FormaldehydeConcentrationMeasurementCluster(private val controller: MatterController, private val endpointId: UShort) {class MeasuredValueAttribute( - val value: Float? - ) +class FormaldehydeConcentrationMeasurementCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class MeasuredValueAttribute(val value: Float?) sealed class MeasuredValueAttributeSubscriptionState { - data class Success( - val value: Float? - ) : MeasuredValueAttributeSubscriptionState() - + data class Success(val value: Float?) : MeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() - } -class MinMeasuredValueAttribute( - val value: Float? - ) + object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() + } + + class MinMeasuredValueAttribute(val value: Float?) sealed class MinMeasuredValueAttributeSubscriptionState { - data class Success( - val value: Float? - ) : MinMeasuredValueAttributeSubscriptionState() - + data class Success(val value: Float?) : MinMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MinMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() - } -class MaxMeasuredValueAttribute( - val value: Float? - ) + object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() + } + + class MaxMeasuredValueAttribute(val value: Float?) sealed class MaxMeasuredValueAttributeSubscriptionState { - data class Success( - val value: Float? - ) : MaxMeasuredValueAttributeSubscriptionState() - + data class Success(val value: Float?) : MaxMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MaxMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() - } -class PeakMeasuredValueAttribute( - val value: Float? - ) + object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() + } + + class PeakMeasuredValueAttribute(val value: Float?) sealed class PeakMeasuredValueAttributeSubscriptionState { - data class Success( - val value: Float? - ) : PeakMeasuredValueAttributeSubscriptionState() - + data class Success(val value: Float?) : PeakMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : PeakMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : PeakMeasuredValueAttributeSubscriptionState() - } -class AverageMeasuredValueAttribute( - val value: Float? - ) + object SubscriptionEstablished : PeakMeasuredValueAttributeSubscriptionState() + } + + class AverageMeasuredValueAttribute(val value: Float?) sealed class AverageMeasuredValueAttributeSubscriptionState { - data class Success( - val value: Float? - ) : AverageMeasuredValueAttributeSubscriptionState() - + data class Success(val value: Float?) : AverageMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : AverageMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : AverageMeasuredValueAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : AverageMeasuredValueAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } -suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } + + suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute { + 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}") - } + 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) { - "Measuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Measuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return MeasuredValueAttribute(decodedValue) } suspend fun subscribeMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MeasuredValueAttributeSubscriptionState.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) { - "Measuredvalue attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Measuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute { + 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}") - } + 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) { - "Minmeasuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Minmeasuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return MinMeasuredValueAttribute(decodedValue) } suspend fun subscribeMinMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MinMeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MinMeasuredValueAttributeSubscriptionState.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) { - "Minmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Minmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MinMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute { + 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}") - } + 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) { - "Maxmeasuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Maxmeasuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return MaxMeasuredValueAttribute(decodedValue) } suspend fun subscribeMaxMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MaxMeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MaxMeasuredValueAttributeSubscriptionState.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) { - "Maxmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Maxmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MaxMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPeakMeasuredValueAttribute(): PeakMeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readPeakMeasuredValueAttribute(): PeakMeasuredValueAttribute { + 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}") - } + 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) { - "Peakmeasuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Peakmeasuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return PeakMeasuredValueAttribute(decodedValue) } suspend fun subscribePeakMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(PeakMeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + PeakMeasuredValueAttributeSubscriptionState.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) { - "Peakmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Peakmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(PeakMeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(PeakMeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(PeakMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPeakMeasuredValueWindowAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 4u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readPeakMeasuredValueWindowAttribute(): UInt? { + 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}") - } + 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) { - "Peakmeasuredvaluewindow attribute not found in response" - } + } + + requireNotNull(attributeData) { "Peakmeasuredvaluewindow attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribePeakMeasuredValueWindowAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Peakmeasuredvaluewindow attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Peakmeasuredvaluewindow attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAverageMeasuredValueAttribute(): AverageMeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 5u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readAverageMeasuredValueAttribute(): AverageMeasuredValueAttribute { + 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}") - } + 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) { - "Averagemeasuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Averagemeasuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return AverageMeasuredValueAttribute(decodedValue) } suspend fun subscribeAverageMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(AverageMeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + AverageMeasuredValueAttributeSubscriptionState.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) { - "Averagemeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Averagemeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(AverageMeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(AverageMeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(AverageMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAverageMeasuredValueWindowAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 6u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readAverageMeasuredValueWindowAttribute(): UInt? { + 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}") - } + 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) { - "Averagemeasuredvaluewindow attribute not found in response" - } + } + + requireNotNull(attributeData) { "Averagemeasuredvaluewindow attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeAverageMeasuredValueWindowAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Averagemeasuredvaluewindow attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Averagemeasuredvaluewindow attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readUncertaintyAttribute(): Float? {val ATTRIBUTE_ID: UInt = 7u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readUncertaintyAttribute(): Float? { + 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}") - } + 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) { - "Uncertainty attribute not found in response" - } + } + + requireNotNull(attributeData) { "Uncertainty attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - + val decodedValue: Float? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeUncertaintyAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(FloatSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + FloatSubscriptionState.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) { - "Uncertainty attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Uncertainty attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(FloatSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(FloatSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(FloatSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMeasurementUnitAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 8u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMeasurementUnitAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 8u + + 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}") - } + 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) { - "Measurementunit attribute not found in response" - } + } + + requireNotNull(attributeData) { "Measurementunit 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeMeasurementUnitAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Measurementunit attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Measurementunit 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)) - } - + 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 readMeasurementMediumAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 9u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMeasurementMediumAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 9u + + 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}") - } + 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) { - "Measurementmedium attribute not found in response" - } + } + + requireNotNull(attributeData) { "Measurementmedium 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeMeasurementMediumAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Measurementmedium attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Measurementmedium 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)) - } - + 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 readLevelValueAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 10u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readLevelValueAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 10u + + 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}") - } + 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) { - "Levelvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Levelvalue 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeLevelValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Levelvalue attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Levelvalue 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)) - } - + 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 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1389,97 +1291,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1487,97 +1388,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1585,97 +1483,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1683,81 +1578,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1769,80 +1659,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1855,11 +1742,12 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { - private val logger = Logger.getLogger(FormaldehydeConcentrationMeasurementCluster::class.java.name) + private val logger = + Logger.getLogger(FormaldehydeConcentrationMeasurementCluster::class.java.name) const val CLUSTER_ID: UInt = 1067u } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/GeneralCommissioningCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/GeneralCommissioningCluster.kt index 7fd6f12433d2fa..92e76e250f0eca 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/GeneralCommissioningCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/GeneralCommissioningCluster.kt @@ -17,136 +17,104 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration 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.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class GeneralCommissioningCluster(private val controller: MatterController, private val endpointId: UShort) { - class ArmFailSafeResponse( - val errorCode: UByte, - val debugText: String - ) +class GeneralCommissioningCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class ArmFailSafeResponse(val errorCode: UByte, val debugText: String) - class SetRegulatoryConfigResponse( - val errorCode: UByte, - val debugText: String - ) + class SetRegulatoryConfigResponse(val errorCode: UByte, val debugText: String) - class CommissioningCompleteResponse( - val errorCode: UByte, - val debugText: String - ) + class CommissioningCompleteResponse(val errorCode: UByte, val debugText: String) - class SetTCAcknowledgementsResponse( - val errorCode: UByte - ) -class BasicCommissioningInfoAttribute( + class SetTCAcknowledgementsResponse(val errorCode: UByte) + + class BasicCommissioningInfoAttribute( val value: GeneralCommissioningClusterBasicCommissioningInfo ) sealed class BasicCommissioningInfoAttributeSubscriptionState { - data class Success( - val value: GeneralCommissioningClusterBasicCommissioningInfo - ) : BasicCommissioningInfoAttributeSubscriptionState() - + data class Success(val value: GeneralCommissioningClusterBasicCommissioningInfo) : + BasicCommissioningInfoAttributeSubscriptionState() + data class Error(val exception: Exception) : BasicCommissioningInfoAttributeSubscriptionState() - object SubscriptionEstablished : BasicCommissioningInfoAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : BasicCommissioningInfoAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun armFailSafe(expiryLengthSeconds: UShort - ,breadcrumb: ULong - ,timedInvokeTimeout: Duration? = null): ArmFailSafeResponse { + suspend fun armFailSafe( + expiryLengthSeconds: UShort, + breadcrumb: ULong, + timedInvokeTimeout: Duration? = null, + ): ArmFailSafeResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() @@ -156,14 +124,14 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_EXPIRY_LENGTH_SECONDS_REQ), expiryLengthSeconds) val TAG_BREADCRUMB_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_BREADCRUMB_REQ), breadcrumb) + tlvWriter.put(ContextSpecificTag(TAG_BREADCRUMB_REQ), breadcrumb) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -173,49 +141,43 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_ERROR_CODE: Int = 0 var errorCode_decoded: UByte? = null - + val TAG_DEBUG_TEXT: Int = 1 var debugText_decoded: String? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_ERROR_CODE)) {errorCode_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_DEBUG_TEXT)) {debugText_decoded = tlvReader.getString(tag)} - + if (tag == ContextSpecificTag(TAG_ERROR_CODE)) { + errorCode_decoded = tlvReader.getUByte(tag) + } - else { + if (tag == ContextSpecificTag(TAG_DEBUG_TEXT)) { + debugText_decoded = tlvReader.getString(tag) + } else { tlvReader.skipElement() } } - - if (errorCode_decoded == null) { - throw IllegalStateException("errorCode not found in TLV") + throw IllegalStateException("errorCode not found in TLV") } - - + if (debugText_decoded == null) { - throw IllegalStateException("debugText not found in TLV") + throw IllegalStateException("debugText not found in TLV") } - tlvReader.exitContainer() - return ArmFailSafeResponse( - errorCode_decoded, - debugText_decoded - ) + return ArmFailSafeResponse(errorCode_decoded, debugText_decoded) } - suspend fun setRegulatoryConfig(newRegulatoryConfig: UByte - ,countryCode: String - ,breadcrumb: ULong - ,timedInvokeTimeout: Duration? = null): SetRegulatoryConfigResponse { + suspend fun setRegulatoryConfig( + newRegulatoryConfig: UByte, + countryCode: String, + breadcrumb: ULong, + timedInvokeTimeout: Duration? = null, + ): SetRegulatoryConfigResponse { val commandId: UInt = 2u val tlvWriter = TlvWriter() @@ -228,14 +190,14 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_COUNTRY_CODE_REQ), countryCode) val TAG_BREADCRUMB_REQ: Int = 2 - tlvWriter.put(ContextSpecificTag(TAG_BREADCRUMB_REQ), breadcrumb) + tlvWriter.put(ContextSpecificTag(TAG_BREADCRUMB_REQ), breadcrumb) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -245,57 +207,51 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_ERROR_CODE: Int = 0 var errorCode_decoded: UByte? = null - + val TAG_DEBUG_TEXT: Int = 1 var debugText_decoded: String? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_ERROR_CODE)) {errorCode_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_DEBUG_TEXT)) {debugText_decoded = tlvReader.getString(tag)} - + if (tag == ContextSpecificTag(TAG_ERROR_CODE)) { + errorCode_decoded = tlvReader.getUByte(tag) + } - else { + if (tag == ContextSpecificTag(TAG_DEBUG_TEXT)) { + debugText_decoded = tlvReader.getString(tag) + } else { tlvReader.skipElement() } } - - if (errorCode_decoded == null) { - throw IllegalStateException("errorCode not found in TLV") + throw IllegalStateException("errorCode not found in TLV") } - - + if (debugText_decoded == null) { - throw IllegalStateException("debugText not found in TLV") + throw IllegalStateException("debugText not found in TLV") } - tlvReader.exitContainer() - return SetRegulatoryConfigResponse( - errorCode_decoded, - debugText_decoded - ) + return SetRegulatoryConfigResponse(errorCode_decoded, debugText_decoded) } - suspend fun commissioningComplete(timedInvokeTimeout: Duration? = null): CommissioningCompleteResponse { + suspend fun commissioningComplete( + timedInvokeTimeout: Duration? = null + ): CommissioningCompleteResponse { val commandId: UInt = 4u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -305,48 +261,42 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_ERROR_CODE: Int = 0 var errorCode_decoded: UByte? = null - + val TAG_DEBUG_TEXT: Int = 1 var debugText_decoded: String? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_ERROR_CODE)) {errorCode_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_DEBUG_TEXT)) {debugText_decoded = tlvReader.getString(tag)} - + if (tag == ContextSpecificTag(TAG_ERROR_CODE)) { + errorCode_decoded = tlvReader.getUByte(tag) + } - else { + if (tag == ContextSpecificTag(TAG_DEBUG_TEXT)) { + debugText_decoded = tlvReader.getString(tag) + } else { tlvReader.skipElement() } } - - if (errorCode_decoded == null) { - throw IllegalStateException("errorCode not found in TLV") + throw IllegalStateException("errorCode not found in TLV") } - - + if (debugText_decoded == null) { - throw IllegalStateException("debugText not found in TLV") + throw IllegalStateException("debugText not found in TLV") } - tlvReader.exitContainer() - return CommissioningCompleteResponse( - errorCode_decoded, - debugText_decoded - ) + return CommissioningCompleteResponse(errorCode_decoded, debugText_decoded) } - suspend fun setTCAcknowledgements(TCVersion: UShort - ,TCUserResponse: UShort - ,timedInvokeTimeout: Duration? = null): SetTCAcknowledgementsResponse { + suspend fun setTCAcknowledgements( + TCVersion: UShort, + TCUserResponse: UShort, + timedInvokeTimeout: Duration? = null, + ): SetTCAcknowledgementsResponse { val commandId: UInt = 6u val tlvWriter = TlvWriter() @@ -356,14 +306,14 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_TC_VERSION_REQ), TCVersion) val TAG_TC_USER_RESPONSE_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_TC_USER_RESPONSE_REQ), TCUserResponse) + tlvWriter.put(ContextSpecificTag(TAG_TC_USER_RESPONSE_REQ), TCUserResponse) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -373,93 +323,74 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_ERROR_CODE: Int = 0 var errorCode_decoded: UByte? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_ERROR_CODE)) {errorCode_decoded = tlvReader.getUByte(tag)} - - - else { + if (tag == ContextSpecificTag(TAG_ERROR_CODE)) { + errorCode_decoded = tlvReader.getUByte(tag) + } else { tlvReader.skipElement() } } - - if (errorCode_decoded == null) { - throw IllegalStateException("errorCode not found in TLV") + throw IllegalStateException("errorCode not found in TLV") } - tlvReader.exitContainer() - return SetTCAcknowledgementsResponse( - errorCode_decoded - ) + return SetTCAcknowledgementsResponse(errorCode_decoded) } -suspend fun readBreadcrumbAttribute(): ULong {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readBreadcrumbAttribute(): ULong { + 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}") - } + 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) { - "Breadcrumb attribute not found in response" - } + } + + requireNotNull(attributeData) { "Breadcrumb attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: ULong = tlvReader.getULong(AnonymousTag) - return decodedValue } - suspend fun writeBreadcrumbAttribute( - value: ULong, - timedWriteTimeout: Duration? = null) { + suspend fun writeBreadcrumbAttribute(value: ULong, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -480,43 +411,45 @@ suspend fun readBreadcrumbAttribute(): ULong {val ATTRIBUTE_ID: UInt = 0u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeBreadcrumbAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ULongSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ULongSubscriptionState.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) { - "Breadcrumb attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Breadcrumb attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -528,85 +461,84 @@ suspend fun readBreadcrumbAttribute(): ULong {val ATTRIBUTE_ID: UInt = 0u emit(ULongSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readBasicCommissioningInfoAttribute(): BasicCommissioningInfoAttribute {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readBasicCommissioningInfoAttribute(): BasicCommissioningInfoAttribute { + 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}") - } + 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) { - "Basiccommissioninginfo attribute not found in response" - } + } + + requireNotNull(attributeData) { "Basiccommissioninginfo attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: GeneralCommissioningClusterBasicCommissioningInfo = GeneralCommissioningClusterBasicCommissioningInfo.fromTlv(AnonymousTag, tlvReader) - + val decodedValue: GeneralCommissioningClusterBasicCommissioningInfo = + GeneralCommissioningClusterBasicCommissioningInfo.fromTlv(AnonymousTag, tlvReader) return BasicCommissioningInfoAttribute(decodedValue) } suspend fun subscribeBasicCommissioningInfoAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(BasicCommissioningInfoAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + BasicCommissioningInfoAttributeSubscriptionState.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) { - "Basiccommissioninginfo attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Basiccommissioninginfo attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: GeneralCommissioningClusterBasicCommissioningInfo = GeneralCommissioningClusterBasicCommissioningInfo.fromTlv(AnonymousTag, tlvReader) + val decodedValue: GeneralCommissioningClusterBasicCommissioningInfo = + GeneralCommissioningClusterBasicCommissioningInfo.fromTlv(AnonymousTag, tlvReader) emit(BasicCommissioningInfoAttributeSubscriptionState.Success(decodedValue)) } @@ -614,80 +546,77 @@ suspend fun readBasicCommissioningInfoAttribute(): BasicCommissioningInfoAttribu emit(BasicCommissioningInfoAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRegulatoryConfigAttribute(): UByte {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readRegulatoryConfigAttribute(): UByte { + 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}") - } + 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) { - "Regulatoryconfig attribute not found in response" - } + } + + requireNotNull(attributeData) { "Regulatoryconfig 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 subscribeRegulatoryConfigAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Regulatoryconfig attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Regulatoryconfig attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -700,80 +629,77 @@ suspend fun readRegulatoryConfigAttribute(): UByte {val ATTRIBUTE_ID: UInt = 2u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readLocationCapabilityAttribute(): UByte {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readLocationCapabilityAttribute(): UByte { + 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}") - } + 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) { - "Locationcapability attribute not found in response" - } + } + + requireNotNull(attributeData) { "Locationcapability 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 subscribeLocationCapabilityAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Locationcapability attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Locationcapability attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -786,80 +712,77 @@ suspend fun readLocationCapabilityAttribute(): UByte {val ATTRIBUTE_ID: UInt = 3 emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readSupportsConcurrentConnectionAttribute(): Boolean {val ATTRIBUTE_ID: UInt = 4u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readSupportsConcurrentConnectionAttribute(): Boolean { + 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}") - } + 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) { - "Supportsconcurrentconnection attribute not found in response" - } + } + + requireNotNull(attributeData) { "Supportsconcurrentconnection attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Boolean = tlvReader.getBoolean(AnonymousTag) - return decodedValue } suspend fun subscribeSupportsConcurrentConnectionAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Supportsconcurrentconnection attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Supportsconcurrentconnection attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -872,485 +795,468 @@ suspend fun readSupportsConcurrentConnectionAttribute(): Boolean {val ATTRIBUTE_ emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readTCAcceptedVersionAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 5u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readTCAcceptedVersionAttribute(): UShort? { + 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}") - } + 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) { - "Tcacceptedversion attribute not found in response" - } + } + + requireNotNull(attributeData) { "Tcacceptedversion 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeTCAcceptedVersionAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Tcacceptedversion attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Tcacceptedversion 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)) - } - + 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 readTCMinRequiredVersionAttribute(): 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) - ) - + + suspend fun readTCMinRequiredVersionAttribute(): 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}") - } + 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) { - "Tcminrequiredversion attribute not found in response" - } + } + + requireNotNull(attributeData) { "Tcminrequiredversion 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeTCMinRequiredVersionAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Tcminrequiredversion attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Tcminrequiredversion 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)) - } - + 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 readTCAcknowledgementsAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 7u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readTCAcknowledgementsAttribute(): UShort? { + 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}") - } + 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) { - "Tcacknowledgements attribute not found in response" - } + } + + requireNotNull(attributeData) { "Tcacknowledgements 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeTCAcknowledgementsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Tcacknowledgements attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Tcacknowledgements 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)) - } - + 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 readTCAcknowledgementsRequiredAttribute(): Boolean? {val ATTRIBUTE_ID: UInt = 8u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readTCAcknowledgementsRequiredAttribute(): Boolean? { + val ATTRIBUTE_ID: UInt = 8u + + 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}") - } + 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) { - "Tcacknowledgementsrequired attribute not found in response" - } + } + + requireNotNull(attributeData) { "Tcacknowledgementsrequired 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 - } - + val decodedValue: Boolean? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeTCAcknowledgementsRequiredAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Tcacknowledgementsrequired attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Tcacknowledgementsrequired 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)) - } - + 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 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1358,97 +1264,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1456,97 +1361,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1554,97 +1456,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1652,81 +1551,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1738,80 +1632,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1824,7 +1715,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/GeneralDiagnosticsCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/GeneralDiagnosticsCluster.kt index b930fde5339fde..93bab933864e0e 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/GeneralDiagnosticsCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/GeneralDiagnosticsCluster.kt @@ -17,165 +17,125 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration 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.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.UShortSubscriptionState +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class GeneralDiagnosticsCluster(private val controller: MatterController, private val endpointId: UShort) { - class TimeSnapshotResponse( - val systemTimeMs: ULong, - val posixTimeMs: ULong? - ) +class GeneralDiagnosticsCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class TimeSnapshotResponse(val systemTimeMs: ULong, val posixTimeMs: ULong?) + + class PayloadTestResponse(val payload: ByteArray) - class PayloadTestResponse( - val payload: ByteArray - ) -class NetworkInterfacesAttribute( - val value: List - ) + class NetworkInterfacesAttribute(val value: List) sealed class NetworkInterfacesAttributeSubscriptionState { - data class Success( - val value: List - ) : NetworkInterfacesAttributeSubscriptionState() - + data class Success(val value: List) : + NetworkInterfacesAttributeSubscriptionState() + data class Error(val exception: Exception) : NetworkInterfacesAttributeSubscriptionState() - object SubscriptionEstablished : NetworkInterfacesAttributeSubscriptionState() - } -class ActiveHardwareFaultsAttribute( - val value: List? - ) + object SubscriptionEstablished : NetworkInterfacesAttributeSubscriptionState() + } + + class ActiveHardwareFaultsAttribute(val value: List?) sealed class ActiveHardwareFaultsAttributeSubscriptionState { - data class Success( - val value: List? - ) : ActiveHardwareFaultsAttributeSubscriptionState() - + data class Success(val value: List?) : ActiveHardwareFaultsAttributeSubscriptionState() + data class Error(val exception: Exception) : ActiveHardwareFaultsAttributeSubscriptionState() - object SubscriptionEstablished : ActiveHardwareFaultsAttributeSubscriptionState() - } -class ActiveRadioFaultsAttribute( - val value: List? - ) + object SubscriptionEstablished : ActiveHardwareFaultsAttributeSubscriptionState() + } + + class ActiveRadioFaultsAttribute(val value: List?) sealed class ActiveRadioFaultsAttributeSubscriptionState { - data class Success( - val value: List? - ) : ActiveRadioFaultsAttributeSubscriptionState() - + data class Success(val value: List?) : ActiveRadioFaultsAttributeSubscriptionState() + data class Error(val exception: Exception) : ActiveRadioFaultsAttributeSubscriptionState() - object SubscriptionEstablished : ActiveRadioFaultsAttributeSubscriptionState() - } -class ActiveNetworkFaultsAttribute( - val value: List? - ) + object SubscriptionEstablished : ActiveRadioFaultsAttributeSubscriptionState() + } + + class ActiveNetworkFaultsAttribute(val value: List?) sealed class ActiveNetworkFaultsAttributeSubscriptionState { - data class Success( - val value: List? - ) : ActiveNetworkFaultsAttributeSubscriptionState() - + data class Success(val value: List?) : ActiveNetworkFaultsAttributeSubscriptionState() + data class Error(val exception: Exception) : ActiveNetworkFaultsAttributeSubscriptionState() - object SubscriptionEstablished : ActiveNetworkFaultsAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : ActiveNetworkFaultsAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun testEventTrigger(enableKey: ByteArray - ,eventTrigger: ULong - ,timedInvokeTimeout: Duration? = null) { + suspend fun testEventTrigger( + enableKey: ByteArray, + eventTrigger: ULong, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 0u val tlvWriter = TlvWriter() @@ -185,14 +145,14 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_ENABLE_KEY_REQ), enableKey) val TAG_EVENT_TRIGGER_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_EVENT_TRIGGER_REQ), eventTrigger) + tlvWriter.put(ContextSpecificTag(TAG_EVENT_TRIGGER_REQ), eventTrigger) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -203,14 +163,14 @@ class AttributeListAttribute( val commandId: UInt = 1u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -220,57 +180,50 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_SYSTEM_TIME_MS: Int = 0 var systemTimeMs_decoded: ULong? = null - + val TAG_POSIX_TIME_MS: Int = 1 var posixTimeMs_decoded: ULong? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_SYSTEM_TIME_MS)) {systemTimeMs_decoded = tlvReader.getULong(tag)} - - if (tag == ContextSpecificTag(TAG_POSIX_TIME_MS)) {posixTimeMs_decoded = + if (tag == ContextSpecificTag(TAG_SYSTEM_TIME_MS)) { + systemTimeMs_decoded = tlvReader.getULong(tag) + } + + if (tag == ContextSpecificTag(TAG_POSIX_TIME_MS)) { + posixTimeMs_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (!tlvReader.isNull()) { - tlvReader.getULong(tag) - } else { - tlvReader.getNull(tag) - null - } - }} - - - else { + tlvReader.getULong(tag) + } else { + tlvReader.getNull(tag) + null + } + } + } else { tlvReader.skipElement() } } - - if (systemTimeMs_decoded == null) { - throw IllegalStateException("systemTimeMs not found in TLV") + throw IllegalStateException("systemTimeMs not found in TLV") } - - - tlvReader.exitContainer() - return TimeSnapshotResponse( - systemTimeMs_decoded, - posixTimeMs_decoded - ) + return TimeSnapshotResponse(systemTimeMs_decoded, posixTimeMs_decoded) } - suspend fun payloadTestRequest(enableKey: ByteArray - ,value: UByte - ,count: UShort - ,timedInvokeTimeout: Duration? = null): PayloadTestResponse { + suspend fun payloadTestRequest( + enableKey: ByteArray, + value: UByte, + count: UShort, + timedInvokeTimeout: Duration? = null, + ): PayloadTestResponse { val commandId: UInt = 3u val tlvWriter = TlvWriter() @@ -283,14 +236,14 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_VALUE_REQ), value) val TAG_COUNT_REQ: Int = 2 - tlvWriter.put(ContextSpecificTag(TAG_COUNT_REQ), count) + tlvWriter.put(ContextSpecificTag(TAG_COUNT_REQ), count) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -300,122 +253,113 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_PAYLOAD: Int = 0 var payload_decoded: ByteArray? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_PAYLOAD)) {payload_decoded = tlvReader.getByteArray(tag)} - - - else { + if (tag == ContextSpecificTag(TAG_PAYLOAD)) { + payload_decoded = tlvReader.getByteArray(tag) + } else { tlvReader.skipElement() } } - - if (payload_decoded == null) { - throw IllegalStateException("payload not found in TLV") + throw IllegalStateException("payload not found in TLV") } - tlvReader.exitContainer() - return PayloadTestResponse( - payload_decoded - ) + return PayloadTestResponse(payload_decoded) } -suspend fun readNetworkInterfacesAttribute(): NetworkInterfacesAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readNetworkInterfacesAttribute(): NetworkInterfacesAttribute { + 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}") - } + 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) { - "Networkinterfaces attribute not found in response" - } + } + + requireNotNull(attributeData) { "Networkinterfaces 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(GeneralDiagnosticsClusterNetworkInterface.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(GeneralDiagnosticsClusterNetworkInterface.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return NetworkInterfacesAttribute(decodedValue) } suspend fun subscribeNetworkInterfacesAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(NetworkInterfacesAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + NetworkInterfacesAttributeSubscriptionState.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) { - "Networkinterfaces attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Networkinterfaces 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(GeneralDiagnosticsClusterNetworkInterface.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(GeneralDiagnosticsClusterNetworkInterface.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(NetworkInterfacesAttributeSubscriptionState.Success(decodedValue)) } @@ -423,81 +367,76 @@ suspend fun readNetworkInterfacesAttribute(): NetworkInterfacesAttribute {val AT emit(NetworkInterfacesAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRebootCountAttribute(): UShort {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readRebootCountAttribute(): UShort { + 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}") - } + 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) { - "Rebootcount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rebootcount 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 subscribeRebootCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Rebootcount attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Rebootcount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -509,698 +448,667 @@ suspend fun readRebootCountAttribute(): UShort {val ATTRIBUTE_ID: UInt = 1u emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readUpTimeAttribute(): ULong? {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readUpTimeAttribute(): ULong? { + 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}") - } + 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) { - "Uptime attribute not found in response" - } + } + + requireNotNull(attributeData) { "Uptime attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ULong? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getULong(AnonymousTag) - } else { - null - } - + val decodedValue: ULong? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeUpTimeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ULongSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ULongSubscriptionState.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) { - "Uptime attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Uptime 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.isNextTag(AnonymousTag)) { - tlvReader.getULong(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(ULongSubscriptionState.Success(it)) - } - + val decodedValue: ULong? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(ULongSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ULongSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readTotalOperationalHoursAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readTotalOperationalHoursAttribute(): UInt? { + 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}") - } + 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) { - "Totaloperationalhours attribute not found in response" - } + } + + requireNotNull(attributeData) { "Totaloperationalhours attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeTotalOperationalHoursAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Totaloperationalhours attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Totaloperationalhours attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readBootReasonAttribute(): 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) - ) - + + suspend fun readBootReasonAttribute(): 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}") - } + 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) { - "Bootreason attribute not found in response" - } + } + + requireNotNull(attributeData) { "Bootreason 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeBootReasonAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Bootreason attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Bootreason 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)) - } - + 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 readActiveHardwareFaultsAttribute(): ActiveHardwareFaultsAttribute {val ATTRIBUTE_ID: UInt = 5u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readActiveHardwareFaultsAttribute(): ActiveHardwareFaultsAttribute { + 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}") - } + 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) { - "Activehardwarefaults attribute not found in response" - } + } + + requireNotNull(attributeData) { "Activehardwarefaults attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null } - tlvReader.exitContainer() - } - } else { - null - } - return ActiveHardwareFaultsAttribute(decodedValue) } suspend fun subscribeActiveHardwareFaultsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ActiveHardwareFaultsAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ActiveHardwareFaultsAttributeSubscriptionState.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) { - "Activehardwarefaults attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Activehardwarefaults attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { - emit(ActiveHardwareFaultsAttributeSubscriptionState.Success(it)) - } - + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { emit(ActiveHardwareFaultsAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ActiveHardwareFaultsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readActiveRadioFaultsAttribute(): ActiveRadioFaultsAttribute {val ATTRIBUTE_ID: UInt = 6u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readActiveRadioFaultsAttribute(): ActiveRadioFaultsAttribute { + 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}") - } + 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) { - "Activeradiofaults attribute not found in response" - } + } + + requireNotNull(attributeData) { "Activeradiofaults attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null } - tlvReader.exitContainer() - } - } else { - null - } - return ActiveRadioFaultsAttribute(decodedValue) } suspend fun subscribeActiveRadioFaultsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ActiveRadioFaultsAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ActiveRadioFaultsAttributeSubscriptionState.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) { - "Activeradiofaults attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Activeradiofaults attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { - emit(ActiveRadioFaultsAttributeSubscriptionState.Success(it)) - } - + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { emit(ActiveRadioFaultsAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ActiveRadioFaultsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readActiveNetworkFaultsAttribute(): ActiveNetworkFaultsAttribute {val ATTRIBUTE_ID: UInt = 7u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readActiveNetworkFaultsAttribute(): ActiveNetworkFaultsAttribute { + 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}") - } + 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) { - "Activenetworkfaults attribute not found in response" - } + } + + requireNotNull(attributeData) { "Activenetworkfaults attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null } - tlvReader.exitContainer() - } - } else { - null - } - return ActiveNetworkFaultsAttribute(decodedValue) } suspend fun subscribeActiveNetworkFaultsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ActiveNetworkFaultsAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ActiveNetworkFaultsAttributeSubscriptionState.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) { - "Activenetworkfaults attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Activenetworkfaults attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { - emit(ActiveNetworkFaultsAttributeSubscriptionState.Success(it)) - } - + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { emit(ActiveNetworkFaultsAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ActiveNetworkFaultsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readTestEventTriggersEnabledAttribute(): Boolean {val ATTRIBUTE_ID: UInt = 8u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readTestEventTriggersEnabledAttribute(): Boolean { + val ATTRIBUTE_ID: UInt = 8u + + 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}") - } + 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) { - "Testeventtriggersenabled attribute not found in response" - } + } + + requireNotNull(attributeData) { "Testeventtriggersenabled attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Boolean = tlvReader.getBoolean(AnonymousTag) - return decodedValue } suspend fun subscribeTestEventTriggersEnabledAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Testeventtriggersenabled attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Testeventtriggersenabled attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -1213,97 +1121,96 @@ suspend fun readTestEventTriggersEnabledAttribute(): Boolean {val ATTRIBUTE_ID: emit(BooleanSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1311,97 +1218,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1409,97 +1315,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1507,97 +1410,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1605,81 +1505,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1691,80 +1586,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1777,7 +1669,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/GroupKeyManagementCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/GroupKeyManagementCluster.kt index b571528b945460..a693149fedc58e 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/GroupKeyManagementCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/GroupKeyManagementCluster.kt @@ -17,173 +17,143 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState -import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class GroupKeyManagementCluster(private val controller: MatterController, private val endpointId: UShort) { - class KeySetReadResponse( - val groupKeySet: GroupKeyManagementClusterGroupKeySetStruct - ) +class GroupKeyManagementCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class KeySetReadResponse(val groupKeySet: GroupKeyManagementClusterGroupKeySetStruct) + + class KeySetReadAllIndicesResponse(val groupKeySetIDs: List) - class KeySetReadAllIndicesResponse( - val groupKeySetIDs: List - ) -class GroupKeyMapAttribute( - val value: List - ) + class GroupKeyMapAttribute(val value: List) sealed class GroupKeyMapAttributeSubscriptionState { - data class Success( - val value: List - ) : GroupKeyMapAttributeSubscriptionState() - + data class Success(val value: List) : + GroupKeyMapAttributeSubscriptionState() + data class Error(val exception: Exception) : GroupKeyMapAttributeSubscriptionState() - object SubscriptionEstablished : GroupKeyMapAttributeSubscriptionState() - } -class GroupTableAttribute( - val value: List - ) + object SubscriptionEstablished : GroupKeyMapAttributeSubscriptionState() + } + + class GroupTableAttribute(val value: List) sealed class GroupTableAttributeSubscriptionState { - data class Success( - val value: List - ) : GroupTableAttributeSubscriptionState() - + data class Success(val value: List) : + GroupTableAttributeSubscriptionState() + data class Error(val exception: Exception) : GroupTableAttributeSubscriptionState() - object SubscriptionEstablished : GroupTableAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GroupTableAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun keySetWrite(groupKeySet: GroupKeyManagementClusterGroupKeySetStruct - ,timedInvokeTimeout: Duration? = null) { + suspend fun keySetWrite( + groupKeySet: GroupKeyManagementClusterGroupKeySetStruct, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_GROUP_KEY_SET_REQ: Int = 0 - groupKeySet.toTlv(ContextSpecificTag(TAG_GROUP_KEY_SET_REQ), tlvWriter) + groupKeySet.toTlv(ContextSpecificTag(TAG_GROUP_KEY_SET_REQ), tlvWriter) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun keySetRead(groupKeySetID: UShort - ,timedInvokeTimeout: Duration? = null): KeySetReadResponse { + suspend fun keySetRead( + groupKeySetID: UShort, + timedInvokeTimeout: Duration? = null, + ): KeySetReadResponse { val commandId: UInt = 1u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_GROUP_KEY_SET_ID_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_GROUP_KEY_SET_ID_REQ), groupKeySetID) + tlvWriter.put(ContextSpecificTag(TAG_GROUP_KEY_SET_ID_REQ), groupKeySetID) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -193,68 +163,61 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_GROUP_KEY_SET: Int = 0 var groupKeySet_decoded: GroupKeyManagementClusterGroupKeySetStruct? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_GROUP_KEY_SET)) {groupKeySet_decoded = GroupKeyManagementClusterGroupKeySetStruct.fromTlv(tag, tlvReader)} - - - else { + if (tag == ContextSpecificTag(TAG_GROUP_KEY_SET)) { + groupKeySet_decoded = GroupKeyManagementClusterGroupKeySetStruct.fromTlv(tag, tlvReader) + } else { tlvReader.skipElement() } } - - if (groupKeySet_decoded == null) { - throw IllegalStateException("groupKeySet not found in TLV") + throw IllegalStateException("groupKeySet not found in TLV") } - tlvReader.exitContainer() - return KeySetReadResponse( - groupKeySet_decoded - ) + return KeySetReadResponse(groupKeySet_decoded) } - suspend fun keySetRemove(groupKeySetID: UShort - ,timedInvokeTimeout: Duration? = null) { + suspend fun keySetRemove(groupKeySetID: UShort, timedInvokeTimeout: Duration? = null) { val commandId: UInt = 3u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_GROUP_KEY_SET_ID_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_GROUP_KEY_SET_ID_REQ), groupKeySetID) + tlvWriter.put(ContextSpecificTag(TAG_GROUP_KEY_SET_ID_REQ), groupKeySetID) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun keySetReadAllIndices(timedInvokeTimeout: Duration? = null): KeySetReadAllIndicesResponse { + suspend fun keySetReadAllIndices( + timedInvokeTimeout: Duration? = null + ): KeySetReadAllIndicesResponse { val commandId: UInt = 4u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -264,109 +227,95 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_GROUP_KEY_SET_I_DS: Int = 0 var groupKeySetIDs_decoded: List? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_GROUP_KEY_SET_I_DS)) {groupKeySetIDs_decoded = buildList { - tlvReader.enterArray(tag) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getUShort(AnonymousTag)) - } - tlvReader.exitContainer() - }} - - - else { + if (tag == ContextSpecificTag(TAG_GROUP_KEY_SET_I_DS)) { + groupKeySetIDs_decoded = + buildList { + tlvReader.enterArray(tag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUShort(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { tlvReader.skipElement() } } - - if (groupKeySetIDs_decoded == null) { - throw IllegalStateException("groupKeySetIDs not found in TLV") + throw IllegalStateException("groupKeySetIDs not found in TLV") } - tlvReader.exitContainer() - return KeySetReadAllIndicesResponse( - groupKeySetIDs_decoded - ) + return KeySetReadAllIndicesResponse(groupKeySetIDs_decoded) } -suspend fun readGroupKeyMapAttribute(): GroupKeyMapAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readGroupKeyMapAttribute(): GroupKeyMapAttribute { + 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}") - } + 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) { - "Groupkeymap attribute not found in response" - } + } + + requireNotNull(attributeData) { "Groupkeymap 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(GroupKeyManagementClusterGroupKeyMapStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(GroupKeyManagementClusterGroupKeyMapStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GroupKeyMapAttribute(decodedValue) } suspend fun writeGroupKeyMapAttribute( value: List, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startArray(AnonymousTag) - for (item in value.iterator()) { - item.toTlv(AnonymousTag, tlvWriter) - } - tlvWriter.endArray() + for (item in value.iterator()) { + item.toTlv(AnonymousTag, tlvWriter) + } + tlvWriter.endArray() val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -387,53 +336,56 @@ suspend fun readGroupKeyMapAttribute(): GroupKeyMapAttribute {val ATTRIBUTE_ID: throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeGroupKeyMapAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(GroupKeyMapAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + GroupKeyMapAttributeSubscriptionState.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) { - "Groupkeymap attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Groupkeymap 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(GroupKeyManagementClusterGroupKeyMapStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(GroupKeyManagementClusterGroupKeyMapStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(GroupKeyMapAttributeSubscriptionState.Success(decodedValue)) } @@ -441,97 +393,94 @@ suspend fun readGroupKeyMapAttribute(): GroupKeyMapAttribute {val ATTRIBUTE_ID: emit(GroupKeyMapAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readGroupTableAttribute(): GroupTableAttribute {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readGroupTableAttribute(): GroupTableAttribute { + 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}") - } + 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) { - "Grouptable attribute not found in response" - } + } + + requireNotNull(attributeData) { "Grouptable 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(GroupKeyManagementClusterGroupInfoMapStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(GroupKeyManagementClusterGroupInfoMapStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GroupTableAttribute(decodedValue) } suspend fun subscribeGroupTableAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(GroupTableAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + GroupTableAttributeSubscriptionState.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) { - "Grouptable attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Grouptable 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(GroupKeyManagementClusterGroupInfoMapStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(GroupKeyManagementClusterGroupInfoMapStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(GroupTableAttributeSubscriptionState.Success(decodedValue)) } @@ -539,80 +488,77 @@ suspend fun readGroupTableAttribute(): GroupTableAttribute {val ATTRIBUTE_ID: UI emit(GroupTableAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMaxGroupsPerFabricAttribute(): 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) - ) - + + suspend fun readMaxGroupsPerFabricAttribute(): 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}") - } + 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) { - "Maxgroupsperfabric attribute not found in response" - } + } + + requireNotNull(attributeData) { "Maxgroupsperfabric 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 subscribeMaxGroupsPerFabricAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Maxgroupsperfabric attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Maxgroupsperfabric attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -625,80 +571,77 @@ suspend fun readMaxGroupsPerFabricAttribute(): UShort {val ATTRIBUTE_ID: UInt = emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMaxGroupKeysPerFabricAttribute(): UShort {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMaxGroupKeysPerFabricAttribute(): UShort { + 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}") - } + 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) { - "Maxgroupkeysperfabric attribute not found in response" - } + } + + requireNotNull(attributeData) { "Maxgroupkeysperfabric 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 subscribeMaxGroupKeysPerFabricAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Maxgroupkeysperfabric attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Maxgroupkeysperfabric attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -711,97 +654,96 @@ suspend fun readMaxGroupKeysPerFabricAttribute(): UShort {val ATTRIBUTE_ID: UInt emit(UShortSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -809,97 +751,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -907,97 +848,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1005,97 +943,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1103,81 +1038,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1189,80 +1119,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1275,7 +1202,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/GroupsCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/GroupsCluster.kt index 3c4c4edab256b0..6af48037daf4f7 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/GroupsCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/GroupsCluster.kt @@ -17,125 +17,83 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.UShortSubscriptionState +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter class GroupsCluster(private val controller: MatterController, private val endpointId: UShort) { - class AddGroupResponse( - val status: UByte, - val groupID: UShort - ) - - class ViewGroupResponse( - val status: UByte, - val groupID: UShort, - val groupName: String - ) - - class GetGroupMembershipResponse( - val capacity: UByte?, - val groupList: List - ) - - class RemoveGroupResponse( - val status: UByte, - val groupID: UShort - ) -class GeneratedCommandListAttribute( - val value: List - ) + class AddGroupResponse(val status: UByte, val groupID: UShort) + + class ViewGroupResponse(val status: UByte, val groupID: UShort, val groupName: String) + + class GetGroupMembershipResponse(val capacity: UByte?, val groupList: List) + + class RemoveGroupResponse(val status: UByte, val groupID: UShort) + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun addGroup(groupID: UShort - ,groupName: String - ,timedInvokeTimeout: Duration? = null): AddGroupResponse { + suspend fun addGroup( + groupID: UShort, + groupName: String, + timedInvokeTimeout: Duration? = null, + ): AddGroupResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() @@ -145,14 +103,14 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_GROUP_ID_REQ), groupID) val TAG_GROUP_NAME_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_GROUP_NAME_REQ), groupName) + tlvWriter.put(ContextSpecificTag(TAG_GROUP_NAME_REQ), groupName) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -162,61 +120,52 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_GROUP_ID: 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_ID)) {groupID_decoded = tlvReader.getUShort(tag)} - + if (tag == ContextSpecificTag(TAG_STATUS)) { + status_decoded = tlvReader.getUByte(tag) + } - else { + if (tag == ContextSpecificTag(TAG_GROUP_ID)) { + groupID_decoded = tlvReader.getUShort(tag) + } else { tlvReader.skipElement() } } - - if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - - + if (groupID_decoded == null) { - throw IllegalStateException("groupID not found in TLV") + throw IllegalStateException("groupID not found in TLV") } - tlvReader.exitContainer() - return AddGroupResponse( - status_decoded, - groupID_decoded - ) + return AddGroupResponse(status_decoded, groupID_decoded) } - suspend fun viewGroup(groupID: UShort - ,timedInvokeTimeout: Duration? = null): ViewGroupResponse { + suspend fun viewGroup(groupID: UShort, timedInvokeTimeout: Duration? = null): ViewGroupResponse { val commandId: UInt = 1u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_GROUP_ID_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_GROUP_ID_REQ), groupID) + tlvWriter.put(ContextSpecificTag(TAG_GROUP_ID_REQ), groupID) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -226,58 +175,52 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_GROUP_ID: Int = 1 var groupID_decoded: UShort? = null - + val TAG_GROUP_NAME: Int = 2 var groupName_decoded: String? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_GROUP_ID)) {groupID_decoded = tlvReader.getUShort(tag)} - - if (tag == ContextSpecificTag(TAG_GROUP_NAME)) {groupName_decoded = tlvReader.getString(tag)} - + if (tag == ContextSpecificTag(TAG_STATUS)) { + status_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_GROUP_ID)) { + groupID_decoded = tlvReader.getUShort(tag) + } - else { + if (tag == ContextSpecificTag(TAG_GROUP_NAME)) { + groupName_decoded = tlvReader.getString(tag) + } else { tlvReader.skipElement() } } - - if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - - + if (groupID_decoded == null) { - throw IllegalStateException("groupID not found in TLV") + throw IllegalStateException("groupID not found in TLV") } - - + if (groupName_decoded == null) { - throw IllegalStateException("groupName not found in TLV") + throw IllegalStateException("groupName not found in TLV") } - tlvReader.exitContainer() - return ViewGroupResponse( - status_decoded, - groupID_decoded, - groupName_decoded - ) + return ViewGroupResponse(status_decoded, groupID_decoded, groupName_decoded) } - suspend fun getGroupMembership(groupList: List - ,timedInvokeTimeout: Duration? = null): GetGroupMembershipResponse { + suspend fun getGroupMembership( + groupList: List, + timedInvokeTimeout: Duration? = null, + ): GetGroupMembershipResponse { val commandId: UInt = 2u val tlvWriter = TlvWriter() @@ -285,17 +228,17 @@ class AttributeListAttribute( val TAG_GROUP_LIST_REQ: Int = 0 tlvWriter.startArray(ContextSpecificTag(TAG_GROUP_LIST_REQ)) - for (item in groupList.iterator()) { - tlvWriter.put(AnonymousTag, item) - } - tlvWriter.endArray() + for (item in groupList.iterator()) { + tlvWriter.put(AnonymousTag, item) + } + tlvWriter.endArray() tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -305,75 +248,69 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_CAPACITY: Int = 0 var capacity_decoded: UByte? = null - + val TAG_GROUP_LIST: Int = 1 var groupList_decoded: List? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_CAPACITY)) {capacity_decoded = + 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_LIST)) {groupList_decoded = buildList { - tlvReader.enterArray(tag) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getUShort(AnonymousTag)) + tlvReader.getUByte(tag) + } else { + tlvReader.getNull(tag) + null + } + } } - tlvReader.exitContainer() - }} - - else { + if (tag == ContextSpecificTag(TAG_GROUP_LIST)) { + groupList_decoded = + buildList { + tlvReader.enterArray(tag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUShort(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { tlvReader.skipElement() } } - - - - if (groupList_decoded == null) { - throw IllegalStateException("groupList not found in TLV") + throw IllegalStateException("groupList not found in TLV") } - tlvReader.exitContainer() - return GetGroupMembershipResponse( - capacity_decoded, - groupList_decoded - ) + return GetGroupMembershipResponse(capacity_decoded, groupList_decoded) } - suspend fun removeGroup(groupID: UShort - ,timedInvokeTimeout: Duration? = null): RemoveGroupResponse { + suspend fun removeGroup( + groupID: UShort, + timedInvokeTimeout: Duration? = null, + ): RemoveGroupResponse { val commandId: UInt = 3u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_GROUP_ID_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_GROUP_ID_REQ), groupID) + tlvWriter.put(ContextSpecificTag(TAG_GROUP_ID_REQ), groupID) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -383,66 +320,60 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_GROUP_ID: 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_ID)) {groupID_decoded = tlvReader.getUShort(tag)} - + if (tag == ContextSpecificTag(TAG_STATUS)) { + status_decoded = tlvReader.getUByte(tag) + } - else { + if (tag == ContextSpecificTag(TAG_GROUP_ID)) { + groupID_decoded = tlvReader.getUShort(tag) + } else { tlvReader.skipElement() } } - - if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - - + if (groupID_decoded == null) { - throw IllegalStateException("groupID not found in TLV") + throw IllegalStateException("groupID not found in TLV") } - tlvReader.exitContainer() - return RemoveGroupResponse( - status_decoded, - groupID_decoded - ) + return RemoveGroupResponse(status_decoded, groupID_decoded) } suspend fun removeAllGroups(timedInvokeTimeout: Duration? = null) { val commandId: UInt = 4u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun addGroupIfIdentifying(groupID: UShort - ,groupName: String - ,timedInvokeTimeout: Duration? = null) { + suspend fun addGroupIfIdentifying( + groupID: UShort, + groupName: String, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 5u val tlvWriter = TlvWriter() @@ -452,92 +383,87 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_GROUP_ID_REQ), groupID) val TAG_GROUP_NAME_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_GROUP_NAME_REQ), groupName) + tlvWriter.put(ContextSpecificTag(TAG_GROUP_NAME_REQ), groupName) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } -suspend fun readNameSupportAttribute(): 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) - ) - + + suspend fun readNameSupportAttribute(): 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -549,97 +475,96 @@ suspend fun readNameSupportAttribute(): UByte {val ATTRIBUTE_ID: UInt = 0u emit(UByteSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -647,97 +572,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -745,97 +669,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -843,97 +764,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -941,81 +859,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1027,80 +940,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1113,7 +1023,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/HepaFilterMonitoringCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/HepaFilterMonitoringCluster.kt index 8ca45695cd230c..f6337f9fac983f 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/HepaFilterMonitoringCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/HepaFilterMonitoringCluster.kt @@ -17,410 +17,369 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration 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.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class HepaFilterMonitoringCluster(private val controller: MatterController, private val endpointId: UShort) {class LastChangedTimeAttribute( - val value: UInt? - ) +class HepaFilterMonitoringCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class LastChangedTimeAttribute(val value: UInt?) sealed class LastChangedTimeAttributeSubscriptionState { - data class Success( - val value: UInt? - ) : LastChangedTimeAttributeSubscriptionState() - + data class Success(val value: UInt?) : LastChangedTimeAttributeSubscriptionState() + data class Error(val exception: Exception) : LastChangedTimeAttributeSubscriptionState() - object SubscriptionEstablished : LastChangedTimeAttributeSubscriptionState() - } -class ReplacementProductListAttribute( + object SubscriptionEstablished : LastChangedTimeAttributeSubscriptionState() + } + + class ReplacementProductListAttribute( val value: List? ) sealed class ReplacementProductListAttributeSubscriptionState { - data class Success( - val value: List? - ) : ReplacementProductListAttributeSubscriptionState() - + data class Success(val value: List?) : + ReplacementProductListAttributeSubscriptionState() + data class Error(val exception: Exception) : ReplacementProductListAttributeSubscriptionState() - object SubscriptionEstablished : ReplacementProductListAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : ReplacementProductListAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } suspend fun resetCondition(timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } -suspend fun readConditionAttribute(): 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) - ) - + + suspend fun readConditionAttribute(): 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}") - } + 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) { - "Condition attribute not found in response" - } + } + + requireNotNull(attributeData) { "Condition 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeConditionAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Condition attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Condition 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)) - } - + 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 readDegradationDirectionAttribute(): 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) - ) - + + suspend fun readDegradationDirectionAttribute(): 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}") - } + 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) { - "Degradationdirection attribute not found in response" - } + } + + requireNotNull(attributeData) { "Degradationdirection 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeDegradationDirectionAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Degradationdirection attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Degradationdirection 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)) - } - + 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 readChangeIndicationAttribute(): UByte {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readChangeIndicationAttribute(): UByte { + 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}") - } + 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) { - "Changeindication attribute not found in response" - } + } + + requireNotNull(attributeData) { "Changeindication 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 subscribeChangeIndicationAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Changeindication attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Changeindication attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -433,174 +392,160 @@ suspend fun readChangeIndicationAttribute(): UByte {val ATTRIBUTE_ID: UInt = 2u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readInPlaceIndicatorAttribute(): 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) - ) - + + suspend fun readInPlaceIndicatorAttribute(): 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}") - } + 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) { - "Inplaceindicator attribute not found in response" - } + } + + requireNotNull(attributeData) { "Inplaceindicator 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 - } - + val decodedValue: Boolean? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeInPlaceIndicatorAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Inplaceindicator attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Inplaceindicator 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)) - } - + 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 readLastChangedTimeAttribute(): LastChangedTimeAttribute {val ATTRIBUTE_ID: UInt = 4u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readLastChangedTimeAttribute(): LastChangedTimeAttribute { + 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}") - } + 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) { - "Lastchangedtime attribute not found in response" - } + } + + requireNotNull(attributeData) { "Lastchangedtime attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return LastChangedTimeAttribute(decodedValue) } - suspend fun writeLastChangedTimeAttribute( - value: UInt, - timedWriteTimeout: Duration? = null) { + suspend fun writeLastChangedTimeAttribute(value: UInt, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 4u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -621,266 +566,270 @@ suspend fun readLastChangedTimeAttribute(): LastChangedTimeAttribute {val ATTRIB throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeLastChangedTimeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(LastChangedTimeAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + LastChangedTimeAttributeSubscriptionState.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) { - "Lastchangedtime attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Lastchangedtime attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(LastChangedTimeAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(LastChangedTimeAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(LastChangedTimeAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readReplacementProductListAttribute(): ReplacementProductListAttribute {val ATTRIBUTE_ID: UInt = 5u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readReplacementProductListAttribute(): ReplacementProductListAttribute { + 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}") - } + 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) { - "Replacementproductlist attribute not found in response" - } + } + + requireNotNull(attributeData) { "Replacementproductlist attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(HepaFilterMonitoringClusterReplacementProductStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add( + HepaFilterMonitoringClusterReplacementProductStruct.fromTlv(AnonymousTag, tlvReader) + ) + } + tlvReader.exitContainer() + } + } else { + null } - tlvReader.exitContainer() - } - } else { - null - } - return ReplacementProductListAttribute(decodedValue) } suspend fun subscribeReplacementProductListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ReplacementProductListAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ReplacementProductListAttributeSubscriptionState.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) { - "Replacementproductlist attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Replacementproductlist attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(HepaFilterMonitoringClusterReplacementProductStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { - emit(ReplacementProductListAttributeSubscriptionState.Success(it)) - } - + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add( + HepaFilterMonitoringClusterReplacementProductStruct.fromTlv( + AnonymousTag, + tlvReader, + ) + ) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { emit(ReplacementProductListAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ReplacementProductListAttributeSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -888,97 +837,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -986,97 +934,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1084,97 +1029,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1182,81 +1124,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1268,80 +1205,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1354,7 +1288,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/IcdManagementCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/IcdManagementCluster.kt index 6eb93060a63d9d..414e38d360a803 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/IcdManagementCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/IcdManagementCluster.kt @@ -17,128 +17,99 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest +import matter.controller.StringSubscriptionState import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.UShortSubscriptionState +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class IcdManagementCluster(private val controller: MatterController, private val endpointId: UShort) { - class RegisterClientResponse( - val ICDCounter: UInt - ) +class IcdManagementCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class RegisterClientResponse(val ICDCounter: UInt) - class StayActiveResponse( - val promisedActiveDuration: UInt - ) -class RegisteredClientsAttribute( + class StayActiveResponse(val promisedActiveDuration: UInt) + + class RegisteredClientsAttribute( val value: List? ) sealed class RegisteredClientsAttributeSubscriptionState { - data class Success( - val value: List? - ) : RegisteredClientsAttributeSubscriptionState() - + data class Success(val value: List?) : + RegisteredClientsAttributeSubscriptionState() + data class Error(val exception: Exception) : RegisteredClientsAttributeSubscriptionState() - object SubscriptionEstablished : RegisteredClientsAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : RegisteredClientsAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun registerClient(checkInNodeID: ULong - ,monitoredSubject: ULong - ,key: ByteArray - ,verificationKey: ByteArray? - ,clientType: UByte - ,timedInvokeTimeout: Duration? = null): RegisterClientResponse { + suspend fun registerClient( + checkInNodeID: ULong, + monitoredSubject: ULong, + key: ByteArray, + verificationKey: ByteArray?, + clientType: UByte, + timedInvokeTimeout: Duration? = null, + ): RegisterClientResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() @@ -159,14 +130,14 @@ class AttributeListAttribute( } val TAG_CLIENT_TYPE_REQ: Int = 4 - tlvWriter.put(ContextSpecificTag(TAG_CLIENT_TYPE_REQ), clientType) + tlvWriter.put(ContextSpecificTag(TAG_CLIENT_TYPE_REQ), clientType) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -176,37 +147,31 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_ICD_COUNTER: Int = 0 var ICDCounter_decoded: UInt? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_ICD_COUNTER)) {ICDCounter_decoded = tlvReader.getUInt(tag)} - - - else { + if (tag == ContextSpecificTag(TAG_ICD_COUNTER)) { + ICDCounter_decoded = tlvReader.getUInt(tag) + } else { tlvReader.skipElement() } } - - if (ICDCounter_decoded == null) { - throw IllegalStateException("ICDCounter not found in TLV") + throw IllegalStateException("ICDCounter not found in TLV") } - tlvReader.exitContainer() - return RegisterClientResponse( - ICDCounter_decoded - ) + return RegisterClientResponse(ICDCounter_decoded) } - suspend fun unregisterClient(checkInNodeID: ULong - ,verificationKey: ByteArray? - ,timedInvokeTimeout: Duration? = null) { + suspend fun unregisterClient( + checkInNodeID: ULong, + verificationKey: ByteArray?, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 2u val tlvWriter = TlvWriter() @@ -218,36 +183,38 @@ class AttributeListAttribute( val TAG_VERIFICATION_KEY_REQ: Int = 1 verificationKey?.let { tlvWriter.put(ContextSpecificTag(TAG_VERIFICATION_KEY_REQ), verificationKey) - } + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun stayActiveRequest(stayActiveDuration: UInt - ,timedInvokeTimeout: Duration? = null): StayActiveResponse { + suspend fun stayActiveRequest( + stayActiveDuration: UInt, + timedInvokeTimeout: Duration? = null, + ): StayActiveResponse { val commandId: UInt = 3u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_STAY_ACTIVE_DURATION_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_STAY_ACTIVE_DURATION_REQ), stayActiveDuration) + tlvWriter.put(ContextSpecificTag(TAG_STAY_ACTIVE_DURATION_REQ), stayActiveDuration) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -257,105 +224,94 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_PROMISED_ACTIVE_DURATION: Int = 0 var promisedActiveDuration_decoded: UInt? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_PROMISED_ACTIVE_DURATION)) {promisedActiveDuration_decoded = tlvReader.getUInt(tag)} - - - else { + if (tag == ContextSpecificTag(TAG_PROMISED_ACTIVE_DURATION)) { + promisedActiveDuration_decoded = tlvReader.getUInt(tag) + } else { tlvReader.skipElement() } } - - if (promisedActiveDuration_decoded == null) { - throw IllegalStateException("promisedActiveDuration not found in TLV") + throw IllegalStateException("promisedActiveDuration not found in TLV") } - tlvReader.exitContainer() - return StayActiveResponse( - promisedActiveDuration_decoded - ) + return StayActiveResponse(promisedActiveDuration_decoded) } -suspend fun readIdleModeDurationAttribute(): UInt {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readIdleModeDurationAttribute(): UInt { + 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}") - } + 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) { - "Idlemodeduration attribute not found in response" - } + } + + requireNotNull(attributeData) { "Idlemodeduration 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 subscribeIdleModeDurationAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Idlemodeduration attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Idlemodeduration attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -368,80 +324,77 @@ suspend fun readIdleModeDurationAttribute(): UInt {val ATTRIBUTE_ID: UInt = 0u emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readActiveModeDurationAttribute(): UInt {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readActiveModeDurationAttribute(): UInt { + 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}") - } + 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) { - "Activemodeduration attribute not found in response" - } + } + + requireNotNull(attributeData) { "Activemodeduration 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 subscribeActiveModeDurationAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Activemodeduration attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Activemodeduration attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -454,80 +407,77 @@ suspend fun readActiveModeDurationAttribute(): UInt {val ATTRIBUTE_ID: UInt = 1u emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readActiveModeThresholdAttribute(): 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) - ) - + + suspend fun readActiveModeThresholdAttribute(): 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}") - } + 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) { - "Activemodethreshold attribute not found in response" - } + } + + requireNotNull(attributeData) { "Activemodethreshold 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 subscribeActiveModeThresholdAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Activemodethreshold attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Activemodethreshold attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -540,788 +490,762 @@ suspend fun readActiveModeThresholdAttribute(): UShort {val ATTRIBUTE_ID: UInt = emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRegisteredClientsAttribute(): RegisteredClientsAttribute {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readRegisteredClientsAttribute(): RegisteredClientsAttribute { + 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}") - } + 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) { - "Registeredclients attribute not found in response" - } + } + + requireNotNull(attributeData) { "Registeredclients attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(IcdManagementClusterMonitoringRegistrationStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(IcdManagementClusterMonitoringRegistrationStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null } - tlvReader.exitContainer() - } - } else { - null - } - return RegisteredClientsAttribute(decodedValue) } suspend fun subscribeRegisteredClientsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(RegisteredClientsAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + RegisteredClientsAttributeSubscriptionState.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) { - "Registeredclients attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Registeredclients attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(IcdManagementClusterMonitoringRegistrationStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { - emit(RegisteredClientsAttributeSubscriptionState.Success(it)) - } - + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add( + IcdManagementClusterMonitoringRegistrationStruct.fromTlv( + AnonymousTag, + tlvReader, + ) + ) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { emit(RegisteredClientsAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(RegisteredClientsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readICDCounterAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 4u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readICDCounterAttribute(): UInt? { + 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}") - } + 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) { - "Icdcounter attribute not found in response" - } + } + + requireNotNull(attributeData) { "Icdcounter attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeICDCounterAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Icdcounter attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Icdcounter attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readClientsSupportedPerFabricAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 5u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readClientsSupportedPerFabricAttribute(): UShort? { + 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}") - } + 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) { - "Clientssupportedperfabric attribute not found in response" - } + } + + requireNotNull(attributeData) { "Clientssupportedperfabric 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeClientsSupportedPerFabricAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Clientssupportedperfabric attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Clientssupportedperfabric 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)) - } - + 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 readUserActiveModeTriggerHintAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 6u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readUserActiveModeTriggerHintAttribute(): UInt? { + 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}") - } + 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) { - "Useractivemodetriggerhint attribute not found in response" - } + } + + requireNotNull(attributeData) { "Useractivemodetriggerhint attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeUserActiveModeTriggerHintAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Useractivemodetriggerhint attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Useractivemodetriggerhint attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readUserActiveModeTriggerInstructionAttribute(): String? {val ATTRIBUTE_ID: UInt = 7u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readUserActiveModeTriggerInstructionAttribute(): String? { + 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}") - } + 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) { - "Useractivemodetriggerinstruction attribute not found in response" + } + + requireNotNull(attributeData) { + "Useractivemodetriggerinstruction attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeUserActiveModeTriggerInstructionAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StringSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StringSubscriptionState.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) { - "Useractivemodetriggerinstruction attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Useractivemodetriggerinstruction attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(StringSubscriptionState.Success(it)) - } - + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(StringSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readOperatingModeAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 8u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readOperatingModeAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 8u + + 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}") - } + 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) { - "Operatingmode attribute not found in response" - } + } + + requireNotNull(attributeData) { "Operatingmode 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeOperatingModeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Operatingmode attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Operatingmode 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)) - } - + 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 readMaximumCheckInBackOffAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 9u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMaximumCheckInBackOffAttribute(): UInt? { + val ATTRIBUTE_ID: UInt = 9u + + 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}") - } + 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) { - "Maximumcheckinbackoff attribute not found in response" - } + } + + requireNotNull(attributeData) { "Maximumcheckinbackoff attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeMaximumCheckInBackOffAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Maximumcheckinbackoff attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Maximumcheckinbackoff attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1329,97 +1253,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1427,97 +1350,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1525,97 +1445,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1623,81 +1540,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1709,80 +1621,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1795,7 +1704,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/IdentifyCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/IdentifyCluster.kt index cdf0dd8d361438..b120e941cac02b 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/IdentifyCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/IdentifyCluster.kt @@ -17,126 +17,99 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class IdentifyCluster(private val controller: MatterController, private val endpointId: UShort) {class GeneratedCommandListAttribute( - val value: List - ) +class IdentifyCluster(private val controller: MatterController, private val endpointId: UShort) { + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun identify(identifyTime: UShort - ,timedInvokeTimeout: Duration? = null) { + suspend fun identify(identifyTime: UShort, timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_IDENTIFY_TIME_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_IDENTIFY_TIME_REQ), identifyTime) + tlvWriter.put(ContextSpecificTag(TAG_IDENTIFY_TIME_REQ), identifyTime) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun triggerEffect(effectIdentifier: UByte - ,effectVariant: UByte - ,timedInvokeTimeout: Duration? = null) { + suspend fun triggerEffect( + effectIdentifier: UByte, + effectVariant: UByte, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 64u val tlvWriter = TlvWriter() @@ -146,79 +119,68 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_EFFECT_IDENTIFIER_REQ), effectIdentifier) val TAG_EFFECT_VARIANT_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_EFFECT_VARIANT_REQ), effectVariant) + tlvWriter.put(ContextSpecificTag(TAG_EFFECT_VARIANT_REQ), effectVariant) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } -suspend fun readIdentifyTimeAttribute(): UShort {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readIdentifyTimeAttribute(): UShort { + 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}") - } + 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) { - "Identifytime attribute not found in response" - } + } + + requireNotNull(attributeData) { "Identifytime 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 writeIdentifyTimeAttribute( - value: UShort, - timedWriteTimeout: Duration? = null) { + suspend fun writeIdentifyTimeAttribute(value: UShort, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -239,43 +201,45 @@ suspend fun readIdentifyTimeAttribute(): UShort {val ATTRIBUTE_ID: UInt = 0u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeIdentifyTimeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Identifytime attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Identifytime attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -287,81 +251,76 @@ suspend fun readIdentifyTimeAttribute(): UShort {val ATTRIBUTE_ID: UInt = 0u emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readIdentifyTypeAttribute(): 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) - ) - + + suspend fun readIdentifyTypeAttribute(): 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}") - } + 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) { - "Identifytype attribute not found in response" - } + } + + requireNotNull(attributeData) { "Identifytype 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 subscribeIdentifyTypeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Identifytype attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Identifytype attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -373,97 +332,96 @@ suspend fun readIdentifyTypeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 1u emit(UByteSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -471,97 +429,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -569,97 +526,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -667,97 +621,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -765,81 +716,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -851,80 +797,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -937,7 +880,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/IlluminanceMeasurementCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/IlluminanceMeasurementCluster.kt index cbfb9f08ed8a40..b5af4230e86c34 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/IlluminanceMeasurementCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/IlluminanceMeasurementCluster.kt @@ -17,742 +17,671 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState -import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse -import matter.controller.model.AttributePath -import matter.controller.model.CommandPath +import matter.controller.UShortSubscriptionState import matter.controller.cluster.structs.* +import matter.controller.model.AttributePath import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader -import matter.tlv.TlvWriter -class IlluminanceMeasurementCluster(private val controller: MatterController, private val endpointId: UShort) {class MeasuredValueAttribute( - val value: UShort? - ) +class IlluminanceMeasurementCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class MeasuredValueAttribute(val value: UShort?) sealed class MeasuredValueAttributeSubscriptionState { - data class Success( - val value: UShort? - ) : MeasuredValueAttributeSubscriptionState() - + data class Success(val value: UShort?) : MeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() - } -class MinMeasuredValueAttribute( - val value: UShort? - ) + object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() + } + + class MinMeasuredValueAttribute(val value: UShort?) sealed class MinMeasuredValueAttributeSubscriptionState { - data class Success( - val value: UShort? - ) : MinMeasuredValueAttributeSubscriptionState() - + data class Success(val value: UShort?) : MinMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MinMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() - } -class MaxMeasuredValueAttribute( - val value: UShort? - ) + object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() + } + + class MaxMeasuredValueAttribute(val value: UShort?) sealed class MaxMeasuredValueAttributeSubscriptionState { - data class Success( - val value: UShort? - ) : MaxMeasuredValueAttributeSubscriptionState() - + data class Success(val value: UShort?) : MaxMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MaxMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() - } -class LightSensorTypeAttribute( - val value: UByte? - ) + object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() + } + + class LightSensorTypeAttribute(val value: UByte?) sealed class LightSensorTypeAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : LightSensorTypeAttributeSubscriptionState() - + data class Success(val value: UByte?) : LightSensorTypeAttributeSubscriptionState() + data class Error(val exception: Exception) : LightSensorTypeAttributeSubscriptionState() - object SubscriptionEstablished : LightSensorTypeAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : LightSensorTypeAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } -suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } + + suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute { + 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}") - } + 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) { - "Measuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Measuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = if (!tlvReader.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return MeasuredValueAttribute(decodedValue) } suspend fun subscribeMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MeasuredValueAttributeSubscriptionState.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) { - "Measuredvalue attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Measuredvalue 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.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute { + 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}") - } + 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) { - "Minmeasuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Minmeasuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = if (!tlvReader.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return MinMeasuredValueAttribute(decodedValue) } suspend fun subscribeMinMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MinMeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MinMeasuredValueAttributeSubscriptionState.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) { - "Minmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Minmeasuredvalue 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.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MinMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute { + 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}") - } + 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) { - "Maxmeasuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Maxmeasuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = if (!tlvReader.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return MaxMeasuredValueAttribute(decodedValue) } suspend fun subscribeMaxMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MaxMeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MaxMeasuredValueAttributeSubscriptionState.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) { - "Maxmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Maxmeasuredvalue 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.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MaxMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readToleranceAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readToleranceAttribute(): UShort? { + 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}") - } + 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) { - "Tolerance attribute not found in response" - } + } + + requireNotNull(attributeData) { "Tolerance 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeToleranceAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Tolerance attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Tolerance 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)) - } - + 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 readLightSensorTypeAttribute(): LightSensorTypeAttribute {val ATTRIBUTE_ID: UInt = 4u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readLightSensorTypeAttribute(): LightSensorTypeAttribute { + 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}") - } + 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) { - "Lightsensortype attribute not found in response" - } + } + + requireNotNull(attributeData) { "Lightsensortype attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return LightSensorTypeAttribute(decodedValue) } suspend fun subscribeLightSensorTypeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(LightSensorTypeAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + LightSensorTypeAttributeSubscriptionState.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) { - "Lightsensortype attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Lightsensortype 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(LightSensorTypeAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(LightSensorTypeAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(LightSensorTypeAttributeSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -760,97 +689,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -858,97 +786,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -956,97 +881,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1054,81 +976,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1140,80 +1057,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1226,7 +1140,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/KeypadInputCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/KeypadInputCluster.kt index 168b0718b0ff16..eb59229ab1a415 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/KeypadInputCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/KeypadInputCluster.kt @@ -17,121 +17,86 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState -import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.UShortSubscriptionState +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter class KeypadInputCluster(private val controller: MatterController, private val endpointId: UShort) { - class SendKeyResponse( - val status: UByte - ) -class GeneratedCommandListAttribute( - val value: List - ) + class SendKeyResponse(val status: UByte) + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun sendKey(keyCode: UByte - ,timedInvokeTimeout: Duration? = null): SendKeyResponse { + suspend fun sendKey(keyCode: UByte, timedInvokeTimeout: Duration? = null): SendKeyResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_KEY_CODE_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_KEY_CODE_REQ), keyCode) + tlvWriter.put(ContextSpecificTag(TAG_KEY_CODE_REQ), keyCode) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -141,122 +106,113 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} - - - else { + if (tag == ContextSpecificTag(TAG_STATUS)) { + status_decoded = tlvReader.getUByte(tag) + } else { tlvReader.skipElement() } } - - if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - tlvReader.exitContainer() - return SendKeyResponse( - status_decoded - ) + return SendKeyResponse(status_decoded) } -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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -264,97 +220,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -362,97 +317,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -460,97 +412,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -558,81 +507,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -644,80 +588,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -730,7 +671,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/LaundryDryerControlsCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/LaundryDryerControlsCluster.kt index c4800abe53cffd..9bd0fdf90b4b2a 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/LaundryDryerControlsCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/LaundryDryerControlsCluster.kt @@ -17,215 +17,178 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState -import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse -import matter.controller.model.AttributePath -import matter.controller.model.CommandPath import matter.controller.cluster.structs.* +import matter.controller.model.AttributePath import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class LaundryDryerControlsCluster(private val controller: MatterController, private val endpointId: UShort) {class SupportedDrynessLevelsAttribute( - val value: List - ) +class LaundryDryerControlsCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class SupportedDrynessLevelsAttribute(val value: List) sealed class SupportedDrynessLevelsAttributeSubscriptionState { - data class Success( - val value: List - ) : SupportedDrynessLevelsAttributeSubscriptionState() - + data class Success(val value: List) : SupportedDrynessLevelsAttributeSubscriptionState() + data class Error(val exception: Exception) : SupportedDrynessLevelsAttributeSubscriptionState() - object SubscriptionEstablished : SupportedDrynessLevelsAttributeSubscriptionState() - } -class SelectedDrynessLevelAttribute( - val value: UByte? - ) + object SubscriptionEstablished : SupportedDrynessLevelsAttributeSubscriptionState() + } + + class SelectedDrynessLevelAttribute(val value: UByte?) sealed class SelectedDrynessLevelAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : SelectedDrynessLevelAttributeSubscriptionState() - + data class Success(val value: UByte?) : SelectedDrynessLevelAttributeSubscriptionState() + data class Error(val exception: Exception) : SelectedDrynessLevelAttributeSubscriptionState() - object SubscriptionEstablished : SelectedDrynessLevelAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : SelectedDrynessLevelAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } -suspend fun readSupportedDrynessLevelsAttribute(): SupportedDrynessLevelsAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } + + suspend fun readSupportedDrynessLevelsAttribute(): SupportedDrynessLevelsAttribute { + 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}") - } + 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) { - "Supporteddrynesslevels attribute not found in response" - } + } + + requireNotNull(attributeData) { "Supporteddrynesslevels 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.getUByte(AnonymousTag)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return SupportedDrynessLevelsAttribute(decodedValue) } suspend fun subscribeSupportedDrynessLevelsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(SupportedDrynessLevelsAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + SupportedDrynessLevelsAttributeSubscriptionState.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) { - "Supporteddrynesslevels attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Supporteddrynesslevels 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.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(SupportedDrynessLevelsAttributeSubscriptionState.Success(decodedValue)) } @@ -233,73 +196,66 @@ suspend fun readSupportedDrynessLevelsAttribute(): SupportedDrynessLevelsAttribu emit(SupportedDrynessLevelsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readSelectedDrynessLevelAttribute(): SelectedDrynessLevelAttribute {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readSelectedDrynessLevelAttribute(): SelectedDrynessLevelAttribute { + 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}") - } + 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) { - "Selecteddrynesslevel attribute not found in response" - } + } + + requireNotNull(attributeData) { "Selecteddrynesslevel attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return SelectedDrynessLevelAttribute(decodedValue) } suspend fun writeSelectedDrynessLevelAttribute( value: UByte, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 1u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -320,153 +276,154 @@ suspend fun readSelectedDrynessLevelAttribute(): SelectedDrynessLevelAttribute { throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeSelectedDrynessLevelAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(SelectedDrynessLevelAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + SelectedDrynessLevelAttributeSubscriptionState.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) { - "Selecteddrynesslevel attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Selecteddrynesslevel 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.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(SelectedDrynessLevelAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(SelectedDrynessLevelAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(SelectedDrynessLevelAttributeSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -474,97 +431,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -572,97 +528,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -670,97 +623,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -768,81 +718,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -854,80 +799,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -940,7 +882,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/LaundryWasherControlsCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/LaundryWasherControlsCluster.kt index 2e547ec206a574..0fb11d882daa52 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/LaundryWasherControlsCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/LaundryWasherControlsCluster.kt @@ -17,317 +17,263 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse -import matter.controller.model.AttributePath -import matter.controller.model.CommandPath import matter.controller.cluster.structs.* +import matter.controller.model.AttributePath import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class LaundryWasherControlsCluster(private val controller: MatterController, private val endpointId: UShort) {class SpinSpeedsAttribute( - val value: List? - ) +class LaundryWasherControlsCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class SpinSpeedsAttribute(val value: List?) sealed class SpinSpeedsAttributeSubscriptionState { - data class Success( - val value: List? - ) : SpinSpeedsAttributeSubscriptionState() - + data class Success(val value: List?) : SpinSpeedsAttributeSubscriptionState() + data class Error(val exception: Exception) : SpinSpeedsAttributeSubscriptionState() - object SubscriptionEstablished : SpinSpeedsAttributeSubscriptionState() - } -class SpinSpeedCurrentAttribute( - val value: UByte? - ) + object SubscriptionEstablished : SpinSpeedsAttributeSubscriptionState() + } + + class SpinSpeedCurrentAttribute(val value: UByte?) sealed class SpinSpeedCurrentAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : SpinSpeedCurrentAttributeSubscriptionState() - + data class Success(val value: UByte?) : SpinSpeedCurrentAttributeSubscriptionState() + data class Error(val exception: Exception) : SpinSpeedCurrentAttributeSubscriptionState() - object SubscriptionEstablished : SpinSpeedCurrentAttributeSubscriptionState() - } -class SupportedRinsesAttribute( - val value: List? - ) + object SubscriptionEstablished : SpinSpeedCurrentAttributeSubscriptionState() + } + + class SupportedRinsesAttribute(val value: List?) sealed class SupportedRinsesAttributeSubscriptionState { - data class Success( - val value: List? - ) : SupportedRinsesAttributeSubscriptionState() - + data class Success(val value: List?) : SupportedRinsesAttributeSubscriptionState() + data class Error(val exception: Exception) : SupportedRinsesAttributeSubscriptionState() - object SubscriptionEstablished : SupportedRinsesAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : SupportedRinsesAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } -suspend fun readSpinSpeedsAttribute(): SpinSpeedsAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } + + suspend fun readSpinSpeedsAttribute(): SpinSpeedsAttribute { + 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}") - } + 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) { - "Spinspeeds attribute not found in response" - } + } + + requireNotNull(attributeData) { "Spinspeeds attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getString(AnonymousTag)) + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getString(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null } - tlvReader.exitContainer() - } - } else { - null - } - return SpinSpeedsAttribute(decodedValue) } suspend fun subscribeSpinSpeedsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(SpinSpeedsAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + SpinSpeedsAttributeSubscriptionState.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) { - "Spinspeeds attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Spinspeeds attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getString(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { - emit(SpinSpeedsAttributeSubscriptionState.Success(it)) - } - + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getString(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { emit(SpinSpeedsAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(SpinSpeedsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readSpinSpeedCurrentAttribute(): SpinSpeedCurrentAttribute {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readSpinSpeedCurrentAttribute(): SpinSpeedCurrentAttribute { + 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}") - } + 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) { - "Spinspeedcurrent attribute not found in response" - } + } + + requireNotNull(attributeData) { "Spinspeedcurrent attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return SpinSpeedCurrentAttribute(decodedValue) } - suspend fun writeSpinSpeedCurrentAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeSpinSpeedCurrentAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 1u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -348,132 +294,124 @@ suspend fun readSpinSpeedCurrentAttribute(): SpinSpeedCurrentAttribute {val ATTR throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeSpinSpeedCurrentAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(SpinSpeedCurrentAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + SpinSpeedCurrentAttributeSubscriptionState.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) { - "Spinspeedcurrent attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Spinspeedcurrent 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(SpinSpeedCurrentAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(SpinSpeedCurrentAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(SpinSpeedCurrentAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNumberOfRinsesAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readNumberOfRinsesAttribute(): UByte? { + 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}") - } + 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) { - "Numberofrinses attribute not found in response" - } + } + + requireNotNull(attributeData) { "Numberofrinses 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } - suspend fun writeNumberOfRinsesAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeNumberOfRinsesAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 2u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -494,261 +432,258 @@ suspend fun readNumberOfRinsesAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 2u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNumberOfRinsesAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Numberofrinses attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Numberofrinses 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)) - } - + 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 readSupportedRinsesAttribute(): SupportedRinsesAttribute {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readSupportedRinsesAttribute(): SupportedRinsesAttribute { + 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}") - } + 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) { - "Supportedrinses attribute not found in response" - } + } + + requireNotNull(attributeData) { "Supportedrinses attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null } - tlvReader.exitContainer() - } - } else { - null - } - return SupportedRinsesAttribute(decodedValue) } suspend fun subscribeSupportedRinsesAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(SupportedRinsesAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + SupportedRinsesAttributeSubscriptionState.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) { - "Supportedrinses attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Supportedrinses attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { - emit(SupportedRinsesAttributeSubscriptionState.Success(it)) - } - + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { emit(SupportedRinsesAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(SupportedRinsesAttributeSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -756,97 +691,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -854,97 +788,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -952,97 +883,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1050,81 +978,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1136,80 +1059,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1222,7 +1142,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/LaundryWasherModeCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/LaundryWasherModeCluster.kt index 3094ee32e0a394..45f9e469f1d91d 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/LaundryWasherModeCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/LaundryWasherModeCluster.kt @@ -17,161 +17,127 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class LaundryWasherModeCluster(private val controller: MatterController, private val endpointId: UShort) { - class ChangeToModeResponse( - val status: UByte, - val statusText: String? - ) -class SupportedModesAttribute( - val value: List - ) +class LaundryWasherModeCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class ChangeToModeResponse(val status: UByte, val statusText: String?) + + class SupportedModesAttribute(val value: List) sealed class SupportedModesAttributeSubscriptionState { - data class Success( - val value: List - ) : SupportedModesAttributeSubscriptionState() - + data class Success(val value: List) : + SupportedModesAttributeSubscriptionState() + data class Error(val exception: Exception) : SupportedModesAttributeSubscriptionState() - object SubscriptionEstablished : SupportedModesAttributeSubscriptionState() - } -class StartUpModeAttribute( - val value: UByte? - ) + object SubscriptionEstablished : SupportedModesAttributeSubscriptionState() + } + + class StartUpModeAttribute(val value: UByte?) sealed class StartUpModeAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : StartUpModeAttributeSubscriptionState() - + data class Success(val value: UByte?) : StartUpModeAttributeSubscriptionState() + data class Error(val exception: Exception) : StartUpModeAttributeSubscriptionState() - object SubscriptionEstablished : StartUpModeAttributeSubscriptionState() - } -class OnModeAttribute( - val value: UByte? - ) + object SubscriptionEstablished : StartUpModeAttributeSubscriptionState() + } + + class OnModeAttribute(val value: UByte?) sealed class OnModeAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : OnModeAttributeSubscriptionState() - + data class Success(val value: UByte?) : OnModeAttributeSubscriptionState() + data class Error(val exception: Exception) : OnModeAttributeSubscriptionState() - object SubscriptionEstablished : OnModeAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : OnModeAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun changeToMode(newMode: UByte - ,timedInvokeTimeout: Duration? = null): ChangeToModeResponse { + suspend fun changeToMode( + newMode: UByte, + timedInvokeTimeout: Duration? = null, + ): ChangeToModeResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_NEW_MODE_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_NEW_MODE_REQ), newMode) + tlvWriter.put(ContextSpecificTag(TAG_NEW_MODE_REQ), newMode) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -181,140 +147,130 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_STATUS_TEXT: Int = 1 var statusText_decoded: String? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_STATUS_TEXT)) {statusText_decoded = + if (tag == ContextSpecificTag(TAG_STATUS)) { + status_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_STATUS_TEXT)) { + statusText_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - }} - - - else { + tlvReader.getString(tag) + } else { + null + } + } + } else { tlvReader.skipElement() } } - - if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - - - tlvReader.exitContainer() - return ChangeToModeResponse( - status_decoded, - statusText_decoded - ) + return ChangeToModeResponse(status_decoded, statusText_decoded) } -suspend fun readSupportedModesAttribute(): SupportedModesAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readSupportedModesAttribute(): SupportedModesAttribute { + 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}") - } + 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) { - "Supportedmodes attribute not found in response" - } + } + + requireNotNull(attributeData) { "Supportedmodes 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(LaundryWasherModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(LaundryWasherModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return SupportedModesAttribute(decodedValue) } suspend fun subscribeSupportedModesAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(SupportedModesAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + SupportedModesAttributeSubscriptionState.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) { - "Supportedmodes attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Supportedmodes 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(LaundryWasherModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(LaundryWasherModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(SupportedModesAttributeSubscriptionState.Success(decodedValue)) } @@ -322,81 +278,76 @@ suspend fun readSupportedModesAttribute(): SupportedModesAttribute {val ATTRIBUT emit(SupportedModesAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCurrentModeAttribute(): 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) - ) - + + suspend fun readCurrentModeAttribute(): 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}") - } + 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) { - "Currentmode attribute not found in response" - } + } + + requireNotNull(attributeData) { "Currentmode 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 subscribeCurrentModeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Currentmode attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Currentmode attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -408,77 +359,67 @@ suspend fun readCurrentModeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 1u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readStartUpModeAttribute(): StartUpModeAttribute {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readStartUpModeAttribute(): StartUpModeAttribute { + 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}") - } + 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) { - "Startupmode attribute not found in response" - } + } + + requireNotNull(attributeData) { "Startupmode attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return StartUpModeAttribute(decodedValue) } - suspend fun writeStartUpModeAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeStartUpModeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 2u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -499,137 +440,127 @@ suspend fun readStartUpModeAttribute(): StartUpModeAttribute {val ATTRIBUTE_ID: throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeStartUpModeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StartUpModeAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StartUpModeAttributeSubscriptionState.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) { - "Startupmode attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Startupmode 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(StartUpModeAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(StartUpModeAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(StartUpModeAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readOnModeAttribute(): OnModeAttribute {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readOnModeAttribute(): OnModeAttribute { + 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}") - } + 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) { - "Onmode attribute not found in response" - } + } + + requireNotNull(attributeData) { "Onmode attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return OnModeAttribute(decodedValue) } - suspend fun writeOnModeAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeOnModeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 3u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -650,157 +581,156 @@ suspend fun readOnModeAttribute(): OnModeAttribute {val ATTRIBUTE_ID: UInt = 3u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeOnModeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(OnModeAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + OnModeAttributeSubscriptionState.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) { - "Onmode attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Onmode 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(OnModeAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(OnModeAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(OnModeAttributeSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -808,97 +738,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -906,97 +835,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1004,97 +930,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1102,81 +1025,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1188,80 +1106,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1274,7 +1189,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/LevelControlCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/LevelControlCluster.kt index 293ad3ccf28462..e77e463d61ce2b 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/LevelControlCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/LevelControlCluster.kt @@ -17,184 +17,143 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class LevelControlCluster(private val controller: MatterController, private val endpointId: UShort) {class CurrentLevelAttribute( - val value: UByte? - ) +class LevelControlCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class CurrentLevelAttribute(val value: UByte?) sealed class CurrentLevelAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : CurrentLevelAttributeSubscriptionState() - + data class Success(val value: UByte?) : CurrentLevelAttributeSubscriptionState() + data class Error(val exception: Exception) : CurrentLevelAttributeSubscriptionState() - object SubscriptionEstablished : CurrentLevelAttributeSubscriptionState() - } -class OnLevelAttribute( - val value: UByte? - ) + object SubscriptionEstablished : CurrentLevelAttributeSubscriptionState() + } + + class OnLevelAttribute(val value: UByte?) sealed class OnLevelAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : OnLevelAttributeSubscriptionState() - + data class Success(val value: UByte?) : OnLevelAttributeSubscriptionState() + data class Error(val exception: Exception) : OnLevelAttributeSubscriptionState() - object SubscriptionEstablished : OnLevelAttributeSubscriptionState() - } -class OnTransitionTimeAttribute( - val value: UShort? - ) + object SubscriptionEstablished : OnLevelAttributeSubscriptionState() + } + + class OnTransitionTimeAttribute(val value: UShort?) sealed class OnTransitionTimeAttributeSubscriptionState { - data class Success( - val value: UShort? - ) : OnTransitionTimeAttributeSubscriptionState() - + data class Success(val value: UShort?) : OnTransitionTimeAttributeSubscriptionState() + data class Error(val exception: Exception) : OnTransitionTimeAttributeSubscriptionState() - object SubscriptionEstablished : OnTransitionTimeAttributeSubscriptionState() - } -class OffTransitionTimeAttribute( - val value: UShort? - ) + object SubscriptionEstablished : OnTransitionTimeAttributeSubscriptionState() + } + + class OffTransitionTimeAttribute(val value: UShort?) sealed class OffTransitionTimeAttributeSubscriptionState { - data class Success( - val value: UShort? - ) : OffTransitionTimeAttributeSubscriptionState() - + data class Success(val value: UShort?) : OffTransitionTimeAttributeSubscriptionState() + data class Error(val exception: Exception) : OffTransitionTimeAttributeSubscriptionState() - object SubscriptionEstablished : OffTransitionTimeAttributeSubscriptionState() - } -class DefaultMoveRateAttribute( - val value: UByte? - ) + object SubscriptionEstablished : OffTransitionTimeAttributeSubscriptionState() + } + + class DefaultMoveRateAttribute(val value: UByte?) sealed class DefaultMoveRateAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : DefaultMoveRateAttributeSubscriptionState() - + data class Success(val value: UByte?) : DefaultMoveRateAttributeSubscriptionState() + data class Error(val exception: Exception) : DefaultMoveRateAttributeSubscriptionState() - object SubscriptionEstablished : DefaultMoveRateAttributeSubscriptionState() - } -class StartUpCurrentLevelAttribute( - val value: UByte? - ) + object SubscriptionEstablished : DefaultMoveRateAttributeSubscriptionState() + } + + class StartUpCurrentLevelAttribute(val value: UByte?) sealed class StartUpCurrentLevelAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : StartUpCurrentLevelAttributeSubscriptionState() - + data class Success(val value: UByte?) : StartUpCurrentLevelAttributeSubscriptionState() + data class Error(val exception: Exception) : StartUpCurrentLevelAttributeSubscriptionState() - object SubscriptionEstablished : StartUpCurrentLevelAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : StartUpCurrentLevelAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun moveToLevel(level: UByte - ,transitionTime: UShort? - ,optionsMask: UByte - ,optionsOverride: UByte - ,timedInvokeTimeout: Duration? = null) { + suspend fun moveToLevel( + level: UByte, + transitionTime: UShort?, + optionsMask: UByte, + optionsOverride: UByte, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 0u val tlvWriter = TlvWriter() @@ -212,25 +171,27 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 3 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun move(moveMode: UByte - ,rate: UByte? - ,optionsMask: UByte - ,optionsOverride: UByte - ,timedInvokeTimeout: Duration? = null) { + suspend fun move( + moveMode: UByte, + rate: UByte?, + optionsMask: UByte, + optionsOverride: UByte, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 1u val tlvWriter = TlvWriter() @@ -240,34 +201,34 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_MOVE_MODE_REQ), moveMode) val TAG_RATE_REQ: Int = 1 - rate?.let { - tlvWriter.put(ContextSpecificTag(TAG_RATE_REQ), rate) - } + rate?.let { tlvWriter.put(ContextSpecificTag(TAG_RATE_REQ), rate) } val TAG_OPTIONS_MASK_REQ: Int = 2 tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 3 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun step(stepMode: UByte - ,stepSize: UByte - ,transitionTime: UShort? - ,optionsMask: UByte - ,optionsOverride: UByte - ,timedInvokeTimeout: Duration? = null) { + suspend fun step( + stepMode: UByte, + stepSize: UByte, + transitionTime: UShort?, + optionsMask: UByte, + optionsOverride: UByte, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 2u val tlvWriter = TlvWriter() @@ -288,23 +249,25 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 4 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun stop(optionsMask: UByte - ,optionsOverride: UByte - ,timedInvokeTimeout: Duration? = null) { + suspend fun stop( + optionsMask: UByte, + optionsOverride: UByte, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 3u val tlvWriter = TlvWriter() @@ -314,25 +277,27 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun moveToLevelWithOnOff(level: UByte - ,transitionTime: UShort? - ,optionsMask: UByte - ,optionsOverride: UByte - ,timedInvokeTimeout: Duration? = null) { + suspend fun moveToLevelWithOnOff( + level: UByte, + transitionTime: UShort?, + optionsMask: UByte, + optionsOverride: UByte, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 4u val tlvWriter = TlvWriter() @@ -350,25 +315,27 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 3 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun moveWithOnOff(moveMode: UByte - ,rate: UByte? - ,optionsMask: UByte - ,optionsOverride: UByte - ,timedInvokeTimeout: Duration? = null) { + suspend fun moveWithOnOff( + moveMode: UByte, + rate: UByte?, + optionsMask: UByte, + optionsOverride: UByte, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 5u val tlvWriter = TlvWriter() @@ -378,34 +345,34 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_MOVE_MODE_REQ), moveMode) val TAG_RATE_REQ: Int = 1 - rate?.let { - tlvWriter.put(ContextSpecificTag(TAG_RATE_REQ), rate) - } + rate?.let { tlvWriter.put(ContextSpecificTag(TAG_RATE_REQ), rate) } val TAG_OPTIONS_MASK_REQ: Int = 2 tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 3 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun stepWithOnOff(stepMode: UByte - ,stepSize: UByte - ,transitionTime: UShort? - ,optionsMask: UByte - ,optionsOverride: UByte - ,timedInvokeTimeout: Duration? = null) { + suspend fun stepWithOnOff( + stepMode: UByte, + stepSize: UByte, + transitionTime: UShort?, + optionsMask: UByte, + optionsOverride: UByte, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 6u val tlvWriter = TlvWriter() @@ -426,23 +393,25 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 4 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun stopWithOnOff(optionsMask: UByte - ,optionsOverride: UByte - ,timedInvokeTimeout: Duration? = null) { + suspend fun stopWithOnOff( + optionsMask: UByte, + optionsOverride: UByte, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 7u val tlvWriter = TlvWriter() @@ -452,782 +421,730 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_MASK_REQ), optionsMask) val TAG_OPTIONS_OVERRIDE_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) + tlvWriter.put(ContextSpecificTag(TAG_OPTIONS_OVERRIDE_REQ), optionsOverride) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun moveToClosestFrequency(frequency: UShort - ,timedInvokeTimeout: Duration? = null) { + suspend fun moveToClosestFrequency(frequency: UShort, timedInvokeTimeout: Duration? = null) { val commandId: UInt = 8u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_FREQUENCY_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_FREQUENCY_REQ), frequency) + tlvWriter.put(ContextSpecificTag(TAG_FREQUENCY_REQ), frequency) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } -suspend fun readCurrentLevelAttribute(): CurrentLevelAttribute {val ATTRIBUTE_ID: UInt = 0u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readCurrentLevelAttribute(): CurrentLevelAttribute { + 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 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}") - } + 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) { - "Currentlevel attribute not found in response" - } + } + + requireNotNull(attributeData) { "Currentlevel attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return CurrentLevelAttribute(decodedValue) } suspend fun subscribeCurrentLevelAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(CurrentLevelAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + CurrentLevelAttributeSubscriptionState.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) { - "Currentlevel attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Currentlevel 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.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(CurrentLevelAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(CurrentLevelAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(CurrentLevelAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRemainingTimeAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 1u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRemainingTimeAttribute(): UShort? { + 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 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}") - } + 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) { - "Remainingtime attribute not found in response" - } + } + + requireNotNull(attributeData) { "Remainingtime 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeRemainingTimeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Remainingtime attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Remainingtime 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMinLevelAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 2u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readMinLevelAttribute(): UByte? { + 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 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}") - } + 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) { - "Minlevel attribute not found in response" - } + } + + requireNotNull(attributeData) { "Minlevel 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeMinLevelAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Minlevel attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Minlevel 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMaxLevelAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 3u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readMaxLevelAttribute(): UByte? { + 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 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}") - } + 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) { - "Maxlevel attribute not found in response" - } + } + + requireNotNull(attributeData) { "Maxlevel 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeMaxLevelAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Maxlevel attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Maxlevel 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCurrentFrequencyAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 4u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readCurrentFrequencyAttribute(): UShort? { + 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 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}") - } + 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) { - "Currentfrequency attribute not found in response" - } + } + + requireNotNull(attributeData) { "Currentfrequency 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeCurrentFrequencyAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Currentfrequency attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Currentfrequency 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMinFrequencyAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 5u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readMinFrequencyAttribute(): UShort? { + 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 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}") - } + 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) { - "Minfrequency attribute not found in response" - } + } + + requireNotNull(attributeData) { "Minfrequency 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeMinFrequencyAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Minfrequency attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Minfrequency 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMaxFrequencyAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 6u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readMaxFrequencyAttribute(): 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 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}") - } + 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) { - "Maxfrequency attribute not found in response" - } + } + + requireNotNull(attributeData) { "Maxfrequency 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeMaxFrequencyAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Maxfrequency attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Maxfrequency 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readOptionsAttribute(): UByte {val ATTRIBUTE_ID: UInt = 15u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readOptionsAttribute(): UByte { + val ATTRIBUTE_ID: UInt = 15u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Options attribute not found in response" - } + } + + requireNotNull(attributeData) { "Options 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 writeOptionsAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeOptionsAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 15u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -1248,43 +1165,45 @@ suspend fun readOptionsAttribute(): UByte {val ATTRIBUTE_ID: UInt = 15u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeOptionsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 15u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Options attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Options attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -1296,72 +1215,65 @@ suspend fun readOptionsAttribute(): UByte {val ATTRIBUTE_ID: UInt = 15u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readOnOffTransitionTimeAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 16u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readOnOffTransitionTimeAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 16u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Onofftransitiontime attribute not found in response" - } + } + + requireNotNull(attributeData) { "Onofftransitiontime 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun writeOnOffTransitionTimeAttribute( value: UShort, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 16u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -1382,128 +1294,120 @@ suspend fun readOnOffTransitionTimeAttribute(): UShort? {val ATTRIBUTE_ID: UInt throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeOnOffTransitionTimeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Onofftransitiontime attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Onofftransitiontime 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readOnLevelAttribute(): OnLevelAttribute {val ATTRIBUTE_ID: UInt = 17u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readOnLevelAttribute(): OnLevelAttribute { + val ATTRIBUTE_ID: UInt = 17u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Onlevel attribute not found in response" - } + } + + requireNotNull(attributeData) { "Onlevel attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return OnLevelAttribute(decodedValue) } - suspend fun writeOnLevelAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeOnLevelAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 17u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -1524,133 +1428,123 @@ suspend fun readOnLevelAttribute(): OnLevelAttribute {val ATTRIBUTE_ID: UInt = 1 throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeOnLevelAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 17u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(OnLevelAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + OnLevelAttributeSubscriptionState.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) { - "Onlevel attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Onlevel 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.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(OnLevelAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(OnLevelAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(OnLevelAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readOnTransitionTimeAttribute(): OnTransitionTimeAttribute {val ATTRIBUTE_ID: UInt = 18u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readOnTransitionTimeAttribute(): OnTransitionTimeAttribute { + val ATTRIBUTE_ID: UInt = 18u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Ontransitiontime attribute not found in response" - } + } + + requireNotNull(attributeData) { "Ontransitiontime attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return OnTransitionTimeAttribute(decodedValue) } - suspend fun writeOnTransitionTimeAttribute( - value: UShort, - timedWriteTimeout: Duration? = null) { + suspend fun writeOnTransitionTimeAttribute(value: UShort, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 18u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -1671,137 +1565,129 @@ suspend fun readOnTransitionTimeAttribute(): OnTransitionTimeAttribute {val ATTR throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeOnTransitionTimeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 18u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(OnTransitionTimeAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + OnTransitionTimeAttributeSubscriptionState.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) { - "Ontransitiontime attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Ontransitiontime 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(OnTransitionTimeAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(OnTransitionTimeAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(OnTransitionTimeAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readOffTransitionTimeAttribute(): OffTransitionTimeAttribute {val ATTRIBUTE_ID: UInt = 19u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readOffTransitionTimeAttribute(): OffTransitionTimeAttribute { + val ATTRIBUTE_ID: UInt = 19u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Offtransitiontime attribute not found in response" - } + } + + requireNotNull(attributeData) { "Offtransitiontime attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return OffTransitionTimeAttribute(decodedValue) } - suspend fun writeOffTransitionTimeAttribute( - value: UShort, - timedWriteTimeout: Duration? = null) { + suspend fun writeOffTransitionTimeAttribute(value: UShort, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 19u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -1822,137 +1708,129 @@ suspend fun readOffTransitionTimeAttribute(): OffTransitionTimeAttribute {val AT throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeOffTransitionTimeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 19u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(OffTransitionTimeAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + OffTransitionTimeAttributeSubscriptionState.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) { - "Offtransitiontime attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Offtransitiontime 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(OffTransitionTimeAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(OffTransitionTimeAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(OffTransitionTimeAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readDefaultMoveRateAttribute(): DefaultMoveRateAttribute {val ATTRIBUTE_ID: UInt = 20u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readDefaultMoveRateAttribute(): DefaultMoveRateAttribute { + val ATTRIBUTE_ID: UInt = 20u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Defaultmoverate attribute not found in response" - } + } + + requireNotNull(attributeData) { "Defaultmoverate attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return DefaultMoveRateAttribute(decodedValue) } - suspend fun writeDefaultMoveRateAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeDefaultMoveRateAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 20u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -1973,137 +1851,129 @@ suspend fun readDefaultMoveRateAttribute(): DefaultMoveRateAttribute {val ATTRIB throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeDefaultMoveRateAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 20u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(DefaultMoveRateAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + DefaultMoveRateAttributeSubscriptionState.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) { - "Defaultmoverate attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Defaultmoverate 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(DefaultMoveRateAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(DefaultMoveRateAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(DefaultMoveRateAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readStartUpCurrentLevelAttribute(): StartUpCurrentLevelAttribute {val ATTRIBUTE_ID: UInt = 16384u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readStartUpCurrentLevelAttribute(): StartUpCurrentLevelAttribute { + val ATTRIBUTE_ID: UInt = 16384u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Startupcurrentlevel attribute not found in response" - } + } + + requireNotNull(attributeData) { "Startupcurrentlevel attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return StartUpCurrentLevelAttribute(decodedValue) } - suspend fun writeStartUpCurrentLevelAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeStartUpCurrentLevelAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16384u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -2124,157 +1994,158 @@ suspend fun readStartUpCurrentLevelAttribute(): StartUpCurrentLevelAttribute {va throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeStartUpCurrentLevelAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16384u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StartUpCurrentLevelAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StartUpCurrentLevelAttributeSubscriptionState.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) { - "Startupcurrentlevel attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Startupcurrentlevel 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(StartUpCurrentLevelAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(StartUpCurrentLevelAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(StartUpCurrentLevelAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65528u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -2282,97 +2153,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { emit(GeneratedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65529u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -2380,97 +2250,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va emit(AcceptedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt = 65530u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -2478,97 +2345,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt emit(EventListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ID: UInt = 65531u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -2576,81 +2440,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ emit(AttributeListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -2662,80 +2521,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 65533u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -2748,7 +2604,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/LocalizationConfigurationCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/LocalizationConfigurationCluster.kt index d2c92eb1b5c1f9..e652658edb19d2 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/LocalizationConfigurationCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/LocalizationConfigurationCluster.kt @@ -17,173 +17,130 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest +import matter.controller.StringSubscriptionState import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState -import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse -import matter.controller.model.AttributePath -import matter.controller.model.CommandPath import matter.controller.cluster.structs.* +import matter.controller.model.AttributePath import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class LocalizationConfigurationCluster(private val controller: MatterController, private val endpointId: UShort) {class SupportedLocalesAttribute( - val value: List - ) +class LocalizationConfigurationCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class SupportedLocalesAttribute(val value: List) sealed class SupportedLocalesAttributeSubscriptionState { - data class Success( - val value: List - ) : SupportedLocalesAttributeSubscriptionState() - + data class Success(val value: List) : SupportedLocalesAttributeSubscriptionState() + data class Error(val exception: Exception) : SupportedLocalesAttributeSubscriptionState() - object SubscriptionEstablished : SupportedLocalesAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : SupportedLocalesAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } -suspend fun readActiveLocaleAttribute(): String {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } + + suspend fun readActiveLocaleAttribute(): String { + 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}") - } + 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) { - "Activelocale attribute not found in response" - } + } + + requireNotNull(attributeData) { "Activelocale attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: String = tlvReader.getString(AnonymousTag) - return decodedValue } - suspend fun writeActiveLocaleAttribute( - value: String, - timedWriteTimeout: Duration? = null) { + suspend fun writeActiveLocaleAttribute(value: String, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -204,43 +161,45 @@ suspend fun readActiveLocaleAttribute(): String {val ATTRIBUTE_ID: UInt = 0u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeActiveLocaleAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StringSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StringSubscriptionState.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) { - "Activelocale attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Activelocale attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -252,97 +211,96 @@ suspend fun readActiveLocaleAttribute(): String {val ATTRIBUTE_ID: UInt = 0u emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readSupportedLocalesAttribute(): SupportedLocalesAttribute {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readSupportedLocalesAttribute(): SupportedLocalesAttribute { + 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}") - } + 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) { - "Supportedlocales attribute not found in response" - } + } + + requireNotNull(attributeData) { "Supportedlocales 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.getString(AnonymousTag)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getString(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return SupportedLocalesAttribute(decodedValue) } suspend fun subscribeSupportedLocalesAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(SupportedLocalesAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + SupportedLocalesAttributeSubscriptionState.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) { - "Supportedlocales attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Supportedlocales 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.getString(AnonymousTag)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getString(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(SupportedLocalesAttributeSubscriptionState.Success(decodedValue)) } @@ -350,97 +308,96 @@ suspend fun readSupportedLocalesAttribute(): SupportedLocalesAttribute {val ATTR emit(SupportedLocalesAttributeSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -448,97 +405,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -546,97 +502,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -644,97 +597,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -742,81 +692,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -828,80 +773,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -914,7 +856,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/LowPowerCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/LowPowerCluster.kt index 93f537837ccd34..126f9b33301e05 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/LowPowerCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/LowPowerCluster.kt @@ -17,207 +17,173 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState -import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.UShortSubscriptionState +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class LowPowerCluster(private val controller: MatterController, private val endpointId: UShort) {class GeneratedCommandListAttribute( - val value: List - ) +class LowPowerCluster(private val controller: MatterController, private val endpointId: UShort) { + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } suspend fun sleep(timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } -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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -225,97 +191,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -323,97 +288,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -421,97 +383,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -519,81 +478,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -605,80 +559,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -691,7 +642,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/MediaInputCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/MediaInputCluster.kt index d26de7c78f7c10..ed65c99541c8e4 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/MediaInputCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/MediaInputCluster.kt @@ -17,130 +17,96 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.UShortSubscriptionState +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class MediaInputCluster(private val controller: MatterController, private val endpointId: UShort) {class InputListAttribute( - val value: List - ) +class MediaInputCluster(private val controller: MatterController, private val endpointId: UShort) { + class InputListAttribute(val value: List) sealed class InputListAttributeSubscriptionState { - data class Success( - val value: List - ) : InputListAttributeSubscriptionState() - + data class Success(val value: List) : + InputListAttributeSubscriptionState() + data class Error(val exception: Exception) : InputListAttributeSubscriptionState() - object SubscriptionEstablished : InputListAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : InputListAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun selectInput(index: UByte - ,timedInvokeTimeout: Duration? = null) { + suspend fun selectInput(index: UByte, timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_INDEX_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_INDEX_REQ), index) + tlvWriter.put(ContextSpecificTag(TAG_INDEX_REQ), index) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -151,14 +117,14 @@ class AttributeListAttribute( val commandId: UInt = 1u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -169,23 +135,21 @@ class AttributeListAttribute( val commandId: UInt = 2u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun renameInput(index: UByte - ,name: String - ,timedInvokeTimeout: Duration? = null) { + suspend fun renameInput(index: UByte, name: String, timedInvokeTimeout: Duration? = null) { val commandId: UInt = 3u val tlvWriter = TlvWriter() @@ -195,108 +159,105 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_INDEX_REQ), index) val TAG_NAME_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_NAME_REQ), name) + tlvWriter.put(ContextSpecificTag(TAG_NAME_REQ), name) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } -suspend fun readInputListAttribute(): InputListAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readInputListAttribute(): InputListAttribute { + 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}") - } + 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) { - "Inputlist attribute not found in response" - } + } + + requireNotNull(attributeData) { "Inputlist 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(MediaInputClusterInputInfoStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(MediaInputClusterInputInfoStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return InputListAttribute(decodedValue) } suspend fun subscribeInputListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(InputListAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + InputListAttributeSubscriptionState.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) { - "Inputlist attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Inputlist 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(MediaInputClusterInputInfoStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(MediaInputClusterInputInfoStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(InputListAttributeSubscriptionState.Success(decodedValue)) } @@ -304,81 +265,76 @@ suspend fun readInputListAttribute(): InputListAttribute {val ATTRIBUTE_ID: UInt emit(InputListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCurrentInputAttribute(): 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) - ) - + + suspend fun readCurrentInputAttribute(): 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}") - } + 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) { - "Currentinput attribute not found in response" - } + } + + requireNotNull(attributeData) { "Currentinput 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 subscribeCurrentInputAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Currentinput attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Currentinput attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -390,97 +346,96 @@ suspend fun readCurrentInputAttribute(): UByte {val ATTRIBUTE_ID: UInt = 1u emit(UByteSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -488,97 +443,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -586,97 +540,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -684,97 +635,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -782,81 +730,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -868,80 +811,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -954,7 +894,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/MediaPlaybackCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/MediaPlaybackCluster.kt index ad3efe69a871ca..53a4847c134590 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/MediaPlaybackCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/MediaPlaybackCluster.kt @@ -17,235 +17,183 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.FloatSubscriptionState +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.UShortSubscriptionState +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class MediaPlaybackCluster(private val controller: MatterController, private val endpointId: UShort) { - class PlaybackResponse( - val status: UByte, - val data: String? - ) -class StartTimeAttribute( - val value: ULong? - ) +class MediaPlaybackCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class PlaybackResponse(val status: UByte, val data: String?) + + class StartTimeAttribute(val value: ULong?) sealed class StartTimeAttributeSubscriptionState { - data class Success( - val value: ULong? - ) : StartTimeAttributeSubscriptionState() - + data class Success(val value: ULong?) : StartTimeAttributeSubscriptionState() + data class Error(val exception: Exception) : StartTimeAttributeSubscriptionState() - object SubscriptionEstablished : StartTimeAttributeSubscriptionState() - } -class DurationAttribute( - val value: ULong? - ) + object SubscriptionEstablished : StartTimeAttributeSubscriptionState() + } + + class DurationAttribute(val value: ULong?) sealed class DurationAttributeSubscriptionState { - data class Success( - val value: ULong? - ) : DurationAttributeSubscriptionState() - + data class Success(val value: ULong?) : DurationAttributeSubscriptionState() + data class Error(val exception: Exception) : DurationAttributeSubscriptionState() - object SubscriptionEstablished : DurationAttributeSubscriptionState() - } -class SampledPositionAttribute( - val value: MediaPlaybackClusterPlaybackPositionStruct? - ) + object SubscriptionEstablished : DurationAttributeSubscriptionState() + } + + class SampledPositionAttribute(val value: MediaPlaybackClusterPlaybackPositionStruct?) sealed class SampledPositionAttributeSubscriptionState { - data class Success( - val value: MediaPlaybackClusterPlaybackPositionStruct? - ) : SampledPositionAttributeSubscriptionState() - + data class Success(val value: MediaPlaybackClusterPlaybackPositionStruct?) : + SampledPositionAttributeSubscriptionState() + data class Error(val exception: Exception) : SampledPositionAttributeSubscriptionState() - object SubscriptionEstablished : SampledPositionAttributeSubscriptionState() - } -class SeekRangeEndAttribute( - val value: ULong? - ) + object SubscriptionEstablished : SampledPositionAttributeSubscriptionState() + } + + class SeekRangeEndAttribute(val value: ULong?) sealed class SeekRangeEndAttributeSubscriptionState { - data class Success( - val value: ULong? - ) : SeekRangeEndAttributeSubscriptionState() - + data class Success(val value: ULong?) : SeekRangeEndAttributeSubscriptionState() + data class Error(val exception: Exception) : SeekRangeEndAttributeSubscriptionState() - object SubscriptionEstablished : SeekRangeEndAttributeSubscriptionState() - } -class SeekRangeStartAttribute( - val value: ULong? - ) + object SubscriptionEstablished : SeekRangeEndAttributeSubscriptionState() + } + + class SeekRangeStartAttribute(val value: ULong?) sealed class SeekRangeStartAttributeSubscriptionState { - data class Success( - val value: ULong? - ) : SeekRangeStartAttributeSubscriptionState() - + data class Success(val value: ULong?) : SeekRangeStartAttributeSubscriptionState() + data class Error(val exception: Exception) : SeekRangeStartAttributeSubscriptionState() - object SubscriptionEstablished : SeekRangeStartAttributeSubscriptionState() - } -class ActiveAudioTrackAttribute( - val value: MediaPlaybackClusterTrackStruct? - ) + object SubscriptionEstablished : SeekRangeStartAttributeSubscriptionState() + } + + class ActiveAudioTrackAttribute(val value: MediaPlaybackClusterTrackStruct?) sealed class ActiveAudioTrackAttributeSubscriptionState { - data class Success( - val value: MediaPlaybackClusterTrackStruct? - ) : ActiveAudioTrackAttributeSubscriptionState() - + data class Success(val value: MediaPlaybackClusterTrackStruct?) : + ActiveAudioTrackAttributeSubscriptionState() + data class Error(val exception: Exception) : ActiveAudioTrackAttributeSubscriptionState() - object SubscriptionEstablished : ActiveAudioTrackAttributeSubscriptionState() - } -class AvailableAudioTracksAttribute( - val value: List? - ) + object SubscriptionEstablished : ActiveAudioTrackAttributeSubscriptionState() + } + + class AvailableAudioTracksAttribute(val value: List?) sealed class AvailableAudioTracksAttributeSubscriptionState { - data class Success( - val value: List? - ) : AvailableAudioTracksAttributeSubscriptionState() - + data class Success(val value: List?) : + AvailableAudioTracksAttributeSubscriptionState() + data class Error(val exception: Exception) : AvailableAudioTracksAttributeSubscriptionState() - object SubscriptionEstablished : AvailableAudioTracksAttributeSubscriptionState() - } -class ActiveTextTrackAttribute( - val value: MediaPlaybackClusterTrackStruct? - ) + object SubscriptionEstablished : AvailableAudioTracksAttributeSubscriptionState() + } + + class ActiveTextTrackAttribute(val value: MediaPlaybackClusterTrackStruct?) sealed class ActiveTextTrackAttributeSubscriptionState { - data class Success( - val value: MediaPlaybackClusterTrackStruct? - ) : ActiveTextTrackAttributeSubscriptionState() - + data class Success(val value: MediaPlaybackClusterTrackStruct?) : + ActiveTextTrackAttributeSubscriptionState() + data class Error(val exception: Exception) : ActiveTextTrackAttributeSubscriptionState() - object SubscriptionEstablished : ActiveTextTrackAttributeSubscriptionState() - } -class AvailableTextTracksAttribute( - val value: List? - ) + object SubscriptionEstablished : ActiveTextTrackAttributeSubscriptionState() + } + + class AvailableTextTracksAttribute(val value: List?) sealed class AvailableTextTracksAttributeSubscriptionState { - data class Success( - val value: List? - ) : AvailableTextTracksAttributeSubscriptionState() - + data class Success(val value: List?) : + AvailableTextTracksAttributeSubscriptionState() + data class Error(val exception: Exception) : AvailableTextTracksAttributeSubscriptionState() - object SubscriptionEstablished : AvailableTextTracksAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : AvailableTextTracksAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } suspend fun play(timedInvokeTimeout: Duration? = null): PlaybackResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -255,64 +203,55 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_DATA: Int = 1 var data_decoded: String? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_DATA)) {data_decoded = + if (tag == ContextSpecificTag(TAG_STATUS)) { + status_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_DATA)) { + data_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - }} - - - else { + tlvReader.getString(tag) + } else { + null + } + } + } else { tlvReader.skipElement() } } - - if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - - - tlvReader.exitContainer() - return PlaybackResponse( - status_decoded, - data_decoded - ) + return PlaybackResponse(status_decoded, data_decoded) } suspend fun pause(timedInvokeTimeout: Duration? = null): PlaybackResponse { val commandId: UInt = 1u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -322,64 +261,55 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_DATA: Int = 1 var data_decoded: String? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_DATA)) {data_decoded = + if (tag == ContextSpecificTag(TAG_STATUS)) { + status_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_DATA)) { + data_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - }} - - - else { + tlvReader.getString(tag) + } else { + null + } + } + } else { tlvReader.skipElement() } } - - if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - - - tlvReader.exitContainer() - return PlaybackResponse( - status_decoded, - data_decoded - ) + return PlaybackResponse(status_decoded, data_decoded) } suspend fun stop(timedInvokeTimeout: Duration? = null): PlaybackResponse { val commandId: UInt = 2u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -389,64 +319,55 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_DATA: Int = 1 var data_decoded: String? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_DATA)) {data_decoded = + if (tag == ContextSpecificTag(TAG_STATUS)) { + status_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_DATA)) { + data_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - }} - - - else { + tlvReader.getString(tag) + } else { + null + } + } + } else { tlvReader.skipElement() } } - - if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - - - tlvReader.exitContainer() - return PlaybackResponse( - status_decoded, - data_decoded - ) + return PlaybackResponse(status_decoded, data_decoded) } suspend fun startOver(timedInvokeTimeout: Duration? = null): PlaybackResponse { val commandId: UInt = 3u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -456,64 +377,55 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_DATA: Int = 1 var data_decoded: String? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_DATA)) {data_decoded = + if (tag == ContextSpecificTag(TAG_STATUS)) { + status_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_DATA)) { + data_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - }} - - - else { + tlvReader.getString(tag) + } else { + null + } + } + } else { tlvReader.skipElement() } } - - if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - - - tlvReader.exitContainer() - return PlaybackResponse( - status_decoded, - data_decoded - ) + return PlaybackResponse(status_decoded, data_decoded) } suspend fun previous(timedInvokeTimeout: Duration? = null): PlaybackResponse { val commandId: UInt = 4u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -523,64 +435,55 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_DATA: Int = 1 var data_decoded: String? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_DATA)) {data_decoded = + if (tag == ContextSpecificTag(TAG_STATUS)) { + status_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_DATA)) { + data_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - }} - - - else { + tlvReader.getString(tag) + } else { + null + } + } + } else { tlvReader.skipElement() } } - - if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - - - tlvReader.exitContainer() - return PlaybackResponse( - status_decoded, - data_decoded - ) + return PlaybackResponse(status_decoded, data_decoded) } suspend fun next(timedInvokeTimeout: Duration? = null): PlaybackResponse { val commandId: UInt = 5u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -590,54 +493,47 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_DATA: Int = 1 var data_decoded: String? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_DATA)) {data_decoded = + if (tag == ContextSpecificTag(TAG_STATUS)) { + status_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_DATA)) { + data_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - }} - - - else { + tlvReader.getString(tag) + } else { + null + } + } + } else { tlvReader.skipElement() } } - - if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - - - tlvReader.exitContainer() - return PlaybackResponse( - status_decoded, - data_decoded - ) + return PlaybackResponse(status_decoded, data_decoded) } - suspend fun rewind(audioAdvanceUnmuted: Boolean? - ,timedInvokeTimeout: Duration? = null): PlaybackResponse { + suspend fun rewind( + audioAdvanceUnmuted: Boolean?, + timedInvokeTimeout: Duration? = null, + ): PlaybackResponse { val commandId: UInt = 6u val tlvWriter = TlvWriter() @@ -646,14 +542,14 @@ class AttributeListAttribute( val TAG_AUDIO_ADVANCE_UNMUTED_REQ: Int = 0 audioAdvanceUnmuted?.let { tlvWriter.put(ContextSpecificTag(TAG_AUDIO_ADVANCE_UNMUTED_REQ), audioAdvanceUnmuted) - } + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -663,54 +559,47 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_DATA: Int = 1 var data_decoded: String? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_DATA)) {data_decoded = + if (tag == ContextSpecificTag(TAG_STATUS)) { + status_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_DATA)) { + data_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - }} - - - else { + tlvReader.getString(tag) + } else { + null + } + } + } else { tlvReader.skipElement() } } - - if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - - - tlvReader.exitContainer() - return PlaybackResponse( - status_decoded, - data_decoded - ) + return PlaybackResponse(status_decoded, data_decoded) } - suspend fun fastForward(audioAdvanceUnmuted: Boolean? - ,timedInvokeTimeout: Duration? = null): PlaybackResponse { + suspend fun fastForward( + audioAdvanceUnmuted: Boolean?, + timedInvokeTimeout: Duration? = null, + ): PlaybackResponse { val commandId: UInt = 7u val tlvWriter = TlvWriter() @@ -719,14 +608,14 @@ class AttributeListAttribute( val TAG_AUDIO_ADVANCE_UNMUTED_REQ: Int = 0 audioAdvanceUnmuted?.let { tlvWriter.put(ContextSpecificTag(TAG_AUDIO_ADVANCE_UNMUTED_REQ), audioAdvanceUnmuted) - } + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -736,68 +625,64 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_DATA: Int = 1 var data_decoded: String? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_DATA)) {data_decoded = + if (tag == ContextSpecificTag(TAG_STATUS)) { + status_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_DATA)) { + data_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - }} - - - else { + tlvReader.getString(tag) + } else { + null + } + } + } else { tlvReader.skipElement() } } - - if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - - - tlvReader.exitContainer() - return PlaybackResponse( - status_decoded, - data_decoded - ) + return PlaybackResponse(status_decoded, data_decoded) } - suspend fun skipForward(deltaPositionMilliseconds: ULong - ,timedInvokeTimeout: Duration? = null): PlaybackResponse { + suspend fun skipForward( + deltaPositionMilliseconds: ULong, + timedInvokeTimeout: Duration? = null, + ): PlaybackResponse { val commandId: UInt = 8u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_DELTA_POSITION_MILLISECONDS_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_DELTA_POSITION_MILLISECONDS_REQ), deltaPositionMilliseconds) + tlvWriter.put( + ContextSpecificTag(TAG_DELTA_POSITION_MILLISECONDS_REQ), + deltaPositionMilliseconds, + ) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -807,68 +692,64 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_DATA: Int = 1 var data_decoded: String? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_DATA)) {data_decoded = + if (tag == ContextSpecificTag(TAG_STATUS)) { + status_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_DATA)) { + data_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - }} - - - else { + tlvReader.getString(tag) + } else { + null + } + } + } else { tlvReader.skipElement() } } - - if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - - - tlvReader.exitContainer() - return PlaybackResponse( - status_decoded, - data_decoded - ) + return PlaybackResponse(status_decoded, data_decoded) } - suspend fun skipBackward(deltaPositionMilliseconds: ULong - ,timedInvokeTimeout: Duration? = null): PlaybackResponse { + suspend fun skipBackward( + deltaPositionMilliseconds: ULong, + timedInvokeTimeout: Duration? = null, + ): PlaybackResponse { val commandId: UInt = 9u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_DELTA_POSITION_MILLISECONDS_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_DELTA_POSITION_MILLISECONDS_REQ), deltaPositionMilliseconds) + tlvWriter.put( + ContextSpecificTag(TAG_DELTA_POSITION_MILLISECONDS_REQ), + deltaPositionMilliseconds, + ) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -878,68 +759,58 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_DATA: Int = 1 var data_decoded: String? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_DATA)) {data_decoded = + if (tag == ContextSpecificTag(TAG_STATUS)) { + status_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_DATA)) { + data_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - }} - - - else { + tlvReader.getString(tag) + } else { + null + } + } + } else { tlvReader.skipElement() } } - - if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - - - tlvReader.exitContainer() - return PlaybackResponse( - status_decoded, - data_decoded - ) + return PlaybackResponse(status_decoded, data_decoded) } - suspend fun seek(position: ULong - ,timedInvokeTimeout: Duration? = null): PlaybackResponse { + suspend fun seek(position: ULong, timedInvokeTimeout: Duration? = null): PlaybackResponse { val commandId: UInt = 11u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_POSITION_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_POSITION_REQ), position) + tlvWriter.put(ContextSpecificTag(TAG_POSITION_REQ), position) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -949,55 +820,48 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_DATA: Int = 1 var data_decoded: String? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_DATA)) {data_decoded = + if (tag == ContextSpecificTag(TAG_STATUS)) { + status_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_DATA)) { + data_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - }} - - - else { + tlvReader.getString(tag) + } else { + null + } + } + } else { tlvReader.skipElement() } } - - if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - - - tlvReader.exitContainer() - return PlaybackResponse( - status_decoded, - data_decoded - ) + return PlaybackResponse(status_decoded, data_decoded) } - suspend fun activateAudioTrack(trackID: String - ,audioOutputIndex: UByte - ,timedInvokeTimeout: Duration? = null) { + suspend fun activateAudioTrack( + trackID: String, + audioOutputIndex: UByte, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 12u val tlvWriter = TlvWriter() @@ -1007,36 +871,35 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_TRACK_ID_REQ), trackID) val TAG_AUDIO_OUTPUT_INDEX_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_AUDIO_OUTPUT_INDEX_REQ), audioOutputIndex) + tlvWriter.put(ContextSpecificTag(TAG_AUDIO_OUTPUT_INDEX_REQ), audioOutputIndex) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun activateTextTrack(trackID: String - ,timedInvokeTimeout: Duration? = null) { + suspend fun activateTextTrack(trackID: String, timedInvokeTimeout: Duration? = null) { val commandId: UInt = 13u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_TRACK_ID_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_TRACK_ID_REQ), trackID) + tlvWriter.put(ContextSpecificTag(TAG_TRACK_ID_REQ), trackID) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -1047,92 +910,87 @@ class AttributeListAttribute( val commandId: UInt = 14u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } -suspend fun readCurrentStateAttribute(): UByte {val ATTRIBUTE_ID: UInt = 0u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readCurrentStateAttribute(): 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 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}") - } + 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) { - "Currentstate attribute not found in response" - } + } + + requireNotNull(attributeData) { "Currentstate 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 subscribeCurrentStateAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Currentstate attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Currentstate attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -1144,1181 +1002,1132 @@ suspend fun readCurrentStateAttribute(): UByte {val ATTRIBUTE_ID: UInt = 0u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readStartTimeAttribute(): StartTimeAttribute {val ATTRIBUTE_ID: UInt = 1u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readStartTimeAttribute(): StartTimeAttribute { + 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 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}") - } + 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) { - "Starttime attribute not found in response" - } + } + + requireNotNull(attributeData) { "Starttime 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 - } - + val decodedValue: ULong? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return StartTimeAttribute(decodedValue) } suspend fun subscribeStartTimeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StartTimeAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StartTimeAttributeSubscriptionState.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) { - "Starttime attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Starttime 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(StartTimeAttributeSubscriptionState.Success(it)) - } - + val decodedValue: ULong? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(StartTimeAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(StartTimeAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readDurationAttribute(): DurationAttribute {val ATTRIBUTE_ID: UInt = 2u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readDurationAttribute(): DurationAttribute { + 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 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}") - } + 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) { - "Duration attribute not found in response" - } + } + + requireNotNull(attributeData) { "Duration 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 - } - + val decodedValue: ULong? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return DurationAttribute(decodedValue) } suspend fun subscribeDurationAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(DurationAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + DurationAttributeSubscriptionState.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) { - "Duration attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Duration 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(DurationAttributeSubscriptionState.Success(it)) - } - + val decodedValue: ULong? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(DurationAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(DurationAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readSampledPositionAttribute(): SampledPositionAttribute {val ATTRIBUTE_ID: UInt = 3u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readSampledPositionAttribute(): SampledPositionAttribute { + 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 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}") - } + 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) { - "Sampledposition attribute not found in response" - } + } + + requireNotNull(attributeData) { "Sampledposition attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: MediaPlaybackClusterPlaybackPositionStruct? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - MediaPlaybackClusterPlaybackPositionStruct.fromTlv(AnonymousTag, tlvReader) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: MediaPlaybackClusterPlaybackPositionStruct? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + MediaPlaybackClusterPlaybackPositionStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return SampledPositionAttribute(decodedValue) } suspend fun subscribeSampledPositionAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(SampledPositionAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + SampledPositionAttributeSubscriptionState.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) { - "Sampledposition attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Sampledposition attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: MediaPlaybackClusterPlaybackPositionStruct? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - MediaPlaybackClusterPlaybackPositionStruct.fromTlv(AnonymousTag, tlvReader) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(SampledPositionAttributeSubscriptionState.Success(it)) - } - + val decodedValue: MediaPlaybackClusterPlaybackPositionStruct? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + MediaPlaybackClusterPlaybackPositionStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(SampledPositionAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(SampledPositionAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPlaybackSpeedAttribute(): Float? {val ATTRIBUTE_ID: UInt = 4u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readPlaybackSpeedAttribute(): Float? { + 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 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}") - } + 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) { - "Playbackspeed attribute not found in response" - } + } + + requireNotNull(attributeData) { "Playbackspeed attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - + val decodedValue: Float? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribePlaybackSpeedAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(FloatSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + FloatSubscriptionState.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) { - "Playbackspeed attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Playbackspeed attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(FloatSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(FloatSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(FloatSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readSeekRangeEndAttribute(): SeekRangeEndAttribute {val ATTRIBUTE_ID: UInt = 5u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readSeekRangeEndAttribute(): SeekRangeEndAttribute { + 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 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}") - } + 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) { - "Seekrangeend attribute not found in response" - } + } + + requireNotNull(attributeData) { "Seekrangeend 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 - } - + val decodedValue: ULong? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return SeekRangeEndAttribute(decodedValue) } suspend fun subscribeSeekRangeEndAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(SeekRangeEndAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + SeekRangeEndAttributeSubscriptionState.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) { - "Seekrangeend attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Seekrangeend 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(SeekRangeEndAttributeSubscriptionState.Success(it)) - } - + val decodedValue: ULong? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(SeekRangeEndAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(SeekRangeEndAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readSeekRangeStartAttribute(): SeekRangeStartAttribute {val ATTRIBUTE_ID: UInt = 6u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readSeekRangeStartAttribute(): SeekRangeStartAttribute { + 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 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}") - } + 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) { - "Seekrangestart attribute not found in response" - } + } + + requireNotNull(attributeData) { "Seekrangestart 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 - } - + val decodedValue: ULong? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return SeekRangeStartAttribute(decodedValue) } suspend fun subscribeSeekRangeStartAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(SeekRangeStartAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + SeekRangeStartAttributeSubscriptionState.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) { - "Seekrangestart attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Seekrangestart 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(SeekRangeStartAttributeSubscriptionState.Success(it)) - } - + val decodedValue: ULong? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(SeekRangeStartAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(SeekRangeStartAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readActiveAudioTrackAttribute(): ActiveAudioTrackAttribute {val ATTRIBUTE_ID: UInt = 7u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readActiveAudioTrackAttribute(): ActiveAudioTrackAttribute { + 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 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}") - } + 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) { - "Activeaudiotrack attribute not found in response" - } + } + + requireNotNull(attributeData) { "Activeaudiotrack attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: MediaPlaybackClusterTrackStruct? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - MediaPlaybackClusterTrackStruct.fromTlv(AnonymousTag, tlvReader) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: MediaPlaybackClusterTrackStruct? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + MediaPlaybackClusterTrackStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return ActiveAudioTrackAttribute(decodedValue) } suspend fun subscribeActiveAudioTrackAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ActiveAudioTrackAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ActiveAudioTrackAttributeSubscriptionState.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) { - "Activeaudiotrack attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Activeaudiotrack attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: MediaPlaybackClusterTrackStruct? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - MediaPlaybackClusterTrackStruct.fromTlv(AnonymousTag, tlvReader) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(ActiveAudioTrackAttributeSubscriptionState.Success(it)) - } - + val decodedValue: MediaPlaybackClusterTrackStruct? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + MediaPlaybackClusterTrackStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(ActiveAudioTrackAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ActiveAudioTrackAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAvailableAudioTracksAttribute(): AvailableAudioTracksAttribute {val ATTRIBUTE_ID: UInt = 8u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readAvailableAudioTracksAttribute(): AvailableAudioTracksAttribute { + val ATTRIBUTE_ID: UInt = 8u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Availableaudiotracks attribute not found in response" - } + } + + requireNotNull(attributeData) { "Availableaudiotracks attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(MediaPlaybackClusterTrackStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(MediaPlaybackClusterTrackStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null } - tlvReader.exitContainer() - } - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - return AvailableAudioTracksAttribute(decodedValue) } suspend fun subscribeAvailableAudioTracksAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(AvailableAudioTracksAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + AvailableAudioTracksAttributeSubscriptionState.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) { - "Availableaudiotracks attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Availableaudiotracks attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(MediaPlaybackClusterTrackStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(AvailableAudioTracksAttributeSubscriptionState.Success(it)) - } - + val decodedValue: List? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(MediaPlaybackClusterTrackStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(AvailableAudioTracksAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(AvailableAudioTracksAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readActiveTextTrackAttribute(): ActiveTextTrackAttribute {val ATTRIBUTE_ID: UInt = 9u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readActiveTextTrackAttribute(): ActiveTextTrackAttribute { + val ATTRIBUTE_ID: UInt = 9u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Activetexttrack attribute not found in response" - } + } + + requireNotNull(attributeData) { "Activetexttrack attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: MediaPlaybackClusterTrackStruct? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - MediaPlaybackClusterTrackStruct.fromTlv(AnonymousTag, tlvReader) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: MediaPlaybackClusterTrackStruct? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + MediaPlaybackClusterTrackStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return ActiveTextTrackAttribute(decodedValue) } suspend fun subscribeActiveTextTrackAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ActiveTextTrackAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ActiveTextTrackAttributeSubscriptionState.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) { - "Activetexttrack attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Activetexttrack attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: MediaPlaybackClusterTrackStruct? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - MediaPlaybackClusterTrackStruct.fromTlv(AnonymousTag, tlvReader) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(ActiveTextTrackAttributeSubscriptionState.Success(it)) - } - + val decodedValue: MediaPlaybackClusterTrackStruct? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + MediaPlaybackClusterTrackStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(ActiveTextTrackAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ActiveTextTrackAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAvailableTextTracksAttribute(): AvailableTextTracksAttribute {val ATTRIBUTE_ID: UInt = 10u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readAvailableTextTracksAttribute(): AvailableTextTracksAttribute { + val ATTRIBUTE_ID: UInt = 10u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Availabletexttracks attribute not found in response" - } + } + + requireNotNull(attributeData) { "Availabletexttracks attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(MediaPlaybackClusterTrackStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(MediaPlaybackClusterTrackStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null } - tlvReader.exitContainer() - } - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - return AvailableTextTracksAttribute(decodedValue) } suspend fun subscribeAvailableTextTracksAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(AvailableTextTracksAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + AvailableTextTracksAttributeSubscriptionState.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) { - "Availabletexttracks attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Availabletexttracks attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(MediaPlaybackClusterTrackStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(AvailableTextTracksAttributeSubscriptionState.Success(it)) - } - + val decodedValue: List? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(MediaPlaybackClusterTrackStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(AvailableTextTracksAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(AvailableTextTracksAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65528u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -2326,97 +2135,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { emit(GeneratedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65529u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -2424,97 +2232,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va emit(AcceptedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt = 65530u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -2522,97 +2327,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt emit(EventListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ID: UInt = 65531u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -2620,81 +2422,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ emit(AttributeListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -2706,80 +2503,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 65533u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -2792,7 +2586,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/MessagesCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/MessagesCluster.kt index effa24084cd5ab..e832c5cefe49b3 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/MessagesCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/MessagesCluster.kt @@ -17,135 +17,100 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState -import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.UShortSubscriptionState +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class MessagesCluster(private val controller: MatterController, private val endpointId: UShort) {class MessagesAttribute( - val value: List - ) +class MessagesCluster(private val controller: MatterController, private val endpointId: UShort) { + class MessagesAttribute(val value: List) sealed class MessagesAttributeSubscriptionState { - data class Success( - val value: List - ) : MessagesAttributeSubscriptionState() - + data class Success(val value: List) : + MessagesAttributeSubscriptionState() + data class Error(val exception: Exception) : MessagesAttributeSubscriptionState() - object SubscriptionEstablished : MessagesAttributeSubscriptionState() - } -class ActiveMessageIDsAttribute( - val value: List - ) + object SubscriptionEstablished : MessagesAttributeSubscriptionState() + } + + class ActiveMessageIDsAttribute(val value: List) sealed class ActiveMessageIDsAttributeSubscriptionState { - data class Success( - val value: List - ) : ActiveMessageIDsAttributeSubscriptionState() - + data class Success(val value: List) : ActiveMessageIDsAttributeSubscriptionState() + data class Error(val exception: Exception) : ActiveMessageIDsAttributeSubscriptionState() - object SubscriptionEstablished : ActiveMessageIDsAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : ActiveMessageIDsAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } - - suspend fun presentMessagesRequest(messageID: ByteArray - ,priority: UByte - ,messageControl: UByte - ,startTime: UInt? - ,duration: ULong? - ,messageText: String - ,responses: List? - ,timedInvokeTimeout: Duration? = null) { + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } + + suspend fun presentMessagesRequest( + messageID: ByteArray, + priority: UByte, + messageControl: UByte, + startTime: UInt?, + duration: ULong?, + messageText: String, + responses: List?, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 0u val tlvWriter = TlvWriter() @@ -161,14 +126,10 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_MESSAGE_CONTROL_REQ), messageControl) val TAG_START_TIME_REQ: Int = 3 - startTime?.let { - tlvWriter.put(ContextSpecificTag(TAG_START_TIME_REQ), startTime) - } + startTime?.let { tlvWriter.put(ContextSpecificTag(TAG_START_TIME_REQ), startTime) } val TAG_DURATION_REQ: Int = 4 - duration?.let { - tlvWriter.put(ContextSpecificTag(TAG_DURATION_REQ), duration) - } + duration?.let { tlvWriter.put(ContextSpecificTag(TAG_DURATION_REQ), duration) } val TAG_MESSAGE_TEXT_REQ: Int = 5 tlvWriter.put(ContextSpecificTag(TAG_MESSAGE_TEXT_REQ), messageText) @@ -180,22 +141,24 @@ class AttributeListAttribute( item.toTlv(AnonymousTag, tlvWriter) } tlvWriter.endArray() - } + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun cancelMessagesRequest(messageIDs: List - ,timedInvokeTimeout: Duration? = null) { + suspend fun cancelMessagesRequest( + messageIDs: List, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 1u val tlvWriter = TlvWriter() @@ -203,111 +166,108 @@ class AttributeListAttribute( val TAG_MESSAGE_I_DS_REQ: Int = 0 tlvWriter.startArray(ContextSpecificTag(TAG_MESSAGE_I_DS_REQ)) - for (item in messageIDs.iterator()) { - tlvWriter.put(AnonymousTag, item) - } - tlvWriter.endArray() + for (item in messageIDs.iterator()) { + tlvWriter.put(AnonymousTag, item) + } + tlvWriter.endArray() tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } -suspend fun readMessagesAttribute(): MessagesAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMessagesAttribute(): MessagesAttribute { + 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}") - } + 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) { - "Messages attribute not found in response" - } + } + + requireNotNull(attributeData) { "Messages 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(MessagesClusterMessageStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(MessagesClusterMessageStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return MessagesAttribute(decodedValue) } suspend fun subscribeMessagesAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MessagesAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MessagesAttributeSubscriptionState.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) { - "Messages attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Messages 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(MessagesClusterMessageStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(MessagesClusterMessageStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(MessagesAttributeSubscriptionState.Success(decodedValue)) } @@ -315,97 +275,96 @@ suspend fun readMessagesAttribute(): MessagesAttribute {val ATTRIBUTE_ID: UInt = emit(MessagesAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readActiveMessageIDsAttribute(): ActiveMessageIDsAttribute {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readActiveMessageIDsAttribute(): ActiveMessageIDsAttribute { + 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}") - } + 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) { - "Activemessageids attribute not found in response" - } + } + + requireNotNull(attributeData) { "Activemessageids 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.getByteArray(AnonymousTag)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getByteArray(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return ActiveMessageIDsAttribute(decodedValue) } suspend fun subscribeActiveMessageIDsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ActiveMessageIDsAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ActiveMessageIDsAttributeSubscriptionState.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) { - "Activemessageids attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Activemessageids 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.getByteArray(AnonymousTag)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getByteArray(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(ActiveMessageIDsAttributeSubscriptionState.Success(decodedValue)) } @@ -413,97 +372,96 @@ suspend fun readActiveMessageIDsAttribute(): ActiveMessageIDsAttribute {val ATTR emit(ActiveMessageIDsAttributeSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -511,97 +469,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -609,97 +566,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -707,97 +661,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -805,81 +756,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -891,80 +837,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -977,7 +920,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/MicrowaveOvenControlCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/MicrowaveOvenControlCluster.kt index 08a1b816898255..55beb250c74862 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/MicrowaveOvenControlCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/MicrowaveOvenControlCluster.kt @@ -17,139 +17,104 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.UShortSubscriptionState +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class MicrowaveOvenControlCluster(private val controller: MatterController, private val endpointId: UShort) {class SupportedWattsAttribute( - val value: List? - ) +class MicrowaveOvenControlCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class SupportedWattsAttribute(val value: List?) sealed class SupportedWattsAttributeSubscriptionState { - data class Success( - val value: List? - ) : SupportedWattsAttributeSubscriptionState() - + data class Success(val value: List?) : SupportedWattsAttributeSubscriptionState() + data class Error(val exception: Exception) : SupportedWattsAttributeSubscriptionState() - object SubscriptionEstablished : SupportedWattsAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : SupportedWattsAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun setCookingParameters(cookMode: UByte? - ,cookTime: UInt? - ,powerSetting: UByte? - ,wattSettingIndex: UByte? - ,startAfterSetting: Boolean? - ,timedInvokeTimeout: Duration? = null) { + suspend fun setCookingParameters( + cookMode: UByte?, + cookTime: UInt?, + powerSetting: UByte?, + wattSettingIndex: UByte?, + startAfterSetting: Boolean?, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_COOK_MODE_REQ: Int = 0 - cookMode?.let { - tlvWriter.put(ContextSpecificTag(TAG_COOK_MODE_REQ), cookMode) - } + cookMode?.let { tlvWriter.put(ContextSpecificTag(TAG_COOK_MODE_REQ), cookMode) } val TAG_COOK_TIME_REQ: Int = 1 - cookTime?.let { - tlvWriter.put(ContextSpecificTag(TAG_COOK_TIME_REQ), cookTime) - } + cookTime?.let { tlvWriter.put(ContextSpecificTag(TAG_COOK_TIME_REQ), cookTime) } val TAG_POWER_SETTING_REQ: Int = 2 - powerSetting?.let { - tlvWriter.put(ContextSpecificTag(TAG_POWER_SETTING_REQ), powerSetting) - } + powerSetting?.let { tlvWriter.put(ContextSpecificTag(TAG_POWER_SETTING_REQ), powerSetting) } val TAG_WATT_SETTING_INDEX_REQ: Int = 3 wattSettingIndex?.let { @@ -159,114 +124,108 @@ class AttributeListAttribute( val TAG_START_AFTER_SETTING_REQ: Int = 4 startAfterSetting?.let { tlvWriter.put(ContextSpecificTag(TAG_START_AFTER_SETTING_REQ), startAfterSetting) - } + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun addMoreTime(timeToAdd: UInt - ,timedInvokeTimeout: Duration? = null) { + suspend fun addMoreTime(timeToAdd: UInt, timedInvokeTimeout: Duration? = null) { val commandId: UInt = 1u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_TIME_TO_ADD_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_TIME_TO_ADD_REQ), timeToAdd) + tlvWriter.put(ContextSpecificTag(TAG_TIME_TO_ADD_REQ), timeToAdd) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } -suspend fun readCookTimeAttribute(): UInt {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readCookTimeAttribute(): UInt { + 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}") - } + 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) { - "Cooktime attribute not found in response" - } + } + + requireNotNull(attributeData) { "Cooktime 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 subscribeCookTimeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Cooktime attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Cooktime attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -278,81 +237,76 @@ suspend fun readCookTimeAttribute(): UInt {val ATTRIBUTE_ID: UInt = 0u emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMaxCookTimeAttribute(): UInt {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMaxCookTimeAttribute(): UInt { + 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}") - } + 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) { - "Maxcooktime attribute not found in response" - } + } + + requireNotNull(attributeData) { "Maxcooktime 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 subscribeMaxCookTimeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Maxcooktime attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Maxcooktime attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -364,788 +318,749 @@ suspend fun readMaxCookTimeAttribute(): UInt {val ATTRIBUTE_ID: UInt = 1u emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPowerSettingAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readPowerSettingAttribute(): UByte? { + 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}") - } + 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) { - "Powersetting attribute not found in response" - } + } + + requireNotNull(attributeData) { "Powersetting 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribePowerSettingAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Powersetting attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Powersetting 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)) - } - + 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 readMinPowerAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMinPowerAttribute(): UByte? { + 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}") - } + 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) { - "Minpower attribute not found in response" - } + } + + requireNotNull(attributeData) { "Minpower 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeMinPowerAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Minpower attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Minpower 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)) - } - + 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 readMaxPowerAttribute(): 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) - ) - + + suspend fun readMaxPowerAttribute(): 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}") - } + 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) { - "Maxpower attribute not found in response" - } + } + + requireNotNull(attributeData) { "Maxpower 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeMaxPowerAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Maxpower attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Maxpower 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)) - } - + 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 readPowerStepAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 5u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readPowerStepAttribute(): UByte? { + 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}") - } + 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) { - "Powerstep attribute not found in response" - } + } + + requireNotNull(attributeData) { "Powerstep 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribePowerStepAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Powerstep attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Powerstep 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)) - } - + 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 readSupportedWattsAttribute(): SupportedWattsAttribute {val ATTRIBUTE_ID: UInt = 6u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readSupportedWattsAttribute(): SupportedWattsAttribute { + 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}") - } + 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) { - "Supportedwatts attribute not found in response" - } + } + + requireNotNull(attributeData) { "Supportedwatts attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getUShort(AnonymousTag)) + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUShort(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null } - tlvReader.exitContainer() - } - } else { - null - } - return SupportedWattsAttribute(decodedValue) } suspend fun subscribeSupportedWattsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(SupportedWattsAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + SupportedWattsAttributeSubscriptionState.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) { - "Supportedwatts attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Supportedwatts attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getUShort(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { - emit(SupportedWattsAttributeSubscriptionState.Success(it)) - } - + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUShort(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { emit(SupportedWattsAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(SupportedWattsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readSelectedWattIndexAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 7u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readSelectedWattIndexAttribute(): UByte? { + 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}") - } + 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) { - "Selectedwattindex attribute not found in response" - } + } + + requireNotNull(attributeData) { "Selectedwattindex 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeSelectedWattIndexAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Selectedwattindex attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Selectedwattindex 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)) - } - + 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 readWattRatingAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 8u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readWattRatingAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 8u + + 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}") - } + 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) { - "Wattrating attribute not found in response" - } + } + + requireNotNull(attributeData) { "Wattrating 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeWattRatingAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Wattrating attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Wattrating 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)) - } - + 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 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1153,97 +1068,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1251,97 +1165,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1349,97 +1260,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1447,81 +1355,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1533,80 +1436,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1619,7 +1519,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/MicrowaveOvenModeCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/MicrowaveOvenModeCluster.kt index 70c0c2f0b02c69..ae3df9b21f5b98 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/MicrowaveOvenModeCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/MicrowaveOvenModeCluster.kt @@ -17,202 +17,166 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse -import matter.controller.model.AttributePath -import matter.controller.model.CommandPath +import matter.controller.UShortSubscriptionState import matter.controller.cluster.structs.* +import matter.controller.model.AttributePath import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader -import matter.tlv.TlvWriter -class MicrowaveOvenModeCluster(private val controller: MatterController, private val endpointId: UShort) {class SupportedModesAttribute( - val value: List - ) +class MicrowaveOvenModeCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class SupportedModesAttribute(val value: List) sealed class SupportedModesAttributeSubscriptionState { - data class Success( - val value: List - ) : SupportedModesAttributeSubscriptionState() - + data class Success(val value: List) : + SupportedModesAttributeSubscriptionState() + data class Error(val exception: Exception) : SupportedModesAttributeSubscriptionState() - object SubscriptionEstablished : SupportedModesAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : SupportedModesAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } -suspend fun readSupportedModesAttribute(): SupportedModesAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } + + suspend fun readSupportedModesAttribute(): SupportedModesAttribute { + 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}") - } + 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) { - "Supportedmodes attribute not found in response" - } + } + + requireNotNull(attributeData) { "Supportedmodes 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(MicrowaveOvenModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(MicrowaveOvenModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return SupportedModesAttribute(decodedValue) } suspend fun subscribeSupportedModesAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(SupportedModesAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + SupportedModesAttributeSubscriptionState.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) { - "Supportedmodes attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Supportedmodes 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(MicrowaveOvenModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(MicrowaveOvenModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(SupportedModesAttributeSubscriptionState.Success(decodedValue)) } @@ -220,81 +184,76 @@ suspend fun readSupportedModesAttribute(): SupportedModesAttribute {val ATTRIBUT emit(SupportedModesAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCurrentModeAttribute(): 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) - ) - + + suspend fun readCurrentModeAttribute(): 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}") - } + 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) { - "Currentmode attribute not found in response" - } + } + + requireNotNull(attributeData) { "Currentmode 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 subscribeCurrentModeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Currentmode attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Currentmode attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -306,97 +265,96 @@ suspend fun readCurrentModeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 1u emit(UByteSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -404,97 +362,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -502,97 +459,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -600,97 +554,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -698,81 +649,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -784,80 +730,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -870,7 +813,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/ModeSelectCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/ModeSelectCluster.kt index e07ee80f76b046..3b93695d9ce56c 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/ModeSelectCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/ModeSelectCluster.kt @@ -17,247 +17,203 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest +import matter.controller.StringSubscriptionState import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class ModeSelectCluster(private val controller: MatterController, private val endpointId: UShort) {class StandardNamespaceAttribute( - val value: UShort? - ) +class ModeSelectCluster(private val controller: MatterController, private val endpointId: UShort) { + class StandardNamespaceAttribute(val value: UShort?) sealed class StandardNamespaceAttributeSubscriptionState { - data class Success( - val value: UShort? - ) : StandardNamespaceAttributeSubscriptionState() - + data class Success(val value: UShort?) : StandardNamespaceAttributeSubscriptionState() + data class Error(val exception: Exception) : StandardNamespaceAttributeSubscriptionState() - object SubscriptionEstablished : StandardNamespaceAttributeSubscriptionState() - } -class SupportedModesAttribute( - val value: List - ) + object SubscriptionEstablished : StandardNamespaceAttributeSubscriptionState() + } + + class SupportedModesAttribute(val value: List) sealed class SupportedModesAttributeSubscriptionState { - data class Success( - val value: List - ) : SupportedModesAttributeSubscriptionState() - + data class Success(val value: List) : + SupportedModesAttributeSubscriptionState() + data class Error(val exception: Exception) : SupportedModesAttributeSubscriptionState() - object SubscriptionEstablished : SupportedModesAttributeSubscriptionState() - } -class StartUpModeAttribute( - val value: UByte? - ) + object SubscriptionEstablished : SupportedModesAttributeSubscriptionState() + } + + class StartUpModeAttribute(val value: UByte?) sealed class StartUpModeAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : StartUpModeAttributeSubscriptionState() - + data class Success(val value: UByte?) : StartUpModeAttributeSubscriptionState() + data class Error(val exception: Exception) : StartUpModeAttributeSubscriptionState() - object SubscriptionEstablished : StartUpModeAttributeSubscriptionState() - } -class OnModeAttribute( - val value: UByte? - ) + object SubscriptionEstablished : StartUpModeAttributeSubscriptionState() + } + + class OnModeAttribute(val value: UByte?) sealed class OnModeAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : OnModeAttributeSubscriptionState() - + data class Success(val value: UByte?) : OnModeAttributeSubscriptionState() + data class Error(val exception: Exception) : OnModeAttributeSubscriptionState() - object SubscriptionEstablished : OnModeAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : OnModeAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun changeToMode(newMode: UByte - ,timedInvokeTimeout: Duration? = null) { + suspend fun changeToMode(newMode: UByte, timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_NEW_MODE_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_NEW_MODE_REQ), newMode) + tlvWriter.put(ContextSpecificTag(TAG_NEW_MODE_REQ), newMode) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } -suspend fun readDescriptionAttribute(): String {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readDescriptionAttribute(): String { + 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}") - } + 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) { - "Description attribute not found in response" - } + } + + requireNotNull(attributeData) { "Description attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: String = tlvReader.getString(AnonymousTag) - return decodedValue } suspend fun subscribeDescriptionAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StringSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StringSubscriptionState.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) { - "Description attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Description attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -269,196 +225,191 @@ suspend fun readDescriptionAttribute(): String {val ATTRIBUTE_ID: UInt = 0u emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readStandardNamespaceAttribute(): StandardNamespaceAttribute {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readStandardNamespaceAttribute(): StandardNamespaceAttribute { + 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}") - } + 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) { - "Standardnamespace attribute not found in response" - } + } + + requireNotNull(attributeData) { "Standardnamespace attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = if (!tlvReader.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return StandardNamespaceAttribute(decodedValue) } suspend fun subscribeStandardNamespaceAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StandardNamespaceAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StandardNamespaceAttributeSubscriptionState.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) { - "Standardnamespace attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Standardnamespace 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.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(StandardNamespaceAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(StandardNamespaceAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(StandardNamespaceAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readSupportedModesAttribute(): SupportedModesAttribute {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readSupportedModesAttribute(): SupportedModesAttribute { + 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}") - } + 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) { - "Supportedmodes attribute not found in response" - } + } + + requireNotNull(attributeData) { "Supportedmodes 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(ModeSelectClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(ModeSelectClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return SupportedModesAttribute(decodedValue) } suspend fun subscribeSupportedModesAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(SupportedModesAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + SupportedModesAttributeSubscriptionState.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) { - "Supportedmodes attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Supportedmodes 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(ModeSelectClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(ModeSelectClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(SupportedModesAttributeSubscriptionState.Success(decodedValue)) } @@ -466,81 +417,76 @@ suspend fun readSupportedModesAttribute(): SupportedModesAttribute {val ATTRIBUT emit(SupportedModesAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCurrentModeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readCurrentModeAttribute(): UByte { + 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}") - } + 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) { - "Currentmode attribute not found in response" - } + } + + requireNotNull(attributeData) { "Currentmode 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 subscribeCurrentModeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Currentmode attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Currentmode attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -552,77 +498,67 @@ suspend fun readCurrentModeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 3u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readStartUpModeAttribute(): StartUpModeAttribute {val ATTRIBUTE_ID: UInt = 4u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readStartUpModeAttribute(): StartUpModeAttribute { + 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}") - } + 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) { - "Startupmode attribute not found in response" - } + } + + requireNotNull(attributeData) { "Startupmode attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return StartUpModeAttribute(decodedValue) } - suspend fun writeStartUpModeAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeStartUpModeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 4u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -643,137 +579,127 @@ suspend fun readStartUpModeAttribute(): StartUpModeAttribute {val ATTRIBUTE_ID: throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeStartUpModeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StartUpModeAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StartUpModeAttributeSubscriptionState.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) { - "Startupmode attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Startupmode 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(StartUpModeAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(StartUpModeAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(StartUpModeAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readOnModeAttribute(): OnModeAttribute {val ATTRIBUTE_ID: UInt = 5u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readOnModeAttribute(): OnModeAttribute { + 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}") - } + 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) { - "Onmode attribute not found in response" - } + } + + requireNotNull(attributeData) { "Onmode attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return OnModeAttribute(decodedValue) } - suspend fun writeOnModeAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeOnModeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 5u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -794,157 +720,156 @@ suspend fun readOnModeAttribute(): OnModeAttribute {val ATTRIBUTE_ID: UInt = 5u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeOnModeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(OnModeAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + OnModeAttributeSubscriptionState.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) { - "Onmode attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Onmode 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(OnModeAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(OnModeAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(OnModeAttributeSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -952,97 +877,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1050,97 +974,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1148,97 +1069,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1246,81 +1164,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1332,80 +1245,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1418,7 +1328,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/NetworkCommissioningCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/NetworkCommissioningCluster.kt index 5a6e43bcee3cb3..2a144baed4f8fd 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/NetworkCommissioningCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/NetworkCommissioningCluster.kt @@ -17,216 +17,173 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration 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.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class NetworkCommissioningCluster(private val controller: MatterController, private val endpointId: UShort) { +class NetworkCommissioningCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { class ScanNetworksResponse( - val networkingStatus: UByte, - val debugText: String?, - val wiFiScanResults: List?, - val threadScanResults: List? + val networkingStatus: UByte, + val debugText: String?, + val wiFiScanResults: List?, + val threadScanResults: List?, ) class NetworkConfigResponse( - val networkingStatus: UByte, - val debugText: String?, - val networkIndex: UByte?, - val clientIdentity: ByteArray?, - val possessionSignature: ByteArray? + val networkingStatus: UByte, + val debugText: String?, + val networkIndex: UByte?, + val clientIdentity: ByteArray?, + val possessionSignature: ByteArray?, ) class ConnectNetworkResponse( - val networkingStatus: UByte, - val debugText: String?, - val errorValue: Int? + val networkingStatus: UByte, + val debugText: String?, + val errorValue: Int?, ) - class QueryIdentityResponse( - val identity: ByteArray, - val possessionSignature: ByteArray? - ) -class NetworksAttribute( - val value: List - ) + class QueryIdentityResponse(val identity: ByteArray, val possessionSignature: ByteArray?) + + class NetworksAttribute(val value: List) sealed class NetworksAttributeSubscriptionState { - data class Success( - val value: List - ) : NetworksAttributeSubscriptionState() - + data class Success(val value: List) : + NetworksAttributeSubscriptionState() + data class Error(val exception: Exception) : NetworksAttributeSubscriptionState() - object SubscriptionEstablished : NetworksAttributeSubscriptionState() - } -class LastNetworkingStatusAttribute( - val value: UByte? - ) + object SubscriptionEstablished : NetworksAttributeSubscriptionState() + } + + class LastNetworkingStatusAttribute(val value: UByte?) sealed class LastNetworkingStatusAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : LastNetworkingStatusAttributeSubscriptionState() - + data class Success(val value: UByte?) : LastNetworkingStatusAttributeSubscriptionState() + data class Error(val exception: Exception) : LastNetworkingStatusAttributeSubscriptionState() - object SubscriptionEstablished : LastNetworkingStatusAttributeSubscriptionState() - } -class LastNetworkIDAttribute( - val value: ByteArray? - ) + object SubscriptionEstablished : LastNetworkingStatusAttributeSubscriptionState() + } + + class LastNetworkIDAttribute(val value: ByteArray?) sealed class LastNetworkIDAttributeSubscriptionState { - data class Success( - val value: ByteArray? - ) : LastNetworkIDAttributeSubscriptionState() - + data class Success(val value: ByteArray?) : LastNetworkIDAttributeSubscriptionState() + data class Error(val exception: Exception) : LastNetworkIDAttributeSubscriptionState() - object SubscriptionEstablished : LastNetworkIDAttributeSubscriptionState() - } -class LastConnectErrorValueAttribute( - val value: Int? - ) + object SubscriptionEstablished : LastNetworkIDAttributeSubscriptionState() + } + + class LastConnectErrorValueAttribute(val value: Int?) sealed class LastConnectErrorValueAttributeSubscriptionState { - data class Success( - val value: Int? - ) : LastConnectErrorValueAttributeSubscriptionState() - + data class Success(val value: Int?) : LastConnectErrorValueAttributeSubscriptionState() + data class Error(val exception: Exception) : LastConnectErrorValueAttributeSubscriptionState() - object SubscriptionEstablished : LastConnectErrorValueAttributeSubscriptionState() - } -class SupportedWiFiBandsAttribute( - val value: List? - ) + object SubscriptionEstablished : LastConnectErrorValueAttributeSubscriptionState() + } + + class SupportedWiFiBandsAttribute(val value: List?) sealed class SupportedWiFiBandsAttributeSubscriptionState { - data class Success( - val value: List? - ) : SupportedWiFiBandsAttributeSubscriptionState() - + data class Success(val value: List?) : SupportedWiFiBandsAttributeSubscriptionState() + data class Error(val exception: Exception) : SupportedWiFiBandsAttributeSubscriptionState() - object SubscriptionEstablished : SupportedWiFiBandsAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : SupportedWiFiBandsAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun scanNetworks(ssid: ByteArray? - ,breadcrumb: ULong? - ,timedInvokeTimeout: Duration? = null): ScanNetworksResponse { + suspend fun scanNetworks( + ssid: ByteArray?, + breadcrumb: ULong?, + timedInvokeTimeout: Duration? = null, + ): ScanNetworksResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_SSID_REQ: Int = 0 - ssid?.let { - tlvWriter.put(ContextSpecificTag(TAG_SSID_REQ), ssid) - } + ssid?.let { tlvWriter.put(ContextSpecificTag(TAG_SSID_REQ), ssid) } val TAG_BREADCRUMB_REQ: Int = 1 - breadcrumb?.let { - tlvWriter.put(ContextSpecificTag(TAG_BREADCRUMB_REQ), breadcrumb) - } + breadcrumb?.let { tlvWriter.put(ContextSpecificTag(TAG_BREADCRUMB_REQ), breadcrumb) } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -236,89 +193,96 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_NETWORKING_STATUS: Int = 0 var networkingStatus_decoded: UByte? = null - + val TAG_DEBUG_TEXT: Int = 1 var debugText_decoded: String? = null - + val TAG_WI_FI_SCAN_RESULTS: Int = 2 - var wiFiScanResults_decoded: List? = null - + var wiFiScanResults_decoded: List? = + null + val TAG_THREAD_SCAN_RESULTS: Int = 3 - var threadScanResults_decoded: List? = null - + var threadScanResults_decoded: + List? = + null while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_NETWORKING_STATUS)) {networkingStatus_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_DEBUG_TEXT)) {debugText_decoded = + if (tag == ContextSpecificTag(TAG_NETWORKING_STATUS)) { + networkingStatus_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_DEBUG_TEXT)) { + debugText_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - }} - - if (tag == ContextSpecificTag(TAG_WI_FI_SCAN_RESULTS)) {wiFiScanResults_decoded = + tlvReader.getString(tag) + } else { + null + } + } + } + + if (tag == ContextSpecificTag(TAG_WI_FI_SCAN_RESULTS)) { + wiFiScanResults_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - buildList { - tlvReader.enterArray(tag) - while(!tlvReader.isEndOfContainer()) { - add(NetworkCommissioningClusterWiFiInterfaceScanResultStruct.fromTlv(AnonymousTag, tlvReader)) + buildList { + tlvReader.enterArray(tag) + while (!tlvReader.isEndOfContainer()) { + add( + NetworkCommissioningClusterWiFiInterfaceScanResultStruct.fromTlv( + AnonymousTag, + tlvReader, + ) + ) + } + tlvReader.exitContainer() + } + } else { + null + } + } } - tlvReader.exitContainer() - } - } else { - null - } - }} - - if (tag == ContextSpecificTag(TAG_THREAD_SCAN_RESULTS)) {threadScanResults_decoded = + + if (tag == ContextSpecificTag(TAG_THREAD_SCAN_RESULTS)) { + threadScanResults_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - buildList { - tlvReader.enterArray(tag) - while(!tlvReader.isEndOfContainer()) { - add(NetworkCommissioningClusterThreadInterfaceScanResultStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null - } - }} - - - else { + buildList { + tlvReader.enterArray(tag) + while (!tlvReader.isEndOfContainer()) { + add( + NetworkCommissioningClusterThreadInterfaceScanResultStruct.fromTlv( + AnonymousTag, + tlvReader, + ) + ) + } + tlvReader.exitContainer() + } + } else { + null + } + } + } else { tlvReader.skipElement() } } - - if (networkingStatus_decoded == null) { - throw IllegalStateException("networkingStatus not found in TLV") + throw IllegalStateException("networkingStatus not found in TLV") } - - - - - - - tlvReader.exitContainer() @@ -326,17 +290,19 @@ class AttributeListAttribute( networkingStatus_decoded, debugText_decoded, wiFiScanResults_decoded, - threadScanResults_decoded + threadScanResults_decoded, ) } - suspend fun addOrUpdateWiFiNetwork(ssid: ByteArray - ,credentials: ByteArray - ,breadcrumb: ULong? - ,networkIdentity: ByteArray? - ,clientIdentifier: ByteArray? - ,possessionNonce: ByteArray? - ,timedInvokeTimeout: Duration? = null): NetworkConfigResponse { + suspend fun addOrUpdateWiFiNetwork( + ssid: ByteArray, + credentials: ByteArray, + breadcrumb: ULong?, + networkIdentity: ByteArray?, + clientIdentifier: ByteArray?, + possessionNonce: ByteArray?, + timedInvokeTimeout: Duration? = null, + ): NetworkConfigResponse { val commandId: UInt = 2u val tlvWriter = TlvWriter() @@ -349,9 +315,7 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_CREDENTIALS_REQ), credentials) val TAG_BREADCRUMB_REQ: Int = 2 - breadcrumb?.let { - tlvWriter.put(ContextSpecificTag(TAG_BREADCRUMB_REQ), breadcrumb) - } + breadcrumb?.let { tlvWriter.put(ContextSpecificTag(TAG_BREADCRUMB_REQ), breadcrumb) } val TAG_NETWORK_IDENTITY_REQ: Int = 3 networkIdentity?.let { @@ -366,14 +330,14 @@ class AttributeListAttribute( val TAG_POSSESSION_NONCE_REQ: Int = 5 possessionNonce?.let { tlvWriter.put(ContextSpecificTag(TAG_POSSESSION_NONCE_REQ), possessionNonce) - } + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -383,94 +347,88 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_NETWORKING_STATUS: Int = 0 var networkingStatus_decoded: UByte? = null - + val TAG_DEBUG_TEXT: Int = 1 var debugText_decoded: String? = null - + val TAG_NETWORK_INDEX: Int = 2 var networkIndex_decoded: UByte? = null - + val TAG_CLIENT_IDENTITY: Int = 3 var clientIdentity_decoded: ByteArray? = null - + val TAG_POSSESSION_SIGNATURE: Int = 4 var possessionSignature_decoded: ByteArray? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_NETWORKING_STATUS)) {networkingStatus_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_DEBUG_TEXT)) {debugText_decoded = + if (tag == ContextSpecificTag(TAG_NETWORKING_STATUS)) { + networkingStatus_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_DEBUG_TEXT)) { + debugText_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - }} - - if (tag == ContextSpecificTag(TAG_NETWORK_INDEX)) {networkIndex_decoded = + tlvReader.getString(tag) + } else { + null + } + } + } + + if (tag == ContextSpecificTag(TAG_NETWORK_INDEX)) { + networkIndex_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getUByte(tag) - } else { - null - } - }} - - if (tag == ContextSpecificTag(TAG_CLIENT_IDENTITY)) {clientIdentity_decoded = + tlvReader.getUByte(tag) + } else { + null + } + } + } + + if (tag == ContextSpecificTag(TAG_CLIENT_IDENTITY)) { + clientIdentity_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getByteArray(tag) - } else { - null - } - }} - - if (tag == ContextSpecificTag(TAG_POSSESSION_SIGNATURE)) {possessionSignature_decoded = + tlvReader.getByteArray(tag) + } else { + null + } + } + } + + if (tag == ContextSpecificTag(TAG_POSSESSION_SIGNATURE)) { + possessionSignature_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getByteArray(tag) - } else { - null - } - }} - - - else { + tlvReader.getByteArray(tag) + } else { + null + } + } + } else { tlvReader.skipElement() } } - - if (networkingStatus_decoded == null) { - throw IllegalStateException("networkingStatus not found in TLV") + throw IllegalStateException("networkingStatus not found in TLV") } - - - - - - - - - tlvReader.exitContainer() @@ -479,13 +437,15 @@ class AttributeListAttribute( debugText_decoded, networkIndex_decoded, clientIdentity_decoded, - possessionSignature_decoded + possessionSignature_decoded, ) } - suspend fun addOrUpdateThreadNetwork(operationalDataset: ByteArray - ,breadcrumb: ULong? - ,timedInvokeTimeout: Duration? = null): NetworkConfigResponse { + suspend fun addOrUpdateThreadNetwork( + operationalDataset: ByteArray, + breadcrumb: ULong?, + timedInvokeTimeout: Duration? = null, + ): NetworkConfigResponse { val commandId: UInt = 3u val tlvWriter = TlvWriter() @@ -495,16 +455,14 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_OPERATIONAL_DATASET_REQ), operationalDataset) val TAG_BREADCRUMB_REQ: Int = 1 - breadcrumb?.let { - tlvWriter.put(ContextSpecificTag(TAG_BREADCRUMB_REQ), breadcrumb) - } + breadcrumb?.let { tlvWriter.put(ContextSpecificTag(TAG_BREADCRUMB_REQ), breadcrumb) } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -514,94 +472,88 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_NETWORKING_STATUS: Int = 0 var networkingStatus_decoded: UByte? = null - + val TAG_DEBUG_TEXT: Int = 1 var debugText_decoded: String? = null - + val TAG_NETWORK_INDEX: Int = 2 var networkIndex_decoded: UByte? = null - + val TAG_CLIENT_IDENTITY: Int = 3 var clientIdentity_decoded: ByteArray? = null - + val TAG_POSSESSION_SIGNATURE: Int = 4 var possessionSignature_decoded: ByteArray? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_NETWORKING_STATUS)) {networkingStatus_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_DEBUG_TEXT)) {debugText_decoded = + if (tag == ContextSpecificTag(TAG_NETWORKING_STATUS)) { + networkingStatus_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_DEBUG_TEXT)) { + debugText_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - }} - - if (tag == ContextSpecificTag(TAG_NETWORK_INDEX)) {networkIndex_decoded = + tlvReader.getString(tag) + } else { + null + } + } + } + + if (tag == ContextSpecificTag(TAG_NETWORK_INDEX)) { + networkIndex_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getUByte(tag) - } else { - null - } - }} - - if (tag == ContextSpecificTag(TAG_CLIENT_IDENTITY)) {clientIdentity_decoded = + tlvReader.getUByte(tag) + } else { + null + } + } + } + + if (tag == ContextSpecificTag(TAG_CLIENT_IDENTITY)) { + clientIdentity_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getByteArray(tag) - } else { - null - } - }} - - if (tag == ContextSpecificTag(TAG_POSSESSION_SIGNATURE)) {possessionSignature_decoded = + tlvReader.getByteArray(tag) + } else { + null + } + } + } + + if (tag == ContextSpecificTag(TAG_POSSESSION_SIGNATURE)) { + possessionSignature_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getByteArray(tag) - } else { - null - } - }} - - - else { + tlvReader.getByteArray(tag) + } else { + null + } + } + } else { tlvReader.skipElement() } } - - if (networkingStatus_decoded == null) { - throw IllegalStateException("networkingStatus not found in TLV") + throw IllegalStateException("networkingStatus not found in TLV") } - - - - - - - - - tlvReader.exitContainer() @@ -610,13 +562,15 @@ class AttributeListAttribute( debugText_decoded, networkIndex_decoded, clientIdentity_decoded, - possessionSignature_decoded + possessionSignature_decoded, ) } - suspend fun removeNetwork(networkID: ByteArray - ,breadcrumb: ULong? - ,timedInvokeTimeout: Duration? = null): NetworkConfigResponse { + suspend fun removeNetwork( + networkID: ByteArray, + breadcrumb: ULong?, + timedInvokeTimeout: Duration? = null, + ): NetworkConfigResponse { val commandId: UInt = 4u val tlvWriter = TlvWriter() @@ -626,16 +580,14 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_NETWORK_ID_REQ), networkID) val TAG_BREADCRUMB_REQ: Int = 1 - breadcrumb?.let { - tlvWriter.put(ContextSpecificTag(TAG_BREADCRUMB_REQ), breadcrumb) - } + breadcrumb?.let { tlvWriter.put(ContextSpecificTag(TAG_BREADCRUMB_REQ), breadcrumb) } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -645,94 +597,88 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_NETWORKING_STATUS: Int = 0 var networkingStatus_decoded: UByte? = null - + val TAG_DEBUG_TEXT: Int = 1 var debugText_decoded: String? = null - + val TAG_NETWORK_INDEX: Int = 2 var networkIndex_decoded: UByte? = null - + val TAG_CLIENT_IDENTITY: Int = 3 var clientIdentity_decoded: ByteArray? = null - + val TAG_POSSESSION_SIGNATURE: Int = 4 var possessionSignature_decoded: ByteArray? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_NETWORKING_STATUS)) {networkingStatus_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_DEBUG_TEXT)) {debugText_decoded = + if (tag == ContextSpecificTag(TAG_NETWORKING_STATUS)) { + networkingStatus_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_DEBUG_TEXT)) { + debugText_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - }} - - if (tag == ContextSpecificTag(TAG_NETWORK_INDEX)) {networkIndex_decoded = + tlvReader.getString(tag) + } else { + null + } + } + } + + if (tag == ContextSpecificTag(TAG_NETWORK_INDEX)) { + networkIndex_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getUByte(tag) - } else { - null - } - }} - - if (tag == ContextSpecificTag(TAG_CLIENT_IDENTITY)) {clientIdentity_decoded = + tlvReader.getUByte(tag) + } else { + null + } + } + } + + if (tag == ContextSpecificTag(TAG_CLIENT_IDENTITY)) { + clientIdentity_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getByteArray(tag) - } else { - null - } - }} - - if (tag == ContextSpecificTag(TAG_POSSESSION_SIGNATURE)) {possessionSignature_decoded = + tlvReader.getByteArray(tag) + } else { + null + } + } + } + + if (tag == ContextSpecificTag(TAG_POSSESSION_SIGNATURE)) { + possessionSignature_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getByteArray(tag) - } else { - null - } - }} - - - else { + tlvReader.getByteArray(tag) + } else { + null + } + } + } else { tlvReader.skipElement() } } - - if (networkingStatus_decoded == null) { - throw IllegalStateException("networkingStatus not found in TLV") + throw IllegalStateException("networkingStatus not found in TLV") } - - - - - - - - - tlvReader.exitContainer() @@ -741,13 +687,15 @@ class AttributeListAttribute( debugText_decoded, networkIndex_decoded, clientIdentity_decoded, - possessionSignature_decoded + possessionSignature_decoded, ) } - suspend fun connectNetwork(networkID: ByteArray - ,breadcrumb: ULong? - ,timedInvokeTimeout: Duration? = null): ConnectNetworkResponse { + suspend fun connectNetwork( + networkID: ByteArray, + breadcrumb: ULong?, + timedInvokeTimeout: Duration? = null, + ): ConnectNetworkResponse { val commandId: UInt = 6u val tlvWriter = TlvWriter() @@ -757,16 +705,14 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_NETWORK_ID_REQ), networkID) val TAG_BREADCRUMB_REQ: Int = 1 - breadcrumb?.let { - tlvWriter.put(ContextSpecificTag(TAG_BREADCRUMB_REQ), breadcrumb) - } + breadcrumb?.let { tlvWriter.put(ContextSpecificTag(TAG_BREADCRUMB_REQ), breadcrumb) } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -776,75 +722,67 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_NETWORKING_STATUS: Int = 0 var networkingStatus_decoded: UByte? = null - + val TAG_DEBUG_TEXT: Int = 1 var debugText_decoded: String? = null - + val TAG_ERROR_VALUE: Int = 2 var errorValue_decoded: Int? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_NETWORKING_STATUS)) {networkingStatus_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_DEBUG_TEXT)) {debugText_decoded = + if (tag == ContextSpecificTag(TAG_NETWORKING_STATUS)) { + networkingStatus_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_DEBUG_TEXT)) { + debugText_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - }} - - if (tag == ContextSpecificTag(TAG_ERROR_VALUE)) {errorValue_decoded = + tlvReader.getString(tag) + } else { + null + } + } + } + + if (tag == ContextSpecificTag(TAG_ERROR_VALUE)) { + errorValue_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (!tlvReader.isNull()) { - tlvReader.getInt(tag) - } else { - tlvReader.getNull(tag) - null - } - }} - - - else { + tlvReader.getInt(tag) + } else { + tlvReader.getNull(tag) + null + } + } + } else { tlvReader.skipElement() } } - - if (networkingStatus_decoded == null) { - throw IllegalStateException("networkingStatus not found in TLV") + throw IllegalStateException("networkingStatus not found in TLV") } - - - - - tlvReader.exitContainer() - return ConnectNetworkResponse( - networkingStatus_decoded, - debugText_decoded, - errorValue_decoded - ) + return ConnectNetworkResponse(networkingStatus_decoded, debugText_decoded, errorValue_decoded) } - suspend fun reorderNetwork(networkID: ByteArray - ,networkIndex: UByte - ,breadcrumb: ULong? - ,timedInvokeTimeout: Duration? = null): NetworkConfigResponse { + suspend fun reorderNetwork( + networkID: ByteArray, + networkIndex: UByte, + breadcrumb: ULong?, + timedInvokeTimeout: Duration? = null, + ): NetworkConfigResponse { val commandId: UInt = 8u val tlvWriter = TlvWriter() @@ -857,16 +795,14 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_NETWORK_INDEX_REQ), networkIndex) val TAG_BREADCRUMB_REQ: Int = 2 - breadcrumb?.let { - tlvWriter.put(ContextSpecificTag(TAG_BREADCRUMB_REQ), breadcrumb) - } + breadcrumb?.let { tlvWriter.put(ContextSpecificTag(TAG_BREADCRUMB_REQ), breadcrumb) } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -876,94 +812,88 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_NETWORKING_STATUS: Int = 0 var networkingStatus_decoded: UByte? = null - + val TAG_DEBUG_TEXT: Int = 1 var debugText_decoded: String? = null - + val TAG_NETWORK_INDEX: Int = 2 var networkIndex_decoded: UByte? = null - + val TAG_CLIENT_IDENTITY: Int = 3 var clientIdentity_decoded: ByteArray? = null - + val TAG_POSSESSION_SIGNATURE: Int = 4 var possessionSignature_decoded: ByteArray? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_NETWORKING_STATUS)) {networkingStatus_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_DEBUG_TEXT)) {debugText_decoded = + if (tag == ContextSpecificTag(TAG_NETWORKING_STATUS)) { + networkingStatus_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_DEBUG_TEXT)) { + debugText_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - }} - - if (tag == ContextSpecificTag(TAG_NETWORK_INDEX)) {networkIndex_decoded = + tlvReader.getString(tag) + } else { + null + } + } + } + + if (tag == ContextSpecificTag(TAG_NETWORK_INDEX)) { + networkIndex_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getUByte(tag) - } else { - null - } - }} - - if (tag == ContextSpecificTag(TAG_CLIENT_IDENTITY)) {clientIdentity_decoded = + tlvReader.getUByte(tag) + } else { + null + } + } + } + + if (tag == ContextSpecificTag(TAG_CLIENT_IDENTITY)) { + clientIdentity_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getByteArray(tag) - } else { - null - } - }} - - if (tag == ContextSpecificTag(TAG_POSSESSION_SIGNATURE)) {possessionSignature_decoded = + tlvReader.getByteArray(tag) + } else { + null + } + } + } + + if (tag == ContextSpecificTag(TAG_POSSESSION_SIGNATURE)) { + possessionSignature_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getByteArray(tag) - } else { - null - } - }} - - - else { + tlvReader.getByteArray(tag) + } else { + null + } + } + } else { tlvReader.skipElement() } } - - if (networkingStatus_decoded == null) { - throw IllegalStateException("networkingStatus not found in TLV") + throw IllegalStateException("networkingStatus not found in TLV") } - - - - - - - - - tlvReader.exitContainer() @@ -972,13 +902,15 @@ class AttributeListAttribute( debugText_decoded, networkIndex_decoded, clientIdentity_decoded, - possessionSignature_decoded + possessionSignature_decoded, ) } - suspend fun queryIdentity(keyIdentifier: ByteArray - ,possessionNonce: ByteArray? - ,timedInvokeTimeout: Duration? = null): QueryIdentityResponse { + suspend fun queryIdentity( + keyIdentifier: ByteArray, + possessionNonce: ByteArray?, + timedInvokeTimeout: Duration? = null, + ): QueryIdentityResponse { val commandId: UInt = 9u val tlvWriter = TlvWriter() @@ -990,14 +922,14 @@ class AttributeListAttribute( val TAG_POSSESSION_NONCE_REQ: Int = 1 possessionNonce?.let { tlvWriter.put(ContextSpecificTag(TAG_POSSESSION_NONCE_REQ), possessionNonce) - } + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -1007,124 +939,110 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_IDENTITY: Int = 0 var identity_decoded: ByteArray? = null - + val TAG_POSSESSION_SIGNATURE: Int = 1 var possessionSignature_decoded: ByteArray? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_IDENTITY)) {identity_decoded = tlvReader.getByteArray(tag)} - - if (tag == ContextSpecificTag(TAG_POSSESSION_SIGNATURE)) {possessionSignature_decoded = + if (tag == ContextSpecificTag(TAG_IDENTITY)) { + identity_decoded = tlvReader.getByteArray(tag) + } + + if (tag == ContextSpecificTag(TAG_POSSESSION_SIGNATURE)) { + possessionSignature_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getByteArray(tag) - } else { - null - } - }} - - - else { + tlvReader.getByteArray(tag) + } else { + null + } + } + } else { tlvReader.skipElement() } } - - if (identity_decoded == null) { - throw IllegalStateException("identity not found in TLV") + throw IllegalStateException("identity not found in TLV") } - - - tlvReader.exitContainer() - return QueryIdentityResponse( - identity_decoded, - possessionSignature_decoded - ) + return QueryIdentityResponse(identity_decoded, possessionSignature_decoded) } -suspend fun readMaxNetworksAttribute(): UByte {val ATTRIBUTE_ID: UInt = 0u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readMaxNetworksAttribute(): 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 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}") - } + 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) { - "Maxnetworks attribute not found in response" - } + } + + requireNotNull(attributeData) { "Maxnetworks 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 subscribeMaxNetworksAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Maxnetworks attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Maxnetworks attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -1136,97 +1054,94 @@ suspend fun readMaxNetworksAttribute(): UByte {val ATTRIBUTE_ID: UInt = 0u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNetworksAttribute(): NetworksAttribute {val ATTRIBUTE_ID: UInt = 1u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNetworksAttribute(): NetworksAttribute { + 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 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}") - } + 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) { - "Networks attribute not found in response" - } + } + + requireNotNull(attributeData) { "Networks 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(NetworkCommissioningClusterNetworkInfoStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(NetworkCommissioningClusterNetworkInfoStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return NetworksAttribute(decodedValue) } suspend fun subscribeNetworksAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(NetworksAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + NetworksAttributeSubscriptionState.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) { - "Networks attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Networks 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(NetworkCommissioningClusterNetworkInfoStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(NetworkCommissioningClusterNetworkInfoStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(NetworksAttributeSubscriptionState.Success(decodedValue)) } @@ -1234,262 +1149,243 @@ suspend fun readNetworksAttribute(): NetworksAttribute {val ATTRIBUTE_ID: UInt = emit(NetworksAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readScanMaxTimeSecondsAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 2u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readScanMaxTimeSecondsAttribute(): UByte? { + 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 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}") - } + 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) { - "Scanmaxtimeseconds attribute not found in response" - } + } + + requireNotNull(attributeData) { "Scanmaxtimeseconds 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeScanMaxTimeSecondsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Scanmaxtimeseconds attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Scanmaxtimeseconds 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)) - } - + 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 readConnectMaxTimeSecondsAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 3u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readConnectMaxTimeSecondsAttribute(): UByte? { + 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 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}") - } + 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) { - "Connectmaxtimeseconds attribute not found in response" - } + } + + requireNotNull(attributeData) { "Connectmaxtimeseconds 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeConnectMaxTimeSecondsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Connectmaxtimeseconds attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Connectmaxtimeseconds 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)) - } - + 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 readInterfaceEnabledAttribute(): Boolean {val ATTRIBUTE_ID: UInt = 4u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readInterfaceEnabledAttribute(): Boolean { + 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 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}") - } + 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) { - "Interfaceenabled attribute not found in response" - } + } + + requireNotNull(attributeData) { "Interfaceenabled attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Boolean = tlvReader.getBoolean(AnonymousTag) - return decodedValue } - suspend fun writeInterfaceEnabledAttribute( - value: Boolean, - timedWriteTimeout: Duration? = null) { + suspend fun writeInterfaceEnabledAttribute(value: Boolean, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 4u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -1510,42 +1406,46 @@ suspend fun readInterfaceEnabledAttribute(): Boolean {val ATTRIBUTE_ID: UInt = 4 throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeInterfaceEnabledAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Interfaceenabled attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Interfaceenabled attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -1558,697 +1458,668 @@ suspend fun readInterfaceEnabledAttribute(): Boolean {val ATTRIBUTE_ID: UInt = 4 emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readLastNetworkingStatusAttribute(): LastNetworkingStatusAttribute {val ATTRIBUTE_ID: UInt = 5u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readLastNetworkingStatusAttribute(): LastNetworkingStatusAttribute { + 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 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}") - } + 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) { - "Lastnetworkingstatus attribute not found in response" - } + } + + requireNotNull(attributeData) { "Lastnetworkingstatus attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return LastNetworkingStatusAttribute(decodedValue) } suspend fun subscribeLastNetworkingStatusAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(LastNetworkingStatusAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + LastNetworkingStatusAttributeSubscriptionState.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) { - "Lastnetworkingstatus attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Lastnetworkingstatus 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.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(LastNetworkingStatusAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(LastNetworkingStatusAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(LastNetworkingStatusAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readLastNetworkIDAttribute(): LastNetworkIDAttribute {val ATTRIBUTE_ID: UInt = 6u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readLastNetworkIDAttribute(): LastNetworkIDAttribute { + 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 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}") - } + 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) { - "Lastnetworkid attribute not found in response" - } + } + + requireNotNull(attributeData) { "Lastnetworkid attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = if (!tlvReader.isNull()) { - tlvReader.getByteArray(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: ByteArray? = + if (!tlvReader.isNull()) { + tlvReader.getByteArray(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return LastNetworkIDAttribute(decodedValue) } suspend fun subscribeLastNetworkIDAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(LastNetworkIDAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + LastNetworkIDAttributeSubscriptionState.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) { - "Lastnetworkid attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Lastnetworkid attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = if (!tlvReader.isNull()) { - tlvReader.getByteArray(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ByteArray? = + if (!tlvReader.isNull()) { + tlvReader.getByteArray(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(LastNetworkIDAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(LastNetworkIDAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(LastNetworkIDAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readLastConnectErrorValueAttribute(): LastConnectErrorValueAttribute {val ATTRIBUTE_ID: UInt = 7u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readLastConnectErrorValueAttribute(): LastConnectErrorValueAttribute { + 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 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}") - } + 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) { - "Lastconnecterrorvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Lastconnecterrorvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Int? = if (!tlvReader.isNull()) { - tlvReader.getInt(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Int? = + if (!tlvReader.isNull()) { + tlvReader.getInt(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return LastConnectErrorValueAttribute(decodedValue) } suspend fun subscribeLastConnectErrorValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(LastConnectErrorValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + LastConnectErrorValueAttributeSubscriptionState.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) { - "Lastconnecterrorvalue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Lastconnecterrorvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Int? = if (!tlvReader.isNull()) { - tlvReader.getInt(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Int? = + if (!tlvReader.isNull()) { + tlvReader.getInt(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(LastConnectErrorValueAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(LastConnectErrorValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(LastConnectErrorValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readSupportedWiFiBandsAttribute(): SupportedWiFiBandsAttribute {val ATTRIBUTE_ID: UInt = 8u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readSupportedWiFiBandsAttribute(): SupportedWiFiBandsAttribute { + val ATTRIBUTE_ID: UInt = 8u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Supportedwifibands attribute not found in response" - } + } + + requireNotNull(attributeData) { "Supportedwifibands attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null } - tlvReader.exitContainer() - } - } else { - null - } - return SupportedWiFiBandsAttribute(decodedValue) } suspend fun subscribeSupportedWiFiBandsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(SupportedWiFiBandsAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + SupportedWiFiBandsAttributeSubscriptionState.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) { - "Supportedwifibands attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Supportedwifibands attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { - emit(SupportedWiFiBandsAttributeSubscriptionState.Success(it)) - } - + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { emit(SupportedWiFiBandsAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(SupportedWiFiBandsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readSupportedThreadFeaturesAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 9u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readSupportedThreadFeaturesAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 9u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Supportedthreadfeatures attribute not found in response" - } + } + + requireNotNull(attributeData) { "Supportedthreadfeatures 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeSupportedThreadFeaturesAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Supportedthreadfeatures attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Supportedthreadfeatures 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)) - } - + 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 readThreadVersionAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 10u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readThreadVersionAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 10u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Threadversion attribute not found in response" - } + } + + requireNotNull(attributeData) { "Threadversion 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeThreadVersionAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Threadversion attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Threadversion 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)) - } - + 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 readGeneratedCommandListAttribute(): GeneratedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65528u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -2256,97 +2127,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { emit(GeneratedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65529u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -2354,97 +2224,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va emit(AcceptedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt = 65530u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -2452,97 +2319,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt emit(EventListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ID: UInt = 65531u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -2550,81 +2414,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ emit(AttributeListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -2636,80 +2495,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 65533u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -2722,7 +2578,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/NitrogenDioxideConcentrationMeasurementCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/NitrogenDioxideConcentrationMeasurementCluster.kt index d34170fb14b72c..5f4aa378c771d6 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/NitrogenDioxideConcentrationMeasurementCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/NitrogenDioxideConcentrationMeasurementCluster.kt @@ -17,1371 +17,1273 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.FloatSubscriptionState import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse -import matter.controller.model.AttributePath -import matter.controller.model.CommandPath +import matter.controller.UShortSubscriptionState import matter.controller.cluster.structs.* +import matter.controller.model.AttributePath import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader -import matter.tlv.TlvWriter -class NitrogenDioxideConcentrationMeasurementCluster(private val controller: MatterController, private val endpointId: UShort) {class MeasuredValueAttribute( - val value: Float? - ) +class NitrogenDioxideConcentrationMeasurementCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class MeasuredValueAttribute(val value: Float?) sealed class MeasuredValueAttributeSubscriptionState { - data class Success( - val value: Float? - ) : MeasuredValueAttributeSubscriptionState() - + data class Success(val value: Float?) : MeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() - } -class MinMeasuredValueAttribute( - val value: Float? - ) + object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() + } + + class MinMeasuredValueAttribute(val value: Float?) sealed class MinMeasuredValueAttributeSubscriptionState { - data class Success( - val value: Float? - ) : MinMeasuredValueAttributeSubscriptionState() - + data class Success(val value: Float?) : MinMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MinMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() - } -class MaxMeasuredValueAttribute( - val value: Float? - ) + object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() + } + + class MaxMeasuredValueAttribute(val value: Float?) sealed class MaxMeasuredValueAttributeSubscriptionState { - data class Success( - val value: Float? - ) : MaxMeasuredValueAttributeSubscriptionState() - + data class Success(val value: Float?) : MaxMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MaxMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() - } -class PeakMeasuredValueAttribute( - val value: Float? - ) + object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() + } + + class PeakMeasuredValueAttribute(val value: Float?) sealed class PeakMeasuredValueAttributeSubscriptionState { - data class Success( - val value: Float? - ) : PeakMeasuredValueAttributeSubscriptionState() - + data class Success(val value: Float?) : PeakMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : PeakMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : PeakMeasuredValueAttributeSubscriptionState() - } -class AverageMeasuredValueAttribute( - val value: Float? - ) + object SubscriptionEstablished : PeakMeasuredValueAttributeSubscriptionState() + } + + class AverageMeasuredValueAttribute(val value: Float?) sealed class AverageMeasuredValueAttributeSubscriptionState { - data class Success( - val value: Float? - ) : AverageMeasuredValueAttributeSubscriptionState() - + data class Success(val value: Float?) : AverageMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : AverageMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : AverageMeasuredValueAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : AverageMeasuredValueAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } -suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } + + suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute { + 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}") - } + 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) { - "Measuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Measuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return MeasuredValueAttribute(decodedValue) } suspend fun subscribeMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MeasuredValueAttributeSubscriptionState.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) { - "Measuredvalue attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Measuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute { + 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}") - } + 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) { - "Minmeasuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Minmeasuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return MinMeasuredValueAttribute(decodedValue) } suspend fun subscribeMinMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MinMeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MinMeasuredValueAttributeSubscriptionState.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) { - "Minmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Minmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MinMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute { + 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}") - } + 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) { - "Maxmeasuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Maxmeasuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return MaxMeasuredValueAttribute(decodedValue) } suspend fun subscribeMaxMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MaxMeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MaxMeasuredValueAttributeSubscriptionState.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) { - "Maxmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Maxmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MaxMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPeakMeasuredValueAttribute(): PeakMeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readPeakMeasuredValueAttribute(): PeakMeasuredValueAttribute { + 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}") - } + 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) { - "Peakmeasuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Peakmeasuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return PeakMeasuredValueAttribute(decodedValue) } suspend fun subscribePeakMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(PeakMeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + PeakMeasuredValueAttributeSubscriptionState.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) { - "Peakmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Peakmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(PeakMeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(PeakMeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(PeakMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPeakMeasuredValueWindowAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 4u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readPeakMeasuredValueWindowAttribute(): UInt? { + 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}") - } + 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) { - "Peakmeasuredvaluewindow attribute not found in response" - } + } + + requireNotNull(attributeData) { "Peakmeasuredvaluewindow attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribePeakMeasuredValueWindowAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Peakmeasuredvaluewindow attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Peakmeasuredvaluewindow attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAverageMeasuredValueAttribute(): AverageMeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 5u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readAverageMeasuredValueAttribute(): AverageMeasuredValueAttribute { + 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}") - } + 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) { - "Averagemeasuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Averagemeasuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return AverageMeasuredValueAttribute(decodedValue) } suspend fun subscribeAverageMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(AverageMeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + AverageMeasuredValueAttributeSubscriptionState.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) { - "Averagemeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Averagemeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(AverageMeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(AverageMeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(AverageMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAverageMeasuredValueWindowAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 6u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readAverageMeasuredValueWindowAttribute(): UInt? { + 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}") - } + 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) { - "Averagemeasuredvaluewindow attribute not found in response" - } + } + + requireNotNull(attributeData) { "Averagemeasuredvaluewindow attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeAverageMeasuredValueWindowAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Averagemeasuredvaluewindow attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Averagemeasuredvaluewindow attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readUncertaintyAttribute(): Float? {val ATTRIBUTE_ID: UInt = 7u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readUncertaintyAttribute(): Float? { + 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}") - } + 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) { - "Uncertainty attribute not found in response" - } + } + + requireNotNull(attributeData) { "Uncertainty attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - + val decodedValue: Float? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeUncertaintyAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(FloatSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + FloatSubscriptionState.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) { - "Uncertainty attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Uncertainty attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(FloatSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(FloatSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(FloatSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMeasurementUnitAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 8u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMeasurementUnitAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 8u + + 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}") - } + 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) { - "Measurementunit attribute not found in response" - } + } + + requireNotNull(attributeData) { "Measurementunit 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeMeasurementUnitAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Measurementunit attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Measurementunit 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)) - } - + 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 readMeasurementMediumAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 9u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMeasurementMediumAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 9u + + 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}") - } + 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) { - "Measurementmedium attribute not found in response" - } + } + + requireNotNull(attributeData) { "Measurementmedium 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeMeasurementMediumAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Measurementmedium attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Measurementmedium 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)) - } - + 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 readLevelValueAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 10u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readLevelValueAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 10u + + 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}") - } + 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) { - "Levelvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Levelvalue 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeLevelValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Levelvalue attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Levelvalue 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)) - } - + 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 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1389,97 +1291,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1487,97 +1388,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1585,97 +1483,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1683,81 +1578,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1769,80 +1659,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1855,11 +1742,12 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { - private val logger = Logger.getLogger(NitrogenDioxideConcentrationMeasurementCluster::class.java.name) + private val logger = + Logger.getLogger(NitrogenDioxideConcentrationMeasurementCluster::class.java.name) const val CLUSTER_ID: UInt = 1043u } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/OccupancySensingCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/OccupancySensingCluster.kt index 5b8960133111fa..bb54163f860ad0 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/OccupancySensingCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/OccupancySensingCluster.kt @@ -17,186 +17,150 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse -import matter.controller.model.AttributePath -import matter.controller.model.CommandPath import matter.controller.cluster.structs.* +import matter.controller.model.AttributePath import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class OccupancySensingCluster(private val controller: MatterController, private val endpointId: UShort) {class HoldTimeLimitsAttribute( - val value: OccupancySensingClusterHoldTimeLimitsStruct? - ) +class OccupancySensingCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class HoldTimeLimitsAttribute(val value: OccupancySensingClusterHoldTimeLimitsStruct?) sealed class HoldTimeLimitsAttributeSubscriptionState { - data class Success( - val value: OccupancySensingClusterHoldTimeLimitsStruct? - ) : HoldTimeLimitsAttributeSubscriptionState() - + data class Success(val value: OccupancySensingClusterHoldTimeLimitsStruct?) : + HoldTimeLimitsAttributeSubscriptionState() + data class Error(val exception: Exception) : HoldTimeLimitsAttributeSubscriptionState() - object SubscriptionEstablished : HoldTimeLimitsAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : HoldTimeLimitsAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } -suspend fun readOccupancyAttribute(): 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) - ) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } + + suspend fun readOccupancyAttribute(): 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}") - } + 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) { - "Occupancy attribute not found in response" - } + } + + requireNotNull(attributeData) { "Occupancy 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 subscribeOccupancyAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Occupancy attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Occupancy attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -208,80 +172,77 @@ suspend fun readOccupancyAttribute(): UByte {val ATTRIBUTE_ID: UInt = 0u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readOccupancySensorTypeAttribute(): 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) - ) - + + suspend fun readOccupancySensorTypeAttribute(): 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}") - } + 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) { - "Occupancysensortype attribute not found in response" - } + } + + requireNotNull(attributeData) { "Occupancysensortype 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 subscribeOccupancySensorTypeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Occupancysensortype attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Occupancysensortype attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -294,80 +255,77 @@ suspend fun readOccupancySensorTypeAttribute(): UByte {val ATTRIBUTE_ID: UInt = emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readOccupancySensorTypeBitmapAttribute(): UByte {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readOccupancySensorTypeBitmapAttribute(): UByte { + 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}") - } + 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) { - "Occupancysensortypebitmap attribute not found in response" - } + } + + requireNotNull(attributeData) { "Occupancysensortypebitmap 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 subscribeOccupancySensorTypeBitmapAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Occupancysensortypebitmap attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Occupancysensortypebitmap attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -380,72 +338,62 @@ suspend fun readOccupancySensorTypeBitmapAttribute(): UByte {val ATTRIBUTE_ID: U emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readHoldTimeAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readHoldTimeAttribute(): UShort? { + 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}") - } + 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) { - "Holdtime attribute not found in response" - } + } + + requireNotNull(attributeData) { "Holdtime 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } - suspend fun writeHoldTimeAttribute( - value: UShort, - timedWriteTimeout: Duration? = null) { + suspend fun writeHoldTimeAttribute(value: UShort, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 3u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -466,224 +414,213 @@ suspend fun readHoldTimeAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 3u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeHoldTimeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Holdtime attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Holdtime 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readHoldTimeLimitsAttribute(): HoldTimeLimitsAttribute {val ATTRIBUTE_ID: UInt = 4u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readHoldTimeLimitsAttribute(): HoldTimeLimitsAttribute { + 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}") - } + 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) { - "Holdtimelimits attribute not found in response" - } + } + + requireNotNull(attributeData) { "Holdtimelimits attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: OccupancySensingClusterHoldTimeLimitsStruct? = if (tlvReader.isNextTag(AnonymousTag)) { - OccupancySensingClusterHoldTimeLimitsStruct.fromTlv(AnonymousTag, tlvReader) - } else { - null - } - + val decodedValue: OccupancySensingClusterHoldTimeLimitsStruct? = + if (tlvReader.isNextTag(AnonymousTag)) { + OccupancySensingClusterHoldTimeLimitsStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } return HoldTimeLimitsAttribute(decodedValue) } suspend fun subscribeHoldTimeLimitsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(HoldTimeLimitsAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + HoldTimeLimitsAttributeSubscriptionState.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) { - "Holdtimelimits attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Holdtimelimits attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: OccupancySensingClusterHoldTimeLimitsStruct? = if (tlvReader.isNextTag(AnonymousTag)) { - OccupancySensingClusterHoldTimeLimitsStruct.fromTlv(AnonymousTag, tlvReader) - } else { - null - } + val decodedValue: OccupancySensingClusterHoldTimeLimitsStruct? = + if (tlvReader.isNextTag(AnonymousTag)) { + OccupancySensingClusterHoldTimeLimitsStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } - decodedValue?.let { - emit(HoldTimeLimitsAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(HoldTimeLimitsAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(HoldTimeLimitsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPIROccupiedToUnoccupiedDelayAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 16u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readPIROccupiedToUnoccupiedDelayAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 16u + + 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}") - } + 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) { - "Piroccupiedtounoccupieddelay attribute not found in response" - } + } + + requireNotNull(attributeData) { "Piroccupiedtounoccupieddelay 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun writePIROccupiedToUnoccupiedDelayAttribute( value: UShort, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 16u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -704,127 +641,122 @@ suspend fun readPIROccupiedToUnoccupiedDelayAttribute(): UShort? {val ATTRIBUTE_ throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribePIROccupiedToUnoccupiedDelayAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Piroccupiedtounoccupieddelay attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Piroccupiedtounoccupieddelay 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPIRUnoccupiedToOccupiedDelayAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 17u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readPIRUnoccupiedToOccupiedDelayAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 17u + + 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}") - } + 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) { - "Pirunoccupiedtooccupieddelay attribute not found in response" - } + } + + requireNotNull(attributeData) { "Pirunoccupiedtooccupieddelay 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun writePIRUnoccupiedToOccupiedDelayAttribute( value: UShort, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 17u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -845,127 +777,124 @@ suspend fun readPIRUnoccupiedToOccupiedDelayAttribute(): UShort? {val ATTRIBUTE_ throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribePIRUnoccupiedToOccupiedDelayAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 17u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Pirunoccupiedtooccupieddelay attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Pirunoccupiedtooccupieddelay 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPIRUnoccupiedToOccupiedThresholdAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 18u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readPIRUnoccupiedToOccupiedThresholdAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 18u + + 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}") - } + 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) { - "Pirunoccupiedtooccupiedthreshold attribute not found in response" + } + + requireNotNull(attributeData) { + "Pirunoccupiedtooccupiedthreshold 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun writePIRUnoccupiedToOccupiedThresholdAttribute( value: UByte, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 18u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -986,127 +915,124 @@ suspend fun readPIRUnoccupiedToOccupiedThresholdAttribute(): UByte? {val ATTRIBU throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribePIRUnoccupiedToOccupiedThresholdAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 18u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Pirunoccupiedtooccupiedthreshold attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Pirunoccupiedtooccupiedthreshold 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readUltrasonicOccupiedToUnoccupiedDelayAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 32u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readUltrasonicOccupiedToUnoccupiedDelayAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 32u + + 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}") - } + 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) { - "Ultrasonicoccupiedtounoccupieddelay attribute not found in response" + } + + requireNotNull(attributeData) { + "Ultrasonicoccupiedtounoccupieddelay 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun writeUltrasonicOccupiedToUnoccupiedDelayAttribute( value: UShort, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 32u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -1127,127 +1053,124 @@ suspend fun readUltrasonicOccupiedToUnoccupiedDelayAttribute(): UShort? {val ATT throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeUltrasonicOccupiedToUnoccupiedDelayAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 32u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Ultrasonicoccupiedtounoccupieddelay attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Ultrasonicoccupiedtounoccupieddelay 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readUltrasonicUnoccupiedToOccupiedDelayAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 33u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readUltrasonicUnoccupiedToOccupiedDelayAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 33u + + 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}") - } + 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) { - "Ultrasonicunoccupiedtooccupieddelay attribute not found in response" + } + + requireNotNull(attributeData) { + "Ultrasonicunoccupiedtooccupieddelay 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun writeUltrasonicUnoccupiedToOccupiedDelayAttribute( value: UShort, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 33u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -1268,127 +1191,124 @@ suspend fun readUltrasonicUnoccupiedToOccupiedDelayAttribute(): UShort? {val ATT throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeUltrasonicUnoccupiedToOccupiedDelayAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 33u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Ultrasonicunoccupiedtooccupieddelay attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Ultrasonicunoccupiedtooccupieddelay 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readUltrasonicUnoccupiedToOccupiedThresholdAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 34u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readUltrasonicUnoccupiedToOccupiedThresholdAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 34u + + 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}") - } + 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) { - "Ultrasonicunoccupiedtooccupiedthreshold attribute not found in response" + } + + requireNotNull(attributeData) { + "Ultrasonicunoccupiedtooccupiedthreshold 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun writeUltrasonicUnoccupiedToOccupiedThresholdAttribute( value: UByte, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 34u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -1409,127 +1329,124 @@ suspend fun readUltrasonicUnoccupiedToOccupiedThresholdAttribute(): UByte? {val throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeUltrasonicUnoccupiedToOccupiedThresholdAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 34u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Ultrasonicunoccupiedtooccupiedthreshold attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Ultrasonicunoccupiedtooccupiedthreshold 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPhysicalContactOccupiedToUnoccupiedDelayAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 48u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readPhysicalContactOccupiedToUnoccupiedDelayAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 48u + + 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}") - } + 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) { - "Physicalcontactoccupiedtounoccupieddelay attribute not found in response" + } + + requireNotNull(attributeData) { + "Physicalcontactoccupiedtounoccupieddelay 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun writePhysicalContactOccupiedToUnoccupiedDelayAttribute( value: UShort, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 48u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -1550,127 +1467,124 @@ suspend fun readPhysicalContactOccupiedToUnoccupiedDelayAttribute(): UShort? {va throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribePhysicalContactOccupiedToUnoccupiedDelayAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 48u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Physicalcontactoccupiedtounoccupieddelay attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Physicalcontactoccupiedtounoccupieddelay 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPhysicalContactUnoccupiedToOccupiedDelayAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 49u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readPhysicalContactUnoccupiedToOccupiedDelayAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 49u + + 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}") - } + 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) { - "Physicalcontactunoccupiedtooccupieddelay attribute not found in response" + } + + requireNotNull(attributeData) { + "Physicalcontactunoccupiedtooccupieddelay 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun writePhysicalContactUnoccupiedToOccupiedDelayAttribute( value: UShort, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 49u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -1691,127 +1605,124 @@ suspend fun readPhysicalContactUnoccupiedToOccupiedDelayAttribute(): UShort? {va throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribePhysicalContactUnoccupiedToOccupiedDelayAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 49u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Physicalcontactunoccupiedtooccupieddelay attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Physicalcontactunoccupiedtooccupieddelay 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPhysicalContactUnoccupiedToOccupiedThresholdAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 50u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readPhysicalContactUnoccupiedToOccupiedThresholdAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 50u + + 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}") - } + 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) { - "Physicalcontactunoccupiedtooccupiedthreshold attribute not found in response" + } + + requireNotNull(attributeData) { + "Physicalcontactunoccupiedtooccupiedthreshold 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun writePhysicalContactUnoccupiedToOccupiedThresholdAttribute( value: UByte, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 50u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -1832,152 +1743,153 @@ suspend fun readPhysicalContactUnoccupiedToOccupiedThresholdAttribute(): UByte? throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribePhysicalContactUnoccupiedToOccupiedThresholdAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 50u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Physicalcontactunoccupiedtooccupiedthreshold attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Physicalcontactunoccupiedtooccupiedthreshold 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1985,97 +1897,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -2083,97 +1994,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -2181,97 +2089,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -2279,81 +2184,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -2365,80 +2265,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -2451,7 +2348,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/OnOffCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/OnOffCluster.kt index 8897b4bd04a433..1701c1dafa527f 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/OnOffCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/OnOffCluster.kt @@ -17,126 +17,95 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration 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.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState -import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class OnOffCluster(private val controller: MatterController, private val endpointId: UShort) {class StartUpOnOffAttribute( - val value: UByte? - ) +class OnOffCluster(private val controller: MatterController, private val endpointId: UShort) { + class StartUpOnOffAttribute(val value: UByte?) sealed class StartUpOnOffAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : StartUpOnOffAttributeSubscriptionState() - + data class Success(val value: UByte?) : StartUpOnOffAttributeSubscriptionState() + data class Error(val exception: Exception) : StartUpOnOffAttributeSubscriptionState() - object SubscriptionEstablished : StartUpOnOffAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : StartUpOnOffAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } suspend fun off(timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -147,14 +116,14 @@ class AttributeListAttribute( val commandId: UInt = 1u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -165,23 +134,25 @@ class AttributeListAttribute( val commandId: UInt = 2u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun offWithEffect(effectIdentifier: UByte - ,effectVariant: UByte - ,timedInvokeTimeout: Duration? = null) { + suspend fun offWithEffect( + effectIdentifier: UByte, + effectVariant: UByte, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 64u val tlvWriter = TlvWriter() @@ -191,14 +162,14 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_EFFECT_IDENTIFIER_REQ), effectIdentifier) val TAG_EFFECT_VARIANT_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_EFFECT_VARIANT_REQ), effectVariant) + tlvWriter.put(ContextSpecificTag(TAG_EFFECT_VARIANT_REQ), effectVariant) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -209,24 +180,26 @@ class AttributeListAttribute( val commandId: UInt = 65u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun onWithTimedOff(onOffControl: UByte - ,onTime: UShort - ,offWaitTime: UShort - ,timedInvokeTimeout: Duration? = null) { + suspend fun onWithTimedOff( + onOffControl: UByte, + onTime: UShort, + offWaitTime: UShort, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 66u val tlvWriter = TlvWriter() @@ -239,92 +212,87 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_ON_TIME_REQ), onTime) val TAG_OFF_WAIT_TIME_REQ: Int = 2 - tlvWriter.put(ContextSpecificTag(TAG_OFF_WAIT_TIME_REQ), offWaitTime) + tlvWriter.put(ContextSpecificTag(TAG_OFF_WAIT_TIME_REQ), offWaitTime) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } -suspend fun readOnOffAttribute(): Boolean {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readOnOffAttribute(): Boolean { + 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}") - } + 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) { - "Onoff attribute not found in response" - } + } + + requireNotNull(attributeData) { "Onoff attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Boolean = tlvReader.getBoolean(AnonymousTag) - return decodedValue } suspend fun subscribeOnOffAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Onoff attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Onoff attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -336,169 +304,155 @@ suspend fun readOnOffAttribute(): Boolean {val ATTRIBUTE_ID: UInt = 0u emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readGlobalSceneControlAttribute(): Boolean? {val ATTRIBUTE_ID: UInt = 16384u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readGlobalSceneControlAttribute(): Boolean? { + val ATTRIBUTE_ID: UInt = 16384u + + 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}") - } + 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) { - "Globalscenecontrol attribute not found in response" - } + } + + requireNotNull(attributeData) { "Globalscenecontrol 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 - } - + val decodedValue: Boolean? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeGlobalSceneControlAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16384u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Globalscenecontrol attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Globalscenecontrol 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)) - } - + 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 readOnTimeAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 16385u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readOnTimeAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 16385u + + 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}") - } + 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) { - "Ontime attribute not found in response" - } + } + + requireNotNull(attributeData) { "Ontime 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } - suspend fun writeOnTimeAttribute( - value: UShort, - timedWriteTimeout: Duration? = null) { + suspend fun writeOnTimeAttribute(value: UShort, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16385u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -519,127 +473,117 @@ suspend fun readOnTimeAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 16385u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeOnTimeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16385u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Ontime attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Ontime 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)) - } - + 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 readOffWaitTimeAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 16386u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readOffWaitTimeAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 16386u + + 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}") - } + 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) { - "Offwaittime attribute not found in response" - } + } + + requireNotNull(attributeData) { "Offwaittime 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } - suspend fun writeOffWaitTimeAttribute( - value: UShort, - timedWriteTimeout: Duration? = null) { + suspend fun writeOffWaitTimeAttribute(value: UShort, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16386u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -660,132 +604,122 @@ suspend fun readOffWaitTimeAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 16386u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeOffWaitTimeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16386u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Offwaittime attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Offwaittime 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)) - } - + 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 readStartUpOnOffAttribute(): StartUpOnOffAttribute {val ATTRIBUTE_ID: UInt = 16387u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readStartUpOnOffAttribute(): StartUpOnOffAttribute { + val ATTRIBUTE_ID: UInt = 16387u + + 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}") - } + 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) { - "Startuponoff attribute not found in response" - } + } + + requireNotNull(attributeData) { "Startuponoff attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return StartUpOnOffAttribute(decodedValue) } - suspend fun writeStartUpOnOffAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeStartUpOnOffAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16387u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -806,157 +740,156 @@ suspend fun readStartUpOnOffAttribute(): StartUpOnOffAttribute {val ATTRIBUTE_ID throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeStartUpOnOffAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16387u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StartUpOnOffAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StartUpOnOffAttributeSubscriptionState.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) { - "Startuponoff attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Startuponoff 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(StartUpOnOffAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(StartUpOnOffAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(StartUpOnOffAttributeSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -964,97 +897,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1062,97 +994,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1160,97 +1089,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1258,81 +1184,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1344,80 +1265,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1430,7 +1348,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/OnOffSwitchConfigurationCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/OnOffSwitchConfigurationCluster.kt index d30268d4c2280c..88a03128e9f596 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/OnOffSwitchConfigurationCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/OnOffSwitchConfigurationCluster.kt @@ -17,173 +17,139 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse -import matter.controller.model.AttributePath -import matter.controller.model.CommandPath import matter.controller.cluster.structs.* +import matter.controller.model.AttributePath import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class OnOffSwitchConfigurationCluster(private val controller: MatterController, private val endpointId: UShort) {class GeneratedCommandListAttribute( - val value: List - ) +class OnOffSwitchConfigurationCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } -suspend fun readSwitchTypeAttribute(): 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) - ) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } + + suspend fun readSwitchTypeAttribute(): 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}") - } + 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) { - "Switchtype attribute not found in response" - } + } + + requireNotNull(attributeData) { "Switchtype 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 subscribeSwitchTypeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Switchtype attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Switchtype attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -195,68 +161,57 @@ suspend fun readSwitchTypeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 0u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readSwitchActionsAttribute(): UByte {val ATTRIBUTE_ID: UInt = 16u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readSwitchActionsAttribute(): UByte { + val ATTRIBUTE_ID: UInt = 16u + + 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}") - } + 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) { - "Switchactions attribute not found in response" - } + } + + requireNotNull(attributeData) { "Switchactions 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 writeSwitchActionsAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeSwitchActionsAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -277,43 +232,45 @@ suspend fun readSwitchActionsAttribute(): UByte {val ATTRIBUTE_ID: UInt = 16u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeSwitchActionsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Switchactions attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Switchactions attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -325,97 +282,96 @@ suspend fun readSwitchActionsAttribute(): UByte {val ATTRIBUTE_ID: UInt = 16u emit(UByteSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -423,97 +379,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -521,97 +476,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -619,97 +571,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -717,81 +666,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -803,80 +747,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -889,7 +830,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/OperationalCredentialsCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/OperationalCredentialsCluster.kt index 07eb5e0061faf5..d96efd654fe092 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/OperationalCredentialsCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/OperationalCredentialsCluster.kt @@ -17,176 +17,136 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.UShortSubscriptionState +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class OperationalCredentialsCluster(private val controller: MatterController, private val endpointId: UShort) { +class OperationalCredentialsCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { class AttestationResponse( - val attestationElements: ByteArray, - val attestationSignature: ByteArray + val attestationElements: ByteArray, + val attestationSignature: ByteArray, ) - class CertificateChainResponse( - val certificate: ByteArray - ) + class CertificateChainResponse(val certificate: ByteArray) - class CSRResponse( - val NOCSRElements: ByteArray, - val attestationSignature: ByteArray - ) + class CSRResponse(val NOCSRElements: ByteArray, val attestationSignature: ByteArray) - class NOCResponse( - val statusCode: UByte, - val fabricIndex: UByte?, - val debugText: String? - ) -class NOCsAttribute( - val value: List - ) + class NOCResponse(val statusCode: UByte, val fabricIndex: UByte?, val debugText: String?) + + class NOCsAttribute(val value: List) sealed class NOCsAttributeSubscriptionState { - data class Success( - val value: List - ) : NOCsAttributeSubscriptionState() - + data class Success(val value: List) : + NOCsAttributeSubscriptionState() + data class Error(val exception: Exception) : NOCsAttributeSubscriptionState() - object SubscriptionEstablished : NOCsAttributeSubscriptionState() - } -class FabricsAttribute( - val value: List - ) + object SubscriptionEstablished : NOCsAttributeSubscriptionState() + } + + class FabricsAttribute(val value: List) sealed class FabricsAttributeSubscriptionState { - data class Success( - val value: List - ) : FabricsAttributeSubscriptionState() - + data class Success(val value: List) : + FabricsAttributeSubscriptionState() + data class Error(val exception: Exception) : FabricsAttributeSubscriptionState() - object SubscriptionEstablished : FabricsAttributeSubscriptionState() - } -class TrustedRootCertificatesAttribute( - val value: List - ) + object SubscriptionEstablished : FabricsAttributeSubscriptionState() + } + + class TrustedRootCertificatesAttribute(val value: List) sealed class TrustedRootCertificatesAttributeSubscriptionState { - data class Success( - val value: List - ) : TrustedRootCertificatesAttributeSubscriptionState() - - data class Error(val exception: Exception) : TrustedRootCertificatesAttributeSubscriptionState() - - object SubscriptionEstablished : TrustedRootCertificatesAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + data class Success(val value: List) : + TrustedRootCertificatesAttributeSubscriptionState() + + data class Error(val exception: Exception) : + TrustedRootCertificatesAttributeSubscriptionState() + + object SubscriptionEstablished : TrustedRootCertificatesAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun attestationRequest(attestationNonce: ByteArray - ,timedInvokeTimeout: Duration? = null): AttestationResponse { + suspend fun attestationRequest( + attestationNonce: ByteArray, + timedInvokeTimeout: Duration? = null, + ): AttestationResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_ATTESTATION_NONCE_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_ATTESTATION_NONCE_REQ), attestationNonce) + tlvWriter.put(ContextSpecificTag(TAG_ATTESTATION_NONCE_REQ), attestationNonce) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -196,61 +156,55 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_ATTESTATION_ELEMENTS: Int = 0 var attestationElements_decoded: ByteArray? = null - + val TAG_ATTESTATION_SIGNATURE: Int = 1 var attestationSignature_decoded: ByteArray? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_ATTESTATION_ELEMENTS)) {attestationElements_decoded = tlvReader.getByteArray(tag)} - - if (tag == ContextSpecificTag(TAG_ATTESTATION_SIGNATURE)) {attestationSignature_decoded = tlvReader.getByteArray(tag)} - + if (tag == ContextSpecificTag(TAG_ATTESTATION_ELEMENTS)) { + attestationElements_decoded = tlvReader.getByteArray(tag) + } - else { + if (tag == ContextSpecificTag(TAG_ATTESTATION_SIGNATURE)) { + attestationSignature_decoded = tlvReader.getByteArray(tag) + } else { tlvReader.skipElement() } } - - if (attestationElements_decoded == null) { - throw IllegalStateException("attestationElements not found in TLV") + throw IllegalStateException("attestationElements not found in TLV") } - - + if (attestationSignature_decoded == null) { - throw IllegalStateException("attestationSignature not found in TLV") + throw IllegalStateException("attestationSignature not found in TLV") } - tlvReader.exitContainer() - return AttestationResponse( - attestationElements_decoded, - attestationSignature_decoded - ) + return AttestationResponse(attestationElements_decoded, attestationSignature_decoded) } - suspend fun certificateChainRequest(certificateType: UByte - ,timedInvokeTimeout: Duration? = null): CertificateChainResponse { + suspend fun certificateChainRequest( + certificateType: UByte, + timedInvokeTimeout: Duration? = null, + ): CertificateChainResponse { val commandId: UInt = 2u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_CERTIFICATE_TYPE_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_CERTIFICATE_TYPE_REQ), certificateType) + tlvWriter.put(ContextSpecificTag(TAG_CERTIFICATE_TYPE_REQ), certificateType) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -260,37 +214,31 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_CERTIFICATE: Int = 0 var certificate_decoded: ByteArray? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_CERTIFICATE)) {certificate_decoded = tlvReader.getByteArray(tag)} - - - else { + if (tag == ContextSpecificTag(TAG_CERTIFICATE)) { + certificate_decoded = tlvReader.getByteArray(tag) + } else { tlvReader.skipElement() } } - - if (certificate_decoded == null) { - throw IllegalStateException("certificate not found in TLV") + throw IllegalStateException("certificate not found in TLV") } - tlvReader.exitContainer() - return CertificateChainResponse( - certificate_decoded - ) + return CertificateChainResponse(certificate_decoded) } - suspend fun CSRRequest(CSRNonce: ByteArray - ,isForUpdateNOC: Boolean? - ,timedInvokeTimeout: Duration? = null): CSRResponse { + suspend fun CSRRequest( + CSRNonce: ByteArray, + isForUpdateNOC: Boolean?, + timedInvokeTimeout: Duration? = null, + ): CSRResponse { val commandId: UInt = 4u val tlvWriter = TlvWriter() @@ -302,14 +250,14 @@ class AttributeListAttribute( val TAG_IS_FOR_UPDATE_NOC_REQ: Int = 1 isForUpdateNOC?.let { tlvWriter.put(ContextSpecificTag(TAG_IS_FOR_UPDATE_NOC_REQ), isForUpdateNOC) - } + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -319,51 +267,45 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_NOCSR_ELEMENTS: Int = 0 var NOCSRElements_decoded: ByteArray? = null - + val TAG_ATTESTATION_SIGNATURE: Int = 1 var attestationSignature_decoded: ByteArray? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_NOCSR_ELEMENTS)) {NOCSRElements_decoded = tlvReader.getByteArray(tag)} - - if (tag == ContextSpecificTag(TAG_ATTESTATION_SIGNATURE)) {attestationSignature_decoded = tlvReader.getByteArray(tag)} - + if (tag == ContextSpecificTag(TAG_NOCSR_ELEMENTS)) { + NOCSRElements_decoded = tlvReader.getByteArray(tag) + } - else { + if (tag == ContextSpecificTag(TAG_ATTESTATION_SIGNATURE)) { + attestationSignature_decoded = tlvReader.getByteArray(tag) + } else { tlvReader.skipElement() } } - - if (NOCSRElements_decoded == null) { - throw IllegalStateException("NOCSRElements not found in TLV") + throw IllegalStateException("NOCSRElements not found in TLV") } - - + if (attestationSignature_decoded == null) { - throw IllegalStateException("attestationSignature not found in TLV") + throw IllegalStateException("attestationSignature not found in TLV") } - tlvReader.exitContainer() - return CSRResponse( - NOCSRElements_decoded, - attestationSignature_decoded - ) + return CSRResponse(NOCSRElements_decoded, attestationSignature_decoded) } - suspend fun addNOC(NOCValue: ByteArray - ,ICACValue: ByteArray? - ,IPKValue: ByteArray - ,caseAdminSubject: ULong - ,adminVendorId: UShort - ,timedInvokeTimeout: Duration? = null): NOCResponse { + suspend fun addNOC( + NOCValue: ByteArray, + ICACValue: ByteArray?, + IPKValue: ByteArray, + caseAdminSubject: ULong, + adminVendorId: UShort, + timedInvokeTimeout: Duration? = null, + ): NOCResponse { val commandId: UInt = 6u val tlvWriter = TlvWriter() @@ -373,9 +315,7 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_NOC_VALUE_REQ), NOCValue) val TAG_ICAC_VALUE_REQ: Int = 1 - ICACValue?.let { - tlvWriter.put(ContextSpecificTag(TAG_ICAC_VALUE_REQ), ICACValue) - } + ICACValue?.let { tlvWriter.put(ContextSpecificTag(TAG_ICAC_VALUE_REQ), ICACValue) } val TAG_IPK_VALUE_REQ: Int = 2 tlvWriter.put(ContextSpecificTag(TAG_IPK_VALUE_REQ), IPKValue) @@ -384,14 +324,14 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_CASE_ADMIN_SUBJECT_REQ), caseAdminSubject) val TAG_ADMIN_VENDOR_ID_REQ: Int = 4 - tlvWriter.put(ContextSpecificTag(TAG_ADMIN_VENDOR_ID_REQ), adminVendorId) + tlvWriter.put(ContextSpecificTag(TAG_ADMIN_VENDOR_ID_REQ), adminVendorId) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -401,73 +341,65 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS_CODE: Int = 0 var statusCode_decoded: UByte? = null - + val TAG_FABRIC_INDEX: Int = 1 var fabricIndex_decoded: UByte? = null - + val TAG_DEBUG_TEXT: Int = 2 var debugText_decoded: String? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_STATUS_CODE)) {statusCode_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_FABRIC_INDEX)) {fabricIndex_decoded = + if (tag == ContextSpecificTag(TAG_STATUS_CODE)) { + statusCode_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_FABRIC_INDEX)) { + fabricIndex_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getUByte(tag) - } else { - null - } - }} - - if (tag == ContextSpecificTag(TAG_DEBUG_TEXT)) {debugText_decoded = + tlvReader.getUByte(tag) + } else { + null + } + } + } + + if (tag == ContextSpecificTag(TAG_DEBUG_TEXT)) { + debugText_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - }} - - - else { + tlvReader.getString(tag) + } else { + null + } + } + } else { tlvReader.skipElement() } } - - if (statusCode_decoded == null) { - throw IllegalStateException("statusCode not found in TLV") + throw IllegalStateException("statusCode not found in TLV") } - - - - - tlvReader.exitContainer() - return NOCResponse( - statusCode_decoded, - fabricIndex_decoded, - debugText_decoded - ) + return NOCResponse(statusCode_decoded, fabricIndex_decoded, debugText_decoded) } - suspend fun updateNOC(NOCValue: ByteArray - ,ICACValue: ByteArray? - ,timedInvokeTimeout: Duration? = null): NOCResponse { + suspend fun updateNOC( + NOCValue: ByteArray, + ICACValue: ByteArray?, + timedInvokeTimeout: Duration? = null, + ): NOCResponse { val commandId: UInt = 7u val tlvWriter = TlvWriter() @@ -477,16 +409,14 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_NOC_VALUE_REQ), NOCValue) val TAG_ICAC_VALUE_REQ: Int = 1 - ICACValue?.let { - tlvWriter.put(ContextSpecificTag(TAG_ICAC_VALUE_REQ), ICACValue) - } + ICACValue?.let { tlvWriter.put(ContextSpecificTag(TAG_ICAC_VALUE_REQ), ICACValue) } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -496,86 +426,75 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS_CODE: Int = 0 var statusCode_decoded: UByte? = null - + val TAG_FABRIC_INDEX: Int = 1 var fabricIndex_decoded: UByte? = null - + val TAG_DEBUG_TEXT: Int = 2 var debugText_decoded: String? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_STATUS_CODE)) {statusCode_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_FABRIC_INDEX)) {fabricIndex_decoded = + if (tag == ContextSpecificTag(TAG_STATUS_CODE)) { + statusCode_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_FABRIC_INDEX)) { + fabricIndex_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getUByte(tag) - } else { - null - } - }} - - if (tag == ContextSpecificTag(TAG_DEBUG_TEXT)) {debugText_decoded = + tlvReader.getUByte(tag) + } else { + null + } + } + } + + if (tag == ContextSpecificTag(TAG_DEBUG_TEXT)) { + debugText_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - }} - - - else { + tlvReader.getString(tag) + } else { + null + } + } + } else { tlvReader.skipElement() } } - - if (statusCode_decoded == null) { - throw IllegalStateException("statusCode not found in TLV") + throw IllegalStateException("statusCode not found in TLV") } - - - - - tlvReader.exitContainer() - return NOCResponse( - statusCode_decoded, - fabricIndex_decoded, - debugText_decoded - ) + return NOCResponse(statusCode_decoded, fabricIndex_decoded, debugText_decoded) } - suspend fun updateFabricLabel(label: String - ,timedInvokeTimeout: Duration? = null): NOCResponse { + suspend fun updateFabricLabel(label: String, timedInvokeTimeout: Duration? = null): NOCResponse { val commandId: UInt = 9u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_LABEL_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_LABEL_REQ), label) + tlvWriter.put(ContextSpecificTag(TAG_LABEL_REQ), label) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -585,86 +504,75 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS_CODE: Int = 0 var statusCode_decoded: UByte? = null - + val TAG_FABRIC_INDEX: Int = 1 var fabricIndex_decoded: UByte? = null - + val TAG_DEBUG_TEXT: Int = 2 var debugText_decoded: String? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_STATUS_CODE)) {statusCode_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_FABRIC_INDEX)) {fabricIndex_decoded = + if (tag == ContextSpecificTag(TAG_STATUS_CODE)) { + statusCode_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_FABRIC_INDEX)) { + fabricIndex_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getUByte(tag) - } else { - null - } - }} - - if (tag == ContextSpecificTag(TAG_DEBUG_TEXT)) {debugText_decoded = + tlvReader.getUByte(tag) + } else { + null + } + } + } + + if (tag == ContextSpecificTag(TAG_DEBUG_TEXT)) { + debugText_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - }} - - - else { + tlvReader.getString(tag) + } else { + null + } + } + } else { tlvReader.skipElement() } } - - if (statusCode_decoded == null) { - throw IllegalStateException("statusCode not found in TLV") + throw IllegalStateException("statusCode not found in TLV") } - - - - - tlvReader.exitContainer() - return NOCResponse( - statusCode_decoded, - fabricIndex_decoded, - debugText_decoded - ) + return NOCResponse(statusCode_decoded, fabricIndex_decoded, debugText_decoded) } - suspend fun removeFabric(fabricIndex: UByte - ,timedInvokeTimeout: Duration? = null): NOCResponse { + suspend fun removeFabric(fabricIndex: UByte, timedInvokeTimeout: Duration? = null): NOCResponse { val commandId: UInt = 10u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_FABRIC_INDEX_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_FABRIC_INDEX_REQ), fabricIndex) + tlvWriter.put(ContextSpecificTag(TAG_FABRIC_INDEX_REQ), fabricIndex) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -674,180 +582,169 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS_CODE: Int = 0 var statusCode_decoded: UByte? = null - + val TAG_FABRIC_INDEX: Int = 1 var fabricIndex_decoded: UByte? = null - + val TAG_DEBUG_TEXT: Int = 2 var debugText_decoded: String? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_STATUS_CODE)) {statusCode_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_FABRIC_INDEX)) {fabricIndex_decoded = + if (tag == ContextSpecificTag(TAG_STATUS_CODE)) { + statusCode_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_FABRIC_INDEX)) { + fabricIndex_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getUByte(tag) - } else { - null - } - }} - - if (tag == ContextSpecificTag(TAG_DEBUG_TEXT)) {debugText_decoded = + tlvReader.getUByte(tag) + } else { + null + } + } + } + + if (tag == ContextSpecificTag(TAG_DEBUG_TEXT)) { + debugText_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - }} - - - else { + tlvReader.getString(tag) + } else { + null + } + } + } else { tlvReader.skipElement() } } - - if (statusCode_decoded == null) { - throw IllegalStateException("statusCode not found in TLV") + throw IllegalStateException("statusCode not found in TLV") } - - - - - tlvReader.exitContainer() - return NOCResponse( - statusCode_decoded, - fabricIndex_decoded, - debugText_decoded - ) + return NOCResponse(statusCode_decoded, fabricIndex_decoded, debugText_decoded) } - suspend fun addTrustedRootCertificate(rootCACertificate: ByteArray - ,timedInvokeTimeout: Duration? = null) { + suspend fun addTrustedRootCertificate( + rootCACertificate: ByteArray, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 11u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_ROOT_CA_CERTIFICATE_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_ROOT_CA_CERTIFICATE_REQ), rootCACertificate) + tlvWriter.put(ContextSpecificTag(TAG_ROOT_CA_CERTIFICATE_REQ), rootCACertificate) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } -suspend fun readNOCsAttribute(): NOCsAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readNOCsAttribute(): NOCsAttribute { + 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}") - } + 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) { - "Nocs attribute not found in response" - } + } + + requireNotNull(attributeData) { "Nocs 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(OperationalCredentialsClusterNOCStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(OperationalCredentialsClusterNOCStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return NOCsAttribute(decodedValue) } suspend fun subscribeNOCsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(NOCsAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + NOCsAttributeSubscriptionState.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) { - "Nocs attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Nocs 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(OperationalCredentialsClusterNOCStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(OperationalCredentialsClusterNOCStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(NOCsAttributeSubscriptionState.Success(decodedValue)) } @@ -855,97 +752,99 @@ suspend fun readNOCsAttribute(): NOCsAttribute {val ATTRIBUTE_ID: UInt = 0u emit(NOCsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readFabricsAttribute(): FabricsAttribute {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readFabricsAttribute(): FabricsAttribute { + 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}") - } + 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) { - "Fabrics attribute not found in response" - } + } + + requireNotNull(attributeData) { "Fabrics 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(OperationalCredentialsClusterFabricDescriptorStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(OperationalCredentialsClusterFabricDescriptorStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return FabricsAttribute(decodedValue) } suspend fun subscribeFabricsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(FabricsAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + FabricsAttributeSubscriptionState.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) { - "Fabrics attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Fabrics 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(OperationalCredentialsClusterFabricDescriptorStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add( + OperationalCredentialsClusterFabricDescriptorStruct.fromTlv( + AnonymousTag, + tlvReader, + ) + ) + } + tlvReader.exitContainer() + } emit(FabricsAttributeSubscriptionState.Success(decodedValue)) } @@ -953,80 +852,77 @@ suspend fun readFabricsAttribute(): FabricsAttribute {val ATTRIBUTE_ID: UInt = 1 emit(FabricsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readSupportedFabricsAttribute(): UByte {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readSupportedFabricsAttribute(): UByte { + 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}") - } + 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) { - "Supportedfabrics attribute not found in response" - } + } + + requireNotNull(attributeData) { "Supportedfabrics 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 subscribeSupportedFabricsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Supportedfabrics attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Supportedfabrics attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -1039,80 +935,77 @@ suspend fun readSupportedFabricsAttribute(): UByte {val ATTRIBUTE_ID: UInt = 2u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCommissionedFabricsAttribute(): UByte {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readCommissionedFabricsAttribute(): UByte { + 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}") - } + 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) { - "Commissionedfabrics attribute not found in response" - } + } + + requireNotNull(attributeData) { "Commissionedfabrics 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 subscribeCommissionedFabricsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Commissionedfabrics attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Commissionedfabrics attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -1125,97 +1018,96 @@ suspend fun readCommissionedFabricsAttribute(): UByte {val ATTRIBUTE_ID: UInt = emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readTrustedRootCertificatesAttribute(): TrustedRootCertificatesAttribute {val ATTRIBUTE_ID: UInt = 4u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readTrustedRootCertificatesAttribute(): TrustedRootCertificatesAttribute { + 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}") - } + 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) { - "Trustedrootcertificates attribute not found in response" - } + } + + requireNotNull(attributeData) { "Trustedrootcertificates 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.getByteArray(AnonymousTag)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getByteArray(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return TrustedRootCertificatesAttribute(decodedValue) } suspend fun subscribeTrustedRootCertificatesAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(TrustedRootCertificatesAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + TrustedRootCertificatesAttributeSubscriptionState.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) { - "Trustedrootcertificates attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Trustedrootcertificates 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.getByteArray(AnonymousTag)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getByteArray(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(TrustedRootCertificatesAttributeSubscriptionState.Success(decodedValue)) } @@ -1223,80 +1115,77 @@ suspend fun readTrustedRootCertificatesAttribute(): TrustedRootCertificatesAttri emit(TrustedRootCertificatesAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCurrentFabricIndexAttribute(): UByte {val ATTRIBUTE_ID: UInt = 5u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readCurrentFabricIndexAttribute(): UByte { + 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}") - } + 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) { - "Currentfabricindex attribute not found in response" - } + } + + requireNotNull(attributeData) { "Currentfabricindex 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 subscribeCurrentFabricIndexAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Currentfabricindex attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Currentfabricindex attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -1309,97 +1198,96 @@ suspend fun readCurrentFabricIndexAttribute(): UByte {val ATTRIBUTE_ID: UInt = 5 emit(UByteSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1407,97 +1295,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1505,97 +1392,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1603,97 +1487,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1701,81 +1582,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1787,80 +1663,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1873,7 +1746,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/OperationalStateCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/OperationalStateCluster.kt index e9f4f326e1fdbe..cef150821f7b44 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/OperationalStateCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/OperationalStateCluster.kt @@ -17,182 +17,143 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.UShortSubscriptionState +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class OperationalStateCluster(private val controller: MatterController, private val endpointId: UShort) { +class OperationalStateCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { class OperationalCommandResponse( val commandResponseState: OperationalStateClusterErrorStateStruct ) -class PhaseListAttribute( - val value: List? - ) + + class PhaseListAttribute(val value: List?) sealed class PhaseListAttributeSubscriptionState { - data class Success( - val value: List? - ) : PhaseListAttributeSubscriptionState() - + data class Success(val value: List?) : PhaseListAttributeSubscriptionState() + data class Error(val exception: Exception) : PhaseListAttributeSubscriptionState() - object SubscriptionEstablished : PhaseListAttributeSubscriptionState() - } -class CurrentPhaseAttribute( - val value: UByte? - ) + object SubscriptionEstablished : PhaseListAttributeSubscriptionState() + } + + class CurrentPhaseAttribute(val value: UByte?) sealed class CurrentPhaseAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : CurrentPhaseAttributeSubscriptionState() - + data class Success(val value: UByte?) : CurrentPhaseAttributeSubscriptionState() + data class Error(val exception: Exception) : CurrentPhaseAttributeSubscriptionState() - object SubscriptionEstablished : CurrentPhaseAttributeSubscriptionState() - } -class CountdownTimeAttribute( - val value: UInt? - ) + object SubscriptionEstablished : CurrentPhaseAttributeSubscriptionState() + } + + class CountdownTimeAttribute(val value: UInt?) sealed class CountdownTimeAttributeSubscriptionState { - data class Success( - val value: UInt? - ) : CountdownTimeAttributeSubscriptionState() - + data class Success(val value: UInt?) : CountdownTimeAttributeSubscriptionState() + data class Error(val exception: Exception) : CountdownTimeAttributeSubscriptionState() - object SubscriptionEstablished : CountdownTimeAttributeSubscriptionState() - } -class OperationalStateListAttribute( + object SubscriptionEstablished : CountdownTimeAttributeSubscriptionState() + } + + class OperationalStateListAttribute( val value: List ) sealed class OperationalStateListAttributeSubscriptionState { - data class Success( - val value: List - ) : OperationalStateListAttributeSubscriptionState() - + data class Success(val value: List) : + OperationalStateListAttributeSubscriptionState() + data class Error(val exception: Exception) : OperationalStateListAttributeSubscriptionState() - object SubscriptionEstablished : OperationalStateListAttributeSubscriptionState() - } -class OperationalErrorAttribute( - val value: OperationalStateClusterErrorStateStruct - ) + object SubscriptionEstablished : OperationalStateListAttributeSubscriptionState() + } + + class OperationalErrorAttribute(val value: OperationalStateClusterErrorStateStruct) sealed class OperationalErrorAttributeSubscriptionState { - data class Success( - val value: OperationalStateClusterErrorStateStruct - ) : OperationalErrorAttributeSubscriptionState() - + data class Success(val value: OperationalStateClusterErrorStateStruct) : + OperationalErrorAttributeSubscriptionState() + data class Error(val exception: Exception) : OperationalErrorAttributeSubscriptionState() - object SubscriptionEstablished : OperationalErrorAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : OperationalErrorAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } suspend fun pause(timedInvokeTimeout: Duration? = null): OperationalCommandResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -202,46 +163,39 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_COMMAND_RESPONSE_STATE: Int = 0 var commandResponseState_decoded: OperationalStateClusterErrorStateStruct? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_COMMAND_RESPONSE_STATE)) {commandResponseState_decoded = OperationalStateClusterErrorStateStruct.fromTlv(tag, tlvReader)} - - - else { + if (tag == ContextSpecificTag(TAG_COMMAND_RESPONSE_STATE)) { + commandResponseState_decoded = + OperationalStateClusterErrorStateStruct.fromTlv(tag, tlvReader) + } else { tlvReader.skipElement() } } - - if (commandResponseState_decoded == null) { - throw IllegalStateException("commandResponseState not found in TLV") + throw IllegalStateException("commandResponseState not found in TLV") } - tlvReader.exitContainer() - return OperationalCommandResponse( - commandResponseState_decoded - ) + return OperationalCommandResponse(commandResponseState_decoded) } suspend fun stop(timedInvokeTimeout: Duration? = null): OperationalCommandResponse { val commandId: UInt = 1u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -251,46 +205,39 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_COMMAND_RESPONSE_STATE: Int = 0 var commandResponseState_decoded: OperationalStateClusterErrorStateStruct? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_COMMAND_RESPONSE_STATE)) {commandResponseState_decoded = OperationalStateClusterErrorStateStruct.fromTlv(tag, tlvReader)} - - - else { + if (tag == ContextSpecificTag(TAG_COMMAND_RESPONSE_STATE)) { + commandResponseState_decoded = + OperationalStateClusterErrorStateStruct.fromTlv(tag, tlvReader) + } else { tlvReader.skipElement() } } - - if (commandResponseState_decoded == null) { - throw IllegalStateException("commandResponseState not found in TLV") + throw IllegalStateException("commandResponseState not found in TLV") } - tlvReader.exitContainer() - return OperationalCommandResponse( - commandResponseState_decoded - ) + return OperationalCommandResponse(commandResponseState_decoded) } suspend fun start(timedInvokeTimeout: Duration? = null): OperationalCommandResponse { val commandId: UInt = 2u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -300,46 +247,39 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_COMMAND_RESPONSE_STATE: Int = 0 var commandResponseState_decoded: OperationalStateClusterErrorStateStruct? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_COMMAND_RESPONSE_STATE)) {commandResponseState_decoded = OperationalStateClusterErrorStateStruct.fromTlv(tag, tlvReader)} - - - else { + if (tag == ContextSpecificTag(TAG_COMMAND_RESPONSE_STATE)) { + commandResponseState_decoded = + OperationalStateClusterErrorStateStruct.fromTlv(tag, tlvReader) + } else { tlvReader.skipElement() } } - - if (commandResponseState_decoded == null) { - throw IllegalStateException("commandResponseState not found in TLV") + throw IllegalStateException("commandResponseState not found in TLV") } - tlvReader.exitContainer() - return OperationalCommandResponse( - commandResponseState_decoded - ) + return OperationalCommandResponse(commandResponseState_decoded) } suspend fun resume(timedInvokeTimeout: Duration? = null): OperationalCommandResponse { val commandId: UInt = 3u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -349,439 +289,413 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_COMMAND_RESPONSE_STATE: Int = 0 var commandResponseState_decoded: OperationalStateClusterErrorStateStruct? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_COMMAND_RESPONSE_STATE)) {commandResponseState_decoded = OperationalStateClusterErrorStateStruct.fromTlv(tag, tlvReader)} - - - else { + if (tag == ContextSpecificTag(TAG_COMMAND_RESPONSE_STATE)) { + commandResponseState_decoded = + OperationalStateClusterErrorStateStruct.fromTlv(tag, tlvReader) + } else { tlvReader.skipElement() } } - - if (commandResponseState_decoded == null) { - throw IllegalStateException("commandResponseState not found in TLV") + throw IllegalStateException("commandResponseState not found in TLV") } - tlvReader.exitContainer() - return OperationalCommandResponse( - commandResponseState_decoded - ) + return OperationalCommandResponse(commandResponseState_decoded) } -suspend fun readPhaseListAttribute(): PhaseListAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readPhaseListAttribute(): PhaseListAttribute { + 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}") - } + 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) { - "Phaselist attribute not found in response" - } + } + + requireNotNull(attributeData) { "Phaselist attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (!tlvReader.isNull()) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getString(AnonymousTag)) + val decodedValue: List? = + if (!tlvReader.isNull()) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getString(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + tlvReader.getNull(AnonymousTag) + null } - tlvReader.exitContainer() - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - return PhaseListAttribute(decodedValue) } suspend fun subscribePhaseListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(PhaseListAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + PhaseListAttributeSubscriptionState.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) { - "Phaselist attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Phaselist attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (!tlvReader.isNull()) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getString(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(PhaseListAttributeSubscriptionState.Success(it)) - } - + val decodedValue: List? = + if (!tlvReader.isNull()) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getString(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(PhaseListAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(PhaseListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCurrentPhaseAttribute(): CurrentPhaseAttribute {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readCurrentPhaseAttribute(): CurrentPhaseAttribute { + 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}") - } + 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) { - "Currentphase attribute not found in response" - } + } + + requireNotNull(attributeData) { "Currentphase attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return CurrentPhaseAttribute(decodedValue) } suspend fun subscribeCurrentPhaseAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(CurrentPhaseAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + CurrentPhaseAttributeSubscriptionState.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) { - "Currentphase attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Currentphase 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.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(CurrentPhaseAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(CurrentPhaseAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(CurrentPhaseAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCountdownTimeAttribute(): CountdownTimeAttribute {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readCountdownTimeAttribute(): CountdownTimeAttribute { + 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}") - } + 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) { - "Countdowntime attribute not found in response" - } + } + + requireNotNull(attributeData) { "Countdowntime attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return CountdownTimeAttribute(decodedValue) } suspend fun subscribeCountdownTimeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(CountdownTimeAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + CountdownTimeAttributeSubscriptionState.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) { - "Countdowntime attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Countdowntime attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(CountdownTimeAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(CountdownTimeAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(CountdownTimeAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readOperationalStateListAttribute(): OperationalStateListAttribute {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readOperationalStateListAttribute(): OperationalStateListAttribute { + 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}") - } + 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) { - "Operationalstatelist attribute not found in response" - } + } + + requireNotNull(attributeData) { "Operationalstatelist 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(OperationalStateClusterOperationalStateStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(OperationalStateClusterOperationalStateStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return OperationalStateListAttribute(decodedValue) } suspend fun subscribeOperationalStateListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(OperationalStateListAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + OperationalStateListAttributeSubscriptionState.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) { - "Operationalstatelist attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Operationalstatelist 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(OperationalStateClusterOperationalStateStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(OperationalStateClusterOperationalStateStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(OperationalStateListAttributeSubscriptionState.Success(decodedValue)) } @@ -789,80 +703,77 @@ suspend fun readOperationalStateListAttribute(): OperationalStateListAttribute { emit(OperationalStateListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readOperationalStateAttribute(): 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) - ) - + + suspend fun readOperationalStateAttribute(): 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}") - } + 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) { - "Operationalstate attribute not found in response" - } + } + + requireNotNull(attributeData) { "Operationalstate 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 subscribeOperationalStateAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Operationalstate attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Operationalstate attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -875,85 +786,84 @@ suspend fun readOperationalStateAttribute(): UByte {val ATTRIBUTE_ID: UInt = 4u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readOperationalErrorAttribute(): OperationalErrorAttribute {val ATTRIBUTE_ID: UInt = 5u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readOperationalErrorAttribute(): OperationalErrorAttribute { + 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}") - } + 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) { - "Operationalerror attribute not found in response" - } + } + + requireNotNull(attributeData) { "Operationalerror attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: OperationalStateClusterErrorStateStruct = OperationalStateClusterErrorStateStruct.fromTlv(AnonymousTag, tlvReader) - + val decodedValue: OperationalStateClusterErrorStateStruct = + OperationalStateClusterErrorStateStruct.fromTlv(AnonymousTag, tlvReader) return OperationalErrorAttribute(decodedValue) } suspend fun subscribeOperationalErrorAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(OperationalErrorAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + OperationalErrorAttributeSubscriptionState.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) { - "Operationalerror attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Operationalerror attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: OperationalStateClusterErrorStateStruct = OperationalStateClusterErrorStateStruct.fromTlv(AnonymousTag, tlvReader) + val decodedValue: OperationalStateClusterErrorStateStruct = + OperationalStateClusterErrorStateStruct.fromTlv(AnonymousTag, tlvReader) emit(OperationalErrorAttributeSubscriptionState.Success(decodedValue)) } @@ -961,97 +871,96 @@ suspend fun readOperationalErrorAttribute(): OperationalErrorAttribute {val ATTR emit(OperationalErrorAttributeSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1059,97 +968,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1157,97 +1065,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1255,97 +1160,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1353,81 +1255,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1439,80 +1336,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1525,7 +1419,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/OtaSoftwareUpdateProviderCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/OtaSoftwareUpdateProviderCluster.kt index 182bdf0e2712c9..cf8525ed7f2ad7 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/OtaSoftwareUpdateProviderCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/OtaSoftwareUpdateProviderCluster.kt @@ -17,126 +17,96 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState -import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.UShortSubscriptionState +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class OtaSoftwareUpdateProviderCluster(private val controller: MatterController, private val endpointId: UShort) { +class OtaSoftwareUpdateProviderCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { class QueryImageResponse( - val status: UByte, - val delayedActionTime: UInt?, - val imageURI: String?, - val softwareVersion: UInt?, - val softwareVersionString: String?, - val updateToken: ByteArray?, - val userConsentNeeded: Boolean?, - val metadataForRequestor: ByteArray? + val status: UByte, + val delayedActionTime: UInt?, + val imageURI: String?, + val softwareVersion: UInt?, + val softwareVersionString: String?, + val updateToken: ByteArray?, + val userConsentNeeded: Boolean?, + val metadataForRequestor: ByteArray?, ) - class ApplyUpdateResponse( - val action: UByte, - val delayedActionTime: UInt - ) -class GeneratedCommandListAttribute( - val value: List - ) + class ApplyUpdateResponse(val action: UByte, val delayedActionTime: UInt) + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } - - suspend fun queryImage(vendorID: UShort - ,productID: UShort - ,softwareVersion: UInt - ,protocolsSupported: List - ,hardwareVersion: UShort? - ,location: String? - ,requestorCanConsent: Boolean? - ,metadataForProvider: ByteArray? - ,timedInvokeTimeout: Duration? = null): QueryImageResponse { + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } + + suspend fun queryImage( + vendorID: UShort, + productID: UShort, + softwareVersion: UInt, + protocolsSupported: List, + hardwareVersion: UShort?, + location: String?, + requestorCanConsent: Boolean?, + metadataForProvider: ByteArray?, + timedInvokeTimeout: Duration? = null, + ): QueryImageResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() @@ -153,10 +123,10 @@ class AttributeListAttribute( val TAG_PROTOCOLS_SUPPORTED_REQ: Int = 3 tlvWriter.startArray(ContextSpecificTag(TAG_PROTOCOLS_SUPPORTED_REQ)) - for (item in protocolsSupported.iterator()) { - tlvWriter.put(AnonymousTag, item) - } - tlvWriter.endArray() + for (item in protocolsSupported.iterator()) { + tlvWriter.put(AnonymousTag, item) + } + tlvWriter.endArray() val TAG_HARDWARE_VERSION_REQ: Int = 4 hardwareVersion?.let { @@ -164,9 +134,7 @@ class AttributeListAttribute( } val TAG_LOCATION_REQ: Int = 5 - location?.let { - tlvWriter.put(ContextSpecificTag(TAG_LOCATION_REQ), location) - } + location?.let { tlvWriter.put(ContextSpecificTag(TAG_LOCATION_REQ), location) } val TAG_REQUESTOR_CAN_CONSENT_REQ: Int = 6 requestorCanConsent?.let { @@ -176,14 +144,14 @@ class AttributeListAttribute( val TAG_METADATA_FOR_PROVIDER_REQ: Int = 7 metadataForProvider?.let { tlvWriter.put(ContextSpecificTag(TAG_METADATA_FOR_PROVIDER_REQ), metadataForProvider) - } + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -193,145 +161,139 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_DELAYED_ACTION_TIME: Int = 1 var delayedActionTime_decoded: UInt? = null - + val TAG_IMAGE_URI: Int = 2 var imageURI_decoded: String? = null - + val TAG_SOFTWARE_VERSION: Int = 3 var softwareVersion_decoded: UInt? = null - + val TAG_SOFTWARE_VERSION_STRING: Int = 4 var softwareVersionString_decoded: String? = null - + val TAG_UPDATE_TOKEN: Int = 5 var updateToken_decoded: ByteArray? = null - + val TAG_USER_CONSENT_NEEDED: Int = 6 var userConsentNeeded_decoded: Boolean? = null - + val TAG_METADATA_FOR_REQUESTOR: Int = 7 var metadataForRequestor_decoded: ByteArray? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_DELAYED_ACTION_TIME)) {delayedActionTime_decoded = + if (tag == ContextSpecificTag(TAG_STATUS)) { + status_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_DELAYED_ACTION_TIME)) { + delayedActionTime_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getUInt(tag) - } else { - null - } - }} - - if (tag == ContextSpecificTag(TAG_IMAGE_URI)) {imageURI_decoded = + tlvReader.getUInt(tag) + } else { + null + } + } + } + + if (tag == ContextSpecificTag(TAG_IMAGE_URI)) { + imageURI_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - }} - - if (tag == ContextSpecificTag(TAG_SOFTWARE_VERSION)) {softwareVersion_decoded = + tlvReader.getString(tag) + } else { + null + } + } + } + + if (tag == ContextSpecificTag(TAG_SOFTWARE_VERSION)) { + softwareVersion_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getUInt(tag) - } else { - null - } - }} - - if (tag == ContextSpecificTag(TAG_SOFTWARE_VERSION_STRING)) {softwareVersionString_decoded = + tlvReader.getUInt(tag) + } else { + null + } + } + } + + if (tag == ContextSpecificTag(TAG_SOFTWARE_VERSION_STRING)) { + softwareVersionString_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - }} - - if (tag == ContextSpecificTag(TAG_UPDATE_TOKEN)) {updateToken_decoded = + tlvReader.getString(tag) + } else { + null + } + } + } + + if (tag == ContextSpecificTag(TAG_UPDATE_TOKEN)) { + updateToken_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getByteArray(tag) - } else { - null - } - }} - - if (tag == ContextSpecificTag(TAG_USER_CONSENT_NEEDED)) {userConsentNeeded_decoded = + tlvReader.getByteArray(tag) + } else { + null + } + } + } + + if (tag == ContextSpecificTag(TAG_USER_CONSENT_NEEDED)) { + userConsentNeeded_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getBoolean(tag) - } else { - null - } - }} - - if (tag == ContextSpecificTag(TAG_METADATA_FOR_REQUESTOR)) {metadataForRequestor_decoded = + tlvReader.getBoolean(tag) + } else { + null + } + } + } + + if (tag == ContextSpecificTag(TAG_METADATA_FOR_REQUESTOR)) { + metadataForRequestor_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getByteArray(tag) - } else { - null - } - }} - - - else { + tlvReader.getByteArray(tag) + } else { + null + } + } + } else { tlvReader.skipElement() } } - - if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - - - - - - - - - - - - - - - tlvReader.exitContainer() @@ -343,13 +305,15 @@ class AttributeListAttribute( softwareVersionString_decoded, updateToken_decoded, userConsentNeeded_decoded, - metadataForRequestor_decoded + metadataForRequestor_decoded, ) } - suspend fun applyUpdateRequest(updateToken: ByteArray - ,newVersion: UInt - ,timedInvokeTimeout: Duration? = null): ApplyUpdateResponse { + suspend fun applyUpdateRequest( + updateToken: ByteArray, + newVersion: UInt, + timedInvokeTimeout: Duration? = null, + ): ApplyUpdateResponse { val commandId: UInt = 2u val tlvWriter = TlvWriter() @@ -359,14 +323,14 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_UPDATE_TOKEN_REQ), updateToken) val TAG_NEW_VERSION_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_NEW_VERSION_REQ), newVersion) + tlvWriter.put(ContextSpecificTag(TAG_NEW_VERSION_REQ), newVersion) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -376,48 +340,42 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_ACTION: Int = 0 var action_decoded: UByte? = null - + val TAG_DELAYED_ACTION_TIME: Int = 1 var delayedActionTime_decoded: UInt? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_ACTION)) {action_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_DELAYED_ACTION_TIME)) {delayedActionTime_decoded = tlvReader.getUInt(tag)} - + if (tag == ContextSpecificTag(TAG_ACTION)) { + action_decoded = tlvReader.getUByte(tag) + } - else { + if (tag == ContextSpecificTag(TAG_DELAYED_ACTION_TIME)) { + delayedActionTime_decoded = tlvReader.getUInt(tag) + } else { tlvReader.skipElement() } } - - if (action_decoded == null) { - throw IllegalStateException("action not found in TLV") + throw IllegalStateException("action not found in TLV") } - - + if (delayedActionTime_decoded == null) { - throw IllegalStateException("delayedActionTime not found in TLV") + throw IllegalStateException("delayedActionTime not found in TLV") } - tlvReader.exitContainer() - return ApplyUpdateResponse( - action_decoded, - delayedActionTime_decoded - ) + return ApplyUpdateResponse(action_decoded, delayedActionTime_decoded) } - suspend fun notifyUpdateApplied(updateToken: ByteArray - ,softwareVersion: UInt - ,timedInvokeTimeout: Duration? = null) { + suspend fun notifyUpdateApplied( + updateToken: ByteArray, + softwareVersion: UInt, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 4u val tlvWriter = TlvWriter() @@ -427,108 +385,107 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_UPDATE_TOKEN_REQ), updateToken) val TAG_SOFTWARE_VERSION_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_SOFTWARE_VERSION_REQ), softwareVersion) + tlvWriter.put(ContextSpecificTag(TAG_SOFTWARE_VERSION_REQ), softwareVersion) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } -suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65528u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -536,97 +493,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { emit(GeneratedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65529u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -634,97 +590,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va emit(AcceptedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt = 65530u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -732,97 +685,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt emit(EventListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ID: UInt = 65531u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -830,81 +780,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ emit(AttributeListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -916,80 +861,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 65533u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1002,7 +944,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/OtaSoftwareUpdateRequestorCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/OtaSoftwareUpdateRequestorCluster.kt index cff6f3e8817cd9..21ca7bd092ed56 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/OtaSoftwareUpdateRequestorCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/OtaSoftwareUpdateRequestorCluster.kt @@ -17,133 +17,108 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration 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.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class OtaSoftwareUpdateRequestorCluster(private val controller: MatterController, private val endpointId: UShort) {class DefaultOTAProvidersAttribute( +class OtaSoftwareUpdateRequestorCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class DefaultOTAProvidersAttribute( val value: List ) sealed class DefaultOTAProvidersAttributeSubscriptionState { - data class Success( - val value: List - ) : DefaultOTAProvidersAttributeSubscriptionState() - + data class Success(val value: List) : + DefaultOTAProvidersAttributeSubscriptionState() + data class Error(val exception: Exception) : DefaultOTAProvidersAttributeSubscriptionState() - object SubscriptionEstablished : DefaultOTAProvidersAttributeSubscriptionState() - } -class UpdateStateProgressAttribute( - val value: UByte? - ) + object SubscriptionEstablished : DefaultOTAProvidersAttributeSubscriptionState() + } + + class UpdateStateProgressAttribute(val value: UByte?) sealed class UpdateStateProgressAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : UpdateStateProgressAttributeSubscriptionState() - + data class Success(val value: UByte?) : UpdateStateProgressAttributeSubscriptionState() + data class Error(val exception: Exception) : UpdateStateProgressAttributeSubscriptionState() - object SubscriptionEstablished : UpdateStateProgressAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : UpdateStateProgressAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun announceOTAProvider(providerNodeID: ULong - ,vendorID: UShort - ,announcementReason: UByte - ,metadataForNode: ByteArray? - ,endpoint: UShort - ,timedInvokeTimeout: Duration? = null) { + suspend fun announceOTAProvider( + providerNodeID: ULong, + vendorID: UShort, + announcementReason: UByte, + metadataForNode: ByteArray?, + endpoint: UShort, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 0u val tlvWriter = TlvWriter() @@ -164,89 +139,82 @@ class AttributeListAttribute( } val TAG_ENDPOINT_REQ: Int = 4 - tlvWriter.put(ContextSpecificTag(TAG_ENDPOINT_REQ), endpoint) + tlvWriter.put(ContextSpecificTag(TAG_ENDPOINT_REQ), endpoint) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } -suspend fun readDefaultOTAProvidersAttribute(): DefaultOTAProvidersAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readDefaultOTAProvidersAttribute(): DefaultOTAProvidersAttribute { + 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}") - } + 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) { - "Defaultotaproviders attribute not found in response" - } + } + + requireNotNull(attributeData) { "Defaultotaproviders 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(OtaSoftwareUpdateRequestorClusterProviderLocation.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(OtaSoftwareUpdateRequestorClusterProviderLocation.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return DefaultOTAProvidersAttribute(decodedValue) } suspend fun writeDefaultOTAProvidersAttribute( value: List, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startArray(AnonymousTag) - for (item in value.iterator()) { - item.toTlv(AnonymousTag, tlvWriter) - } - tlvWriter.endArray() + for (item in value.iterator()) { + item.toTlv(AnonymousTag, tlvWriter) + } + tlvWriter.endArray() val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -267,53 +235,60 @@ suspend fun readDefaultOTAProvidersAttribute(): DefaultOTAProvidersAttribute {va throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeDefaultOTAProvidersAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(DefaultOTAProvidersAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + DefaultOTAProvidersAttributeSubscriptionState.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) { - "Defaultotaproviders attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Defaultotaproviders 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(OtaSoftwareUpdateRequestorClusterProviderLocation.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add( + OtaSoftwareUpdateRequestorClusterProviderLocation.fromTlv(AnonymousTag, tlvReader) + ) + } + tlvReader.exitContainer() + } emit(DefaultOTAProvidersAttributeSubscriptionState.Success(decodedValue)) } @@ -321,80 +296,77 @@ suspend fun readDefaultOTAProvidersAttribute(): DefaultOTAProvidersAttribute {va emit(DefaultOTAProvidersAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readUpdatePossibleAttribute(): Boolean {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readUpdatePossibleAttribute(): Boolean { + 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}") - } + 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) { - "Updatepossible attribute not found in response" - } + } + + requireNotNull(attributeData) { "Updatepossible attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Boolean = tlvReader.getBoolean(AnonymousTag) - return decodedValue } suspend fun subscribeUpdatePossibleAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Updatepossible attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Updatepossible attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -407,81 +379,76 @@ suspend fun readUpdatePossibleAttribute(): Boolean {val ATTRIBUTE_ID: UInt = 1u emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readUpdateStateAttribute(): UByte {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readUpdateStateAttribute(): UByte { + 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}") - } + 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) { - "Updatestate attribute not found in response" - } + } + + requireNotNull(attributeData) { "Updatestate 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 subscribeUpdateStateAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Updatestate attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Updatestate attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -493,196 +460,191 @@ suspend fun readUpdateStateAttribute(): UByte {val ATTRIBUTE_ID: UInt = 2u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readUpdateStateProgressAttribute(): UpdateStateProgressAttribute {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readUpdateStateProgressAttribute(): UpdateStateProgressAttribute { + 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}") - } + 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) { - "Updatestateprogress attribute not found in response" - } + } + + requireNotNull(attributeData) { "Updatestateprogress attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return UpdateStateProgressAttribute(decodedValue) } suspend fun subscribeUpdateStateProgressAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(UpdateStateProgressAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + UpdateStateProgressAttributeSubscriptionState.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) { - "Updatestateprogress attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Updatestateprogress 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.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(UpdateStateProgressAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(UpdateStateProgressAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UpdateStateProgressAttributeSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -690,97 +652,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -788,97 +749,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -886,97 +844,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -984,81 +939,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1070,80 +1020,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1156,7 +1103,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/OvenCavityOperationalStateCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/OvenCavityOperationalStateCluster.kt index 4ca4bd4f9307c1..545b2c620a0237 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/OvenCavityOperationalStateCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/OvenCavityOperationalStateCluster.kt @@ -17,182 +17,143 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.UShortSubscriptionState +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class OvenCavityOperationalStateCluster(private val controller: MatterController, private val endpointId: UShort) { +class OvenCavityOperationalStateCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { class OperationalCommandResponse( val commandResponseState: OvenCavityOperationalStateClusterErrorStateStruct ) -class PhaseListAttribute( - val value: List? - ) + + class PhaseListAttribute(val value: List?) sealed class PhaseListAttributeSubscriptionState { - data class Success( - val value: List? - ) : PhaseListAttributeSubscriptionState() - + data class Success(val value: List?) : PhaseListAttributeSubscriptionState() + data class Error(val exception: Exception) : PhaseListAttributeSubscriptionState() - object SubscriptionEstablished : PhaseListAttributeSubscriptionState() - } -class CurrentPhaseAttribute( - val value: UByte? - ) + object SubscriptionEstablished : PhaseListAttributeSubscriptionState() + } + + class CurrentPhaseAttribute(val value: UByte?) sealed class CurrentPhaseAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : CurrentPhaseAttributeSubscriptionState() - + data class Success(val value: UByte?) : CurrentPhaseAttributeSubscriptionState() + data class Error(val exception: Exception) : CurrentPhaseAttributeSubscriptionState() - object SubscriptionEstablished : CurrentPhaseAttributeSubscriptionState() - } -class CountdownTimeAttribute( - val value: UInt? - ) + object SubscriptionEstablished : CurrentPhaseAttributeSubscriptionState() + } + + class CountdownTimeAttribute(val value: UInt?) sealed class CountdownTimeAttributeSubscriptionState { - data class Success( - val value: UInt? - ) : CountdownTimeAttributeSubscriptionState() - + data class Success(val value: UInt?) : CountdownTimeAttributeSubscriptionState() + data class Error(val exception: Exception) : CountdownTimeAttributeSubscriptionState() - object SubscriptionEstablished : CountdownTimeAttributeSubscriptionState() - } -class OperationalStateListAttribute( + object SubscriptionEstablished : CountdownTimeAttributeSubscriptionState() + } + + class OperationalStateListAttribute( val value: List ) sealed class OperationalStateListAttributeSubscriptionState { - data class Success( - val value: List - ) : OperationalStateListAttributeSubscriptionState() - + data class Success(val value: List) : + OperationalStateListAttributeSubscriptionState() + data class Error(val exception: Exception) : OperationalStateListAttributeSubscriptionState() - object SubscriptionEstablished : OperationalStateListAttributeSubscriptionState() - } -class OperationalErrorAttribute( - val value: OvenCavityOperationalStateClusterErrorStateStruct - ) + object SubscriptionEstablished : OperationalStateListAttributeSubscriptionState() + } + + class OperationalErrorAttribute(val value: OvenCavityOperationalStateClusterErrorStateStruct) sealed class OperationalErrorAttributeSubscriptionState { - data class Success( - val value: OvenCavityOperationalStateClusterErrorStateStruct - ) : OperationalErrorAttributeSubscriptionState() - + data class Success(val value: OvenCavityOperationalStateClusterErrorStateStruct) : + OperationalErrorAttributeSubscriptionState() + data class Error(val exception: Exception) : OperationalErrorAttributeSubscriptionState() - object SubscriptionEstablished : OperationalErrorAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : OperationalErrorAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } suspend fun pause(timedInvokeTimeout: Duration? = null): OperationalCommandResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -202,46 +163,39 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_COMMAND_RESPONSE_STATE: Int = 0 var commandResponseState_decoded: OvenCavityOperationalStateClusterErrorStateStruct? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_COMMAND_RESPONSE_STATE)) {commandResponseState_decoded = OvenCavityOperationalStateClusterErrorStateStruct.fromTlv(tag, tlvReader)} - - - else { + if (tag == ContextSpecificTag(TAG_COMMAND_RESPONSE_STATE)) { + commandResponseState_decoded = + OvenCavityOperationalStateClusterErrorStateStruct.fromTlv(tag, tlvReader) + } else { tlvReader.skipElement() } } - - if (commandResponseState_decoded == null) { - throw IllegalStateException("commandResponseState not found in TLV") + throw IllegalStateException("commandResponseState not found in TLV") } - tlvReader.exitContainer() - return OperationalCommandResponse( - commandResponseState_decoded - ) + return OperationalCommandResponse(commandResponseState_decoded) } suspend fun stop(timedInvokeTimeout: Duration? = null): OperationalCommandResponse { val commandId: UInt = 1u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -251,46 +205,39 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_COMMAND_RESPONSE_STATE: Int = 0 var commandResponseState_decoded: OvenCavityOperationalStateClusterErrorStateStruct? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_COMMAND_RESPONSE_STATE)) {commandResponseState_decoded = OvenCavityOperationalStateClusterErrorStateStruct.fromTlv(tag, tlvReader)} - - - else { + if (tag == ContextSpecificTag(TAG_COMMAND_RESPONSE_STATE)) { + commandResponseState_decoded = + OvenCavityOperationalStateClusterErrorStateStruct.fromTlv(tag, tlvReader) + } else { tlvReader.skipElement() } } - - if (commandResponseState_decoded == null) { - throw IllegalStateException("commandResponseState not found in TLV") + throw IllegalStateException("commandResponseState not found in TLV") } - tlvReader.exitContainer() - return OperationalCommandResponse( - commandResponseState_decoded - ) + return OperationalCommandResponse(commandResponseState_decoded) } suspend fun start(timedInvokeTimeout: Duration? = null): OperationalCommandResponse { val commandId: UInt = 2u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -300,46 +247,39 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_COMMAND_RESPONSE_STATE: Int = 0 var commandResponseState_decoded: OvenCavityOperationalStateClusterErrorStateStruct? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_COMMAND_RESPONSE_STATE)) {commandResponseState_decoded = OvenCavityOperationalStateClusterErrorStateStruct.fromTlv(tag, tlvReader)} - - - else { + if (tag == ContextSpecificTag(TAG_COMMAND_RESPONSE_STATE)) { + commandResponseState_decoded = + OvenCavityOperationalStateClusterErrorStateStruct.fromTlv(tag, tlvReader) + } else { tlvReader.skipElement() } } - - if (commandResponseState_decoded == null) { - throw IllegalStateException("commandResponseState not found in TLV") + throw IllegalStateException("commandResponseState not found in TLV") } - tlvReader.exitContainer() - return OperationalCommandResponse( - commandResponseState_decoded - ) + return OperationalCommandResponse(commandResponseState_decoded) } suspend fun resume(timedInvokeTimeout: Duration? = null): OperationalCommandResponse { val commandId: UInt = 3u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -349,439 +289,420 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_COMMAND_RESPONSE_STATE: Int = 0 var commandResponseState_decoded: OvenCavityOperationalStateClusterErrorStateStruct? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_COMMAND_RESPONSE_STATE)) {commandResponseState_decoded = OvenCavityOperationalStateClusterErrorStateStruct.fromTlv(tag, tlvReader)} - - - else { + if (tag == ContextSpecificTag(TAG_COMMAND_RESPONSE_STATE)) { + commandResponseState_decoded = + OvenCavityOperationalStateClusterErrorStateStruct.fromTlv(tag, tlvReader) + } else { tlvReader.skipElement() } } - - if (commandResponseState_decoded == null) { - throw IllegalStateException("commandResponseState not found in TLV") + throw IllegalStateException("commandResponseState not found in TLV") } - tlvReader.exitContainer() - return OperationalCommandResponse( - commandResponseState_decoded - ) + return OperationalCommandResponse(commandResponseState_decoded) } -suspend fun readPhaseListAttribute(): PhaseListAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readPhaseListAttribute(): PhaseListAttribute { + 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}") - } + 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) { - "Phaselist attribute not found in response" - } + } + + requireNotNull(attributeData) { "Phaselist attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (!tlvReader.isNull()) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getString(AnonymousTag)) + val decodedValue: List? = + if (!tlvReader.isNull()) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getString(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + tlvReader.getNull(AnonymousTag) + null } - tlvReader.exitContainer() - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - return PhaseListAttribute(decodedValue) } suspend fun subscribePhaseListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(PhaseListAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + PhaseListAttributeSubscriptionState.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) { - "Phaselist attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Phaselist attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (!tlvReader.isNull()) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getString(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(PhaseListAttributeSubscriptionState.Success(it)) - } - + val decodedValue: List? = + if (!tlvReader.isNull()) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getString(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(PhaseListAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(PhaseListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCurrentPhaseAttribute(): CurrentPhaseAttribute {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readCurrentPhaseAttribute(): CurrentPhaseAttribute { + 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}") - } + 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) { - "Currentphase attribute not found in response" - } + } + + requireNotNull(attributeData) { "Currentphase attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return CurrentPhaseAttribute(decodedValue) } suspend fun subscribeCurrentPhaseAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(CurrentPhaseAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + CurrentPhaseAttributeSubscriptionState.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) { - "Currentphase attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Currentphase 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.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(CurrentPhaseAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(CurrentPhaseAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(CurrentPhaseAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCountdownTimeAttribute(): CountdownTimeAttribute {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readCountdownTimeAttribute(): CountdownTimeAttribute { + 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}") - } + 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) { - "Countdowntime attribute not found in response" - } + } + + requireNotNull(attributeData) { "Countdowntime attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return CountdownTimeAttribute(decodedValue) } suspend fun subscribeCountdownTimeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(CountdownTimeAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + CountdownTimeAttributeSubscriptionState.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) { - "Countdowntime attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Countdowntime attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(CountdownTimeAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(CountdownTimeAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(CountdownTimeAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readOperationalStateListAttribute(): OperationalStateListAttribute {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readOperationalStateListAttribute(): OperationalStateListAttribute { + 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}") - } + 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) { - "Operationalstatelist attribute not found in response" - } + } + + requireNotNull(attributeData) { "Operationalstatelist 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(OvenCavityOperationalStateClusterOperationalStateStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add( + OvenCavityOperationalStateClusterOperationalStateStruct.fromTlv(AnonymousTag, tlvReader) + ) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return OperationalStateListAttribute(decodedValue) } suspend fun subscribeOperationalStateListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(OperationalStateListAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + OperationalStateListAttributeSubscriptionState.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) { - "Operationalstatelist attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Operationalstatelist 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(OvenCavityOperationalStateClusterOperationalStateStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add( + OvenCavityOperationalStateClusterOperationalStateStruct.fromTlv( + AnonymousTag, + tlvReader, + ) + ) + } + tlvReader.exitContainer() + } emit(OperationalStateListAttributeSubscriptionState.Success(decodedValue)) } @@ -789,80 +710,77 @@ suspend fun readOperationalStateListAttribute(): OperationalStateListAttribute { emit(OperationalStateListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readOperationalStateAttribute(): 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) - ) - + + suspend fun readOperationalStateAttribute(): 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}") - } + 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) { - "Operationalstate attribute not found in response" - } + } + + requireNotNull(attributeData) { "Operationalstate 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 subscribeOperationalStateAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Operationalstate attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Operationalstate attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -875,85 +793,84 @@ suspend fun readOperationalStateAttribute(): UByte {val ATTRIBUTE_ID: UInt = 4u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readOperationalErrorAttribute(): OperationalErrorAttribute {val ATTRIBUTE_ID: UInt = 5u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readOperationalErrorAttribute(): OperationalErrorAttribute { + 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}") - } + 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) { - "Operationalerror attribute not found in response" - } + } + + requireNotNull(attributeData) { "Operationalerror attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: OvenCavityOperationalStateClusterErrorStateStruct = OvenCavityOperationalStateClusterErrorStateStruct.fromTlv(AnonymousTag, tlvReader) - + val decodedValue: OvenCavityOperationalStateClusterErrorStateStruct = + OvenCavityOperationalStateClusterErrorStateStruct.fromTlv(AnonymousTag, tlvReader) return OperationalErrorAttribute(decodedValue) } suspend fun subscribeOperationalErrorAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(OperationalErrorAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + OperationalErrorAttributeSubscriptionState.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) { - "Operationalerror attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Operationalerror attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: OvenCavityOperationalStateClusterErrorStateStruct = OvenCavityOperationalStateClusterErrorStateStruct.fromTlv(AnonymousTag, tlvReader) + val decodedValue: OvenCavityOperationalStateClusterErrorStateStruct = + OvenCavityOperationalStateClusterErrorStateStruct.fromTlv(AnonymousTag, tlvReader) emit(OperationalErrorAttributeSubscriptionState.Success(decodedValue)) } @@ -961,97 +878,96 @@ suspend fun readOperationalErrorAttribute(): OperationalErrorAttribute {val ATTR emit(OperationalErrorAttributeSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1059,97 +975,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1157,97 +1072,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1255,97 +1167,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1353,81 +1262,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1439,80 +1343,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1525,7 +1426,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/OvenModeCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/OvenModeCluster.kt index 072808ed1b0f75..3bf17486833050 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/OvenModeCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/OvenModeCluster.kt @@ -17,161 +17,124 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter class OvenModeCluster(private val controller: MatterController, private val endpointId: UShort) { - class ChangeToModeResponse( - val status: UByte, - val statusText: String? - ) -class SupportedModesAttribute( - val value: List - ) + class ChangeToModeResponse(val status: UByte, val statusText: String?) + + class SupportedModesAttribute(val value: List) sealed class SupportedModesAttributeSubscriptionState { - data class Success( - val value: List - ) : SupportedModesAttributeSubscriptionState() - + data class Success(val value: List) : + SupportedModesAttributeSubscriptionState() + data class Error(val exception: Exception) : SupportedModesAttributeSubscriptionState() - object SubscriptionEstablished : SupportedModesAttributeSubscriptionState() - } -class StartUpModeAttribute( - val value: UByte? - ) + object SubscriptionEstablished : SupportedModesAttributeSubscriptionState() + } + + class StartUpModeAttribute(val value: UByte?) sealed class StartUpModeAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : StartUpModeAttributeSubscriptionState() - + data class Success(val value: UByte?) : StartUpModeAttributeSubscriptionState() + data class Error(val exception: Exception) : StartUpModeAttributeSubscriptionState() - object SubscriptionEstablished : StartUpModeAttributeSubscriptionState() - } -class OnModeAttribute( - val value: UByte? - ) + object SubscriptionEstablished : StartUpModeAttributeSubscriptionState() + } + + class OnModeAttribute(val value: UByte?) sealed class OnModeAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : OnModeAttributeSubscriptionState() - + data class Success(val value: UByte?) : OnModeAttributeSubscriptionState() + data class Error(val exception: Exception) : OnModeAttributeSubscriptionState() - object SubscriptionEstablished : OnModeAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : OnModeAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun changeToMode(newMode: UByte - ,timedInvokeTimeout: Duration? = null): ChangeToModeResponse { + suspend fun changeToMode( + newMode: UByte, + timedInvokeTimeout: Duration? = null, + ): ChangeToModeResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_NEW_MODE_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_NEW_MODE_REQ), newMode) + tlvWriter.put(ContextSpecificTag(TAG_NEW_MODE_REQ), newMode) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -181,140 +144,130 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_STATUS_TEXT: Int = 1 var statusText_decoded: String? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_STATUS_TEXT)) {statusText_decoded = + if (tag == ContextSpecificTag(TAG_STATUS)) { + status_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_STATUS_TEXT)) { + statusText_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - }} - - - else { + tlvReader.getString(tag) + } else { + null + } + } + } else { tlvReader.skipElement() } } - - if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - - - tlvReader.exitContainer() - return ChangeToModeResponse( - status_decoded, - statusText_decoded - ) + return ChangeToModeResponse(status_decoded, statusText_decoded) } -suspend fun readSupportedModesAttribute(): SupportedModesAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readSupportedModesAttribute(): SupportedModesAttribute { + 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}") - } + 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) { - "Supportedmodes attribute not found in response" - } + } + + requireNotNull(attributeData) { "Supportedmodes 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(OvenModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(OvenModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return SupportedModesAttribute(decodedValue) } suspend fun subscribeSupportedModesAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(SupportedModesAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + SupportedModesAttributeSubscriptionState.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) { - "Supportedmodes attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Supportedmodes 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(OvenModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(OvenModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(SupportedModesAttributeSubscriptionState.Success(decodedValue)) } @@ -322,81 +275,76 @@ suspend fun readSupportedModesAttribute(): SupportedModesAttribute {val ATTRIBUT emit(SupportedModesAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCurrentModeAttribute(): 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) - ) - + + suspend fun readCurrentModeAttribute(): 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}") - } + 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) { - "Currentmode attribute not found in response" - } + } + + requireNotNull(attributeData) { "Currentmode 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 subscribeCurrentModeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Currentmode attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Currentmode attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -408,77 +356,67 @@ suspend fun readCurrentModeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 1u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readStartUpModeAttribute(): StartUpModeAttribute {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readStartUpModeAttribute(): StartUpModeAttribute { + 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}") - } + 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) { - "Startupmode attribute not found in response" - } + } + + requireNotNull(attributeData) { "Startupmode attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return StartUpModeAttribute(decodedValue) } - suspend fun writeStartUpModeAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeStartUpModeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 2u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -499,137 +437,127 @@ suspend fun readStartUpModeAttribute(): StartUpModeAttribute {val ATTRIBUTE_ID: throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeStartUpModeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StartUpModeAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StartUpModeAttributeSubscriptionState.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) { - "Startupmode attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Startupmode 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(StartUpModeAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(StartUpModeAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(StartUpModeAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readOnModeAttribute(): OnModeAttribute {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readOnModeAttribute(): OnModeAttribute { + 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}") - } + 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) { - "Onmode attribute not found in response" - } + } + + requireNotNull(attributeData) { "Onmode attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return OnModeAttribute(decodedValue) } - suspend fun writeOnModeAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeOnModeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 3u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -650,157 +578,156 @@ suspend fun readOnModeAttribute(): OnModeAttribute {val ATTRIBUTE_ID: UInt = 3u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeOnModeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(OnModeAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + OnModeAttributeSubscriptionState.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) { - "Onmode attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Onmode 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(OnModeAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(OnModeAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(OnModeAttributeSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -808,97 +735,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -906,97 +832,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1004,97 +927,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1102,81 +1022,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1188,80 +1103,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1274,7 +1186,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/OzoneConcentrationMeasurementCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/OzoneConcentrationMeasurementCluster.kt index 427cf896b35373..a8285931c68e63 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/OzoneConcentrationMeasurementCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/OzoneConcentrationMeasurementCluster.kt @@ -17,1371 +17,1273 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.FloatSubscriptionState import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse -import matter.controller.model.AttributePath -import matter.controller.model.CommandPath +import matter.controller.UShortSubscriptionState import matter.controller.cluster.structs.* +import matter.controller.model.AttributePath import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader -import matter.tlv.TlvWriter -class OzoneConcentrationMeasurementCluster(private val controller: MatterController, private val endpointId: UShort) {class MeasuredValueAttribute( - val value: Float? - ) +class OzoneConcentrationMeasurementCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class MeasuredValueAttribute(val value: Float?) sealed class MeasuredValueAttributeSubscriptionState { - data class Success( - val value: Float? - ) : MeasuredValueAttributeSubscriptionState() - + data class Success(val value: Float?) : MeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() - } -class MinMeasuredValueAttribute( - val value: Float? - ) + object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() + } + + class MinMeasuredValueAttribute(val value: Float?) sealed class MinMeasuredValueAttributeSubscriptionState { - data class Success( - val value: Float? - ) : MinMeasuredValueAttributeSubscriptionState() - + data class Success(val value: Float?) : MinMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MinMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() - } -class MaxMeasuredValueAttribute( - val value: Float? - ) + object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() + } + + class MaxMeasuredValueAttribute(val value: Float?) sealed class MaxMeasuredValueAttributeSubscriptionState { - data class Success( - val value: Float? - ) : MaxMeasuredValueAttributeSubscriptionState() - + data class Success(val value: Float?) : MaxMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MaxMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() - } -class PeakMeasuredValueAttribute( - val value: Float? - ) + object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() + } + + class PeakMeasuredValueAttribute(val value: Float?) sealed class PeakMeasuredValueAttributeSubscriptionState { - data class Success( - val value: Float? - ) : PeakMeasuredValueAttributeSubscriptionState() - + data class Success(val value: Float?) : PeakMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : PeakMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : PeakMeasuredValueAttributeSubscriptionState() - } -class AverageMeasuredValueAttribute( - val value: Float? - ) + object SubscriptionEstablished : PeakMeasuredValueAttributeSubscriptionState() + } + + class AverageMeasuredValueAttribute(val value: Float?) sealed class AverageMeasuredValueAttributeSubscriptionState { - data class Success( - val value: Float? - ) : AverageMeasuredValueAttributeSubscriptionState() - + data class Success(val value: Float?) : AverageMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : AverageMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : AverageMeasuredValueAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : AverageMeasuredValueAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } -suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } + + suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute { + 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}") - } + 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) { - "Measuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Measuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return MeasuredValueAttribute(decodedValue) } suspend fun subscribeMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MeasuredValueAttributeSubscriptionState.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) { - "Measuredvalue attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Measuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute { + 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}") - } + 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) { - "Minmeasuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Minmeasuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return MinMeasuredValueAttribute(decodedValue) } suspend fun subscribeMinMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MinMeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MinMeasuredValueAttributeSubscriptionState.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) { - "Minmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Minmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MinMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute { + 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}") - } + 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) { - "Maxmeasuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Maxmeasuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return MaxMeasuredValueAttribute(decodedValue) } suspend fun subscribeMaxMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MaxMeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MaxMeasuredValueAttributeSubscriptionState.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) { - "Maxmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Maxmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MaxMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPeakMeasuredValueAttribute(): PeakMeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readPeakMeasuredValueAttribute(): PeakMeasuredValueAttribute { + 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}") - } + 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) { - "Peakmeasuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Peakmeasuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return PeakMeasuredValueAttribute(decodedValue) } suspend fun subscribePeakMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(PeakMeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + PeakMeasuredValueAttributeSubscriptionState.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) { - "Peakmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Peakmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(PeakMeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(PeakMeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(PeakMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPeakMeasuredValueWindowAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 4u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readPeakMeasuredValueWindowAttribute(): UInt? { + 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}") - } + 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) { - "Peakmeasuredvaluewindow attribute not found in response" - } + } + + requireNotNull(attributeData) { "Peakmeasuredvaluewindow attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribePeakMeasuredValueWindowAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Peakmeasuredvaluewindow attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Peakmeasuredvaluewindow attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAverageMeasuredValueAttribute(): AverageMeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 5u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readAverageMeasuredValueAttribute(): AverageMeasuredValueAttribute { + 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}") - } + 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) { - "Averagemeasuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Averagemeasuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return AverageMeasuredValueAttribute(decodedValue) } suspend fun subscribeAverageMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(AverageMeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + AverageMeasuredValueAttributeSubscriptionState.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) { - "Averagemeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Averagemeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(AverageMeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(AverageMeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(AverageMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAverageMeasuredValueWindowAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 6u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readAverageMeasuredValueWindowAttribute(): UInt? { + 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}") - } + 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) { - "Averagemeasuredvaluewindow attribute not found in response" - } + } + + requireNotNull(attributeData) { "Averagemeasuredvaluewindow attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeAverageMeasuredValueWindowAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Averagemeasuredvaluewindow attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Averagemeasuredvaluewindow attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readUncertaintyAttribute(): Float? {val ATTRIBUTE_ID: UInt = 7u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readUncertaintyAttribute(): Float? { + 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}") - } + 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) { - "Uncertainty attribute not found in response" - } + } + + requireNotNull(attributeData) { "Uncertainty attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - + val decodedValue: Float? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeUncertaintyAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(FloatSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + FloatSubscriptionState.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) { - "Uncertainty attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Uncertainty attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(FloatSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(FloatSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(FloatSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMeasurementUnitAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 8u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMeasurementUnitAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 8u + + 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}") - } + 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) { - "Measurementunit attribute not found in response" - } + } + + requireNotNull(attributeData) { "Measurementunit 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeMeasurementUnitAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Measurementunit attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Measurementunit 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)) - } - + 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 readMeasurementMediumAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 9u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMeasurementMediumAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 9u + + 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}") - } + 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) { - "Measurementmedium attribute not found in response" - } + } + + requireNotNull(attributeData) { "Measurementmedium 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeMeasurementMediumAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Measurementmedium attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Measurementmedium 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)) - } - + 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 readLevelValueAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 10u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readLevelValueAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 10u + + 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}") - } + 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) { - "Levelvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Levelvalue 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeLevelValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Levelvalue attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Levelvalue 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)) - } - + 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 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1389,97 +1291,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1487,97 +1388,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1585,97 +1483,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1683,81 +1578,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1769,80 +1659,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1855,7 +1742,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/Pm10ConcentrationMeasurementCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/Pm10ConcentrationMeasurementCluster.kt index 0105d1d2a3b075..e77f7bab254198 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/Pm10ConcentrationMeasurementCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/Pm10ConcentrationMeasurementCluster.kt @@ -17,1371 +17,1273 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.FloatSubscriptionState import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse -import matter.controller.model.AttributePath -import matter.controller.model.CommandPath +import matter.controller.UShortSubscriptionState import matter.controller.cluster.structs.* +import matter.controller.model.AttributePath import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader -import matter.tlv.TlvWriter -class Pm10ConcentrationMeasurementCluster(private val controller: MatterController, private val endpointId: UShort) {class MeasuredValueAttribute( - val value: Float? - ) +class Pm10ConcentrationMeasurementCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class MeasuredValueAttribute(val value: Float?) sealed class MeasuredValueAttributeSubscriptionState { - data class Success( - val value: Float? - ) : MeasuredValueAttributeSubscriptionState() - + data class Success(val value: Float?) : MeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() - } -class MinMeasuredValueAttribute( - val value: Float? - ) + object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() + } + + class MinMeasuredValueAttribute(val value: Float?) sealed class MinMeasuredValueAttributeSubscriptionState { - data class Success( - val value: Float? - ) : MinMeasuredValueAttributeSubscriptionState() - + data class Success(val value: Float?) : MinMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MinMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() - } -class MaxMeasuredValueAttribute( - val value: Float? - ) + object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() + } + + class MaxMeasuredValueAttribute(val value: Float?) sealed class MaxMeasuredValueAttributeSubscriptionState { - data class Success( - val value: Float? - ) : MaxMeasuredValueAttributeSubscriptionState() - + data class Success(val value: Float?) : MaxMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MaxMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() - } -class PeakMeasuredValueAttribute( - val value: Float? - ) + object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() + } + + class PeakMeasuredValueAttribute(val value: Float?) sealed class PeakMeasuredValueAttributeSubscriptionState { - data class Success( - val value: Float? - ) : PeakMeasuredValueAttributeSubscriptionState() - + data class Success(val value: Float?) : PeakMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : PeakMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : PeakMeasuredValueAttributeSubscriptionState() - } -class AverageMeasuredValueAttribute( - val value: Float? - ) + object SubscriptionEstablished : PeakMeasuredValueAttributeSubscriptionState() + } + + class AverageMeasuredValueAttribute(val value: Float?) sealed class AverageMeasuredValueAttributeSubscriptionState { - data class Success( - val value: Float? - ) : AverageMeasuredValueAttributeSubscriptionState() - + data class Success(val value: Float?) : AverageMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : AverageMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : AverageMeasuredValueAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : AverageMeasuredValueAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } -suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } + + suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute { + 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}") - } + 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) { - "Measuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Measuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return MeasuredValueAttribute(decodedValue) } suspend fun subscribeMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MeasuredValueAttributeSubscriptionState.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) { - "Measuredvalue attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Measuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute { + 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}") - } + 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) { - "Minmeasuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Minmeasuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return MinMeasuredValueAttribute(decodedValue) } suspend fun subscribeMinMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MinMeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MinMeasuredValueAttributeSubscriptionState.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) { - "Minmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Minmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MinMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute { + 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}") - } + 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) { - "Maxmeasuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Maxmeasuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return MaxMeasuredValueAttribute(decodedValue) } suspend fun subscribeMaxMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MaxMeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MaxMeasuredValueAttributeSubscriptionState.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) { - "Maxmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Maxmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MaxMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPeakMeasuredValueAttribute(): PeakMeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readPeakMeasuredValueAttribute(): PeakMeasuredValueAttribute { + 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}") - } + 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) { - "Peakmeasuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Peakmeasuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return PeakMeasuredValueAttribute(decodedValue) } suspend fun subscribePeakMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(PeakMeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + PeakMeasuredValueAttributeSubscriptionState.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) { - "Peakmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Peakmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(PeakMeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(PeakMeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(PeakMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPeakMeasuredValueWindowAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 4u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readPeakMeasuredValueWindowAttribute(): UInt? { + 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}") - } + 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) { - "Peakmeasuredvaluewindow attribute not found in response" - } + } + + requireNotNull(attributeData) { "Peakmeasuredvaluewindow attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribePeakMeasuredValueWindowAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Peakmeasuredvaluewindow attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Peakmeasuredvaluewindow attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAverageMeasuredValueAttribute(): AverageMeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 5u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readAverageMeasuredValueAttribute(): AverageMeasuredValueAttribute { + 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}") - } + 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) { - "Averagemeasuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Averagemeasuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return AverageMeasuredValueAttribute(decodedValue) } suspend fun subscribeAverageMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(AverageMeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + AverageMeasuredValueAttributeSubscriptionState.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) { - "Averagemeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Averagemeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(AverageMeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(AverageMeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(AverageMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAverageMeasuredValueWindowAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 6u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readAverageMeasuredValueWindowAttribute(): UInt? { + 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}") - } + 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) { - "Averagemeasuredvaluewindow attribute not found in response" - } + } + + requireNotNull(attributeData) { "Averagemeasuredvaluewindow attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeAverageMeasuredValueWindowAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Averagemeasuredvaluewindow attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Averagemeasuredvaluewindow attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readUncertaintyAttribute(): Float? {val ATTRIBUTE_ID: UInt = 7u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readUncertaintyAttribute(): Float? { + 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}") - } + 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) { - "Uncertainty attribute not found in response" - } + } + + requireNotNull(attributeData) { "Uncertainty attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - + val decodedValue: Float? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeUncertaintyAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(FloatSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + FloatSubscriptionState.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) { - "Uncertainty attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Uncertainty attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(FloatSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(FloatSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(FloatSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMeasurementUnitAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 8u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMeasurementUnitAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 8u + + 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}") - } + 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) { - "Measurementunit attribute not found in response" - } + } + + requireNotNull(attributeData) { "Measurementunit 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeMeasurementUnitAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Measurementunit attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Measurementunit 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)) - } - + 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 readMeasurementMediumAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 9u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMeasurementMediumAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 9u + + 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}") - } + 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) { - "Measurementmedium attribute not found in response" - } + } + + requireNotNull(attributeData) { "Measurementmedium 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeMeasurementMediumAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Measurementmedium attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Measurementmedium 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)) - } - + 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 readLevelValueAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 10u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readLevelValueAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 10u + + 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}") - } + 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) { - "Levelvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Levelvalue 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeLevelValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Levelvalue attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Levelvalue 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)) - } - + 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 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1389,97 +1291,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1487,97 +1388,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1585,97 +1483,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1683,81 +1578,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1769,80 +1659,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1855,7 +1742,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/Pm1ConcentrationMeasurementCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/Pm1ConcentrationMeasurementCluster.kt index 56a19df1bc928d..81986a50338d73 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/Pm1ConcentrationMeasurementCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/Pm1ConcentrationMeasurementCluster.kt @@ -17,1371 +17,1273 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.FloatSubscriptionState import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse -import matter.controller.model.AttributePath -import matter.controller.model.CommandPath +import matter.controller.UShortSubscriptionState import matter.controller.cluster.structs.* +import matter.controller.model.AttributePath import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader -import matter.tlv.TlvWriter -class Pm1ConcentrationMeasurementCluster(private val controller: MatterController, private val endpointId: UShort) {class MeasuredValueAttribute( - val value: Float? - ) +class Pm1ConcentrationMeasurementCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class MeasuredValueAttribute(val value: Float?) sealed class MeasuredValueAttributeSubscriptionState { - data class Success( - val value: Float? - ) : MeasuredValueAttributeSubscriptionState() - + data class Success(val value: Float?) : MeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() - } -class MinMeasuredValueAttribute( - val value: Float? - ) + object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() + } + + class MinMeasuredValueAttribute(val value: Float?) sealed class MinMeasuredValueAttributeSubscriptionState { - data class Success( - val value: Float? - ) : MinMeasuredValueAttributeSubscriptionState() - + data class Success(val value: Float?) : MinMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MinMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() - } -class MaxMeasuredValueAttribute( - val value: Float? - ) + object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() + } + + class MaxMeasuredValueAttribute(val value: Float?) sealed class MaxMeasuredValueAttributeSubscriptionState { - data class Success( - val value: Float? - ) : MaxMeasuredValueAttributeSubscriptionState() - + data class Success(val value: Float?) : MaxMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MaxMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() - } -class PeakMeasuredValueAttribute( - val value: Float? - ) + object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() + } + + class PeakMeasuredValueAttribute(val value: Float?) sealed class PeakMeasuredValueAttributeSubscriptionState { - data class Success( - val value: Float? - ) : PeakMeasuredValueAttributeSubscriptionState() - + data class Success(val value: Float?) : PeakMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : PeakMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : PeakMeasuredValueAttributeSubscriptionState() - } -class AverageMeasuredValueAttribute( - val value: Float? - ) + object SubscriptionEstablished : PeakMeasuredValueAttributeSubscriptionState() + } + + class AverageMeasuredValueAttribute(val value: Float?) sealed class AverageMeasuredValueAttributeSubscriptionState { - data class Success( - val value: Float? - ) : AverageMeasuredValueAttributeSubscriptionState() - + data class Success(val value: Float?) : AverageMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : AverageMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : AverageMeasuredValueAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : AverageMeasuredValueAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } -suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } + + suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute { + 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}") - } + 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) { - "Measuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Measuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return MeasuredValueAttribute(decodedValue) } suspend fun subscribeMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MeasuredValueAttributeSubscriptionState.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) { - "Measuredvalue attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Measuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute { + 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}") - } + 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) { - "Minmeasuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Minmeasuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return MinMeasuredValueAttribute(decodedValue) } suspend fun subscribeMinMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MinMeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MinMeasuredValueAttributeSubscriptionState.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) { - "Minmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Minmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MinMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute { + 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}") - } + 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) { - "Maxmeasuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Maxmeasuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return MaxMeasuredValueAttribute(decodedValue) } suspend fun subscribeMaxMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MaxMeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MaxMeasuredValueAttributeSubscriptionState.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) { - "Maxmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Maxmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MaxMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPeakMeasuredValueAttribute(): PeakMeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readPeakMeasuredValueAttribute(): PeakMeasuredValueAttribute { + 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}") - } + 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) { - "Peakmeasuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Peakmeasuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return PeakMeasuredValueAttribute(decodedValue) } suspend fun subscribePeakMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(PeakMeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + PeakMeasuredValueAttributeSubscriptionState.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) { - "Peakmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Peakmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(PeakMeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(PeakMeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(PeakMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPeakMeasuredValueWindowAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 4u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readPeakMeasuredValueWindowAttribute(): UInt? { + 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}") - } + 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) { - "Peakmeasuredvaluewindow attribute not found in response" - } + } + + requireNotNull(attributeData) { "Peakmeasuredvaluewindow attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribePeakMeasuredValueWindowAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Peakmeasuredvaluewindow attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Peakmeasuredvaluewindow attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAverageMeasuredValueAttribute(): AverageMeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 5u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readAverageMeasuredValueAttribute(): AverageMeasuredValueAttribute { + 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}") - } + 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) { - "Averagemeasuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Averagemeasuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return AverageMeasuredValueAttribute(decodedValue) } suspend fun subscribeAverageMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(AverageMeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + AverageMeasuredValueAttributeSubscriptionState.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) { - "Averagemeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Averagemeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(AverageMeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(AverageMeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(AverageMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAverageMeasuredValueWindowAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 6u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readAverageMeasuredValueWindowAttribute(): UInt? { + 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}") - } + 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) { - "Averagemeasuredvaluewindow attribute not found in response" - } + } + + requireNotNull(attributeData) { "Averagemeasuredvaluewindow attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeAverageMeasuredValueWindowAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Averagemeasuredvaluewindow attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Averagemeasuredvaluewindow attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readUncertaintyAttribute(): Float? {val ATTRIBUTE_ID: UInt = 7u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readUncertaintyAttribute(): Float? { + 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}") - } + 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) { - "Uncertainty attribute not found in response" - } + } + + requireNotNull(attributeData) { "Uncertainty attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - + val decodedValue: Float? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeUncertaintyAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(FloatSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + FloatSubscriptionState.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) { - "Uncertainty attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Uncertainty attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(FloatSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(FloatSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(FloatSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMeasurementUnitAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 8u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMeasurementUnitAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 8u + + 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}") - } + 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) { - "Measurementunit attribute not found in response" - } + } + + requireNotNull(attributeData) { "Measurementunit 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeMeasurementUnitAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Measurementunit attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Measurementunit 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)) - } - + 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 readMeasurementMediumAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 9u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMeasurementMediumAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 9u + + 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}") - } + 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) { - "Measurementmedium attribute not found in response" - } + } + + requireNotNull(attributeData) { "Measurementmedium 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeMeasurementMediumAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Measurementmedium attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Measurementmedium 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)) - } - + 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 readLevelValueAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 10u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readLevelValueAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 10u + + 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}") - } + 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) { - "Levelvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Levelvalue 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeLevelValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Levelvalue attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Levelvalue 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)) - } - + 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 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1389,97 +1291,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1487,97 +1388,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1585,97 +1483,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1683,81 +1578,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1769,80 +1659,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1855,7 +1742,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/Pm25ConcentrationMeasurementCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/Pm25ConcentrationMeasurementCluster.kt index 090d17ca0c1584..4c236f2255d213 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/Pm25ConcentrationMeasurementCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/Pm25ConcentrationMeasurementCluster.kt @@ -17,1371 +17,1273 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.FloatSubscriptionState import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse -import matter.controller.model.AttributePath -import matter.controller.model.CommandPath +import matter.controller.UShortSubscriptionState import matter.controller.cluster.structs.* +import matter.controller.model.AttributePath import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader -import matter.tlv.TlvWriter -class Pm25ConcentrationMeasurementCluster(private val controller: MatterController, private val endpointId: UShort) {class MeasuredValueAttribute( - val value: Float? - ) +class Pm25ConcentrationMeasurementCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class MeasuredValueAttribute(val value: Float?) sealed class MeasuredValueAttributeSubscriptionState { - data class Success( - val value: Float? - ) : MeasuredValueAttributeSubscriptionState() - + data class Success(val value: Float?) : MeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() - } -class MinMeasuredValueAttribute( - val value: Float? - ) + object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() + } + + class MinMeasuredValueAttribute(val value: Float?) sealed class MinMeasuredValueAttributeSubscriptionState { - data class Success( - val value: Float? - ) : MinMeasuredValueAttributeSubscriptionState() - + data class Success(val value: Float?) : MinMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MinMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() - } -class MaxMeasuredValueAttribute( - val value: Float? - ) + object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() + } + + class MaxMeasuredValueAttribute(val value: Float?) sealed class MaxMeasuredValueAttributeSubscriptionState { - data class Success( - val value: Float? - ) : MaxMeasuredValueAttributeSubscriptionState() - + data class Success(val value: Float?) : MaxMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MaxMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() - } -class PeakMeasuredValueAttribute( - val value: Float? - ) + object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() + } + + class PeakMeasuredValueAttribute(val value: Float?) sealed class PeakMeasuredValueAttributeSubscriptionState { - data class Success( - val value: Float? - ) : PeakMeasuredValueAttributeSubscriptionState() - + data class Success(val value: Float?) : PeakMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : PeakMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : PeakMeasuredValueAttributeSubscriptionState() - } -class AverageMeasuredValueAttribute( - val value: Float? - ) + object SubscriptionEstablished : PeakMeasuredValueAttributeSubscriptionState() + } + + class AverageMeasuredValueAttribute(val value: Float?) sealed class AverageMeasuredValueAttributeSubscriptionState { - data class Success( - val value: Float? - ) : AverageMeasuredValueAttributeSubscriptionState() - + data class Success(val value: Float?) : AverageMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : AverageMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : AverageMeasuredValueAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : AverageMeasuredValueAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } -suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } + + suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute { + 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}") - } + 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) { - "Measuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Measuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return MeasuredValueAttribute(decodedValue) } suspend fun subscribeMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MeasuredValueAttributeSubscriptionState.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) { - "Measuredvalue attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Measuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute { + 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}") - } + 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) { - "Minmeasuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Minmeasuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return MinMeasuredValueAttribute(decodedValue) } suspend fun subscribeMinMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MinMeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MinMeasuredValueAttributeSubscriptionState.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) { - "Minmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Minmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MinMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute { + 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}") - } + 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) { - "Maxmeasuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Maxmeasuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return MaxMeasuredValueAttribute(decodedValue) } suspend fun subscribeMaxMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MaxMeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MaxMeasuredValueAttributeSubscriptionState.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) { - "Maxmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Maxmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MaxMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPeakMeasuredValueAttribute(): PeakMeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readPeakMeasuredValueAttribute(): PeakMeasuredValueAttribute { + 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}") - } + 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) { - "Peakmeasuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Peakmeasuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return PeakMeasuredValueAttribute(decodedValue) } suspend fun subscribePeakMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(PeakMeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + PeakMeasuredValueAttributeSubscriptionState.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) { - "Peakmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Peakmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(PeakMeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(PeakMeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(PeakMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPeakMeasuredValueWindowAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 4u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readPeakMeasuredValueWindowAttribute(): UInt? { + 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}") - } + 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) { - "Peakmeasuredvaluewindow attribute not found in response" - } + } + + requireNotNull(attributeData) { "Peakmeasuredvaluewindow attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribePeakMeasuredValueWindowAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Peakmeasuredvaluewindow attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Peakmeasuredvaluewindow attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAverageMeasuredValueAttribute(): AverageMeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 5u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readAverageMeasuredValueAttribute(): AverageMeasuredValueAttribute { + 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}") - } + 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) { - "Averagemeasuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Averagemeasuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return AverageMeasuredValueAttribute(decodedValue) } suspend fun subscribeAverageMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(AverageMeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + AverageMeasuredValueAttributeSubscriptionState.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) { - "Averagemeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Averagemeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(AverageMeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(AverageMeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(AverageMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAverageMeasuredValueWindowAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 6u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readAverageMeasuredValueWindowAttribute(): UInt? { + 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}") - } + 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) { - "Averagemeasuredvaluewindow attribute not found in response" - } + } + + requireNotNull(attributeData) { "Averagemeasuredvaluewindow attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeAverageMeasuredValueWindowAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Averagemeasuredvaluewindow attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Averagemeasuredvaluewindow attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readUncertaintyAttribute(): Float? {val ATTRIBUTE_ID: UInt = 7u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readUncertaintyAttribute(): Float? { + 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}") - } + 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) { - "Uncertainty attribute not found in response" - } + } + + requireNotNull(attributeData) { "Uncertainty attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - + val decodedValue: Float? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeUncertaintyAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(FloatSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + FloatSubscriptionState.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) { - "Uncertainty attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Uncertainty attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(FloatSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(FloatSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(FloatSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMeasurementUnitAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 8u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMeasurementUnitAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 8u + + 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}") - } + 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) { - "Measurementunit attribute not found in response" - } + } + + requireNotNull(attributeData) { "Measurementunit 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeMeasurementUnitAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Measurementunit attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Measurementunit 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)) - } - + 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 readMeasurementMediumAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 9u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMeasurementMediumAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 9u + + 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}") - } + 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) { - "Measurementmedium attribute not found in response" - } + } + + requireNotNull(attributeData) { "Measurementmedium 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeMeasurementMediumAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Measurementmedium attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Measurementmedium 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)) - } - + 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 readLevelValueAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 10u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readLevelValueAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 10u + + 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}") - } + 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) { - "Levelvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Levelvalue 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeLevelValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Levelvalue attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Levelvalue 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)) - } - + 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 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1389,97 +1291,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1487,97 +1388,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1585,97 +1483,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1683,81 +1578,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1769,80 +1659,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1855,7 +1742,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/PowerSourceCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/PowerSourceCluster.kt index 835ea746f9a7d8..fa4dd69d99fdd1 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/PowerSourceCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/PowerSourceCluster.kt @@ -17,329 +17,257 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.BooleanSubscriptionState import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest +import matter.controller.StringSubscriptionState import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse -import matter.controller.model.AttributePath -import matter.controller.model.CommandPath +import matter.controller.UShortSubscriptionState import matter.controller.cluster.structs.* +import matter.controller.model.AttributePath import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader -import matter.tlv.TlvWriter -class PowerSourceCluster(private val controller: MatterController, private val endpointId: UShort) {class WiredAssessedInputVoltageAttribute( - val value: UInt? - ) +class PowerSourceCluster(private val controller: MatterController, private val endpointId: UShort) { + class WiredAssessedInputVoltageAttribute(val value: UInt?) sealed class WiredAssessedInputVoltageAttributeSubscriptionState { - data class Success( - val value: UInt? - ) : WiredAssessedInputVoltageAttributeSubscriptionState() - - data class Error(val exception: Exception) : WiredAssessedInputVoltageAttributeSubscriptionState() - - object SubscriptionEstablished : WiredAssessedInputVoltageAttributeSubscriptionState() - } -class WiredAssessedInputFrequencyAttribute( - val value: UShort? - ) + data class Success(val value: UInt?) : WiredAssessedInputVoltageAttributeSubscriptionState() + + data class Error(val exception: Exception) : + WiredAssessedInputVoltageAttributeSubscriptionState() + + object SubscriptionEstablished : WiredAssessedInputVoltageAttributeSubscriptionState() + } + + class WiredAssessedInputFrequencyAttribute(val value: UShort?) sealed class WiredAssessedInputFrequencyAttributeSubscriptionState { - data class Success( - val value: UShort? - ) : WiredAssessedInputFrequencyAttributeSubscriptionState() - - data class Error(val exception: Exception) : WiredAssessedInputFrequencyAttributeSubscriptionState() - - object SubscriptionEstablished : WiredAssessedInputFrequencyAttributeSubscriptionState() - } -class WiredAssessedCurrentAttribute( - val value: UInt? - ) + data class Success(val value: UShort?) : + WiredAssessedInputFrequencyAttributeSubscriptionState() + + data class Error(val exception: Exception) : + WiredAssessedInputFrequencyAttributeSubscriptionState() + + object SubscriptionEstablished : WiredAssessedInputFrequencyAttributeSubscriptionState() + } + + class WiredAssessedCurrentAttribute(val value: UInt?) sealed class WiredAssessedCurrentAttributeSubscriptionState { - data class Success( - val value: UInt? - ) : WiredAssessedCurrentAttributeSubscriptionState() - + data class Success(val value: UInt?) : WiredAssessedCurrentAttributeSubscriptionState() + data class Error(val exception: Exception) : WiredAssessedCurrentAttributeSubscriptionState() - object SubscriptionEstablished : WiredAssessedCurrentAttributeSubscriptionState() - } -class ActiveWiredFaultsAttribute( - val value: List? - ) + object SubscriptionEstablished : WiredAssessedCurrentAttributeSubscriptionState() + } + + class ActiveWiredFaultsAttribute(val value: List?) sealed class ActiveWiredFaultsAttributeSubscriptionState { - data class Success( - val value: List? - ) : ActiveWiredFaultsAttributeSubscriptionState() - + data class Success(val value: List?) : ActiveWiredFaultsAttributeSubscriptionState() + data class Error(val exception: Exception) : ActiveWiredFaultsAttributeSubscriptionState() - object SubscriptionEstablished : ActiveWiredFaultsAttributeSubscriptionState() - } -class BatVoltageAttribute( - val value: UInt? - ) + object SubscriptionEstablished : ActiveWiredFaultsAttributeSubscriptionState() + } + + class BatVoltageAttribute(val value: UInt?) sealed class BatVoltageAttributeSubscriptionState { - data class Success( - val value: UInt? - ) : BatVoltageAttributeSubscriptionState() - + data class Success(val value: UInt?) : BatVoltageAttributeSubscriptionState() + data class Error(val exception: Exception) : BatVoltageAttributeSubscriptionState() - object SubscriptionEstablished : BatVoltageAttributeSubscriptionState() - } -class BatPercentRemainingAttribute( - val value: UByte? - ) + object SubscriptionEstablished : BatVoltageAttributeSubscriptionState() + } + + class BatPercentRemainingAttribute(val value: UByte?) sealed class BatPercentRemainingAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : BatPercentRemainingAttributeSubscriptionState() - + data class Success(val value: UByte?) : BatPercentRemainingAttributeSubscriptionState() + data class Error(val exception: Exception) : BatPercentRemainingAttributeSubscriptionState() - object SubscriptionEstablished : BatPercentRemainingAttributeSubscriptionState() - } -class BatTimeRemainingAttribute( - val value: UInt? - ) + object SubscriptionEstablished : BatPercentRemainingAttributeSubscriptionState() + } + + class BatTimeRemainingAttribute(val value: UInt?) sealed class BatTimeRemainingAttributeSubscriptionState { - data class Success( - val value: UInt? - ) : BatTimeRemainingAttributeSubscriptionState() - + data class Success(val value: UInt?) : BatTimeRemainingAttributeSubscriptionState() + data class Error(val exception: Exception) : BatTimeRemainingAttributeSubscriptionState() - object SubscriptionEstablished : BatTimeRemainingAttributeSubscriptionState() - } -class ActiveBatFaultsAttribute( - val value: List? - ) + object SubscriptionEstablished : BatTimeRemainingAttributeSubscriptionState() + } + + class ActiveBatFaultsAttribute(val value: List?) sealed class ActiveBatFaultsAttributeSubscriptionState { - data class Success( - val value: List? - ) : ActiveBatFaultsAttributeSubscriptionState() - + data class Success(val value: List?) : ActiveBatFaultsAttributeSubscriptionState() + data class Error(val exception: Exception) : ActiveBatFaultsAttributeSubscriptionState() - object SubscriptionEstablished : ActiveBatFaultsAttributeSubscriptionState() - } -class BatTimeToFullChargeAttribute( - val value: UInt? - ) + object SubscriptionEstablished : ActiveBatFaultsAttributeSubscriptionState() + } + + class BatTimeToFullChargeAttribute(val value: UInt?) sealed class BatTimeToFullChargeAttributeSubscriptionState { - data class Success( - val value: UInt? - ) : BatTimeToFullChargeAttributeSubscriptionState() - + data class Success(val value: UInt?) : BatTimeToFullChargeAttributeSubscriptionState() + data class Error(val exception: Exception) : BatTimeToFullChargeAttributeSubscriptionState() - object SubscriptionEstablished : BatTimeToFullChargeAttributeSubscriptionState() - } -class BatChargingCurrentAttribute( - val value: UInt? - ) + object SubscriptionEstablished : BatTimeToFullChargeAttributeSubscriptionState() + } + + class BatChargingCurrentAttribute(val value: UInt?) sealed class BatChargingCurrentAttributeSubscriptionState { - data class Success( - val value: UInt? - ) : BatChargingCurrentAttributeSubscriptionState() - + data class Success(val value: UInt?) : BatChargingCurrentAttributeSubscriptionState() + data class Error(val exception: Exception) : BatChargingCurrentAttributeSubscriptionState() - object SubscriptionEstablished : BatChargingCurrentAttributeSubscriptionState() - } -class ActiveBatChargeFaultsAttribute( - val value: List? - ) + object SubscriptionEstablished : BatChargingCurrentAttributeSubscriptionState() + } + + class ActiveBatChargeFaultsAttribute(val value: List?) sealed class ActiveBatChargeFaultsAttributeSubscriptionState { - data class Success( - val value: List? - ) : ActiveBatChargeFaultsAttributeSubscriptionState() - + data class Success(val value: List?) : ActiveBatChargeFaultsAttributeSubscriptionState() + data class Error(val exception: Exception) : ActiveBatChargeFaultsAttributeSubscriptionState() - object SubscriptionEstablished : ActiveBatChargeFaultsAttributeSubscriptionState() - } -class EndpointListAttribute( - val value: List - ) + object SubscriptionEstablished : ActiveBatChargeFaultsAttributeSubscriptionState() + } + + class EndpointListAttribute(val value: List) sealed class EndpointListAttributeSubscriptionState { - data class Success( - val value: List - ) : EndpointListAttributeSubscriptionState() - + data class Success(val value: List) : EndpointListAttributeSubscriptionState() + data class Error(val exception: Exception) : EndpointListAttributeSubscriptionState() - object SubscriptionEstablished : EndpointListAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : EndpointListAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } -suspend fun readStatusAttribute(): 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) - ) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } + + suspend fun readStatusAttribute(): 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}") - } + 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) { - "Status attribute not found in response" - } + } + + requireNotNull(attributeData) { "Status 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 subscribeStatusAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Status attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Status attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -351,81 +279,76 @@ suspend fun readStatusAttribute(): UByte {val ATTRIBUTE_ID: UInt = 0u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readOrderAttribute(): UByte {val ATTRIBUTE_ID: UInt = 1u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readOrderAttribute(): 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 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}") - } + 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) { - "Order attribute not found in response" - } + } + + requireNotNull(attributeData) { "Order 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 subscribeOrderAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Order attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Order attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -437,81 +360,76 @@ suspend fun readOrderAttribute(): UByte {val ATTRIBUTE_ID: UInt = 1u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readDescriptionAttribute(): String {val ATTRIBUTE_ID: UInt = 2u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readDescriptionAttribute(): String { + 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 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}") - } + 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) { - "Description attribute not found in response" - } + } + + requireNotNull(attributeData) { "Description attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: String = tlvReader.getString(AnonymousTag) - return decodedValue } suspend fun subscribeDescriptionAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StringSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StringSubscriptionState.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) { - "Description attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Description attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -523,2929 +441,2808 @@ suspend fun readDescriptionAttribute(): String {val ATTRIBUTE_ID: UInt = 2u emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readWiredAssessedInputVoltageAttribute(): WiredAssessedInputVoltageAttribute {val ATTRIBUTE_ID: UInt = 3u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readWiredAssessedInputVoltageAttribute(): WiredAssessedInputVoltageAttribute { + 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 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}") - } + 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) { - "Wiredassessedinputvoltage attribute not found in response" - } + } + + requireNotNull(attributeData) { "Wiredassessedinputvoltage attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return WiredAssessedInputVoltageAttribute(decodedValue) } suspend fun subscribeWiredAssessedInputVoltageAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(WiredAssessedInputVoltageAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + WiredAssessedInputVoltageAttributeSubscriptionState.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) { - "Wiredassessedinputvoltage attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Wiredassessedinputvoltage attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } decodedValue?.let { emit(WiredAssessedInputVoltageAttributeSubscriptionState.Success(it)) } - } SubscriptionState.SubscriptionEstablished -> { emit(WiredAssessedInputVoltageAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readWiredAssessedInputFrequencyAttribute(): WiredAssessedInputFrequencyAttribute {val ATTRIBUTE_ID: UInt = 4u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readWiredAssessedInputFrequencyAttribute(): WiredAssessedInputFrequencyAttribute { + 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 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}") - } + 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) { - "Wiredassessedinputfrequency attribute not found in response" - } + } + + requireNotNull(attributeData) { "Wiredassessedinputfrequency attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return WiredAssessedInputFrequencyAttribute(decodedValue) } suspend fun subscribeWiredAssessedInputFrequencyAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(WiredAssessedInputFrequencyAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + WiredAssessedInputFrequencyAttributeSubscriptionState.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) { - "Wiredassessedinputfrequency attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Wiredassessedinputfrequency 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } decodedValue?.let { emit(WiredAssessedInputFrequencyAttributeSubscriptionState.Success(it)) } - } SubscriptionState.SubscriptionEstablished -> { emit(WiredAssessedInputFrequencyAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readWiredCurrentTypeAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 5u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readWiredCurrentTypeAttribute(): UByte? { + 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 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}") - } + 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) { - "Wiredcurrenttype attribute not found in response" - } + } + + requireNotNull(attributeData) { "Wiredcurrenttype 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeWiredCurrentTypeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Wiredcurrenttype attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Wiredcurrenttype 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readWiredAssessedCurrentAttribute(): WiredAssessedCurrentAttribute {val ATTRIBUTE_ID: UInt = 6u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readWiredAssessedCurrentAttribute(): WiredAssessedCurrentAttribute { + 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 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}") - } + 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) { - "Wiredassessedcurrent attribute not found in response" - } + } + + requireNotNull(attributeData) { "Wiredassessedcurrent attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return WiredAssessedCurrentAttribute(decodedValue) } suspend fun subscribeWiredAssessedCurrentAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(WiredAssessedCurrentAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + WiredAssessedCurrentAttributeSubscriptionState.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) { - "Wiredassessedcurrent attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Wiredassessedcurrent attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(WiredAssessedCurrentAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(WiredAssessedCurrentAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(WiredAssessedCurrentAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readWiredNominalVoltageAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 7u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readWiredNominalVoltageAttribute(): UInt? { + 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 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}") - } + 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) { - "Wirednominalvoltage attribute not found in response" - } + } + + requireNotNull(attributeData) { "Wirednominalvoltage attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeWiredNominalVoltageAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Wirednominalvoltage attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Wirednominalvoltage attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readWiredMaximumCurrentAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 8u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readWiredMaximumCurrentAttribute(): UInt? { + val ATTRIBUTE_ID: UInt = 8u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Wiredmaximumcurrent attribute not found in response" - } + } + + requireNotNull(attributeData) { "Wiredmaximumcurrent attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeWiredMaximumCurrentAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Wiredmaximumcurrent attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Wiredmaximumcurrent attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readWiredPresentAttribute(): Boolean? {val ATTRIBUTE_ID: UInt = 9u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readWiredPresentAttribute(): Boolean? { + val ATTRIBUTE_ID: UInt = 9u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Wiredpresent attribute not found in response" - } + } + + requireNotNull(attributeData) { "Wiredpresent 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 - } - + val decodedValue: Boolean? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeWiredPresentAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Wiredpresent attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Wiredpresent 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 - } + val decodedValue: Boolean? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(BooleanSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(BooleanSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readActiveWiredFaultsAttribute(): ActiveWiredFaultsAttribute {val ATTRIBUTE_ID: UInt = 10u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readActiveWiredFaultsAttribute(): ActiveWiredFaultsAttribute { + val ATTRIBUTE_ID: UInt = 10u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Activewiredfaults attribute not found in response" - } + } + + requireNotNull(attributeData) { "Activewiredfaults attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null } - tlvReader.exitContainer() - } - } else { - null - } - return ActiveWiredFaultsAttribute(decodedValue) } suspend fun subscribeActiveWiredFaultsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ActiveWiredFaultsAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ActiveWiredFaultsAttributeSubscriptionState.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) { - "Activewiredfaults attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Activewiredfaults attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { - emit(ActiveWiredFaultsAttributeSubscriptionState.Success(it)) - } - + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { emit(ActiveWiredFaultsAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ActiveWiredFaultsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readBatVoltageAttribute(): BatVoltageAttribute {val ATTRIBUTE_ID: UInt = 11u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readBatVoltageAttribute(): BatVoltageAttribute { + val ATTRIBUTE_ID: UInt = 11u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Batvoltage attribute not found in response" - } + } + + requireNotNull(attributeData) { "Batvoltage attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return BatVoltageAttribute(decodedValue) } suspend fun subscribeBatVoltageAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 11u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(BatVoltageAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + BatVoltageAttributeSubscriptionState.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) { - "Batvoltage attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Batvoltage attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(BatVoltageAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(BatVoltageAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(BatVoltageAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readBatPercentRemainingAttribute(): BatPercentRemainingAttribute {val ATTRIBUTE_ID: UInt = 12u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readBatPercentRemainingAttribute(): BatPercentRemainingAttribute { + val ATTRIBUTE_ID: UInt = 12u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Batpercentremaining attribute not found in response" - } + } + + requireNotNull(attributeData) { "Batpercentremaining attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return BatPercentRemainingAttribute(decodedValue) } suspend fun subscribeBatPercentRemainingAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 12u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(BatPercentRemainingAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + BatPercentRemainingAttributeSubscriptionState.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) { - "Batpercentremaining attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Batpercentremaining 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(BatPercentRemainingAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(BatPercentRemainingAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(BatPercentRemainingAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readBatTimeRemainingAttribute(): BatTimeRemainingAttribute {val ATTRIBUTE_ID: UInt = 13u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readBatTimeRemainingAttribute(): BatTimeRemainingAttribute { + val ATTRIBUTE_ID: UInt = 13u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Battimeremaining attribute not found in response" - } + } + + requireNotNull(attributeData) { "Battimeremaining attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return BatTimeRemainingAttribute(decodedValue) } suspend fun subscribeBatTimeRemainingAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 13u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(BatTimeRemainingAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + BatTimeRemainingAttributeSubscriptionState.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) { - "Battimeremaining attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Battimeremaining attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(BatTimeRemainingAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(BatTimeRemainingAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(BatTimeRemainingAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readBatChargeLevelAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 14u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readBatChargeLevelAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 14u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Batchargelevel attribute not found in response" - } + } + + requireNotNull(attributeData) { "Batchargelevel 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeBatChargeLevelAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 14u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Batchargelevel attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Batchargelevel 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readBatReplacementNeededAttribute(): Boolean? {val ATTRIBUTE_ID: UInt = 15u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readBatReplacementNeededAttribute(): Boolean? { + val ATTRIBUTE_ID: UInt = 15u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Batreplacementneeded attribute not found in response" - } + } + + requireNotNull(attributeData) { "Batreplacementneeded 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 - } - + val decodedValue: Boolean? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeBatReplacementNeededAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 15u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Batreplacementneeded attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Batreplacementneeded 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 - } + val decodedValue: Boolean? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(BooleanSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(BooleanSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readBatReplaceabilityAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 16u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readBatReplaceabilityAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 16u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Batreplaceability attribute not found in response" - } + } + + requireNotNull(attributeData) { "Batreplaceability 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeBatReplaceabilityAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Batreplaceability attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Batreplaceability 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readBatPresentAttribute(): Boolean? {val ATTRIBUTE_ID: UInt = 17u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readBatPresentAttribute(): Boolean? { + val ATTRIBUTE_ID: UInt = 17u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Batpresent attribute not found in response" - } + } + + requireNotNull(attributeData) { "Batpresent 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 - } - + val decodedValue: Boolean? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeBatPresentAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 17u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Batpresent attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Batpresent 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 - } + val decodedValue: Boolean? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(BooleanSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(BooleanSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readActiveBatFaultsAttribute(): ActiveBatFaultsAttribute {val ATTRIBUTE_ID: UInt = 18u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readActiveBatFaultsAttribute(): ActiveBatFaultsAttribute { + val ATTRIBUTE_ID: UInt = 18u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Activebatfaults attribute not found in response" - } + } + + requireNotNull(attributeData) { "Activebatfaults attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null } - tlvReader.exitContainer() - } - } else { - null - } - return ActiveBatFaultsAttribute(decodedValue) } suspend fun subscribeActiveBatFaultsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 18u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ActiveBatFaultsAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ActiveBatFaultsAttributeSubscriptionState.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) { - "Activebatfaults attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Activebatfaults attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { - emit(ActiveBatFaultsAttributeSubscriptionState.Success(it)) - } - + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { emit(ActiveBatFaultsAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ActiveBatFaultsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readBatReplacementDescriptionAttribute(): String? {val ATTRIBUTE_ID: UInt = 19u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readBatReplacementDescriptionAttribute(): String? { + val ATTRIBUTE_ID: UInt = 19u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Batreplacementdescription attribute not found in response" - } + } + + requireNotNull(attributeData) { "Batreplacementdescription attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeBatReplacementDescriptionAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 19u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StringSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StringSubscriptionState.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) { - "Batreplacementdescription attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Batreplacementdescription attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(StringSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(StringSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readBatCommonDesignationAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 20u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readBatCommonDesignationAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 20u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Batcommondesignation attribute not found in response" - } + } + + requireNotNull(attributeData) { "Batcommondesignation 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeBatCommonDesignationAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 20u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Batcommondesignation attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Batcommondesignation 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readBatANSIDesignationAttribute(): String? {val ATTRIBUTE_ID: UInt = 21u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readBatANSIDesignationAttribute(): String? { + val ATTRIBUTE_ID: UInt = 21u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Batansidesignation attribute not found in response" - } + } + + requireNotNull(attributeData) { "Batansidesignation attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeBatANSIDesignationAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 21u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StringSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StringSubscriptionState.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) { - "Batansidesignation attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Batansidesignation attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(StringSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(StringSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readBatIECDesignationAttribute(): String? {val ATTRIBUTE_ID: UInt = 22u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readBatIECDesignationAttribute(): String? { + val ATTRIBUTE_ID: UInt = 22u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Batiecdesignation attribute not found in response" - } + } + + requireNotNull(attributeData) { "Batiecdesignation attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeBatIECDesignationAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 22u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StringSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StringSubscriptionState.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) { - "Batiecdesignation attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Batiecdesignation attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(StringSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(StringSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readBatApprovedChemistryAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 23u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readBatApprovedChemistryAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 23u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Batapprovedchemistry attribute not found in response" - } + } + + requireNotNull(attributeData) { "Batapprovedchemistry 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeBatApprovedChemistryAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 23u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Batapprovedchemistry attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Batapprovedchemistry 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readBatCapacityAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 24u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readBatCapacityAttribute(): UInt? { + val ATTRIBUTE_ID: UInt = 24u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Batcapacity attribute not found in response" - } + } + + requireNotNull(attributeData) { "Batcapacity attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeBatCapacityAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 24u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Batcapacity attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Batcapacity attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readBatQuantityAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 25u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readBatQuantityAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 25u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Batquantity attribute not found in response" - } + } + + requireNotNull(attributeData) { "Batquantity 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeBatQuantityAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 25u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Batquantity attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Batquantity 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readBatChargeStateAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 26u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readBatChargeStateAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 26u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Batchargestate attribute not found in response" - } + } + + requireNotNull(attributeData) { "Batchargestate 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeBatChargeStateAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 26u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Batchargestate attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Batchargestate 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readBatTimeToFullChargeAttribute(): BatTimeToFullChargeAttribute {val ATTRIBUTE_ID: UInt = 27u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readBatTimeToFullChargeAttribute(): BatTimeToFullChargeAttribute { + val ATTRIBUTE_ID: UInt = 27u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Battimetofullcharge attribute not found in response" - } + } + + requireNotNull(attributeData) { "Battimetofullcharge attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return BatTimeToFullChargeAttribute(decodedValue) } suspend fun subscribeBatTimeToFullChargeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 27u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(BatTimeToFullChargeAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + BatTimeToFullChargeAttributeSubscriptionState.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) { - "Battimetofullcharge attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Battimetofullcharge attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(BatTimeToFullChargeAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(BatTimeToFullChargeAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(BatTimeToFullChargeAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readBatFunctionalWhileChargingAttribute(): Boolean? {val ATTRIBUTE_ID: UInt = 28u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readBatFunctionalWhileChargingAttribute(): Boolean? { + val ATTRIBUTE_ID: UInt = 28u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Batfunctionalwhilecharging attribute not found in response" - } + } + + requireNotNull(attributeData) { "Batfunctionalwhilecharging 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 - } - + val decodedValue: Boolean? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeBatFunctionalWhileChargingAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 28u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Batfunctionalwhilecharging attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Batfunctionalwhilecharging 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 - } + val decodedValue: Boolean? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(BooleanSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(BooleanSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readBatChargingCurrentAttribute(): BatChargingCurrentAttribute {val ATTRIBUTE_ID: UInt = 29u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readBatChargingCurrentAttribute(): BatChargingCurrentAttribute { + val ATTRIBUTE_ID: UInt = 29u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Batchargingcurrent attribute not found in response" - } + } + + requireNotNull(attributeData) { "Batchargingcurrent attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return BatChargingCurrentAttribute(decodedValue) } suspend fun subscribeBatChargingCurrentAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 29u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(BatChargingCurrentAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + BatChargingCurrentAttributeSubscriptionState.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) { - "Batchargingcurrent attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Batchargingcurrent attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(BatChargingCurrentAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(BatChargingCurrentAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(BatChargingCurrentAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readActiveBatChargeFaultsAttribute(): ActiveBatChargeFaultsAttribute {val ATTRIBUTE_ID: UInt = 30u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readActiveBatChargeFaultsAttribute(): ActiveBatChargeFaultsAttribute { + val ATTRIBUTE_ID: UInt = 30u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Activebatchargefaults attribute not found in response" - } + } + + requireNotNull(attributeData) { "Activebatchargefaults attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null } - tlvReader.exitContainer() - } - } else { - null - } - return ActiveBatChargeFaultsAttribute(decodedValue) } suspend fun subscribeActiveBatChargeFaultsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 30u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ActiveBatChargeFaultsAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ActiveBatChargeFaultsAttributeSubscriptionState.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) { - "Activebatchargefaults attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Activebatchargefaults attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { - emit(ActiveBatChargeFaultsAttributeSubscriptionState.Success(it)) - } - + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { emit(ActiveBatChargeFaultsAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ActiveBatChargeFaultsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readEndpointListAttribute(): EndpointListAttribute {val ATTRIBUTE_ID: UInt = 31u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readEndpointListAttribute(): EndpointListAttribute { + val ATTRIBUTE_ID: UInt = 31u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Endpointlist attribute not found in response" - } + } + + requireNotNull(attributeData) { "Endpointlist 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.getUShort(AnonymousTag)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUShort(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EndpointListAttribute(decodedValue) } suspend fun subscribeEndpointListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 31u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(EndpointListAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + EndpointListAttributeSubscriptionState.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) { - "Endpointlist attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Endpointlist 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.getUShort(AnonymousTag)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUShort(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EndpointListAttributeSubscriptionState.Success(decodedValue)) } @@ -3453,97 +3250,96 @@ suspend fun readEndpointListAttribute(): EndpointListAttribute {val ATTRIBUTE_ID emit(EndpointListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65528u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -3551,97 +3347,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { emit(GeneratedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65529u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -3649,97 +3444,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va emit(AcceptedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt = 65530u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -3747,97 +3539,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt emit(EventListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ID: UInt = 65531u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -3845,81 +3634,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ emit(AttributeListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -3931,80 +3715,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 65533u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -4017,7 +3798,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/PowerSourceConfigurationCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/PowerSourceConfigurationCluster.kt index 59bfeff63ee455..edf0fe59a8a295 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/PowerSourceConfigurationCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/PowerSourceConfigurationCluster.kt @@ -17,202 +17,162 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState -import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse -import matter.controller.model.AttributePath -import matter.controller.model.CommandPath +import matter.controller.UShortSubscriptionState import matter.controller.cluster.structs.* +import matter.controller.model.AttributePath import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader -import matter.tlv.TlvWriter -class PowerSourceConfigurationCluster(private val controller: MatterController, private val endpointId: UShort) {class SourcesAttribute( - val value: List - ) +class PowerSourceConfigurationCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class SourcesAttribute(val value: List) sealed class SourcesAttributeSubscriptionState { - data class Success( - val value: List - ) : SourcesAttributeSubscriptionState() - + data class Success(val value: List) : SourcesAttributeSubscriptionState() + data class Error(val exception: Exception) : SourcesAttributeSubscriptionState() - object SubscriptionEstablished : SourcesAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : SourcesAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } -suspend fun readSourcesAttribute(): SourcesAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } + + suspend fun readSourcesAttribute(): SourcesAttribute { + 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}") - } + 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) { - "Sources attribute not found in response" - } + } + + requireNotNull(attributeData) { "Sources 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.getUShort(AnonymousTag)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUShort(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return SourcesAttribute(decodedValue) } suspend fun subscribeSourcesAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(SourcesAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + SourcesAttributeSubscriptionState.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) { - "Sources attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Sources 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.getUShort(AnonymousTag)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUShort(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(SourcesAttributeSubscriptionState.Success(decodedValue)) } @@ -220,97 +180,96 @@ suspend fun readSourcesAttribute(): SourcesAttribute {val ATTRIBUTE_ID: UInt = 0 emit(SourcesAttributeSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -318,97 +277,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -416,97 +374,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -514,97 +469,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -612,81 +564,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -698,80 +645,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -784,7 +728,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/PowerTopologyCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/PowerTopologyCluster.kt index 2555983a6cc8b5..276501e391d049 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/PowerTopologyCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/PowerTopologyCluster.kt @@ -17,433 +17,384 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState -import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse -import matter.controller.model.AttributePath -import matter.controller.model.CommandPath +import matter.controller.UShortSubscriptionState import matter.controller.cluster.structs.* +import matter.controller.model.AttributePath import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader -import matter.tlv.TlvWriter -class PowerTopologyCluster(private val controller: MatterController, private val endpointId: UShort) {class AvailableEndpointsAttribute( - val value: List? - ) +class PowerTopologyCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class AvailableEndpointsAttribute(val value: List?) sealed class AvailableEndpointsAttributeSubscriptionState { - data class Success( - val value: List? - ) : AvailableEndpointsAttributeSubscriptionState() - + data class Success(val value: List?) : AvailableEndpointsAttributeSubscriptionState() + data class Error(val exception: Exception) : AvailableEndpointsAttributeSubscriptionState() - object SubscriptionEstablished : AvailableEndpointsAttributeSubscriptionState() - } -class ActiveEndpointsAttribute( - val value: List? - ) + object SubscriptionEstablished : AvailableEndpointsAttributeSubscriptionState() + } + + class ActiveEndpointsAttribute(val value: List?) sealed class ActiveEndpointsAttributeSubscriptionState { - data class Success( - val value: List? - ) : ActiveEndpointsAttributeSubscriptionState() - + data class Success(val value: List?) : ActiveEndpointsAttributeSubscriptionState() + data class Error(val exception: Exception) : ActiveEndpointsAttributeSubscriptionState() - object SubscriptionEstablished : ActiveEndpointsAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : ActiveEndpointsAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } -suspend fun readAvailableEndpointsAttribute(): AvailableEndpointsAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } + + suspend fun readAvailableEndpointsAttribute(): AvailableEndpointsAttribute { + 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}") - } + 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) { - "Availableendpoints attribute not found in response" - } + } + + requireNotNull(attributeData) { "Availableendpoints attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getUShort(AnonymousTag)) + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUShort(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null } - tlvReader.exitContainer() - } - } else { - null - } - return AvailableEndpointsAttribute(decodedValue) } suspend fun subscribeAvailableEndpointsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(AvailableEndpointsAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + AvailableEndpointsAttributeSubscriptionState.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) { - "Availableendpoints attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Availableendpoints attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getUShort(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { - emit(AvailableEndpointsAttributeSubscriptionState.Success(it)) - } - + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUShort(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { emit(AvailableEndpointsAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(AvailableEndpointsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readActiveEndpointsAttribute(): ActiveEndpointsAttribute {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readActiveEndpointsAttribute(): ActiveEndpointsAttribute { + 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}") - } + 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) { - "Activeendpoints attribute not found in response" - } + } + + requireNotNull(attributeData) { "Activeendpoints attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getUShort(AnonymousTag)) + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUShort(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null } - tlvReader.exitContainer() - } - } else { - null - } - return ActiveEndpointsAttribute(decodedValue) } suspend fun subscribeActiveEndpointsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ActiveEndpointsAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ActiveEndpointsAttributeSubscriptionState.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) { - "Activeendpoints attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Activeendpoints attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getUShort(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { - emit(ActiveEndpointsAttributeSubscriptionState.Success(it)) - } - + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUShort(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { emit(ActiveEndpointsAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ActiveEndpointsAttributeSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -451,97 +402,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -549,97 +499,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -647,97 +594,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -745,81 +689,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -831,80 +770,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -917,7 +853,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/PressureMeasurementCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/PressureMeasurementCluster.kt index e8726e5f3a3cac..fe46298d0def38 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/PressureMeasurementCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/PressureMeasurementCluster.kt @@ -17,1176 +17,1080 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.ByteSubscriptionState import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState -import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse -import matter.controller.model.AttributePath -import matter.controller.model.CommandPath +import matter.controller.UShortSubscriptionState import matter.controller.cluster.structs.* +import matter.controller.model.AttributePath import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader -import matter.tlv.TlvWriter -class PressureMeasurementCluster(private val controller: MatterController, private val endpointId: UShort) {class MeasuredValueAttribute( - val value: Short? - ) +class PressureMeasurementCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class MeasuredValueAttribute(val value: Short?) sealed class MeasuredValueAttributeSubscriptionState { - data class Success( - val value: Short? - ) : MeasuredValueAttributeSubscriptionState() - + data class Success(val value: Short?) : MeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() - } -class MinMeasuredValueAttribute( - val value: Short? - ) + object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() + } + + class MinMeasuredValueAttribute(val value: Short?) sealed class MinMeasuredValueAttributeSubscriptionState { - data class Success( - val value: Short? - ) : MinMeasuredValueAttributeSubscriptionState() - + data class Success(val value: Short?) : MinMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MinMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() - } -class MaxMeasuredValueAttribute( - val value: Short? - ) + object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() + } + + class MaxMeasuredValueAttribute(val value: Short?) sealed class MaxMeasuredValueAttributeSubscriptionState { - data class Success( - val value: Short? - ) : MaxMeasuredValueAttributeSubscriptionState() - + data class Success(val value: Short?) : MaxMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MaxMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() - } -class ScaledValueAttribute( - val value: Short? - ) + object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() + } + + class ScaledValueAttribute(val value: Short?) sealed class ScaledValueAttributeSubscriptionState { - data class Success( - val value: Short? - ) : ScaledValueAttributeSubscriptionState() - + data class Success(val value: Short?) : ScaledValueAttributeSubscriptionState() + data class Error(val exception: Exception) : ScaledValueAttributeSubscriptionState() - object SubscriptionEstablished : ScaledValueAttributeSubscriptionState() - } -class MinScaledValueAttribute( - val value: Short? - ) + object SubscriptionEstablished : ScaledValueAttributeSubscriptionState() + } + + class MinScaledValueAttribute(val value: Short?) sealed class MinScaledValueAttributeSubscriptionState { - data class Success( - val value: Short? - ) : MinScaledValueAttributeSubscriptionState() - + data class Success(val value: Short?) : MinScaledValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MinScaledValueAttributeSubscriptionState() - object SubscriptionEstablished : MinScaledValueAttributeSubscriptionState() - } -class MaxScaledValueAttribute( - val value: Short? - ) + object SubscriptionEstablished : MinScaledValueAttributeSubscriptionState() + } + + class MaxScaledValueAttribute(val value: Short?) sealed class MaxScaledValueAttributeSubscriptionState { - data class Success( - val value: Short? - ) : MaxScaledValueAttributeSubscriptionState() - + data class Success(val value: Short?) : MaxScaledValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MaxScaledValueAttributeSubscriptionState() - object SubscriptionEstablished : MaxScaledValueAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : MaxScaledValueAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } -suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } + + suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute { + 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}") - } + 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) { - "Measuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Measuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (!tlvReader.isNull()) { - tlvReader.getShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Short? = + if (!tlvReader.isNull()) { + tlvReader.getShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return MeasuredValueAttribute(decodedValue) } suspend fun subscribeMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MeasuredValueAttributeSubscriptionState.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) { - "Measuredvalue attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Measuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (!tlvReader.isNull()) { - tlvReader.getShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Short? = + if (!tlvReader.isNull()) { + tlvReader.getShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute { + 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}") - } + 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) { - "Minmeasuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Minmeasuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (!tlvReader.isNull()) { - tlvReader.getShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Short? = + if (!tlvReader.isNull()) { + tlvReader.getShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return MinMeasuredValueAttribute(decodedValue) } suspend fun subscribeMinMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MinMeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MinMeasuredValueAttributeSubscriptionState.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) { - "Minmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Minmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (!tlvReader.isNull()) { - tlvReader.getShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Short? = + if (!tlvReader.isNull()) { + tlvReader.getShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MinMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute { + 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}") - } + 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) { - "Maxmeasuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Maxmeasuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (!tlvReader.isNull()) { - tlvReader.getShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Short? = + if (!tlvReader.isNull()) { + tlvReader.getShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return MaxMeasuredValueAttribute(decodedValue) } suspend fun subscribeMaxMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MaxMeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MaxMeasuredValueAttributeSubscriptionState.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) { - "Maxmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Maxmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (!tlvReader.isNull()) { - tlvReader.getShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Short? = + if (!tlvReader.isNull()) { + tlvReader.getShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MaxMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readToleranceAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readToleranceAttribute(): UShort? { + 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}") - } + 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) { - "Tolerance attribute not found in response" - } + } + + requireNotNull(attributeData) { "Tolerance 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeToleranceAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Tolerance attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Tolerance 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)) - } - + 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 readScaledValueAttribute(): ScaledValueAttribute {val ATTRIBUTE_ID: UInt = 16u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readScaledValueAttribute(): ScaledValueAttribute { + val ATTRIBUTE_ID: UInt = 16u + + 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}") - } + 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) { - "Scaledvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Scaledvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Short? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return ScaledValueAttribute(decodedValue) } suspend fun subscribeScaledValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ScaledValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ScaledValueAttributeSubscriptionState.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) { - "Scaledvalue attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Scaledvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(ScaledValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Short? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(ScaledValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ScaledValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMinScaledValueAttribute(): MinScaledValueAttribute {val ATTRIBUTE_ID: UInt = 17u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMinScaledValueAttribute(): MinScaledValueAttribute { + val ATTRIBUTE_ID: UInt = 17u + + 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}") - } + 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) { - "Minscaledvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Minscaledvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Short? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return MinScaledValueAttribute(decodedValue) } suspend fun subscribeMinScaledValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 17u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MinScaledValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MinScaledValueAttributeSubscriptionState.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) { - "Minscaledvalue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Minscaledvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MinScaledValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Short? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MinScaledValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MinScaledValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMaxScaledValueAttribute(): MaxScaledValueAttribute {val ATTRIBUTE_ID: UInt = 18u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMaxScaledValueAttribute(): MaxScaledValueAttribute { + val ATTRIBUTE_ID: UInt = 18u + + 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}") - } + 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) { - "Maxscaledvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Maxscaledvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Short? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return MaxScaledValueAttribute(decodedValue) } suspend fun subscribeMaxScaledValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 18u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MaxScaledValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MaxScaledValueAttributeSubscriptionState.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) { - "Maxscaledvalue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Maxscaledvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MaxScaledValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Short? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MaxScaledValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MaxScaledValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readScaledToleranceAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 19u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readScaledToleranceAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 19u + + 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}") - } + 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) { - "Scaledtolerance attribute not found in response" - } + } + + requireNotNull(attributeData) { "Scaledtolerance 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeScaledToleranceAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 19u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Scaledtolerance attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Scaledtolerance 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)) - } - + 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 readScaleAttribute(): Byte? {val ATTRIBUTE_ID: UInt = 20u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readScaleAttribute(): Byte? { + val ATTRIBUTE_ID: UInt = 20u + + 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}") - } + 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) { - "Scale attribute not found in response" - } + } + + requireNotNull(attributeData) { "Scale attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Byte? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByte(AnonymousTag) - } else { - null - } - + val decodedValue: Byte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeScaleAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 20u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ByteSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ByteSubscriptionState.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) { - "Scale attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Scale attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Byte? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByte(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(ByteSubscriptionState.Success(it)) - } - + val decodedValue: Byte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByte(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(ByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ByteSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1194,97 +1098,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1292,97 +1195,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1390,97 +1290,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1488,81 +1385,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1574,80 +1466,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1660,7 +1549,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/ProxyConfigurationCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/ProxyConfigurationCluster.kt index b08df6933b9fd1..30c37cc34c5ccb 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/ProxyConfigurationCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/ProxyConfigurationCluster.kt @@ -17,189 +17,154 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState -import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse -import matter.controller.model.AttributePath -import matter.controller.model.CommandPath +import matter.controller.UShortSubscriptionState import matter.controller.cluster.structs.* +import matter.controller.model.AttributePath import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader -import matter.tlv.TlvWriter -class ProxyConfigurationCluster(private val controller: MatterController, private val endpointId: UShort) {class GeneratedCommandListAttribute( - val value: List - ) +class ProxyConfigurationCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } -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) - ) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -207,97 +172,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -305,97 +269,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -403,97 +364,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -501,81 +459,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -587,80 +540,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -673,7 +623,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/ProxyDiscoveryCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/ProxyDiscoveryCluster.kt index 42d50e762f785c..b3059610100e44 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/ProxyDiscoveryCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/ProxyDiscoveryCluster.kt @@ -17,189 +17,154 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState -import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse -import matter.controller.model.AttributePath -import matter.controller.model.CommandPath +import matter.controller.UShortSubscriptionState import matter.controller.cluster.structs.* +import matter.controller.model.AttributePath import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader -import matter.tlv.TlvWriter -class ProxyDiscoveryCluster(private val controller: MatterController, private val endpointId: UShort) {class GeneratedCommandListAttribute( - val value: List - ) +class ProxyDiscoveryCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } -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) - ) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -207,97 +172,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -305,97 +269,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -403,97 +364,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -501,81 +459,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -587,80 +540,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -673,7 +623,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/ProxyValidCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/ProxyValidCluster.kt index 79217bb65e2c72..c615844ad6a6f3 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/ProxyValidCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/ProxyValidCluster.kt @@ -17,189 +17,151 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState -import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse -import matter.controller.model.AttributePath -import matter.controller.model.CommandPath +import matter.controller.UShortSubscriptionState import matter.controller.cluster.structs.* +import matter.controller.model.AttributePath import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader -import matter.tlv.TlvWriter -class ProxyValidCluster(private val controller: MatterController, private val endpointId: UShort) {class GeneratedCommandListAttribute( - val value: List - ) +class ProxyValidCluster(private val controller: MatterController, private val endpointId: UShort) { + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } -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) - ) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -207,97 +169,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -305,97 +266,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -403,97 +361,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -501,81 +456,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -587,80 +537,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -673,7 +620,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/PulseWidthModulationCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/PulseWidthModulationCluster.kt index 0ae147a5169862..e4548cf40a2413 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/PulseWidthModulationCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/PulseWidthModulationCluster.kt @@ -17,189 +17,154 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState -import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse -import matter.controller.model.AttributePath -import matter.controller.model.CommandPath +import matter.controller.UShortSubscriptionState import matter.controller.cluster.structs.* +import matter.controller.model.AttributePath import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader -import matter.tlv.TlvWriter -class PulseWidthModulationCluster(private val controller: MatterController, private val endpointId: UShort) {class GeneratedCommandListAttribute( - val value: List - ) +class PulseWidthModulationCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } -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) - ) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -207,97 +172,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -305,97 +269,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -403,97 +364,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -501,81 +459,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -587,80 +540,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -673,7 +623,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/PumpConfigurationAndControlCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/PumpConfigurationAndControlCluster.kt index 77f27057b0a555..a39b8376dfd650 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/PumpConfigurationAndControlCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/PumpConfigurationAndControlCluster.kt @@ -17,1870 +17,1708 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse -import matter.controller.model.AttributePath -import matter.controller.model.CommandPath import matter.controller.cluster.structs.* +import matter.controller.model.AttributePath import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class PumpConfigurationAndControlCluster(private val controller: MatterController, private val endpointId: UShort) {class MaxPressureAttribute( - val value: Short? - ) +class PumpConfigurationAndControlCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class MaxPressureAttribute(val value: Short?) sealed class MaxPressureAttributeSubscriptionState { - data class Success( - val value: Short? - ) : MaxPressureAttributeSubscriptionState() - + data class Success(val value: Short?) : MaxPressureAttributeSubscriptionState() + data class Error(val exception: Exception) : MaxPressureAttributeSubscriptionState() - object SubscriptionEstablished : MaxPressureAttributeSubscriptionState() - } -class MaxSpeedAttribute( - val value: UShort? - ) + object SubscriptionEstablished : MaxPressureAttributeSubscriptionState() + } + + class MaxSpeedAttribute(val value: UShort?) sealed class MaxSpeedAttributeSubscriptionState { - data class Success( - val value: UShort? - ) : MaxSpeedAttributeSubscriptionState() - + data class Success(val value: UShort?) : MaxSpeedAttributeSubscriptionState() + data class Error(val exception: Exception) : MaxSpeedAttributeSubscriptionState() - object SubscriptionEstablished : MaxSpeedAttributeSubscriptionState() - } -class MaxFlowAttribute( - val value: UShort? - ) + object SubscriptionEstablished : MaxSpeedAttributeSubscriptionState() + } + + class MaxFlowAttribute(val value: UShort?) sealed class MaxFlowAttributeSubscriptionState { - data class Success( - val value: UShort? - ) : MaxFlowAttributeSubscriptionState() - + data class Success(val value: UShort?) : MaxFlowAttributeSubscriptionState() + data class Error(val exception: Exception) : MaxFlowAttributeSubscriptionState() - object SubscriptionEstablished : MaxFlowAttributeSubscriptionState() - } -class MinConstPressureAttribute( - val value: Short? - ) + object SubscriptionEstablished : MaxFlowAttributeSubscriptionState() + } + + class MinConstPressureAttribute(val value: Short?) sealed class MinConstPressureAttributeSubscriptionState { - data class Success( - val value: Short? - ) : MinConstPressureAttributeSubscriptionState() - + data class Success(val value: Short?) : MinConstPressureAttributeSubscriptionState() + data class Error(val exception: Exception) : MinConstPressureAttributeSubscriptionState() - object SubscriptionEstablished : MinConstPressureAttributeSubscriptionState() - } -class MaxConstPressureAttribute( - val value: Short? - ) + object SubscriptionEstablished : MinConstPressureAttributeSubscriptionState() + } + + class MaxConstPressureAttribute(val value: Short?) sealed class MaxConstPressureAttributeSubscriptionState { - data class Success( - val value: Short? - ) : MaxConstPressureAttributeSubscriptionState() - + data class Success(val value: Short?) : MaxConstPressureAttributeSubscriptionState() + data class Error(val exception: Exception) : MaxConstPressureAttributeSubscriptionState() - object SubscriptionEstablished : MaxConstPressureAttributeSubscriptionState() - } -class MinCompPressureAttribute( - val value: Short? - ) + object SubscriptionEstablished : MaxConstPressureAttributeSubscriptionState() + } + + class MinCompPressureAttribute(val value: Short?) sealed class MinCompPressureAttributeSubscriptionState { - data class Success( - val value: Short? - ) : MinCompPressureAttributeSubscriptionState() - + data class Success(val value: Short?) : MinCompPressureAttributeSubscriptionState() + data class Error(val exception: Exception) : MinCompPressureAttributeSubscriptionState() - object SubscriptionEstablished : MinCompPressureAttributeSubscriptionState() - } -class MaxCompPressureAttribute( - val value: Short? - ) + object SubscriptionEstablished : MinCompPressureAttributeSubscriptionState() + } + + class MaxCompPressureAttribute(val value: Short?) sealed class MaxCompPressureAttributeSubscriptionState { - data class Success( - val value: Short? - ) : MaxCompPressureAttributeSubscriptionState() - + data class Success(val value: Short?) : MaxCompPressureAttributeSubscriptionState() + data class Error(val exception: Exception) : MaxCompPressureAttributeSubscriptionState() - object SubscriptionEstablished : MaxCompPressureAttributeSubscriptionState() - } -class MinConstSpeedAttribute( - val value: UShort? - ) + object SubscriptionEstablished : MaxCompPressureAttributeSubscriptionState() + } + + class MinConstSpeedAttribute(val value: UShort?) sealed class MinConstSpeedAttributeSubscriptionState { - data class Success( - val value: UShort? - ) : MinConstSpeedAttributeSubscriptionState() - + data class Success(val value: UShort?) : MinConstSpeedAttributeSubscriptionState() + data class Error(val exception: Exception) : MinConstSpeedAttributeSubscriptionState() - object SubscriptionEstablished : MinConstSpeedAttributeSubscriptionState() - } -class MaxConstSpeedAttribute( - val value: UShort? - ) + object SubscriptionEstablished : MinConstSpeedAttributeSubscriptionState() + } + + class MaxConstSpeedAttribute(val value: UShort?) sealed class MaxConstSpeedAttributeSubscriptionState { - data class Success( - val value: UShort? - ) : MaxConstSpeedAttributeSubscriptionState() - + data class Success(val value: UShort?) : MaxConstSpeedAttributeSubscriptionState() + data class Error(val exception: Exception) : MaxConstSpeedAttributeSubscriptionState() - object SubscriptionEstablished : MaxConstSpeedAttributeSubscriptionState() - } -class MinConstFlowAttribute( - val value: UShort? - ) + object SubscriptionEstablished : MaxConstSpeedAttributeSubscriptionState() + } + + class MinConstFlowAttribute(val value: UShort?) sealed class MinConstFlowAttributeSubscriptionState { - data class Success( - val value: UShort? - ) : MinConstFlowAttributeSubscriptionState() - + data class Success(val value: UShort?) : MinConstFlowAttributeSubscriptionState() + data class Error(val exception: Exception) : MinConstFlowAttributeSubscriptionState() - object SubscriptionEstablished : MinConstFlowAttributeSubscriptionState() - } -class MaxConstFlowAttribute( - val value: UShort? - ) + object SubscriptionEstablished : MinConstFlowAttributeSubscriptionState() + } + + class MaxConstFlowAttribute(val value: UShort?) sealed class MaxConstFlowAttributeSubscriptionState { - data class Success( - val value: UShort? - ) : MaxConstFlowAttributeSubscriptionState() - + data class Success(val value: UShort?) : MaxConstFlowAttributeSubscriptionState() + data class Error(val exception: Exception) : MaxConstFlowAttributeSubscriptionState() - object SubscriptionEstablished : MaxConstFlowAttributeSubscriptionState() - } -class MinConstTempAttribute( - val value: Short? - ) + object SubscriptionEstablished : MaxConstFlowAttributeSubscriptionState() + } + + class MinConstTempAttribute(val value: Short?) sealed class MinConstTempAttributeSubscriptionState { - data class Success( - val value: Short? - ) : MinConstTempAttributeSubscriptionState() - + data class Success(val value: Short?) : MinConstTempAttributeSubscriptionState() + data class Error(val exception: Exception) : MinConstTempAttributeSubscriptionState() - object SubscriptionEstablished : MinConstTempAttributeSubscriptionState() - } -class MaxConstTempAttribute( - val value: Short? - ) + object SubscriptionEstablished : MinConstTempAttributeSubscriptionState() + } + + class MaxConstTempAttribute(val value: Short?) sealed class MaxConstTempAttributeSubscriptionState { - data class Success( - val value: Short? - ) : MaxConstTempAttributeSubscriptionState() - + data class Success(val value: Short?) : MaxConstTempAttributeSubscriptionState() + data class Error(val exception: Exception) : MaxConstTempAttributeSubscriptionState() - object SubscriptionEstablished : MaxConstTempAttributeSubscriptionState() - } -class CapacityAttribute( - val value: Short? - ) + object SubscriptionEstablished : MaxConstTempAttributeSubscriptionState() + } + + class CapacityAttribute(val value: Short?) sealed class CapacityAttributeSubscriptionState { - data class Success( - val value: Short? - ) : CapacityAttributeSubscriptionState() - + data class Success(val value: Short?) : CapacityAttributeSubscriptionState() + data class Error(val exception: Exception) : CapacityAttributeSubscriptionState() - object SubscriptionEstablished : CapacityAttributeSubscriptionState() - } -class SpeedAttribute( - val value: UShort? - ) + object SubscriptionEstablished : CapacityAttributeSubscriptionState() + } + + class SpeedAttribute(val value: UShort?) sealed class SpeedAttributeSubscriptionState { - data class Success( - val value: UShort? - ) : SpeedAttributeSubscriptionState() - + data class Success(val value: UShort?) : SpeedAttributeSubscriptionState() + data class Error(val exception: Exception) : SpeedAttributeSubscriptionState() - object SubscriptionEstablished : SpeedAttributeSubscriptionState() - } -class LifetimeRunningHoursAttribute( - val value: UInt? - ) + object SubscriptionEstablished : SpeedAttributeSubscriptionState() + } + + class LifetimeRunningHoursAttribute(val value: UInt?) sealed class LifetimeRunningHoursAttributeSubscriptionState { - data class Success( - val value: UInt? - ) : LifetimeRunningHoursAttributeSubscriptionState() - + data class Success(val value: UInt?) : LifetimeRunningHoursAttributeSubscriptionState() + data class Error(val exception: Exception) : LifetimeRunningHoursAttributeSubscriptionState() - object SubscriptionEstablished : LifetimeRunningHoursAttributeSubscriptionState() - } -class PowerAttribute( - val value: UInt? - ) + object SubscriptionEstablished : LifetimeRunningHoursAttributeSubscriptionState() + } + + class PowerAttribute(val value: UInt?) sealed class PowerAttributeSubscriptionState { - data class Success( - val value: UInt? - ) : PowerAttributeSubscriptionState() - + data class Success(val value: UInt?) : PowerAttributeSubscriptionState() + data class Error(val exception: Exception) : PowerAttributeSubscriptionState() - object SubscriptionEstablished : PowerAttributeSubscriptionState() - } -class LifetimeEnergyConsumedAttribute( - val value: UInt? - ) + object SubscriptionEstablished : PowerAttributeSubscriptionState() + } + + class LifetimeEnergyConsumedAttribute(val value: UInt?) sealed class LifetimeEnergyConsumedAttributeSubscriptionState { - data class Success( - val value: UInt? - ) : LifetimeEnergyConsumedAttributeSubscriptionState() - + data class Success(val value: UInt?) : LifetimeEnergyConsumedAttributeSubscriptionState() + data class Error(val exception: Exception) : LifetimeEnergyConsumedAttributeSubscriptionState() - object SubscriptionEstablished : LifetimeEnergyConsumedAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : LifetimeEnergyConsumedAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } -suspend fun readMaxPressureAttribute(): MaxPressureAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } + + suspend fun readMaxPressureAttribute(): MaxPressureAttribute { + 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}") - } + 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) { - "Maxpressure attribute not found in response" - } + } + + requireNotNull(attributeData) { "Maxpressure attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (!tlvReader.isNull()) { - tlvReader.getShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Short? = + if (!tlvReader.isNull()) { + tlvReader.getShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return MaxPressureAttribute(decodedValue) } suspend fun subscribeMaxPressureAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MaxPressureAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MaxPressureAttributeSubscriptionState.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) { - "Maxpressure attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Maxpressure attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (!tlvReader.isNull()) { - tlvReader.getShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Short? = + if (!tlvReader.isNull()) { + tlvReader.getShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(MaxPressureAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(MaxPressureAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MaxPressureAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMaxSpeedAttribute(): MaxSpeedAttribute {val ATTRIBUTE_ID: UInt = 1u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readMaxSpeedAttribute(): MaxSpeedAttribute { + 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 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}") - } + 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) { - "Maxspeed attribute not found in response" - } + } + + requireNotNull(attributeData) { "Maxspeed attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = if (!tlvReader.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return MaxSpeedAttribute(decodedValue) } suspend fun subscribeMaxSpeedAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MaxSpeedAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MaxSpeedAttributeSubscriptionState.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) { - "Maxspeed attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Maxspeed 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.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(MaxSpeedAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(MaxSpeedAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MaxSpeedAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMaxFlowAttribute(): MaxFlowAttribute {val ATTRIBUTE_ID: UInt = 2u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readMaxFlowAttribute(): MaxFlowAttribute { + 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 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}") - } + 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) { - "Maxflow attribute not found in response" - } + } + + requireNotNull(attributeData) { "Maxflow attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = if (!tlvReader.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return MaxFlowAttribute(decodedValue) } suspend fun subscribeMaxFlowAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MaxFlowAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MaxFlowAttributeSubscriptionState.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) { - "Maxflow attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Maxflow 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.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(MaxFlowAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(MaxFlowAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MaxFlowAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMinConstPressureAttribute(): MinConstPressureAttribute {val ATTRIBUTE_ID: UInt = 3u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readMinConstPressureAttribute(): MinConstPressureAttribute { + 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 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}") - } + 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) { - "Minconstpressure attribute not found in response" - } + } + + requireNotNull(attributeData) { "Minconstpressure attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Short? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return MinConstPressureAttribute(decodedValue) } suspend fun subscribeMinConstPressureAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MinConstPressureAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MinConstPressureAttributeSubscriptionState.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) { - "Minconstpressure attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Minconstpressure attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MinConstPressureAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Short? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MinConstPressureAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MinConstPressureAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMaxConstPressureAttribute(): MaxConstPressureAttribute {val ATTRIBUTE_ID: UInt = 4u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readMaxConstPressureAttribute(): MaxConstPressureAttribute { + 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 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}") - } + 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) { - "Maxconstpressure attribute not found in response" - } + } + + requireNotNull(attributeData) { "Maxconstpressure attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Short? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return MaxConstPressureAttribute(decodedValue) } suspend fun subscribeMaxConstPressureAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MaxConstPressureAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MaxConstPressureAttributeSubscriptionState.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) { - "Maxconstpressure attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Maxconstpressure attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MaxConstPressureAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Short? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MaxConstPressureAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MaxConstPressureAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMinCompPressureAttribute(): MinCompPressureAttribute {val ATTRIBUTE_ID: UInt = 5u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readMinCompPressureAttribute(): MinCompPressureAttribute { + 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 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}") - } + 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) { - "Mincomppressure attribute not found in response" - } + } + + requireNotNull(attributeData) { "Mincomppressure attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Short? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return MinCompPressureAttribute(decodedValue) } suspend fun subscribeMinCompPressureAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MinCompPressureAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MinCompPressureAttributeSubscriptionState.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) { - "Mincomppressure attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Mincomppressure attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MinCompPressureAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Short? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MinCompPressureAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MinCompPressureAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMaxCompPressureAttribute(): MaxCompPressureAttribute {val ATTRIBUTE_ID: UInt = 6u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readMaxCompPressureAttribute(): MaxCompPressureAttribute { + 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 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}") - } + 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) { - "Maxcomppressure attribute not found in response" - } + } + + requireNotNull(attributeData) { "Maxcomppressure attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Short? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return MaxCompPressureAttribute(decodedValue) } suspend fun subscribeMaxCompPressureAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MaxCompPressureAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MaxCompPressureAttributeSubscriptionState.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) { - "Maxcomppressure attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Maxcomppressure attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MaxCompPressureAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Short? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MaxCompPressureAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MaxCompPressureAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMinConstSpeedAttribute(): MinConstSpeedAttribute {val ATTRIBUTE_ID: UInt = 7u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readMinConstSpeedAttribute(): MinConstSpeedAttribute { + 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 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}") - } + 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) { - "Minconstspeed attribute not found in response" - } + } + + requireNotNull(attributeData) { "Minconstspeed attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return MinConstSpeedAttribute(decodedValue) } suspend fun subscribeMinConstSpeedAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MinConstSpeedAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MinConstSpeedAttributeSubscriptionState.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) { - "Minconstspeed attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Minconstspeed 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MinConstSpeedAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MinConstSpeedAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MinConstSpeedAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMaxConstSpeedAttribute(): MaxConstSpeedAttribute {val ATTRIBUTE_ID: UInt = 8u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readMaxConstSpeedAttribute(): MaxConstSpeedAttribute { + val ATTRIBUTE_ID: UInt = 8u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Maxconstspeed attribute not found in response" - } + } + + requireNotNull(attributeData) { "Maxconstspeed attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return MaxConstSpeedAttribute(decodedValue) } suspend fun subscribeMaxConstSpeedAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MaxConstSpeedAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MaxConstSpeedAttributeSubscriptionState.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) { - "Maxconstspeed attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Maxconstspeed 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MaxConstSpeedAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MaxConstSpeedAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MaxConstSpeedAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMinConstFlowAttribute(): MinConstFlowAttribute {val ATTRIBUTE_ID: UInt = 9u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readMinConstFlowAttribute(): MinConstFlowAttribute { + val ATTRIBUTE_ID: UInt = 9u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Minconstflow attribute not found in response" - } + } + + requireNotNull(attributeData) { "Minconstflow attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return MinConstFlowAttribute(decodedValue) } suspend fun subscribeMinConstFlowAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MinConstFlowAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MinConstFlowAttributeSubscriptionState.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) { - "Minconstflow attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Minconstflow 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MinConstFlowAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MinConstFlowAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MinConstFlowAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMaxConstFlowAttribute(): MaxConstFlowAttribute {val ATTRIBUTE_ID: UInt = 10u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readMaxConstFlowAttribute(): MaxConstFlowAttribute { + val ATTRIBUTE_ID: UInt = 10u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Maxconstflow attribute not found in response" - } + } + + requireNotNull(attributeData) { "Maxconstflow attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return MaxConstFlowAttribute(decodedValue) } suspend fun subscribeMaxConstFlowAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MaxConstFlowAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MaxConstFlowAttributeSubscriptionState.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) { - "Maxconstflow attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Maxconstflow 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MaxConstFlowAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MaxConstFlowAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MaxConstFlowAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMinConstTempAttribute(): MinConstTempAttribute {val ATTRIBUTE_ID: UInt = 11u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readMinConstTempAttribute(): MinConstTempAttribute { + val ATTRIBUTE_ID: UInt = 11u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Minconsttemp attribute not found in response" - } + } + + requireNotNull(attributeData) { "Minconsttemp attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Short? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return MinConstTempAttribute(decodedValue) } suspend fun subscribeMinConstTempAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 11u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MinConstTempAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MinConstTempAttributeSubscriptionState.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) { - "Minconsttemp attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Minconsttemp attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MinConstTempAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Short? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MinConstTempAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MinConstTempAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMaxConstTempAttribute(): MaxConstTempAttribute {val ATTRIBUTE_ID: UInt = 12u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readMaxConstTempAttribute(): MaxConstTempAttribute { + val ATTRIBUTE_ID: UInt = 12u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Maxconsttemp attribute not found in response" - } + } + + requireNotNull(attributeData) { "Maxconsttemp attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Short? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return MaxConstTempAttribute(decodedValue) } suspend fun subscribeMaxConstTempAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 12u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MaxConstTempAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MaxConstTempAttributeSubscriptionState.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) { - "Maxconsttemp attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Maxconsttemp attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MaxConstTempAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Short? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MaxConstTempAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MaxConstTempAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPumpStatusAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 16u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readPumpStatusAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 16u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Pumpstatus attribute not found in response" - } + } + + requireNotNull(attributeData) { "Pumpstatus 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribePumpStatusAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Pumpstatus attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Pumpstatus 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readEffectiveOperationModeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 17u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readEffectiveOperationModeAttribute(): UByte { + val ATTRIBUTE_ID: UInt = 17u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Effectiveoperationmode attribute not found in response" - } + } + + requireNotNull(attributeData) { "Effectiveoperationmode 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 subscribeEffectiveOperationModeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 17u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Effectiveoperationmode attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Effectiveoperationmode attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -1893,80 +1731,77 @@ suspend fun readEffectiveOperationModeAttribute(): UByte {val ATTRIBUTE_ID: UInt emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readEffectiveControlModeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 18u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readEffectiveControlModeAttribute(): UByte { + val ATTRIBUTE_ID: UInt = 18u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Effectivecontrolmode attribute not found in response" - } + } + + requireNotNull(attributeData) { "Effectivecontrolmode 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 subscribeEffectiveControlModeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 18u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Effectivecontrolmode attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Effectivecontrolmode attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -1979,283 +1814,261 @@ suspend fun readEffectiveControlModeAttribute(): UByte {val ATTRIBUTE_ID: UInt = emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCapacityAttribute(): CapacityAttribute {val ATTRIBUTE_ID: UInt = 19u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readCapacityAttribute(): CapacityAttribute { + val ATTRIBUTE_ID: UInt = 19u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Capacity attribute not found in response" - } + } + + requireNotNull(attributeData) { "Capacity attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (!tlvReader.isNull()) { - tlvReader.getShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Short? = + if (!tlvReader.isNull()) { + tlvReader.getShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return CapacityAttribute(decodedValue) } suspend fun subscribeCapacityAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 19u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(CapacityAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + CapacityAttributeSubscriptionState.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) { - "Capacity attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Capacity attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (!tlvReader.isNull()) { - tlvReader.getShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Short? = + if (!tlvReader.isNull()) { + tlvReader.getShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(CapacityAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(CapacityAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(CapacityAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readSpeedAttribute(): SpeedAttribute {val ATTRIBUTE_ID: UInt = 20u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readSpeedAttribute(): SpeedAttribute { + val ATTRIBUTE_ID: UInt = 20u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Speed attribute not found in response" - } + } + + requireNotNull(attributeData) { "Speed attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return SpeedAttribute(decodedValue) } suspend fun subscribeSpeedAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 20u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(SpeedAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + SpeedAttributeSubscriptionState.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) { - "Speed attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Speed 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(SpeedAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(SpeedAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(SpeedAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readLifetimeRunningHoursAttribute(): LifetimeRunningHoursAttribute {val ATTRIBUTE_ID: UInt = 21u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readLifetimeRunningHoursAttribute(): LifetimeRunningHoursAttribute { + val ATTRIBUTE_ID: UInt = 21u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Lifetimerunninghours attribute not found in response" - } + } + + requireNotNull(attributeData) { "Lifetimerunninghours attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return LifetimeRunningHoursAttribute(decodedValue) } - suspend fun writeLifetimeRunningHoursAttribute( - value: UInt, - timedWriteTimeout: Duration? = null) { + suspend fun writeLifetimeRunningHoursAttribute(value: UInt, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 21u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -2276,244 +2089,233 @@ suspend fun readLifetimeRunningHoursAttribute(): LifetimeRunningHoursAttribute { throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeLifetimeRunningHoursAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 21u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(LifetimeRunningHoursAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + LifetimeRunningHoursAttributeSubscriptionState.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) { - "Lifetimerunninghours attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Lifetimerunninghours attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(LifetimeRunningHoursAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(LifetimeRunningHoursAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(LifetimeRunningHoursAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPowerAttribute(): PowerAttribute {val ATTRIBUTE_ID: UInt = 22u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readPowerAttribute(): PowerAttribute { + val ATTRIBUTE_ID: UInt = 22u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Power attribute not found in response" - } + } + + requireNotNull(attributeData) { "Power attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return PowerAttribute(decodedValue) } suspend fun subscribePowerAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 22u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(PowerAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + PowerAttributeSubscriptionState.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) { - "Power attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Power attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(PowerAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(PowerAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(PowerAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readLifetimeEnergyConsumedAttribute(): LifetimeEnergyConsumedAttribute {val ATTRIBUTE_ID: UInt = 23u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readLifetimeEnergyConsumedAttribute(): LifetimeEnergyConsumedAttribute { + val ATTRIBUTE_ID: UInt = 23u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Lifetimeenergyconsumed attribute not found in response" - } + } + + requireNotNull(attributeData) { "Lifetimeenergyconsumed attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return LifetimeEnergyConsumedAttribute(decodedValue) } suspend fun writeLifetimeEnergyConsumedAttribute( value: UInt, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 23u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -2534,128 +2336,119 @@ suspend fun readLifetimeEnergyConsumedAttribute(): LifetimeEnergyConsumedAttribu throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeLifetimeEnergyConsumedAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 23u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(LifetimeEnergyConsumedAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + LifetimeEnergyConsumedAttributeSubscriptionState.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) { - "Lifetimeenergyconsumed attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Lifetimeenergyconsumed attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(LifetimeEnergyConsumedAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(LifetimeEnergyConsumedAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(LifetimeEnergyConsumedAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readOperationModeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 32u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readOperationModeAttribute(): UByte { + val ATTRIBUTE_ID: UInt = 32u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Operationmode attribute not found in response" - } + } + + requireNotNull(attributeData) { "Operationmode 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 writeOperationModeAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeOperationModeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 32u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -2676,43 +2469,45 @@ suspend fun readOperationModeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 32u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeOperationModeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 32u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Operationmode attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Operationmode attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -2724,72 +2519,62 @@ suspend fun readOperationModeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 32u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readControlModeAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 33u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readControlModeAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 33u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Controlmode attribute not found in response" - } + } + + requireNotNull(attributeData) { "Controlmode 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } - suspend fun writeControlModeAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeControlModeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 33u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -2810,152 +2595,151 @@ suspend fun readControlModeAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 33u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeControlModeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 33u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Controlmode attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Controlmode 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65528u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -2963,97 +2747,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { emit(GeneratedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65529u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -3061,97 +2844,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va emit(AcceptedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt = 65530u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -3159,97 +2939,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt emit(EventListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ID: UInt = 65531u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -3257,81 +3034,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ emit(AttributeListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -3343,80 +3115,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 65533u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -3429,7 +3198,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/RadonConcentrationMeasurementCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/RadonConcentrationMeasurementCluster.kt index 05e3ef50cbd96d..0f8a0720b9fd89 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/RadonConcentrationMeasurementCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/RadonConcentrationMeasurementCluster.kt @@ -17,1371 +17,1273 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.FloatSubscriptionState import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse -import matter.controller.model.AttributePath -import matter.controller.model.CommandPath +import matter.controller.UShortSubscriptionState import matter.controller.cluster.structs.* +import matter.controller.model.AttributePath import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader -import matter.tlv.TlvWriter -class RadonConcentrationMeasurementCluster(private val controller: MatterController, private val endpointId: UShort) {class MeasuredValueAttribute( - val value: Float? - ) +class RadonConcentrationMeasurementCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class MeasuredValueAttribute(val value: Float?) sealed class MeasuredValueAttributeSubscriptionState { - data class Success( - val value: Float? - ) : MeasuredValueAttributeSubscriptionState() - + data class Success(val value: Float?) : MeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() - } -class MinMeasuredValueAttribute( - val value: Float? - ) + object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() + } + + class MinMeasuredValueAttribute(val value: Float?) sealed class MinMeasuredValueAttributeSubscriptionState { - data class Success( - val value: Float? - ) : MinMeasuredValueAttributeSubscriptionState() - + data class Success(val value: Float?) : MinMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MinMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() - } -class MaxMeasuredValueAttribute( - val value: Float? - ) + object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() + } + + class MaxMeasuredValueAttribute(val value: Float?) sealed class MaxMeasuredValueAttributeSubscriptionState { - data class Success( - val value: Float? - ) : MaxMeasuredValueAttributeSubscriptionState() - + data class Success(val value: Float?) : MaxMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MaxMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() - } -class PeakMeasuredValueAttribute( - val value: Float? - ) + object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() + } + + class PeakMeasuredValueAttribute(val value: Float?) sealed class PeakMeasuredValueAttributeSubscriptionState { - data class Success( - val value: Float? - ) : PeakMeasuredValueAttributeSubscriptionState() - + data class Success(val value: Float?) : PeakMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : PeakMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : PeakMeasuredValueAttributeSubscriptionState() - } -class AverageMeasuredValueAttribute( - val value: Float? - ) + object SubscriptionEstablished : PeakMeasuredValueAttributeSubscriptionState() + } + + class AverageMeasuredValueAttribute(val value: Float?) sealed class AverageMeasuredValueAttributeSubscriptionState { - data class Success( - val value: Float? - ) : AverageMeasuredValueAttributeSubscriptionState() - + data class Success(val value: Float?) : AverageMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : AverageMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : AverageMeasuredValueAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : AverageMeasuredValueAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } -suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } + + suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute { + 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}") - } + 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) { - "Measuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Measuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return MeasuredValueAttribute(decodedValue) } suspend fun subscribeMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MeasuredValueAttributeSubscriptionState.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) { - "Measuredvalue attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Measuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute { + 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}") - } + 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) { - "Minmeasuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Minmeasuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return MinMeasuredValueAttribute(decodedValue) } suspend fun subscribeMinMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MinMeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MinMeasuredValueAttributeSubscriptionState.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) { - "Minmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Minmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MinMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute { + 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}") - } + 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) { - "Maxmeasuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Maxmeasuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return MaxMeasuredValueAttribute(decodedValue) } suspend fun subscribeMaxMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MaxMeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MaxMeasuredValueAttributeSubscriptionState.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) { - "Maxmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Maxmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MaxMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPeakMeasuredValueAttribute(): PeakMeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readPeakMeasuredValueAttribute(): PeakMeasuredValueAttribute { + 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}") - } + 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) { - "Peakmeasuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Peakmeasuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return PeakMeasuredValueAttribute(decodedValue) } suspend fun subscribePeakMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(PeakMeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + PeakMeasuredValueAttributeSubscriptionState.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) { - "Peakmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Peakmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(PeakMeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(PeakMeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(PeakMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPeakMeasuredValueWindowAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 4u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readPeakMeasuredValueWindowAttribute(): UInt? { + 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}") - } + 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) { - "Peakmeasuredvaluewindow attribute not found in response" - } + } + + requireNotNull(attributeData) { "Peakmeasuredvaluewindow attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribePeakMeasuredValueWindowAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Peakmeasuredvaluewindow attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Peakmeasuredvaluewindow attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAverageMeasuredValueAttribute(): AverageMeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 5u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readAverageMeasuredValueAttribute(): AverageMeasuredValueAttribute { + 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}") - } + 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) { - "Averagemeasuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Averagemeasuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return AverageMeasuredValueAttribute(decodedValue) } suspend fun subscribeAverageMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(AverageMeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + AverageMeasuredValueAttributeSubscriptionState.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) { - "Averagemeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Averagemeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(AverageMeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(AverageMeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(AverageMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAverageMeasuredValueWindowAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 6u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readAverageMeasuredValueWindowAttribute(): UInt? { + 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}") - } + 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) { - "Averagemeasuredvaluewindow attribute not found in response" - } + } + + requireNotNull(attributeData) { "Averagemeasuredvaluewindow attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeAverageMeasuredValueWindowAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Averagemeasuredvaluewindow attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Averagemeasuredvaluewindow attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readUncertaintyAttribute(): Float? {val ATTRIBUTE_ID: UInt = 7u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readUncertaintyAttribute(): Float? { + 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}") - } + 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) { - "Uncertainty attribute not found in response" - } + } + + requireNotNull(attributeData) { "Uncertainty attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - + val decodedValue: Float? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeUncertaintyAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(FloatSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + FloatSubscriptionState.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) { - "Uncertainty attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Uncertainty attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(FloatSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(FloatSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(FloatSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMeasurementUnitAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 8u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMeasurementUnitAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 8u + + 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}") - } + 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) { - "Measurementunit attribute not found in response" - } + } + + requireNotNull(attributeData) { "Measurementunit 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeMeasurementUnitAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Measurementunit attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Measurementunit 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)) - } - + 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 readMeasurementMediumAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 9u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMeasurementMediumAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 9u + + 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}") - } + 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) { - "Measurementmedium attribute not found in response" - } + } + + requireNotNull(attributeData) { "Measurementmedium 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeMeasurementMediumAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Measurementmedium attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Measurementmedium 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)) - } - + 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 readLevelValueAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 10u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readLevelValueAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 10u + + 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}") - } + 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) { - "Levelvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Levelvalue 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeLevelValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Levelvalue attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Levelvalue 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)) - } - + 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 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1389,97 +1291,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1487,97 +1388,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1585,97 +1483,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1683,81 +1578,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1769,80 +1659,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1855,7 +1742,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/RefrigeratorAlarmCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/RefrigeratorAlarmCluster.kt index fc8ca10f3d18d2..a25f0f3349b6fb 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/RefrigeratorAlarmCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/RefrigeratorAlarmCluster.kt @@ -17,173 +17,134 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState -import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse -import matter.controller.model.AttributePath -import matter.controller.model.CommandPath +import matter.controller.UShortSubscriptionState import matter.controller.cluster.structs.* +import matter.controller.model.AttributePath import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader -import matter.tlv.TlvWriter -class RefrigeratorAlarmCluster(private val controller: MatterController, private val endpointId: UShort) {class GeneratedCommandListAttribute( - val value: List - ) +class RefrigeratorAlarmCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } -suspend fun readMaskAttribute(): UInt {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } + + suspend fun readMaskAttribute(): UInt { + 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}") - } + 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) { - "Mask attribute not found in response" - } + } + + requireNotNull(attributeData) { "Mask 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 subscribeMaskAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Mask attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Mask attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -195,81 +156,76 @@ suspend fun readMaskAttribute(): UInt {val ATTRIBUTE_ID: UInt = 0u emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readStateAttribute(): UInt {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readStateAttribute(): UInt { + 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}") - } + 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) { - "State attribute not found in response" - } + } + + requireNotNull(attributeData) { "State 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 subscribeStateAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "State attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "State attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -281,81 +237,76 @@ suspend fun readStateAttribute(): UInt {val ATTRIBUTE_ID: UInt = 2u emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readSupportedAttribute(): UInt {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readSupportedAttribute(): UInt { + 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}") - } + 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) { - "Supported attribute not found in response" - } + } + + requireNotNull(attributeData) { "Supported 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 subscribeSupportedAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Supported attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Supported attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -367,97 +318,96 @@ suspend fun readSupportedAttribute(): UInt {val ATTRIBUTE_ID: UInt = 3u emit(UIntSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -465,97 +415,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -563,97 +512,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -661,97 +607,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -759,81 +702,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -845,80 +783,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -931,7 +866,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/RefrigeratorAndTemperatureControlledCabinetModeCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/RefrigeratorAndTemperatureControlledCabinetModeCluster.kt index ce6565c3397935..4dae3004f2a277 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/RefrigeratorAndTemperatureControlledCabinetModeCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/RefrigeratorAndTemperatureControlledCabinetModeCluster.kt @@ -17,161 +17,130 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class RefrigeratorAndTemperatureControlledCabinetModeCluster(private val controller: MatterController, private val endpointId: UShort) { - class ChangeToModeResponse( - val status: UByte, - val statusText: String? - ) -class SupportedModesAttribute( +class RefrigeratorAndTemperatureControlledCabinetModeCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class ChangeToModeResponse(val status: UByte, val statusText: String?) + + class SupportedModesAttribute( val value: List ) sealed class SupportedModesAttributeSubscriptionState { data class Success( - val value: List + val value: List ) : SupportedModesAttributeSubscriptionState() - + data class Error(val exception: Exception) : SupportedModesAttributeSubscriptionState() - object SubscriptionEstablished : SupportedModesAttributeSubscriptionState() - } -class StartUpModeAttribute( - val value: UByte? - ) + object SubscriptionEstablished : SupportedModesAttributeSubscriptionState() + } + + class StartUpModeAttribute(val value: UByte?) sealed class StartUpModeAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : StartUpModeAttributeSubscriptionState() - + data class Success(val value: UByte?) : StartUpModeAttributeSubscriptionState() + data class Error(val exception: Exception) : StartUpModeAttributeSubscriptionState() - object SubscriptionEstablished : StartUpModeAttributeSubscriptionState() - } -class OnModeAttribute( - val value: UByte? - ) + object SubscriptionEstablished : StartUpModeAttributeSubscriptionState() + } + + class OnModeAttribute(val value: UByte?) sealed class OnModeAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : OnModeAttributeSubscriptionState() - + data class Success(val value: UByte?) : OnModeAttributeSubscriptionState() + data class Error(val exception: Exception) : OnModeAttributeSubscriptionState() - object SubscriptionEstablished : OnModeAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : OnModeAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun changeToMode(newMode: UByte - ,timedInvokeTimeout: Duration? = null): ChangeToModeResponse { + suspend fun changeToMode( + newMode: UByte, + timedInvokeTimeout: Duration? = null, + ): ChangeToModeResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_NEW_MODE_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_NEW_MODE_REQ), newMode) + tlvWriter.put(ContextSpecificTag(TAG_NEW_MODE_REQ), newMode) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -181,140 +150,141 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_STATUS_TEXT: Int = 1 var statusText_decoded: String? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_STATUS_TEXT)) {statusText_decoded = + if (tag == ContextSpecificTag(TAG_STATUS)) { + status_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_STATUS_TEXT)) { + statusText_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - }} - - - else { + tlvReader.getString(tag) + } else { + null + } + } + } else { tlvReader.skipElement() } } - - if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - - - tlvReader.exitContainer() - return ChangeToModeResponse( - status_decoded, - statusText_decoded - ) + return ChangeToModeResponse(status_decoded, statusText_decoded) } -suspend fun readSupportedModesAttribute(): SupportedModesAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readSupportedModesAttribute(): SupportedModesAttribute { + 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}") - } + 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) { - "Supportedmodes attribute not found in response" - } + } + + requireNotNull(attributeData) { "Supportedmodes 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(RefrigeratorAndTemperatureControlledCabinetModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add( + RefrigeratorAndTemperatureControlledCabinetModeClusterModeOptionStruct.fromTlv( + AnonymousTag, + tlvReader, + ) + ) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return SupportedModesAttribute(decodedValue) } suspend fun subscribeSupportedModesAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(SupportedModesAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + SupportedModesAttributeSubscriptionState.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) { - "Supportedmodes attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Supportedmodes 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(RefrigeratorAndTemperatureControlledCabinetModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: + List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add( + RefrigeratorAndTemperatureControlledCabinetModeClusterModeOptionStruct.fromTlv( + AnonymousTag, + tlvReader, + ) + ) + } + tlvReader.exitContainer() + } emit(SupportedModesAttributeSubscriptionState.Success(decodedValue)) } @@ -322,81 +292,76 @@ suspend fun readSupportedModesAttribute(): SupportedModesAttribute {val ATTRIBUT emit(SupportedModesAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCurrentModeAttribute(): 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) - ) - + + suspend fun readCurrentModeAttribute(): 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}") - } + 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) { - "Currentmode attribute not found in response" - } + } + + requireNotNull(attributeData) { "Currentmode 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 subscribeCurrentModeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Currentmode attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Currentmode attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -408,77 +373,67 @@ suspend fun readCurrentModeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 1u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readStartUpModeAttribute(): StartUpModeAttribute {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readStartUpModeAttribute(): StartUpModeAttribute { + 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}") - } + 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) { - "Startupmode attribute not found in response" - } + } + + requireNotNull(attributeData) { "Startupmode attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return StartUpModeAttribute(decodedValue) } - suspend fun writeStartUpModeAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeStartUpModeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 2u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -499,137 +454,127 @@ suspend fun readStartUpModeAttribute(): StartUpModeAttribute {val ATTRIBUTE_ID: throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeStartUpModeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StartUpModeAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StartUpModeAttributeSubscriptionState.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) { - "Startupmode attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Startupmode 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(StartUpModeAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(StartUpModeAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(StartUpModeAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readOnModeAttribute(): OnModeAttribute {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readOnModeAttribute(): OnModeAttribute { + 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}") - } + 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) { - "Onmode attribute not found in response" - } + } + + requireNotNull(attributeData) { "Onmode attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return OnModeAttribute(decodedValue) } - suspend fun writeOnModeAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeOnModeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 3u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -650,157 +595,156 @@ suspend fun readOnModeAttribute(): OnModeAttribute {val ATTRIBUTE_ID: UInt = 3u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeOnModeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(OnModeAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + OnModeAttributeSubscriptionState.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) { - "Onmode attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Onmode 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(OnModeAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(OnModeAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(OnModeAttributeSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -808,97 +752,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -906,97 +849,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1004,97 +944,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1102,81 +1039,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1188,80 +1120,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1274,11 +1203,12 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { - private val logger = Logger.getLogger(RefrigeratorAndTemperatureControlledCabinetModeCluster::class.java.name) + private val logger = + Logger.getLogger(RefrigeratorAndTemperatureControlledCabinetModeCluster::class.java.name) const val CLUSTER_ID: UInt = 82u } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/RelativeHumidityMeasurementCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/RelativeHumidityMeasurementCluster.kt index c7f6f1f5cc66a8..94ed23289669b2 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/RelativeHumidityMeasurementCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/RelativeHumidityMeasurementCluster.kt @@ -17,622 +17,558 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState -import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse -import matter.controller.model.AttributePath -import matter.controller.model.CommandPath +import matter.controller.UShortSubscriptionState import matter.controller.cluster.structs.* +import matter.controller.model.AttributePath import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader -import matter.tlv.TlvWriter -class RelativeHumidityMeasurementCluster(private val controller: MatterController, private val endpointId: UShort) {class MeasuredValueAttribute( - val value: UShort? - ) +class RelativeHumidityMeasurementCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class MeasuredValueAttribute(val value: UShort?) sealed class MeasuredValueAttributeSubscriptionState { - data class Success( - val value: UShort? - ) : MeasuredValueAttributeSubscriptionState() - + data class Success(val value: UShort?) : MeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() - } -class MinMeasuredValueAttribute( - val value: UShort? - ) + object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() + } + + class MinMeasuredValueAttribute(val value: UShort?) sealed class MinMeasuredValueAttributeSubscriptionState { - data class Success( - val value: UShort? - ) : MinMeasuredValueAttributeSubscriptionState() - + data class Success(val value: UShort?) : MinMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MinMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() - } -class MaxMeasuredValueAttribute( - val value: UShort? - ) + object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() + } + + class MaxMeasuredValueAttribute(val value: UShort?) sealed class MaxMeasuredValueAttributeSubscriptionState { - data class Success( - val value: UShort? - ) : MaxMeasuredValueAttributeSubscriptionState() - + data class Success(val value: UShort?) : MaxMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MaxMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } -suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } + + suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute { + 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}") - } + 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) { - "Measuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Measuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = if (!tlvReader.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return MeasuredValueAttribute(decodedValue) } suspend fun subscribeMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MeasuredValueAttributeSubscriptionState.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) { - "Measuredvalue attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Measuredvalue 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.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute { + 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}") - } + 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) { - "Minmeasuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Minmeasuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = if (!tlvReader.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return MinMeasuredValueAttribute(decodedValue) } suspend fun subscribeMinMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MinMeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MinMeasuredValueAttributeSubscriptionState.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) { - "Minmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Minmeasuredvalue 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.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MinMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute { + 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}") - } + 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) { - "Maxmeasuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Maxmeasuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = if (!tlvReader.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return MaxMeasuredValueAttribute(decodedValue) } suspend fun subscribeMaxMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MaxMeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MaxMeasuredValueAttributeSubscriptionState.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) { - "Maxmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Maxmeasuredvalue 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.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MaxMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readToleranceAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readToleranceAttribute(): UShort? { + 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}") - } + 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) { - "Tolerance attribute not found in response" - } + } + + requireNotNull(attributeData) { "Tolerance 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeToleranceAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Tolerance attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Tolerance 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)) - } - + 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 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -640,97 +576,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -738,97 +673,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -836,97 +768,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -934,81 +863,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1020,80 +944,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1106,7 +1027,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/RvcCleanModeCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/RvcCleanModeCluster.kt index 7ac51acbac5c46..af5017f099437a 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/RvcCleanModeCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/RvcCleanModeCluster.kt @@ -17,135 +17,104 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.UShortSubscriptionState +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class RvcCleanModeCluster(private val controller: MatterController, private val endpointId: UShort) { - class ChangeToModeResponse( - val status: UByte, - val statusText: String? - ) -class SupportedModesAttribute( - val value: List - ) +class RvcCleanModeCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class ChangeToModeResponse(val status: UByte, val statusText: String?) + + class SupportedModesAttribute(val value: List) sealed class SupportedModesAttributeSubscriptionState { - data class Success( - val value: List - ) : SupportedModesAttributeSubscriptionState() - + data class Success(val value: List) : + SupportedModesAttributeSubscriptionState() + data class Error(val exception: Exception) : SupportedModesAttributeSubscriptionState() - object SubscriptionEstablished : SupportedModesAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : SupportedModesAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun changeToMode(newMode: UByte - ,timedInvokeTimeout: Duration? = null): ChangeToModeResponse { + suspend fun changeToMode( + newMode: UByte, + timedInvokeTimeout: Duration? = null, + ): ChangeToModeResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_NEW_MODE_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_NEW_MODE_REQ), newMode) + tlvWriter.put(ContextSpecificTag(TAG_NEW_MODE_REQ), newMode) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -155,140 +124,130 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_STATUS_TEXT: Int = 1 var statusText_decoded: String? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_STATUS_TEXT)) {statusText_decoded = + if (tag == ContextSpecificTag(TAG_STATUS)) { + status_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_STATUS_TEXT)) { + statusText_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - }} - - - else { + tlvReader.getString(tag) + } else { + null + } + } + } else { tlvReader.skipElement() } } - - if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - - - tlvReader.exitContainer() - return ChangeToModeResponse( - status_decoded, - statusText_decoded - ) + return ChangeToModeResponse(status_decoded, statusText_decoded) } -suspend fun readSupportedModesAttribute(): SupportedModesAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readSupportedModesAttribute(): SupportedModesAttribute { + 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}") - } + 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) { - "Supportedmodes attribute not found in response" - } + } + + requireNotNull(attributeData) { "Supportedmodes 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(RvcCleanModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(RvcCleanModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return SupportedModesAttribute(decodedValue) } suspend fun subscribeSupportedModesAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(SupportedModesAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + SupportedModesAttributeSubscriptionState.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) { - "Supportedmodes attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Supportedmodes 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(RvcCleanModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(RvcCleanModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(SupportedModesAttributeSubscriptionState.Success(decodedValue)) } @@ -296,81 +255,76 @@ suspend fun readSupportedModesAttribute(): SupportedModesAttribute {val ATTRIBUT emit(SupportedModesAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCurrentModeAttribute(): 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) - ) - + + suspend fun readCurrentModeAttribute(): 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}") - } + 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) { - "Currentmode attribute not found in response" - } + } + + requireNotNull(attributeData) { "Currentmode 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 subscribeCurrentModeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Currentmode attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Currentmode attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -382,97 +336,96 @@ suspend fun readCurrentModeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 1u emit(UByteSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -480,97 +433,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -578,97 +530,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -676,97 +625,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -774,81 +720,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -860,80 +801,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -946,7 +884,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/RvcOperationalStateCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/RvcOperationalStateCluster.kt index 87da9febd27bcd..6f60044e8ef432 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/RvcOperationalStateCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/RvcOperationalStateCluster.kt @@ -17,182 +17,143 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.UShortSubscriptionState +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class RvcOperationalStateCluster(private val controller: MatterController, private val endpointId: UShort) { +class RvcOperationalStateCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { class OperationalCommandResponse( val commandResponseState: RvcOperationalStateClusterErrorStateStruct ) -class PhaseListAttribute( - val value: List? - ) + + class PhaseListAttribute(val value: List?) sealed class PhaseListAttributeSubscriptionState { - data class Success( - val value: List? - ) : PhaseListAttributeSubscriptionState() - + data class Success(val value: List?) : PhaseListAttributeSubscriptionState() + data class Error(val exception: Exception) : PhaseListAttributeSubscriptionState() - object SubscriptionEstablished : PhaseListAttributeSubscriptionState() - } -class CurrentPhaseAttribute( - val value: UByte? - ) + object SubscriptionEstablished : PhaseListAttributeSubscriptionState() + } + + class CurrentPhaseAttribute(val value: UByte?) sealed class CurrentPhaseAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : CurrentPhaseAttributeSubscriptionState() - + data class Success(val value: UByte?) : CurrentPhaseAttributeSubscriptionState() + data class Error(val exception: Exception) : CurrentPhaseAttributeSubscriptionState() - object SubscriptionEstablished : CurrentPhaseAttributeSubscriptionState() - } -class CountdownTimeAttribute( - val value: UInt? - ) + object SubscriptionEstablished : CurrentPhaseAttributeSubscriptionState() + } + + class CountdownTimeAttribute(val value: UInt?) sealed class CountdownTimeAttributeSubscriptionState { - data class Success( - val value: UInt? - ) : CountdownTimeAttributeSubscriptionState() - + data class Success(val value: UInt?) : CountdownTimeAttributeSubscriptionState() + data class Error(val exception: Exception) : CountdownTimeAttributeSubscriptionState() - object SubscriptionEstablished : CountdownTimeAttributeSubscriptionState() - } -class OperationalStateListAttribute( + object SubscriptionEstablished : CountdownTimeAttributeSubscriptionState() + } + + class OperationalStateListAttribute( val value: List ) sealed class OperationalStateListAttributeSubscriptionState { - data class Success( - val value: List - ) : OperationalStateListAttributeSubscriptionState() - + data class Success(val value: List) : + OperationalStateListAttributeSubscriptionState() + data class Error(val exception: Exception) : OperationalStateListAttributeSubscriptionState() - object SubscriptionEstablished : OperationalStateListAttributeSubscriptionState() - } -class OperationalErrorAttribute( - val value: RvcOperationalStateClusterErrorStateStruct - ) + object SubscriptionEstablished : OperationalStateListAttributeSubscriptionState() + } + + class OperationalErrorAttribute(val value: RvcOperationalStateClusterErrorStateStruct) sealed class OperationalErrorAttributeSubscriptionState { - data class Success( - val value: RvcOperationalStateClusterErrorStateStruct - ) : OperationalErrorAttributeSubscriptionState() - + data class Success(val value: RvcOperationalStateClusterErrorStateStruct) : + OperationalErrorAttributeSubscriptionState() + data class Error(val exception: Exception) : OperationalErrorAttributeSubscriptionState() - object SubscriptionEstablished : OperationalErrorAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : OperationalErrorAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } suspend fun pause(timedInvokeTimeout: Duration? = null): OperationalCommandResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -202,46 +163,39 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_COMMAND_RESPONSE_STATE: Int = 0 var commandResponseState_decoded: RvcOperationalStateClusterErrorStateStruct? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_COMMAND_RESPONSE_STATE)) {commandResponseState_decoded = RvcOperationalStateClusterErrorStateStruct.fromTlv(tag, tlvReader)} - - - else { + if (tag == ContextSpecificTag(TAG_COMMAND_RESPONSE_STATE)) { + commandResponseState_decoded = + RvcOperationalStateClusterErrorStateStruct.fromTlv(tag, tlvReader) + } else { tlvReader.skipElement() } } - - if (commandResponseState_decoded == null) { - throw IllegalStateException("commandResponseState not found in TLV") + throw IllegalStateException("commandResponseState not found in TLV") } - tlvReader.exitContainer() - return OperationalCommandResponse( - commandResponseState_decoded - ) + return OperationalCommandResponse(commandResponseState_decoded) } suspend fun resume(timedInvokeTimeout: Duration? = null): OperationalCommandResponse { val commandId: UInt = 3u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -251,46 +205,39 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_COMMAND_RESPONSE_STATE: Int = 0 var commandResponseState_decoded: RvcOperationalStateClusterErrorStateStruct? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_COMMAND_RESPONSE_STATE)) {commandResponseState_decoded = RvcOperationalStateClusterErrorStateStruct.fromTlv(tag, tlvReader)} - - - else { + if (tag == ContextSpecificTag(TAG_COMMAND_RESPONSE_STATE)) { + commandResponseState_decoded = + RvcOperationalStateClusterErrorStateStruct.fromTlv(tag, tlvReader) + } else { tlvReader.skipElement() } } - - if (commandResponseState_decoded == null) { - throw IllegalStateException("commandResponseState not found in TLV") + throw IllegalStateException("commandResponseState not found in TLV") } - tlvReader.exitContainer() - return OperationalCommandResponse( - commandResponseState_decoded - ) + return OperationalCommandResponse(commandResponseState_decoded) } suspend fun goHome(timedInvokeTimeout: Duration? = null): OperationalCommandResponse { val commandId: UInt = 128u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -300,439 +247,415 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_COMMAND_RESPONSE_STATE: Int = 0 var commandResponseState_decoded: RvcOperationalStateClusterErrorStateStruct? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_COMMAND_RESPONSE_STATE)) {commandResponseState_decoded = RvcOperationalStateClusterErrorStateStruct.fromTlv(tag, tlvReader)} - - - else { + if (tag == ContextSpecificTag(TAG_COMMAND_RESPONSE_STATE)) { + commandResponseState_decoded = + RvcOperationalStateClusterErrorStateStruct.fromTlv(tag, tlvReader) + } else { tlvReader.skipElement() } } - - if (commandResponseState_decoded == null) { - throw IllegalStateException("commandResponseState not found in TLV") + throw IllegalStateException("commandResponseState not found in TLV") } - tlvReader.exitContainer() - return OperationalCommandResponse( - commandResponseState_decoded - ) + return OperationalCommandResponse(commandResponseState_decoded) } -suspend fun readPhaseListAttribute(): PhaseListAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readPhaseListAttribute(): PhaseListAttribute { + 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}") - } + 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) { - "Phaselist attribute not found in response" - } + } + + requireNotNull(attributeData) { "Phaselist attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (!tlvReader.isNull()) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getString(AnonymousTag)) + val decodedValue: List? = + if (!tlvReader.isNull()) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getString(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + tlvReader.getNull(AnonymousTag) + null } - tlvReader.exitContainer() - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - return PhaseListAttribute(decodedValue) } suspend fun subscribePhaseListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(PhaseListAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + PhaseListAttributeSubscriptionState.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) { - "Phaselist attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Phaselist attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (!tlvReader.isNull()) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getString(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(PhaseListAttributeSubscriptionState.Success(it)) - } - + val decodedValue: List? = + if (!tlvReader.isNull()) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getString(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(PhaseListAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(PhaseListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCurrentPhaseAttribute(): CurrentPhaseAttribute {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readCurrentPhaseAttribute(): CurrentPhaseAttribute { + 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}") - } + 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) { - "Currentphase attribute not found in response" - } + } + + requireNotNull(attributeData) { "Currentphase attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return CurrentPhaseAttribute(decodedValue) } suspend fun subscribeCurrentPhaseAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(CurrentPhaseAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + CurrentPhaseAttributeSubscriptionState.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) { - "Currentphase attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Currentphase 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.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(CurrentPhaseAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(CurrentPhaseAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(CurrentPhaseAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCountdownTimeAttribute(): CountdownTimeAttribute {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readCountdownTimeAttribute(): CountdownTimeAttribute { + 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}") - } + 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) { - "Countdowntime attribute not found in response" - } + } + + requireNotNull(attributeData) { "Countdowntime attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return CountdownTimeAttribute(decodedValue) } suspend fun subscribeCountdownTimeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(CountdownTimeAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + CountdownTimeAttributeSubscriptionState.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) { - "Countdowntime attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Countdowntime attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(CountdownTimeAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(CountdownTimeAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(CountdownTimeAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readOperationalStateListAttribute(): OperationalStateListAttribute {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readOperationalStateListAttribute(): OperationalStateListAttribute { + 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}") - } + 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) { - "Operationalstatelist attribute not found in response" - } + } + + requireNotNull(attributeData) { "Operationalstatelist 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(RvcOperationalStateClusterOperationalStateStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(RvcOperationalStateClusterOperationalStateStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return OperationalStateListAttribute(decodedValue) } suspend fun subscribeOperationalStateListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(OperationalStateListAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + OperationalStateListAttributeSubscriptionState.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) { - "Operationalstatelist attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Operationalstatelist 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(RvcOperationalStateClusterOperationalStateStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add( + RvcOperationalStateClusterOperationalStateStruct.fromTlv(AnonymousTag, tlvReader) + ) + } + tlvReader.exitContainer() + } emit(OperationalStateListAttributeSubscriptionState.Success(decodedValue)) } @@ -740,80 +663,77 @@ suspend fun readOperationalStateListAttribute(): OperationalStateListAttribute { emit(OperationalStateListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readOperationalStateAttribute(): 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) - ) - + + suspend fun readOperationalStateAttribute(): 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}") - } + 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) { - "Operationalstate attribute not found in response" - } + } + + requireNotNull(attributeData) { "Operationalstate 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 subscribeOperationalStateAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Operationalstate attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Operationalstate attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -826,85 +746,84 @@ suspend fun readOperationalStateAttribute(): UByte {val ATTRIBUTE_ID: UInt = 4u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readOperationalErrorAttribute(): OperationalErrorAttribute {val ATTRIBUTE_ID: UInt = 5u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readOperationalErrorAttribute(): OperationalErrorAttribute { + 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}") - } + 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) { - "Operationalerror attribute not found in response" - } + } + + requireNotNull(attributeData) { "Operationalerror attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: RvcOperationalStateClusterErrorStateStruct = RvcOperationalStateClusterErrorStateStruct.fromTlv(AnonymousTag, tlvReader) - + val decodedValue: RvcOperationalStateClusterErrorStateStruct = + RvcOperationalStateClusterErrorStateStruct.fromTlv(AnonymousTag, tlvReader) return OperationalErrorAttribute(decodedValue) } suspend fun subscribeOperationalErrorAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(OperationalErrorAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + OperationalErrorAttributeSubscriptionState.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) { - "Operationalerror attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Operationalerror attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: RvcOperationalStateClusterErrorStateStruct = RvcOperationalStateClusterErrorStateStruct.fromTlv(AnonymousTag, tlvReader) + val decodedValue: RvcOperationalStateClusterErrorStateStruct = + RvcOperationalStateClusterErrorStateStruct.fromTlv(AnonymousTag, tlvReader) emit(OperationalErrorAttributeSubscriptionState.Success(decodedValue)) } @@ -912,97 +831,96 @@ suspend fun readOperationalErrorAttribute(): OperationalErrorAttribute {val ATTR emit(OperationalErrorAttributeSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1010,97 +928,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1108,97 +1025,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1206,97 +1120,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1304,81 +1215,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1390,80 +1296,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1476,7 +1379,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/RvcRunModeCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/RvcRunModeCluster.kt index e1baabf44d5473..931b95c4a3ab6d 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/RvcRunModeCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/RvcRunModeCluster.kt @@ -17,135 +17,101 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.UShortSubscriptionState +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter class RvcRunModeCluster(private val controller: MatterController, private val endpointId: UShort) { - class ChangeToModeResponse( - val status: UByte, - val statusText: String? - ) -class SupportedModesAttribute( - val value: List - ) + class ChangeToModeResponse(val status: UByte, val statusText: String?) + + class SupportedModesAttribute(val value: List) sealed class SupportedModesAttributeSubscriptionState { - data class Success( - val value: List - ) : SupportedModesAttributeSubscriptionState() - + data class Success(val value: List) : + SupportedModesAttributeSubscriptionState() + data class Error(val exception: Exception) : SupportedModesAttributeSubscriptionState() - object SubscriptionEstablished : SupportedModesAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : SupportedModesAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun changeToMode(newMode: UByte - ,timedInvokeTimeout: Duration? = null): ChangeToModeResponse { + suspend fun changeToMode( + newMode: UByte, + timedInvokeTimeout: Duration? = null, + ): ChangeToModeResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_NEW_MODE_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_NEW_MODE_REQ), newMode) + tlvWriter.put(ContextSpecificTag(TAG_NEW_MODE_REQ), newMode) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -155,140 +121,130 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_STATUS_TEXT: Int = 1 var statusText_decoded: String? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_STATUS_TEXT)) {statusText_decoded = + if (tag == ContextSpecificTag(TAG_STATUS)) { + status_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_STATUS_TEXT)) { + statusText_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - }} - - - else { + tlvReader.getString(tag) + } else { + null + } + } + } else { tlvReader.skipElement() } } - - if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - - - tlvReader.exitContainer() - return ChangeToModeResponse( - status_decoded, - statusText_decoded - ) + return ChangeToModeResponse(status_decoded, statusText_decoded) } -suspend fun readSupportedModesAttribute(): SupportedModesAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readSupportedModesAttribute(): SupportedModesAttribute { + 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}") - } + 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) { - "Supportedmodes attribute not found in response" - } + } + + requireNotNull(attributeData) { "Supportedmodes 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(RvcRunModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(RvcRunModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return SupportedModesAttribute(decodedValue) } suspend fun subscribeSupportedModesAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(SupportedModesAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + SupportedModesAttributeSubscriptionState.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) { - "Supportedmodes attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Supportedmodes 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(RvcRunModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(RvcRunModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(SupportedModesAttributeSubscriptionState.Success(decodedValue)) } @@ -296,81 +252,76 @@ suspend fun readSupportedModesAttribute(): SupportedModesAttribute {val ATTRIBUT emit(SupportedModesAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCurrentModeAttribute(): 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) - ) - + + suspend fun readCurrentModeAttribute(): 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}") - } + 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) { - "Currentmode attribute not found in response" - } + } + + requireNotNull(attributeData) { "Currentmode 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 subscribeCurrentModeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Currentmode attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Currentmode attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -382,97 +333,96 @@ suspend fun readCurrentModeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 1u emit(UByteSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -480,97 +430,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -578,97 +527,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -676,97 +622,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -774,81 +717,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -860,80 +798,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -946,7 +881,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/SampleMeiCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/SampleMeiCluster.kt index 9d5b10e9a5a6ce..0c96750d8a58e5 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/SampleMeiCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/SampleMeiCluster.kt @@ -17,126 +17,98 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration 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.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState -import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter class SampleMeiCluster(private val controller: MatterController, private val endpointId: UShort) { - class AddArgumentsResponse( - val returnValue: UByte - ) -class GeneratedCommandListAttribute( - val value: List - ) + class AddArgumentsResponse(val returnValue: UByte) + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } suspend fun ping(timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun addArguments(arg1: UByte - ,arg2: UByte - ,timedInvokeTimeout: Duration? = null): AddArgumentsResponse { + suspend fun addArguments( + arg1: UByte, + arg2: UByte, + timedInvokeTimeout: Duration? = null, + ): AddArgumentsResponse { val commandId: UInt = 2u val tlvWriter = TlvWriter() @@ -146,14 +118,14 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_ARG1_REQ), arg1) val TAG_ARG2_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_ARG2_REQ), arg2) + tlvWriter.put(ContextSpecificTag(TAG_ARG2_REQ), arg2) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -163,93 +135,74 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_RETURN_VALUE: Int = 0 var returnValue_decoded: UByte? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_RETURN_VALUE)) {returnValue_decoded = tlvReader.getUByte(tag)} - - - else { + if (tag == ContextSpecificTag(TAG_RETURN_VALUE)) { + returnValue_decoded = tlvReader.getUByte(tag) + } else { tlvReader.skipElement() } } - - if (returnValue_decoded == null) { - throw IllegalStateException("returnValue not found in TLV") + throw IllegalStateException("returnValue not found in TLV") } - tlvReader.exitContainer() - return AddArgumentsResponse( - returnValue_decoded - ) + return AddArgumentsResponse(returnValue_decoded) } -suspend fun readFlipFlopAttribute(): Boolean {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readFlipFlopAttribute(): Boolean { + 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}") - } + 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) { - "Flipflop attribute not found in response" - } + } + + requireNotNull(attributeData) { "Flipflop attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Boolean = tlvReader.getBoolean(AnonymousTag) - return decodedValue } - suspend fun writeFlipFlopAttribute( - value: Boolean, - timedWriteTimeout: Duration? = null) { + suspend fun writeFlipFlopAttribute(value: Boolean, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -270,43 +223,45 @@ suspend fun readFlipFlopAttribute(): Boolean {val ATTRIBUTE_ID: UInt = 0u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeFlipFlopAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Flipflop attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Flipflop attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -318,97 +273,96 @@ suspend fun readFlipFlopAttribute(): Boolean {val ATTRIBUTE_ID: UInt = 0u emit(BooleanSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -416,97 +370,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -514,97 +467,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -612,97 +562,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -710,81 +657,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -796,80 +738,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -882,7 +821,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/ScenesManagementCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/ScenesManagementCluster.kt index 2a67e9827d36a1..e363f8c88f37f3 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/ScenesManagementCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/ScenesManagementCluster.kt @@ -17,178 +17,131 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState -import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.UShortSubscriptionState +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class ScenesManagementCluster(private val controller: MatterController, private val endpointId: UShort) { - class AddSceneResponse( - val status: UByte, - val groupID: UShort, - val sceneID: UByte - ) +class ScenesManagementCluster( + 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: UInt?, - val sceneName: String?, - val extensionFieldSets: List? + val status: UByte, + val groupID: UShort, + val sceneID: UByte, + val transitionTime: UInt?, + val sceneName: String?, + val extensionFieldSets: List?, ) - class RemoveSceneResponse( - val status: UByte, - val groupID: UShort, - val sceneID: UByte - ) + class RemoveSceneResponse(val status: UByte, val groupID: UShort, val sceneID: UByte) - class RemoveAllScenesResponse( - val status: UByte, - val groupID: UShort - ) + class RemoveAllScenesResponse(val status: UByte, val groupID: UShort) - class StoreSceneResponse( - val status: UByte, - val groupID: UShort, - val sceneID: UByte - ) + 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? + val status: UByte, + val capacity: UByte?, + val groupID: UShort, + val sceneList: List?, ) class CopySceneResponse( - val status: UByte, - val groupIdentifierFrom: UShort, - val sceneIdentifierFrom: UByte - ) -class LastConfiguredByAttribute( - val value: ULong? + 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 Success(val value: ULong?) : LastConfiguredByAttributeSubscriptionState() + data class Error(val exception: Exception) : LastConfiguredByAttributeSubscriptionState() - object SubscriptionEstablished : LastConfiguredByAttributeSubscriptionState() - } -class FabricSceneInfoAttribute( - val value: List - ) + object SubscriptionEstablished : LastConfiguredByAttributeSubscriptionState() + } + + class FabricSceneInfoAttribute(val value: List) sealed class FabricSceneInfoAttributeSubscriptionState { - data class Success( - val value: List - ) : FabricSceneInfoAttributeSubscriptionState() - + data class Success(val value: List) : + FabricSceneInfoAttributeSubscriptionState() + data class Error(val exception: Exception) : FabricSceneInfoAttributeSubscriptionState() - object SubscriptionEstablished : FabricSceneInfoAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : FabricSceneInfoAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun addScene(groupID: UShort - ,sceneID: UByte - ,transitionTime: UInt - ,sceneName: String - ,extensionFieldSets: List - ,timedInvokeTimeout: Duration? = null): AddSceneResponse { + suspend fun addScene( + groupID: UShort, + sceneID: UByte, + transitionTime: UInt, + sceneName: String, + extensionFieldSets: List, + timedInvokeTimeout: Duration? = null, + ): AddSceneResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() @@ -208,17 +161,17 @@ class AttributeListAttribute( 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() + 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 + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -228,59 +181,53 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_GROUP_ID: Int = 1 var groupID_decoded: UShort? = null - + val TAG_SCENE_ID: 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_ID)) {groupID_decoded = tlvReader.getUShort(tag)} - - if (tag == ContextSpecificTag(TAG_SCENE_ID)) {sceneID_decoded = tlvReader.getUByte(tag)} - + if (tag == ContextSpecificTag(TAG_STATUS)) { + status_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_GROUP_ID)) { + groupID_decoded = tlvReader.getUShort(tag) + } - else { + if (tag == ContextSpecificTag(TAG_SCENE_ID)) { + sceneID_decoded = tlvReader.getUByte(tag) + } else { tlvReader.skipElement() } } - - if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - - + if (groupID_decoded == null) { - throw IllegalStateException("groupID not found in TLV") + throw IllegalStateException("groupID not found in TLV") } - - + if (sceneID_decoded == null) { - throw IllegalStateException("sceneID not found in TLV") + throw IllegalStateException("sceneID not found in TLV") } - tlvReader.exitContainer() - return AddSceneResponse( - status_decoded, - groupID_decoded, - sceneID_decoded - ) + return AddSceneResponse(status_decoded, groupID_decoded, sceneID_decoded) } - suspend fun viewScene(groupID: UShort - ,sceneID: UByte - ,timedInvokeTimeout: Duration? = null): ViewSceneResponse { + suspend fun viewScene( + groupID: UShort, + sceneID: UByte, + timedInvokeTimeout: Duration? = null, + ): ViewSceneResponse { val commandId: UInt = 1u val tlvWriter = TlvWriter() @@ -290,14 +237,14 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_GROUP_ID_REQ), groupID) val TAG_SCENE_ID_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_SCENE_ID_REQ), sceneID) + tlvWriter.put(ContextSpecificTag(TAG_SCENE_ID_REQ), sceneID) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -307,103 +254,99 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_GROUP_ID: Int = 1 var groupID_decoded: UShort? = null - + val TAG_SCENE_ID: Int = 2 var sceneID_decoded: UByte? = null - + val TAG_TRANSITION_TIME: Int = 3 var transitionTime_decoded: UInt? = 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_ID)) {groupID_decoded = tlvReader.getUShort(tag)} - - if (tag == ContextSpecificTag(TAG_SCENE_ID)) {sceneID_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_TRANSITION_TIME)) {transitionTime_decoded = + if (tag == ContextSpecificTag(TAG_STATUS)) { + status_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_GROUP_ID)) { + groupID_decoded = tlvReader.getUShort(tag) + } + + if (tag == ContextSpecificTag(TAG_SCENE_ID)) { + 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.getUInt(tag) - } else { - null - } - }} - - if (tag == ContextSpecificTag(TAG_SCENE_NAME)) {sceneName_decoded = + tlvReader.getUInt(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 = + 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(ScenesManagementClusterExtensionFieldSet.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null - } - }} - - - else { + buildList { + tlvReader.enterArray(tag) + while (!tlvReader.isEndOfContainer()) { + add(ScenesManagementClusterExtensionFieldSet.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null + } + } + } else { tlvReader.skipElement() } } - - if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - - + if (groupID_decoded == null) { - throw IllegalStateException("groupID not found in TLV") + throw IllegalStateException("groupID not found in TLV") } - - + if (sceneID_decoded == null) { - throw IllegalStateException("sceneID not found in TLV") + throw IllegalStateException("sceneID not found in TLV") } - - - - - - - tlvReader.exitContainer() @@ -413,13 +356,15 @@ class AttributeListAttribute( sceneID_decoded, transitionTime_decoded, sceneName_decoded, - extensionFieldSets_decoded + extensionFieldSets_decoded, ) } - suspend fun removeScene(groupID: UShort - ,sceneID: UByte - ,timedInvokeTimeout: Duration? = null): RemoveSceneResponse { + suspend fun removeScene( + groupID: UShort, + sceneID: UByte, + timedInvokeTimeout: Duration? = null, + ): RemoveSceneResponse { val commandId: UInt = 2u val tlvWriter = TlvWriter() @@ -429,14 +374,14 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_GROUP_ID_REQ), groupID) val TAG_SCENE_ID_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_SCENE_ID_REQ), sceneID) + tlvWriter.put(ContextSpecificTag(TAG_SCENE_ID_REQ), sceneID) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -446,72 +391,66 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_GROUP_ID: Int = 1 var groupID_decoded: UShort? = null - + val TAG_SCENE_ID: 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_ID)) {groupID_decoded = tlvReader.getUShort(tag)} - - if (tag == ContextSpecificTag(TAG_SCENE_ID)) {sceneID_decoded = tlvReader.getUByte(tag)} - + if (tag == ContextSpecificTag(TAG_STATUS)) { + status_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_GROUP_ID)) { + groupID_decoded = tlvReader.getUShort(tag) + } - else { + if (tag == ContextSpecificTag(TAG_SCENE_ID)) { + sceneID_decoded = tlvReader.getUByte(tag) + } else { tlvReader.skipElement() } } - - if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - - + if (groupID_decoded == null) { - throw IllegalStateException("groupID not found in TLV") + throw IllegalStateException("groupID not found in TLV") } - - + if (sceneID_decoded == null) { - throw IllegalStateException("sceneID not found in TLV") + throw IllegalStateException("sceneID not found in TLV") } - tlvReader.exitContainer() - return RemoveSceneResponse( - status_decoded, - groupID_decoded, - sceneID_decoded - ) + return RemoveSceneResponse(status_decoded, groupID_decoded, sceneID_decoded) } - suspend fun removeAllScenes(groupID: UShort - ,timedInvokeTimeout: Duration? = null): RemoveAllScenesResponse { + suspend fun removeAllScenes( + groupID: UShort, + timedInvokeTimeout: Duration? = null, + ): RemoveAllScenesResponse { val commandId: UInt = 3u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_GROUP_ID_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_GROUP_ID_REQ), groupID) + tlvWriter.put(ContextSpecificTag(TAG_GROUP_ID_REQ), groupID) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -521,48 +460,42 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_GROUP_ID: 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_ID)) {groupID_decoded = tlvReader.getUShort(tag)} - + if (tag == ContextSpecificTag(TAG_STATUS)) { + status_decoded = tlvReader.getUByte(tag) + } - else { + if (tag == ContextSpecificTag(TAG_GROUP_ID)) { + groupID_decoded = tlvReader.getUShort(tag) + } else { tlvReader.skipElement() } } - - if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - - + if (groupID_decoded == null) { - throw IllegalStateException("groupID not found in TLV") + throw IllegalStateException("groupID not found in TLV") } - tlvReader.exitContainer() - return RemoveAllScenesResponse( - status_decoded, - groupID_decoded - ) + return RemoveAllScenesResponse(status_decoded, groupID_decoded) } - suspend fun storeScene(groupID: UShort - ,sceneID: UByte - ,timedInvokeTimeout: Duration? = null): StoreSceneResponse { + suspend fun storeScene( + groupID: UShort, + sceneID: UByte, + timedInvokeTimeout: Duration? = null, + ): StoreSceneResponse { val commandId: UInt = 4u val tlvWriter = TlvWriter() @@ -572,14 +505,14 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_GROUP_ID_REQ), groupID) val TAG_SCENE_ID_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_SCENE_ID_REQ), sceneID) + tlvWriter.put(ContextSpecificTag(TAG_SCENE_ID_REQ), sceneID) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -589,60 +522,54 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_GROUP_ID: Int = 1 var groupID_decoded: UShort? = null - + val TAG_SCENE_ID: 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_ID)) {groupID_decoded = tlvReader.getUShort(tag)} - - if (tag == ContextSpecificTag(TAG_SCENE_ID)) {sceneID_decoded = tlvReader.getUByte(tag)} - + if (tag == ContextSpecificTag(TAG_STATUS)) { + status_decoded = tlvReader.getUByte(tag) + } - else { + if (tag == ContextSpecificTag(TAG_GROUP_ID)) { + groupID_decoded = tlvReader.getUShort(tag) + } + + if (tag == ContextSpecificTag(TAG_SCENE_ID)) { + sceneID_decoded = tlvReader.getUByte(tag) + } else { tlvReader.skipElement() } } - - if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - - + if (groupID_decoded == null) { - throw IllegalStateException("groupID not found in TLV") + throw IllegalStateException("groupID not found in TLV") } - - + if (sceneID_decoded == null) { - throw IllegalStateException("sceneID not found in TLV") + throw IllegalStateException("sceneID not found in TLV") } - tlvReader.exitContainer() - return StoreSceneResponse( - status_decoded, - groupID_decoded, - sceneID_decoded - ) + return StoreSceneResponse(status_decoded, groupID_decoded, sceneID_decoded) } - suspend fun recallScene(groupID: UShort - ,sceneID: UByte - ,transitionTime: UInt? - ,timedInvokeTimeout: Duration? = null) { + suspend fun recallScene( + groupID: UShort, + sceneID: UByte, + transitionTime: UInt?, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 5u val tlvWriter = TlvWriter() @@ -657,36 +584,38 @@ class AttributeListAttribute( 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 + 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 { + suspend fun getSceneMembership( + groupID: UShort, + timedInvokeTimeout: Duration? = null, + ): GetSceneMembershipResponse { val commandId: UInt = 6u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_GROUP_ID_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_GROUP_ID_REQ), groupID) + tlvWriter.put(ContextSpecificTag(TAG_GROUP_ID_REQ), groupID) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -696,77 +625,72 @@ class AttributeListAttribute( 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_ID: 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 (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_ID)) {groupID_decoded = tlvReader.getUShort(tag)} - - if (tag == ContextSpecificTag(TAG_SCENE_LIST)) {sceneList_decoded = + tlvReader.getUByte(tag) + } else { + tlvReader.getNull(tag) + null + } + } + } + + if (tag == ContextSpecificTag(TAG_GROUP_ID)) { + 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 { + 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") + throw IllegalStateException("status not found in TLV") } - - - - + if (groupID_decoded == null) { - throw IllegalStateException("groupID not found in TLV") + throw IllegalStateException("groupID not found in TLV") } - - - tlvReader.exitContainer() @@ -774,16 +698,18 @@ class AttributeListAttribute( status_decoded, capacity_decoded, groupID_decoded, - sceneList_decoded + sceneList_decoded, ) } - suspend fun copyScene(mode: UByte - ,groupIdentifierFrom: UShort - ,sceneIdentifierFrom: UByte - ,groupIdentifierTo: UShort - ,sceneIdentifierTo: UByte - ,timedInvokeTimeout: Duration? = null): CopySceneResponse { + suspend fun copyScene( + mode: UByte, + groupIdentifierFrom: UShort, + sceneIdentifierFrom: UByte, + groupIdentifierTo: UShort, + sceneIdentifierTo: UByte, + timedInvokeTimeout: Duration? = null, + ): CopySceneResponse { val commandId: UInt = 64u val tlvWriter = TlvWriter() @@ -802,14 +728,14 @@ class AttributeListAttribute( 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.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 + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -819,234 +745,223 @@ class AttributeListAttribute( 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)} - + if (tag == ContextSpecificTag(TAG_STATUS)) { + status_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_GROUP_IDENTIFIER_FROM)) { + groupIdentifierFrom_decoded = tlvReader.getUShort(tag) + } - else { + 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") + throw IllegalStateException("status not found in TLV") } - - + if (groupIdentifierFrom_decoded == null) { - throw IllegalStateException("groupIdentifierFrom not found in TLV") + throw IllegalStateException("groupIdentifierFrom not found in TLV") } - - + if (sceneIdentifierFrom_decoded == null) { - throw IllegalStateException("sceneIdentifierFrom not found in TLV") + throw IllegalStateException("sceneIdentifierFrom not found in TLV") } - tlvReader.exitContainer() return CopySceneResponse( status_decoded, groupIdentifierFrom_decoded, - sceneIdentifierFrom_decoded + sceneIdentifierFrom_decoded, ) } -suspend fun readLastConfiguredByAttribute(): LastConfiguredByAttribute {val ATTRIBUTE_ID: UInt = 0u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readLastConfiguredByAttribute(): LastConfiguredByAttribute { + 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 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}") - } + 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" - } + } + + 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 - } - + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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)) - } - + 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 = 1u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readSceneTableSizeAttribute(): UShort { + 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 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1059,97 +974,96 @@ suspend fun readSceneTableSizeAttribute(): UShort {val ATTRIBUTE_ID: UInt = 1u emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readFabricSceneInfoAttribute(): FabricSceneInfoAttribute {val ATTRIBUTE_ID: UInt = 2u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readFabricSceneInfoAttribute(): FabricSceneInfoAttribute { + 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 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}") - } + 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" - } + } + + 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(ScenesManagementClusterSceneInfoStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(ScenesManagementClusterSceneInfoStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return FabricSceneInfoAttribute(decodedValue) } suspend fun subscribeFabricSceneInfoAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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(ScenesManagementClusterSceneInfoStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(ScenesManagementClusterSceneInfoStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(FabricSceneInfoAttributeSubscriptionState.Success(decodedValue)) } @@ -1157,97 +1071,96 @@ suspend fun readFabricSceneInfoAttribute(): FabricSceneInfoAttribute {val ATTRIB emit(FabricSceneInfoAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65528u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1255,97 +1168,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { emit(GeneratedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65529u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1353,97 +1265,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va emit(AcceptedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt = 65530u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1451,97 +1360,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt emit(EventListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ID: UInt = 65531u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1549,81 +1455,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ emit(AttributeListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1635,80 +1536,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 65533u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1721,7 +1619,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/ServiceAreaCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/ServiceAreaCluster.kt index a79587828803e2..b526c0ea4c38b9 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/ServiceAreaCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/ServiceAreaCluster.kt @@ -17,191 +17,140 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState -import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.UShortSubscriptionState +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter class ServiceAreaCluster(private val controller: MatterController, private val endpointId: UShort) { - class SelectAreasResponse( - val status: UByte, - val statusText: String - ) - - class SkipAreaResponse( - val status: UByte, - val statusText: String - ) -class SupportedAreasAttribute( - val value: List - ) + class SelectAreasResponse(val status: UByte, val statusText: String) + + class SkipAreaResponse(val status: UByte, val statusText: String) + + class SupportedAreasAttribute(val value: List) sealed class SupportedAreasAttributeSubscriptionState { - data class Success( - val value: List - ) : SupportedAreasAttributeSubscriptionState() - + data class Success(val value: List) : + SupportedAreasAttributeSubscriptionState() + data class Error(val exception: Exception) : SupportedAreasAttributeSubscriptionState() - object SubscriptionEstablished : SupportedAreasAttributeSubscriptionState() - } -class SupportedMapsAttribute( - val value: List? - ) + object SubscriptionEstablished : SupportedAreasAttributeSubscriptionState() + } + + class SupportedMapsAttribute(val value: List?) sealed class SupportedMapsAttributeSubscriptionState { - data class Success( - val value: List? - ) : SupportedMapsAttributeSubscriptionState() - + data class Success(val value: List?) : + SupportedMapsAttributeSubscriptionState() + data class Error(val exception: Exception) : SupportedMapsAttributeSubscriptionState() - object SubscriptionEstablished : SupportedMapsAttributeSubscriptionState() - } -class SelectedAreasAttribute( - val value: List - ) + object SubscriptionEstablished : SupportedMapsAttributeSubscriptionState() + } + + class SelectedAreasAttribute(val value: List) sealed class SelectedAreasAttributeSubscriptionState { - data class Success( - val value: List - ) : SelectedAreasAttributeSubscriptionState() - + data class Success(val value: List) : SelectedAreasAttributeSubscriptionState() + data class Error(val exception: Exception) : SelectedAreasAttributeSubscriptionState() - object SubscriptionEstablished : SelectedAreasAttributeSubscriptionState() - } -class CurrentAreaAttribute( - val value: UInt? - ) + object SubscriptionEstablished : SelectedAreasAttributeSubscriptionState() + } + + class CurrentAreaAttribute(val value: UInt?) sealed class CurrentAreaAttributeSubscriptionState { - data class Success( - val value: UInt? - ) : CurrentAreaAttributeSubscriptionState() - + data class Success(val value: UInt?) : CurrentAreaAttributeSubscriptionState() + data class Error(val exception: Exception) : CurrentAreaAttributeSubscriptionState() - object SubscriptionEstablished : CurrentAreaAttributeSubscriptionState() - } -class EstimatedEndTimeAttribute( - val value: UInt? - ) + object SubscriptionEstablished : CurrentAreaAttributeSubscriptionState() + } + + class EstimatedEndTimeAttribute(val value: UInt?) sealed class EstimatedEndTimeAttributeSubscriptionState { - data class Success( - val value: UInt? - ) : EstimatedEndTimeAttributeSubscriptionState() - + data class Success(val value: UInt?) : EstimatedEndTimeAttributeSubscriptionState() + data class Error(val exception: Exception) : EstimatedEndTimeAttributeSubscriptionState() - object SubscriptionEstablished : EstimatedEndTimeAttributeSubscriptionState() - } -class ProgressAttribute( - val value: List? - ) + object SubscriptionEstablished : EstimatedEndTimeAttributeSubscriptionState() + } + + class ProgressAttribute(val value: List?) sealed class ProgressAttributeSubscriptionState { - data class Success( - val value: List? - ) : ProgressAttributeSubscriptionState() - + data class Success(val value: List?) : + ProgressAttributeSubscriptionState() + data class Error(val exception: Exception) : ProgressAttributeSubscriptionState() - object SubscriptionEstablished : ProgressAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : ProgressAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun selectAreas(newAreas: List - ,timedInvokeTimeout: Duration? = null): SelectAreasResponse { + suspend fun selectAreas( + newAreas: List, + timedInvokeTimeout: Duration? = null, + ): SelectAreasResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() @@ -209,17 +158,17 @@ class AttributeListAttribute( val TAG_NEW_AREAS_REQ: Int = 0 tlvWriter.startArray(ContextSpecificTag(TAG_NEW_AREAS_REQ)) - for (item in newAreas.iterator()) { - tlvWriter.put(AnonymousTag, item) - } - tlvWriter.endArray() + for (item in newAreas.iterator()) { + tlvWriter.put(AnonymousTag, item) + } + tlvWriter.endArray() tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -229,61 +178,52 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_STATUS_TEXT: Int = 1 var statusText_decoded: String? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_STATUS_TEXT)) {statusText_decoded = tlvReader.getString(tag)} - + if (tag == ContextSpecificTag(TAG_STATUS)) { + status_decoded = tlvReader.getUByte(tag) + } - else { + if (tag == ContextSpecificTag(TAG_STATUS_TEXT)) { + statusText_decoded = tlvReader.getString(tag) + } else { tlvReader.skipElement() } } - - if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - - + if (statusText_decoded == null) { - throw IllegalStateException("statusText not found in TLV") + throw IllegalStateException("statusText not found in TLV") } - tlvReader.exitContainer() - return SelectAreasResponse( - status_decoded, - statusText_decoded - ) + return SelectAreasResponse(status_decoded, statusText_decoded) } - suspend fun skipArea(skippedArea: UInt - ,timedInvokeTimeout: Duration? = null): SkipAreaResponse { + suspend fun skipArea(skippedArea: UInt, timedInvokeTimeout: Duration? = null): SkipAreaResponse { val commandId: UInt = 2u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_SKIPPED_AREA_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_SKIPPED_AREA_REQ), skippedArea) + tlvWriter.put(ContextSpecificTag(TAG_SKIPPED_AREA_REQ), skippedArea) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -293,133 +233,124 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_STATUS_TEXT: Int = 1 var statusText_decoded: String? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_STATUS_TEXT)) {statusText_decoded = tlvReader.getString(tag)} - + if (tag == ContextSpecificTag(TAG_STATUS)) { + status_decoded = tlvReader.getUByte(tag) + } - else { + if (tag == ContextSpecificTag(TAG_STATUS_TEXT)) { + statusText_decoded = tlvReader.getString(tag) + } else { tlvReader.skipElement() } } - - if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - - + if (statusText_decoded == null) { - throw IllegalStateException("statusText not found in TLV") + throw IllegalStateException("statusText not found in TLV") } - tlvReader.exitContainer() - return SkipAreaResponse( - status_decoded, - statusText_decoded - ) + return SkipAreaResponse(status_decoded, statusText_decoded) } -suspend fun readSupportedAreasAttribute(): SupportedAreasAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readSupportedAreasAttribute(): SupportedAreasAttribute { + 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}") - } + 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) { - "Supportedareas attribute not found in response" - } + } + + requireNotNull(attributeData) { "Supportedareas 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(ServiceAreaClusterAreaStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(ServiceAreaClusterAreaStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return SupportedAreasAttribute(decodedValue) } suspend fun subscribeSupportedAreasAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(SupportedAreasAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + SupportedAreasAttributeSubscriptionState.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) { - "Supportedareas attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Supportedareas 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(ServiceAreaClusterAreaStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(ServiceAreaClusterAreaStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(SupportedAreasAttributeSubscriptionState.Success(decodedValue)) } @@ -427,206 +358,197 @@ suspend fun readSupportedAreasAttribute(): SupportedAreasAttribute {val ATTRIBUT emit(SupportedAreasAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readSupportedMapsAttribute(): SupportedMapsAttribute {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readSupportedMapsAttribute(): SupportedMapsAttribute { + 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}") - } + 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) { - "Supportedmaps attribute not found in response" - } + } + + requireNotNull(attributeData) { "Supportedmaps attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(ServiceAreaClusterMapStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(ServiceAreaClusterMapStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null } - tlvReader.exitContainer() - } - } else { - null - } - return SupportedMapsAttribute(decodedValue) } suspend fun subscribeSupportedMapsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(SupportedMapsAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + SupportedMapsAttributeSubscriptionState.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) { - "Supportedmaps attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Supportedmaps attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(ServiceAreaClusterMapStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { - emit(SupportedMapsAttributeSubscriptionState.Success(it)) - } - + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(ServiceAreaClusterMapStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { emit(SupportedMapsAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(SupportedMapsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readSelectedAreasAttribute(): SelectedAreasAttribute {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readSelectedAreasAttribute(): SelectedAreasAttribute { + 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}") - } + 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) { - "Selectedareas attribute not found in response" - } + } + + requireNotNull(attributeData) { "Selectedareas 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return SelectedAreasAttribute(decodedValue) } suspend fun subscribeSelectedAreasAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(SelectedAreasAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + SelectedAreasAttributeSubscriptionState.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) { - "Selectedareas attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Selectedareas 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(SelectedAreasAttributeSubscriptionState.Success(decodedValue)) } @@ -634,420 +556,403 @@ suspend fun readSelectedAreasAttribute(): SelectedAreasAttribute {val ATTRIBUTE_ emit(SelectedAreasAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCurrentAreaAttribute(): CurrentAreaAttribute {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readCurrentAreaAttribute(): CurrentAreaAttribute { + 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}") - } + 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) { - "Currentarea attribute not found in response" - } + } + + requireNotNull(attributeData) { "Currentarea attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return CurrentAreaAttribute(decodedValue) } suspend fun subscribeCurrentAreaAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(CurrentAreaAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + CurrentAreaAttributeSubscriptionState.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) { - "Currentarea attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Currentarea attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(CurrentAreaAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(CurrentAreaAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(CurrentAreaAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readEstimatedEndTimeAttribute(): EstimatedEndTimeAttribute {val ATTRIBUTE_ID: UInt = 4u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readEstimatedEndTimeAttribute(): EstimatedEndTimeAttribute { + 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}") - } + 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) { - "Estimatedendtime attribute not found in response" - } + } + + requireNotNull(attributeData) { "Estimatedendtime attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return EstimatedEndTimeAttribute(decodedValue) } suspend fun subscribeEstimatedEndTimeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(EstimatedEndTimeAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + EstimatedEndTimeAttributeSubscriptionState.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) { - "Estimatedendtime attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Estimatedendtime attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(EstimatedEndTimeAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(EstimatedEndTimeAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(EstimatedEndTimeAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readProgressAttribute(): ProgressAttribute {val ATTRIBUTE_ID: UInt = 5u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readProgressAttribute(): ProgressAttribute { + 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}") - } + 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) { - "Progress attribute not found in response" - } + } + + requireNotNull(attributeData) { "Progress attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(ServiceAreaClusterProgressStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(ServiceAreaClusterProgressStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null } - tlvReader.exitContainer() - } - } else { - null - } - return ProgressAttribute(decodedValue) } suspend fun subscribeProgressAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ProgressAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ProgressAttributeSubscriptionState.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) { - "Progress attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Progress attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(ServiceAreaClusterProgressStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { - emit(ProgressAttributeSubscriptionState.Success(it)) - } - + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(ServiceAreaClusterProgressStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { emit(ProgressAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ProgressAttributeSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1055,97 +960,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1153,97 +1057,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1251,97 +1152,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1349,81 +1247,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1435,80 +1328,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1521,7 +1411,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/SmokeCoAlarmCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/SmokeCoAlarmCluster.kt index ec9ca8d0e7e65a..f859709eaf7aab 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/SmokeCoAlarmCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/SmokeCoAlarmCluster.kt @@ -17,190 +17,162 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration 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.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class SmokeCoAlarmCluster(private val controller: MatterController, private val endpointId: UShort) {class GeneratedCommandListAttribute( - val value: List - ) +class SmokeCoAlarmCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } suspend fun selfTestRequest(timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } -suspend fun readExpressedStateAttribute(): 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) - ) - + + suspend fun readExpressedStateAttribute(): 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}") - } + 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) { - "Expressedstate attribute not found in response" - } + } + + requireNotNull(attributeData) { "Expressedstate 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 subscribeExpressedStateAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Expressedstate attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Expressedstate attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -213,275 +185,258 @@ suspend fun readExpressedStateAttribute(): UByte {val ATTRIBUTE_ID: UInt = 0u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readSmokeStateAttribute(): 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) - ) - + + suspend fun readSmokeStateAttribute(): 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}") - } + 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) { - "Smokestate attribute not found in response" - } + } + + requireNotNull(attributeData) { "Smokestate 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeSmokeStateAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Smokestate attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Smokestate 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)) - } - + 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 readCOStateAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readCOStateAttribute(): UByte? { + 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}") - } + 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) { - "Costate attribute not found in response" - } + } + + requireNotNull(attributeData) { "Costate 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeCOStateAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Costate attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Costate 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)) - } - + 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 readBatteryAlertAttribute(): UByte {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readBatteryAlertAttribute(): UByte { + 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}") - } + 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) { - "Batteryalert attribute not found in response" - } + } + + requireNotNull(attributeData) { "Batteryalert 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 subscribeBatteryAlertAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Batteryalert attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Batteryalert attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -493,177 +448,168 @@ suspend fun readBatteryAlertAttribute(): UByte {val ATTRIBUTE_ID: UInt = 3u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readDeviceMutedAttribute(): 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) - ) - + + suspend fun readDeviceMutedAttribute(): 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}") - } + 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) { - "Devicemuted attribute not found in response" - } + } + + requireNotNull(attributeData) { "Devicemuted 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeDeviceMutedAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Devicemuted attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Devicemuted 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)) - } - + 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 readTestInProgressAttribute(): Boolean {val ATTRIBUTE_ID: UInt = 5u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readTestInProgressAttribute(): Boolean { + 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}") - } + 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) { - "Testinprogress attribute not found in response" - } + } + + requireNotNull(attributeData) { "Testinprogress attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Boolean = tlvReader.getBoolean(AnonymousTag) - return decodedValue } suspend fun subscribeTestInProgressAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Testinprogress attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Testinprogress attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -676,80 +622,77 @@ suspend fun readTestInProgressAttribute(): Boolean {val ATTRIBUTE_ID: UInt = 5u emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readHardwareFaultAlertAttribute(): Boolean {val ATTRIBUTE_ID: UInt = 6u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readHardwareFaultAlertAttribute(): Boolean { + 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}") - } + 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) { - "Hardwarefaultalert attribute not found in response" - } + } + + requireNotNull(attributeData) { "Hardwarefaultalert attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Boolean = tlvReader.getBoolean(AnonymousTag) - return decodedValue } suspend fun subscribeHardwareFaultAlertAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Hardwarefaultalert attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Hardwarefaultalert attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -762,80 +705,77 @@ suspend fun readHardwareFaultAlertAttribute(): Boolean {val ATTRIBUTE_ID: UInt = emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readEndOfServiceAlertAttribute(): UByte {val ATTRIBUTE_ID: UInt = 7u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readEndOfServiceAlertAttribute(): UByte { + 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}") - } + 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) { - "Endofservicealert attribute not found in response" - } + } + + requireNotNull(attributeData) { "Endofservicealert 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 subscribeEndOfServiceAlertAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Endofservicealert attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Endofservicealert attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -848,363 +788,344 @@ suspend fun readEndOfServiceAlertAttribute(): UByte {val ATTRIBUTE_ID: UInt = 7u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readInterconnectSmokeAlarmAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 8u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readInterconnectSmokeAlarmAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 8u + + 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}") - } + 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) { - "Interconnectsmokealarm attribute not found in response" - } + } + + requireNotNull(attributeData) { "Interconnectsmokealarm 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeInterconnectSmokeAlarmAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Interconnectsmokealarm attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Interconnectsmokealarm 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)) - } - + 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 readInterconnectCOAlarmAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 9u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readInterconnectCOAlarmAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 9u + + 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}") - } + 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) { - "Interconnectcoalarm attribute not found in response" - } + } + + requireNotNull(attributeData) { "Interconnectcoalarm 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeInterconnectCOAlarmAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Interconnectcoalarm attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Interconnectcoalarm 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)) - } - + 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 readContaminationStateAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 10u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readContaminationStateAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 10u + + 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}") - } + 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) { - "Contaminationstate attribute not found in response" - } + } + + requireNotNull(attributeData) { "Contaminationstate 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeContaminationStateAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Contaminationstate attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Contaminationstate 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)) - } - + 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 readSmokeSensitivityLevelAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 11u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readSmokeSensitivityLevelAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 11u + + 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}") - } + 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) { - "Smokesensitivitylevel attribute not found in response" - } + } + + requireNotNull(attributeData) { "Smokesensitivitylevel 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun writeSmokeSensitivityLevelAttribute( value: UByte, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 11u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -1225,249 +1146,244 @@ suspend fun readSmokeSensitivityLevelAttribute(): UByte? {val ATTRIBUTE_ID: UInt throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeSmokeSensitivityLevelAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 11u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Smokesensitivitylevel attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Smokesensitivitylevel 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)) - } - + 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 readExpiryDateAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 12u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readExpiryDateAttribute(): UInt? { + val ATTRIBUTE_ID: UInt = 12u + + 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}") - } + 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) { - "Expirydate attribute not found in response" - } + } + + requireNotNull(attributeData) { "Expirydate attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeExpiryDateAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 12u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Expirydate attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Expirydate attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1475,97 +1391,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1573,97 +1488,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1671,97 +1583,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1769,81 +1678,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1855,80 +1759,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1941,7 +1842,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/SoftwareDiagnosticsCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/SoftwareDiagnosticsCluster.kt index 3e60be49a852ca..e9b7a01ed3b816 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/SoftwareDiagnosticsCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/SoftwareDiagnosticsCluster.kt @@ -17,620 +17,572 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState -import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.UShortSubscriptionState +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class SoftwareDiagnosticsCluster(private val controller: MatterController, private val endpointId: UShort) {class ThreadMetricsAttribute( - val value: List? - ) +class SoftwareDiagnosticsCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class ThreadMetricsAttribute(val value: List?) sealed class ThreadMetricsAttributeSubscriptionState { - data class Success( - val value: List? - ) : ThreadMetricsAttributeSubscriptionState() - + data class Success(val value: List?) : + ThreadMetricsAttributeSubscriptionState() + data class Error(val exception: Exception) : ThreadMetricsAttributeSubscriptionState() - object SubscriptionEstablished : ThreadMetricsAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : ThreadMetricsAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } suspend fun resetWatermarks(timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } -suspend fun readThreadMetricsAttribute(): ThreadMetricsAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readThreadMetricsAttribute(): ThreadMetricsAttribute { + 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}") - } + 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) { - "Threadmetrics attribute not found in response" - } + } + + requireNotNull(attributeData) { "Threadmetrics attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(SoftwareDiagnosticsClusterThreadMetricsStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(SoftwareDiagnosticsClusterThreadMetricsStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null } - tlvReader.exitContainer() - } - } else { - null - } - return ThreadMetricsAttribute(decodedValue) } suspend fun subscribeThreadMetricsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ThreadMetricsAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ThreadMetricsAttributeSubscriptionState.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) { - "Threadmetrics attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Threadmetrics attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(SoftwareDiagnosticsClusterThreadMetricsStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { - emit(ThreadMetricsAttributeSubscriptionState.Success(it)) - } - + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add( + SoftwareDiagnosticsClusterThreadMetricsStruct.fromTlv(AnonymousTag, tlvReader) + ) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { emit(ThreadMetricsAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ThreadMetricsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCurrentHeapFreeAttribute(): ULong? {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readCurrentHeapFreeAttribute(): ULong? { + 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}") - } + 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) { - "Currentheapfree attribute not found in response" - } + } + + requireNotNull(attributeData) { "Currentheapfree attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ULong? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getULong(AnonymousTag) - } else { - null - } - + val decodedValue: ULong? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeCurrentHeapFreeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ULongSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ULongSubscriptionState.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) { - "Currentheapfree attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Currentheapfree 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.isNextTag(AnonymousTag)) { - tlvReader.getULong(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(ULongSubscriptionState.Success(it)) - } - + val decodedValue: ULong? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(ULongSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ULongSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCurrentHeapUsedAttribute(): ULong? {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readCurrentHeapUsedAttribute(): ULong? { + 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}") - } + 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) { - "Currentheapused attribute not found in response" - } + } + + requireNotNull(attributeData) { "Currentheapused attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ULong? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getULong(AnonymousTag) - } else { - null - } - + val decodedValue: ULong? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeCurrentHeapUsedAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ULongSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ULongSubscriptionState.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) { - "Currentheapused attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Currentheapused 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.isNextTag(AnonymousTag)) { - tlvReader.getULong(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(ULongSubscriptionState.Success(it)) - } - + val decodedValue: ULong? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(ULongSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ULongSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCurrentHeapHighWatermarkAttribute(): ULong? {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readCurrentHeapHighWatermarkAttribute(): ULong? { + 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}") - } + 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) { - "Currentheaphighwatermark attribute not found in response" - } + } + + requireNotNull(attributeData) { "Currentheaphighwatermark attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ULong? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getULong(AnonymousTag) - } else { - null - } - + val decodedValue: ULong? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeCurrentHeapHighWatermarkAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ULongSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ULongSubscriptionState.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) { - "Currentheaphighwatermark attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Currentheaphighwatermark 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.isNextTag(AnonymousTag)) { - tlvReader.getULong(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(ULongSubscriptionState.Success(it)) - } - + val decodedValue: ULong? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(ULongSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ULongSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -638,97 +590,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -736,97 +687,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -834,97 +782,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -932,81 +877,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1018,80 +958,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1104,7 +1041,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/SwitchCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/SwitchCluster.kt index 0462ac9b0c886c..8f509aeedab056 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/SwitchCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/SwitchCluster.kt @@ -17,172 +17,133 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse -import matter.controller.model.AttributePath -import matter.controller.model.CommandPath +import matter.controller.UShortSubscriptionState import matter.controller.cluster.structs.* +import matter.controller.model.AttributePath import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader -import matter.tlv.TlvWriter -class SwitchCluster(private val controller: MatterController, private val endpointId: UShort) {class GeneratedCommandListAttribute( - val value: List - ) +class SwitchCluster(private val controller: MatterController, private val endpointId: UShort) { + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } -suspend fun readNumberOfPositionsAttribute(): 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) - ) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } + + suspend fun readNumberOfPositionsAttribute(): 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}") - } + 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) { - "Numberofpositions attribute not found in response" - } + } + + requireNotNull(attributeData) { "Numberofpositions 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 subscribeNumberOfPositionsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Numberofpositions attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Numberofpositions attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -195,80 +156,77 @@ suspend fun readNumberOfPositionsAttribute(): UByte {val ATTRIBUTE_ID: UInt = 0u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCurrentPositionAttribute(): 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) - ) - + + suspend fun readCurrentPositionAttribute(): 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}") - } + 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) { - "Currentposition attribute not found in response" - } + } + + requireNotNull(attributeData) { "Currentposition 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 subscribeCurrentPositionAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Currentposition attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Currentposition attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -281,194 +239,187 @@ suspend fun readCurrentPositionAttribute(): UByte {val ATTRIBUTE_ID: UInt = 1u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMultiPressMaxAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMultiPressMaxAttribute(): UByte? { + 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}") - } + 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) { - "Multipressmax attribute not found in response" - } + } + + requireNotNull(attributeData) { "Multipressmax 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeMultiPressMaxAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Multipressmax attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Multipressmax 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)) - } - + 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 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -476,97 +427,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -574,97 +524,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -672,97 +619,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -770,81 +714,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -856,80 +795,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -942,7 +878,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/TargetNavigatorCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/TargetNavigatorCluster.kt index c7aee150c59e6c..79ab138ac63767 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/TargetNavigatorCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/TargetNavigatorCluster.kt @@ -17,122 +17,91 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.UShortSubscriptionState +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class TargetNavigatorCluster(private val controller: MatterController, private val endpointId: UShort) { - class NavigateTargetResponse( - val status: UByte, - val data: String? - ) -class TargetListAttribute( - val value: List - ) +class TargetNavigatorCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class NavigateTargetResponse(val status: UByte, val data: String?) + + class TargetListAttribute(val value: List) sealed class TargetListAttributeSubscriptionState { - data class Success( - val value: List - ) : TargetListAttributeSubscriptionState() - + data class Success(val value: List) : + TargetListAttributeSubscriptionState() + data class Error(val exception: Exception) : TargetListAttributeSubscriptionState() - object SubscriptionEstablished : TargetListAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : TargetListAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun navigateTarget(target: UByte - ,data: String? - ,timedInvokeTimeout: Duration? = null): NavigateTargetResponse { + suspend fun navigateTarget( + target: UByte, + data: String?, + timedInvokeTimeout: Duration? = null, + ): NavigateTargetResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() @@ -142,16 +111,14 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_TARGET_REQ), target) val TAG_DATA_REQ: Int = 1 - data?.let { - tlvWriter.put(ContextSpecificTag(TAG_DATA_REQ), data) - } + data?.let { tlvWriter.put(ContextSpecificTag(TAG_DATA_REQ), data) } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -161,140 +128,128 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_DATA: Int = 1 var data_decoded: String? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_DATA)) {data_decoded = + if (tag == ContextSpecificTag(TAG_STATUS)) { + status_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_DATA)) { + data_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - }} - - - else { + tlvReader.getString(tag) + } else { + null + } + } + } else { tlvReader.skipElement() } } - - if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - - - tlvReader.exitContainer() - return NavigateTargetResponse( - status_decoded, - data_decoded - ) + return NavigateTargetResponse(status_decoded, data_decoded) } -suspend fun readTargetListAttribute(): TargetListAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readTargetListAttribute(): TargetListAttribute { + 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}") - } + 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) { - "Targetlist attribute not found in response" - } + } + + requireNotNull(attributeData) { "Targetlist 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(TargetNavigatorClusterTargetInfoStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(TargetNavigatorClusterTargetInfoStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return TargetListAttribute(decodedValue) } suspend fun subscribeTargetListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(TargetListAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + TargetListAttributeSubscriptionState.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) { - "Targetlist attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Targetlist 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(TargetNavigatorClusterTargetInfoStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(TargetNavigatorClusterTargetInfoStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(TargetListAttributeSubscriptionState.Success(decodedValue)) } @@ -302,194 +257,187 @@ suspend fun readTargetListAttribute(): TargetListAttribute {val ATTRIBUTE_ID: UI emit(TargetListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCurrentTargetAttribute(): 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) - ) - + + suspend fun readCurrentTargetAttribute(): 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}") - } + 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) { - "Currenttarget attribute not found in response" - } + } + + requireNotNull(attributeData) { "Currenttarget 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeCurrentTargetAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Currenttarget attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Currenttarget 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)) - } - + 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 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -497,97 +445,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -595,97 +542,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -693,97 +637,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -791,81 +732,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -877,80 +813,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -963,7 +896,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/TemperatureControlCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/TemperatureControlCluster.kt index 879479e9577967..414914cd5a45f2 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/TemperatureControlCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/TemperatureControlCluster.kt @@ -17,117 +17,91 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest +import matter.controller.ShortSubscriptionState import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.UShortSubscriptionState +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class TemperatureControlCluster(private val controller: MatterController, private val endpointId: UShort) {class SupportedTemperatureLevelsAttribute( - val value: List? - ) +class TemperatureControlCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class SupportedTemperatureLevelsAttribute(val value: List?) sealed class SupportedTemperatureLevelsAttributeSubscriptionState { - data class Success( - val value: List? - ) : SupportedTemperatureLevelsAttributeSubscriptionState() - - data class Error(val exception: Exception) : SupportedTemperatureLevelsAttributeSubscriptionState() - - object SubscriptionEstablished : SupportedTemperatureLevelsAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + data class Success(val value: List?) : + SupportedTemperatureLevelsAttributeSubscriptionState() + + data class Error(val exception: Exception) : + SupportedTemperatureLevelsAttributeSubscriptionState() + + object SubscriptionEstablished : SupportedTemperatureLevelsAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun setTemperature(targetTemperature: Short? - ,targetTemperatureLevel: UByte? - ,timedInvokeTimeout: Duration? = null) { + suspend fun setTemperature( + targetTemperature: Short?, + targetTemperatureLevel: UByte?, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 0u val tlvWriter = TlvWriter() @@ -141,702 +115,677 @@ class AttributeListAttribute( val TAG_TARGET_TEMPERATURE_LEVEL_REQ: Int = 1 targetTemperatureLevel?.let { tlvWriter.put(ContextSpecificTag(TAG_TARGET_TEMPERATURE_LEVEL_REQ), targetTemperatureLevel) - } + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } -suspend fun readTemperatureSetpointAttribute(): Short? {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readTemperatureSetpointAttribute(): Short? { + 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}") - } + 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) { - "Temperaturesetpoint attribute not found in response" - } + } + + requireNotNull(attributeData) { "Temperaturesetpoint attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeTemperatureSetpointAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Temperaturesetpoint attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Temperaturesetpoint attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMinTemperatureAttribute(): Short? {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMinTemperatureAttribute(): Short? { + 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}") - } + 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) { - "Mintemperature attribute not found in response" - } + } + + requireNotNull(attributeData) { "Mintemperature attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeMinTemperatureAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Mintemperature attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Mintemperature attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMaxTemperatureAttribute(): Short? {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMaxTemperatureAttribute(): Short? { + 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}") - } + 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) { - "Maxtemperature attribute not found in response" - } + } + + requireNotNull(attributeData) { "Maxtemperature attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeMaxTemperatureAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Maxtemperature attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Maxtemperature attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readStepAttribute(): Short? {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readStepAttribute(): Short? { + 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}") - } + 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) { - "Step attribute not found in response" - } + } + + requireNotNull(attributeData) { "Step attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeStepAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Step attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Step attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readSelectedTemperatureLevelAttribute(): 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) - ) - + + suspend fun readSelectedTemperatureLevelAttribute(): 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}") - } + 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) { - "Selectedtemperaturelevel attribute not found in response" - } + } + + requireNotNull(attributeData) { "Selectedtemperaturelevel 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeSelectedTemperatureLevelAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Selectedtemperaturelevel attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Selectedtemperaturelevel 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)) - } - + 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 readSupportedTemperatureLevelsAttribute(): SupportedTemperatureLevelsAttribute {val ATTRIBUTE_ID: UInt = 5u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readSupportedTemperatureLevelsAttribute(): SupportedTemperatureLevelsAttribute { + 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}") - } + 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) { - "Supportedtemperaturelevels attribute not found in response" - } + } + + requireNotNull(attributeData) { "Supportedtemperaturelevels attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getString(AnonymousTag)) + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getString(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null } - tlvReader.exitContainer() - } - } else { - null - } - return SupportedTemperatureLevelsAttribute(decodedValue) } suspend fun subscribeSupportedTemperatureLevelsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(SupportedTemperatureLevelsAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + SupportedTemperatureLevelsAttributeSubscriptionState.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) { - "Supportedtemperaturelevels attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Supportedtemperaturelevels attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getString(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null - } + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getString(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null + } decodedValue?.let { emit(SupportedTemperatureLevelsAttributeSubscriptionState.Success(it)) } - } SubscriptionState.SubscriptionEstablished -> { emit(SupportedTemperatureLevelsAttributeSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -844,97 +793,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -942,97 +890,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1040,97 +985,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1138,81 +1080,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1224,80 +1161,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1310,7 +1244,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/TemperatureMeasurementCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/TemperatureMeasurementCluster.kt index ef6d1043bbbf5b..60b2bc3e6f90b6 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/TemperatureMeasurementCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/TemperatureMeasurementCluster.kt @@ -17,622 +17,558 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState -import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse -import matter.controller.model.AttributePath -import matter.controller.model.CommandPath +import matter.controller.UShortSubscriptionState import matter.controller.cluster.structs.* +import matter.controller.model.AttributePath import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader -import matter.tlv.TlvWriter -class TemperatureMeasurementCluster(private val controller: MatterController, private val endpointId: UShort) {class MeasuredValueAttribute( - val value: Short? - ) +class TemperatureMeasurementCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class MeasuredValueAttribute(val value: Short?) sealed class MeasuredValueAttributeSubscriptionState { - data class Success( - val value: Short? - ) : MeasuredValueAttributeSubscriptionState() - + data class Success(val value: Short?) : MeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() - } -class MinMeasuredValueAttribute( - val value: Short? - ) + object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() + } + + class MinMeasuredValueAttribute(val value: Short?) sealed class MinMeasuredValueAttributeSubscriptionState { - data class Success( - val value: Short? - ) : MinMeasuredValueAttributeSubscriptionState() - + data class Success(val value: Short?) : MinMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MinMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() - } -class MaxMeasuredValueAttribute( - val value: Short? - ) + object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() + } + + class MaxMeasuredValueAttribute(val value: Short?) sealed class MaxMeasuredValueAttributeSubscriptionState { - data class Success( - val value: Short? - ) : MaxMeasuredValueAttributeSubscriptionState() - + data class Success(val value: Short?) : MaxMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MaxMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } -suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } + + suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute { + 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}") - } + 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) { - "Measuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Measuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (!tlvReader.isNull()) { - tlvReader.getShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Short? = + if (!tlvReader.isNull()) { + tlvReader.getShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return MeasuredValueAttribute(decodedValue) } suspend fun subscribeMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MeasuredValueAttributeSubscriptionState.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) { - "Measuredvalue attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Measuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (!tlvReader.isNull()) { - tlvReader.getShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Short? = + if (!tlvReader.isNull()) { + tlvReader.getShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute { + 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}") - } + 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) { - "Minmeasuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Minmeasuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (!tlvReader.isNull()) { - tlvReader.getShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Short? = + if (!tlvReader.isNull()) { + tlvReader.getShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return MinMeasuredValueAttribute(decodedValue) } suspend fun subscribeMinMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MinMeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MinMeasuredValueAttributeSubscriptionState.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) { - "Minmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Minmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (!tlvReader.isNull()) { - tlvReader.getShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Short? = + if (!tlvReader.isNull()) { + tlvReader.getShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MinMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute { + 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}") - } + 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) { - "Maxmeasuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Maxmeasuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (!tlvReader.isNull()) { - tlvReader.getShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Short? = + if (!tlvReader.isNull()) { + tlvReader.getShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return MaxMeasuredValueAttribute(decodedValue) } suspend fun subscribeMaxMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MaxMeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MaxMeasuredValueAttributeSubscriptionState.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) { - "Maxmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Maxmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (!tlvReader.isNull()) { - tlvReader.getShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Short? = + if (!tlvReader.isNull()) { + tlvReader.getShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MaxMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readToleranceAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readToleranceAttribute(): UShort? { + 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}") - } + 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) { - "Tolerance attribute not found in response" - } + } + + requireNotNull(attributeData) { "Tolerance 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeToleranceAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Tolerance attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Tolerance 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)) - } - + 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 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -640,97 +576,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -738,97 +673,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -836,97 +768,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -934,81 +863,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1020,80 +944,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1106,7 +1027,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/ThermostatCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/ThermostatCluster.kt index 8024c0d931b0b7..b9166c12e937a1 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/ThermostatCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/ThermostatCluster.kt @@ -17,364 +17,288 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.ByteSubscriptionState +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest +import matter.controller.ShortSubscriptionState import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter class ThermostatCluster(private val controller: MatterController, private val endpointId: UShort) { class GetWeeklyScheduleResponse( - val numberOfTransitionsForSequence: UByte, - val dayOfWeekForSequence: UByte, - val modeForSequence: UByte, - val transitions: List + val numberOfTransitionsForSequence: UByte, + val dayOfWeekForSequence: UByte, + val modeForSequence: UByte, + val transitions: List, ) class AtomicResponse( - val statusCode: UByte, - val attributeStatus: List, - val timeout: UShort? - ) -class LocalTemperatureAttribute( - val value: Short? + val statusCode: UByte, + val attributeStatus: List, + val timeout: UShort?, ) + class LocalTemperatureAttribute(val value: Short?) + sealed class LocalTemperatureAttributeSubscriptionState { - data class Success( - val value: Short? - ) : LocalTemperatureAttributeSubscriptionState() - + data class Success(val value: Short?) : LocalTemperatureAttributeSubscriptionState() + data class Error(val exception: Exception) : LocalTemperatureAttributeSubscriptionState() - object SubscriptionEstablished : LocalTemperatureAttributeSubscriptionState() - } -class OutdoorTemperatureAttribute( - val value: Short? - ) + object SubscriptionEstablished : LocalTemperatureAttributeSubscriptionState() + } + + class OutdoorTemperatureAttribute(val value: Short?) sealed class OutdoorTemperatureAttributeSubscriptionState { - data class Success( - val value: Short? - ) : OutdoorTemperatureAttributeSubscriptionState() - + data class Success(val value: Short?) : OutdoorTemperatureAttributeSubscriptionState() + data class Error(val exception: Exception) : OutdoorTemperatureAttributeSubscriptionState() - object SubscriptionEstablished : OutdoorTemperatureAttributeSubscriptionState() - } -class TemperatureSetpointHoldDurationAttribute( - val value: UShort? - ) + object SubscriptionEstablished : OutdoorTemperatureAttributeSubscriptionState() + } + + class TemperatureSetpointHoldDurationAttribute(val value: UShort?) sealed class TemperatureSetpointHoldDurationAttributeSubscriptionState { - data class Success( - val value: UShort? - ) : TemperatureSetpointHoldDurationAttributeSubscriptionState() - - data class Error(val exception: Exception) : TemperatureSetpointHoldDurationAttributeSubscriptionState() - - object SubscriptionEstablished : TemperatureSetpointHoldDurationAttributeSubscriptionState() - } -class SetpointChangeAmountAttribute( - val value: Short? - ) + data class Success(val value: UShort?) : + TemperatureSetpointHoldDurationAttributeSubscriptionState() + + data class Error(val exception: Exception) : + TemperatureSetpointHoldDurationAttributeSubscriptionState() + + object SubscriptionEstablished : TemperatureSetpointHoldDurationAttributeSubscriptionState() + } + + class SetpointChangeAmountAttribute(val value: Short?) sealed class SetpointChangeAmountAttributeSubscriptionState { - data class Success( - val value: Short? - ) : SetpointChangeAmountAttributeSubscriptionState() - + data class Success(val value: Short?) : SetpointChangeAmountAttributeSubscriptionState() + data class Error(val exception: Exception) : SetpointChangeAmountAttributeSubscriptionState() - object SubscriptionEstablished : SetpointChangeAmountAttributeSubscriptionState() - } -class OccupiedSetbackAttribute( - val value: UByte? - ) + object SubscriptionEstablished : SetpointChangeAmountAttributeSubscriptionState() + } + + class OccupiedSetbackAttribute(val value: UByte?) sealed class OccupiedSetbackAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : OccupiedSetbackAttributeSubscriptionState() - + data class Success(val value: UByte?) : OccupiedSetbackAttributeSubscriptionState() + data class Error(val exception: Exception) : OccupiedSetbackAttributeSubscriptionState() - object SubscriptionEstablished : OccupiedSetbackAttributeSubscriptionState() - } -class OccupiedSetbackMinAttribute( - val value: UByte? - ) + object SubscriptionEstablished : OccupiedSetbackAttributeSubscriptionState() + } + + class OccupiedSetbackMinAttribute(val value: UByte?) sealed class OccupiedSetbackMinAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : OccupiedSetbackMinAttributeSubscriptionState() - + data class Success(val value: UByte?) : OccupiedSetbackMinAttributeSubscriptionState() + data class Error(val exception: Exception) : OccupiedSetbackMinAttributeSubscriptionState() - object SubscriptionEstablished : OccupiedSetbackMinAttributeSubscriptionState() - } -class OccupiedSetbackMaxAttribute( - val value: UByte? - ) + object SubscriptionEstablished : OccupiedSetbackMinAttributeSubscriptionState() + } + + class OccupiedSetbackMaxAttribute(val value: UByte?) sealed class OccupiedSetbackMaxAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : OccupiedSetbackMaxAttributeSubscriptionState() - + data class Success(val value: UByte?) : OccupiedSetbackMaxAttributeSubscriptionState() + data class Error(val exception: Exception) : OccupiedSetbackMaxAttributeSubscriptionState() - object SubscriptionEstablished : OccupiedSetbackMaxAttributeSubscriptionState() - } -class UnoccupiedSetbackAttribute( - val value: UByte? - ) + object SubscriptionEstablished : OccupiedSetbackMaxAttributeSubscriptionState() + } + + class UnoccupiedSetbackAttribute(val value: UByte?) sealed class UnoccupiedSetbackAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : UnoccupiedSetbackAttributeSubscriptionState() - + data class Success(val value: UByte?) : UnoccupiedSetbackAttributeSubscriptionState() + data class Error(val exception: Exception) : UnoccupiedSetbackAttributeSubscriptionState() - object SubscriptionEstablished : UnoccupiedSetbackAttributeSubscriptionState() - } -class UnoccupiedSetbackMinAttribute( - val value: UByte? - ) + object SubscriptionEstablished : UnoccupiedSetbackAttributeSubscriptionState() + } + + class UnoccupiedSetbackMinAttribute(val value: UByte?) sealed class UnoccupiedSetbackMinAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : UnoccupiedSetbackMinAttributeSubscriptionState() - + data class Success(val value: UByte?) : UnoccupiedSetbackMinAttributeSubscriptionState() + data class Error(val exception: Exception) : UnoccupiedSetbackMinAttributeSubscriptionState() - object SubscriptionEstablished : UnoccupiedSetbackMinAttributeSubscriptionState() - } -class UnoccupiedSetbackMaxAttribute( - val value: UByte? - ) + object SubscriptionEstablished : UnoccupiedSetbackMinAttributeSubscriptionState() + } + + class UnoccupiedSetbackMaxAttribute(val value: UByte?) sealed class UnoccupiedSetbackMaxAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : UnoccupiedSetbackMaxAttributeSubscriptionState() - + data class Success(val value: UByte?) : UnoccupiedSetbackMaxAttributeSubscriptionState() + data class Error(val exception: Exception) : UnoccupiedSetbackMaxAttributeSubscriptionState() - object SubscriptionEstablished : UnoccupiedSetbackMaxAttributeSubscriptionState() - } -class ACCoilTemperatureAttribute( - val value: Short? - ) + object SubscriptionEstablished : UnoccupiedSetbackMaxAttributeSubscriptionState() + } + + class ACCoilTemperatureAttribute(val value: Short?) sealed class ACCoilTemperatureAttributeSubscriptionState { - data class Success( - val value: Short? - ) : ACCoilTemperatureAttributeSubscriptionState() - + data class Success(val value: Short?) : ACCoilTemperatureAttributeSubscriptionState() + data class Error(val exception: Exception) : ACCoilTemperatureAttributeSubscriptionState() - object SubscriptionEstablished : ACCoilTemperatureAttributeSubscriptionState() - } -class PresetTypesAttribute( - val value: List? - ) + object SubscriptionEstablished : ACCoilTemperatureAttributeSubscriptionState() + } + + class PresetTypesAttribute(val value: List?) sealed class PresetTypesAttributeSubscriptionState { - data class Success( - val value: List? - ) : PresetTypesAttributeSubscriptionState() - + data class Success(val value: List?) : + PresetTypesAttributeSubscriptionState() + data class Error(val exception: Exception) : PresetTypesAttributeSubscriptionState() - object SubscriptionEstablished : PresetTypesAttributeSubscriptionState() - } -class ScheduleTypesAttribute( - val value: List? - ) + object SubscriptionEstablished : PresetTypesAttributeSubscriptionState() + } + + class ScheduleTypesAttribute(val value: List?) sealed class ScheduleTypesAttributeSubscriptionState { - data class Success( - val value: List? - ) : ScheduleTypesAttributeSubscriptionState() - + data class Success(val value: List?) : + ScheduleTypesAttributeSubscriptionState() + data class Error(val exception: Exception) : ScheduleTypesAttributeSubscriptionState() - object SubscriptionEstablished : ScheduleTypesAttributeSubscriptionState() - } -class NumberOfScheduleTransitionPerDayAttribute( - val value: UByte? - ) + object SubscriptionEstablished : ScheduleTypesAttributeSubscriptionState() + } + + class NumberOfScheduleTransitionPerDayAttribute(val value: UByte?) sealed class NumberOfScheduleTransitionPerDayAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : NumberOfScheduleTransitionPerDayAttributeSubscriptionState() - - data class Error(val exception: Exception) : NumberOfScheduleTransitionPerDayAttributeSubscriptionState() - - object SubscriptionEstablished : NumberOfScheduleTransitionPerDayAttributeSubscriptionState() - } -class ActivePresetHandleAttribute( - val value: ByteArray? - ) + data class Success(val value: UByte?) : + NumberOfScheduleTransitionPerDayAttributeSubscriptionState() + + data class Error(val exception: Exception) : + NumberOfScheduleTransitionPerDayAttributeSubscriptionState() + + object SubscriptionEstablished : NumberOfScheduleTransitionPerDayAttributeSubscriptionState() + } + + class ActivePresetHandleAttribute(val value: ByteArray?) sealed class ActivePresetHandleAttributeSubscriptionState { - data class Success( - val value: ByteArray? - ) : ActivePresetHandleAttributeSubscriptionState() - + data class Success(val value: ByteArray?) : ActivePresetHandleAttributeSubscriptionState() + data class Error(val exception: Exception) : ActivePresetHandleAttributeSubscriptionState() - object SubscriptionEstablished : ActivePresetHandleAttributeSubscriptionState() - } -class ActiveScheduleHandleAttribute( - val value: ByteArray? - ) + object SubscriptionEstablished : ActivePresetHandleAttributeSubscriptionState() + } + + class ActiveScheduleHandleAttribute(val value: ByteArray?) sealed class ActiveScheduleHandleAttributeSubscriptionState { - data class Success( - val value: ByteArray? - ) : ActiveScheduleHandleAttributeSubscriptionState() - + data class Success(val value: ByteArray?) : ActiveScheduleHandleAttributeSubscriptionState() + data class Error(val exception: Exception) : ActiveScheduleHandleAttributeSubscriptionState() - object SubscriptionEstablished : ActiveScheduleHandleAttributeSubscriptionState() - } -class PresetsAttribute( - val value: List? - ) + object SubscriptionEstablished : ActiveScheduleHandleAttributeSubscriptionState() + } + + class PresetsAttribute(val value: List?) sealed class PresetsAttributeSubscriptionState { - data class Success( - val value: List? - ) : PresetsAttributeSubscriptionState() - + data class Success(val value: List?) : + PresetsAttributeSubscriptionState() + data class Error(val exception: Exception) : PresetsAttributeSubscriptionState() - object SubscriptionEstablished : PresetsAttributeSubscriptionState() - } -class SchedulesAttribute( - val value: List? - ) + object SubscriptionEstablished : PresetsAttributeSubscriptionState() + } + + class SchedulesAttribute(val value: List?) sealed class SchedulesAttributeSubscriptionState { - data class Success( - val value: List? - ) : SchedulesAttributeSubscriptionState() - + data class Success(val value: List?) : + SchedulesAttributeSubscriptionState() + data class Error(val exception: Exception) : SchedulesAttributeSubscriptionState() - object SubscriptionEstablished : SchedulesAttributeSubscriptionState() - } -class SetpointHoldExpiryTimestampAttribute( - val value: UInt? - ) + object SubscriptionEstablished : SchedulesAttributeSubscriptionState() + } + + class SetpointHoldExpiryTimestampAttribute(val value: UInt?) sealed class SetpointHoldExpiryTimestampAttributeSubscriptionState { - data class Success( - val value: UInt? - ) : SetpointHoldExpiryTimestampAttributeSubscriptionState() - - data class Error(val exception: Exception) : SetpointHoldExpiryTimestampAttributeSubscriptionState() - - object SubscriptionEstablished : SetpointHoldExpiryTimestampAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + data class Success(val value: UInt?) : SetpointHoldExpiryTimestampAttributeSubscriptionState() + + data class Error(val exception: Exception) : + SetpointHoldExpiryTimestampAttributeSubscriptionState() + + object SubscriptionEstablished : SetpointHoldExpiryTimestampAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun setpointRaiseLower(mode: UByte - ,amount: Byte - ,timedInvokeTimeout: Duration? = null) { + suspend fun setpointRaiseLower(mode: UByte, amount: Byte, timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() @@ -384,32 +308,37 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_MODE_REQ), mode) val TAG_AMOUNT_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_AMOUNT_REQ), amount) + tlvWriter.put(ContextSpecificTag(TAG_AMOUNT_REQ), amount) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun setWeeklySchedule(numberOfTransitionsForSequence: UByte - ,dayOfWeekForSequence: UByte - ,modeForSequence: UByte - ,transitions: List - ,timedInvokeTimeout: Duration? = null) { + suspend fun setWeeklySchedule( + numberOfTransitionsForSequence: UByte, + dayOfWeekForSequence: UByte, + modeForSequence: UByte, + transitions: List, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 1u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_NUMBER_OF_TRANSITIONS_FOR_SEQUENCE_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_NUMBER_OF_TRANSITIONS_FOR_SEQUENCE_REQ), numberOfTransitionsForSequence) + tlvWriter.put( + ContextSpecificTag(TAG_NUMBER_OF_TRANSITIONS_FOR_SEQUENCE_REQ), + numberOfTransitionsForSequence, + ) val TAG_DAY_OF_WEEK_FOR_SEQUENCE_REQ: Int = 1 tlvWriter.put(ContextSpecificTag(TAG_DAY_OF_WEEK_FOR_SEQUENCE_REQ), dayOfWeekForSequence) @@ -419,26 +348,28 @@ class AttributeListAttribute( val TAG_TRANSITIONS_REQ: Int = 3 tlvWriter.startArray(ContextSpecificTag(TAG_TRANSITIONS_REQ)) - for (item in transitions.iterator()) { - item.toTlv(AnonymousTag, tlvWriter) - } - tlvWriter.endArray() + for (item in transitions.iterator()) { + item.toTlv(AnonymousTag, tlvWriter) + } + tlvWriter.endArray() tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun getWeeklySchedule(daysToReturn: UByte - ,modeToReturn: UByte - ,timedInvokeTimeout: Duration? = null): GetWeeklyScheduleResponse { + suspend fun getWeeklySchedule( + daysToReturn: UByte, + modeToReturn: UByte, + timedInvokeTimeout: Duration? = null, + ): GetWeeklyScheduleResponse { val commandId: UInt = 2u val tlvWriter = TlvWriter() @@ -448,14 +379,14 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_DAYS_TO_RETURN_REQ), daysToReturn) val TAG_MODE_TO_RETURN_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_MODE_TO_RETURN_REQ), modeToReturn) + tlvWriter.put(ContextSpecificTag(TAG_MODE_TO_RETURN_REQ), modeToReturn) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -465,62 +396,60 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_NUMBER_OF_TRANSITIONS_FOR_SEQUENCE: Int = 0 var numberOfTransitionsForSequence_decoded: UByte? = null - + val TAG_DAY_OF_WEEK_FOR_SEQUENCE: Int = 1 var dayOfWeekForSequence_decoded: UByte? = null - + val TAG_MODE_FOR_SEQUENCE: Int = 2 var modeForSequence_decoded: UByte? = null - + val TAG_TRANSITIONS: Int = 3 var transitions_decoded: List? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_NUMBER_OF_TRANSITIONS_FOR_SEQUENCE)) {numberOfTransitionsForSequence_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_DAY_OF_WEEK_FOR_SEQUENCE)) {dayOfWeekForSequence_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_MODE_FOR_SEQUENCE)) {modeForSequence_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_TRANSITIONS)) {transitions_decoded = buildList { - tlvReader.enterArray(tag) - while(!tlvReader.isEndOfContainer()) { - add(ThermostatClusterWeeklyScheduleTransitionStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - }} - - - else { + if (tag == ContextSpecificTag(TAG_NUMBER_OF_TRANSITIONS_FOR_SEQUENCE)) { + numberOfTransitionsForSequence_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_DAY_OF_WEEK_FOR_SEQUENCE)) { + dayOfWeekForSequence_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_MODE_FOR_SEQUENCE)) { + modeForSequence_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_TRANSITIONS)) { + transitions_decoded = + buildList { + tlvReader.enterArray(tag) + while (!tlvReader.isEndOfContainer()) { + add(ThermostatClusterWeeklyScheduleTransitionStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { tlvReader.skipElement() } } - - if (numberOfTransitionsForSequence_decoded == null) { - throw IllegalStateException("numberOfTransitionsForSequence not found in TLV") + throw IllegalStateException("numberOfTransitionsForSequence not found in TLV") } - - + if (dayOfWeekForSequence_decoded == null) { - throw IllegalStateException("dayOfWeekForSequence not found in TLV") + throw IllegalStateException("dayOfWeekForSequence not found in TLV") } - - + if (modeForSequence_decoded == null) { - throw IllegalStateException("modeForSequence not found in TLV") + throw IllegalStateException("modeForSequence not found in TLV") } - - + if (transitions_decoded == null) { - throw IllegalStateException("transitions not found in TLV") + throw IllegalStateException("transitions not found in TLV") } - tlvReader.exitContainer() @@ -528,7 +457,7 @@ class AttributeListAttribute( numberOfTransitionsForSequence_decoded, dayOfWeekForSequence_decoded, modeForSequence_decoded, - transitions_decoded + transitions_decoded, ) } @@ -536,68 +465,74 @@ class AttributeListAttribute( val commandId: UInt = 3u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun setActiveScheduleRequest(scheduleHandle: ByteArray - ,timedInvokeTimeout: Duration? = null) { + suspend fun setActiveScheduleRequest( + scheduleHandle: ByteArray, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 5u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_SCHEDULE_HANDLE_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_SCHEDULE_HANDLE_REQ), scheduleHandle) + tlvWriter.put(ContextSpecificTag(TAG_SCHEDULE_HANDLE_REQ), scheduleHandle) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun setActivePresetRequest(presetHandle: ByteArray - ,timedInvokeTimeout: Duration? = null) { + suspend fun setActivePresetRequest( + presetHandle: ByteArray, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 6u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_PRESET_HANDLE_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_PRESET_HANDLE_REQ), presetHandle) + tlvWriter.put(ContextSpecificTag(TAG_PRESET_HANDLE_REQ), presetHandle) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun atomicRequest(requestType: UByte - ,attributeRequests: List - ,timeout: UShort? - ,timedInvokeTimeout: Duration? = null): AtomicResponse { + suspend fun atomicRequest( + requestType: UByte, + attributeRequests: List, + timeout: UShort?, + timedInvokeTimeout: Duration? = null, + ): AtomicResponse { val commandId: UInt = 254u val tlvWriter = TlvWriter() @@ -608,22 +543,20 @@ class AttributeListAttribute( val TAG_ATTRIBUTE_REQUESTS_REQ: Int = 1 tlvWriter.startArray(ContextSpecificTag(TAG_ATTRIBUTE_REQUESTS_REQ)) - for (item in attributeRequests.iterator()) { - tlvWriter.put(AnonymousTag, item) - } - tlvWriter.endArray() + for (item in attributeRequests.iterator()) { + tlvWriter.put(AnonymousTag, item) + } + tlvWriter.endArray() val TAG_TIMEOUT_REQ: Int = 2 - timeout?.let { - tlvWriter.put(ContextSpecificTag(TAG_TIMEOUT_REQ), timeout) - } + timeout?.let { tlvWriter.put(ContextSpecificTag(TAG_TIMEOUT_REQ), timeout) } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -633,1017 +566,964 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS_CODE: Int = 0 var statusCode_decoded: UByte? = null - + val TAG_ATTRIBUTE_STATUS: Int = 1 var attributeStatus_decoded: List? = null - + val TAG_TIMEOUT: Int = 2 var timeout_decoded: UShort? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_STATUS_CODE)) {statusCode_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_ATTRIBUTE_STATUS)) {attributeStatus_decoded = buildList { - tlvReader.enterArray(tag) - while(!tlvReader.isEndOfContainer()) { - add(ThermostatClusterAtomicAttributeStatusStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - }} - - if (tag == ContextSpecificTag(TAG_TIMEOUT)) {timeout_decoded = + if (tag == ContextSpecificTag(TAG_STATUS_CODE)) { + statusCode_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_ATTRIBUTE_STATUS)) { + attributeStatus_decoded = + buildList { + tlvReader.enterArray(tag) + while (!tlvReader.isEndOfContainer()) { + add(ThermostatClusterAtomicAttributeStatusStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } + + if (tag == ContextSpecificTag(TAG_TIMEOUT)) { + timeout_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getUShort(tag) - } else { - null - } - }} - - - else { + tlvReader.getUShort(tag) + } else { + null + } + } + } else { tlvReader.skipElement() } } - - if (statusCode_decoded == null) { - throw IllegalStateException("statusCode not found in TLV") + throw IllegalStateException("statusCode not found in TLV") } - - + if (attributeStatus_decoded == null) { - throw IllegalStateException("attributeStatus not found in TLV") + throw IllegalStateException("attributeStatus not found in TLV") } - - - tlvReader.exitContainer() - return AtomicResponse( - statusCode_decoded, - attributeStatus_decoded, - timeout_decoded - ) + return AtomicResponse(statusCode_decoded, attributeStatus_decoded, timeout_decoded) } -suspend fun readLocalTemperatureAttribute(): LocalTemperatureAttribute {val ATTRIBUTE_ID: UInt = 0u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readLocalTemperatureAttribute(): LocalTemperatureAttribute { + 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 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}") - } + 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) { - "Localtemperature attribute not found in response" - } + } + + requireNotNull(attributeData) { "Localtemperature attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (!tlvReader.isNull()) { - tlvReader.getShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Short? = + if (!tlvReader.isNull()) { + tlvReader.getShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return LocalTemperatureAttribute(decodedValue) } suspend fun subscribeLocalTemperatureAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(LocalTemperatureAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + LocalTemperatureAttributeSubscriptionState.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) { - "Localtemperature attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Localtemperature attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (!tlvReader.isNull()) { - tlvReader.getShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Short? = + if (!tlvReader.isNull()) { + tlvReader.getShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(LocalTemperatureAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(LocalTemperatureAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(LocalTemperatureAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readOutdoorTemperatureAttribute(): OutdoorTemperatureAttribute {val ATTRIBUTE_ID: UInt = 1u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readOutdoorTemperatureAttribute(): OutdoorTemperatureAttribute { + 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 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}") - } + 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) { - "Outdoortemperature attribute not found in response" - } + } + + requireNotNull(attributeData) { "Outdoortemperature attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Short? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return OutdoorTemperatureAttribute(decodedValue) } suspend fun subscribeOutdoorTemperatureAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(OutdoorTemperatureAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + OutdoorTemperatureAttributeSubscriptionState.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) { - "Outdoortemperature attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Outdoortemperature attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(OutdoorTemperatureAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Short? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(OutdoorTemperatureAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(OutdoorTemperatureAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readOccupancyAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 2u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readOccupancyAttribute(): UByte? { + 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 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}") - } + 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) { - "Occupancy attribute not found in response" - } + } + + requireNotNull(attributeData) { "Occupancy 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeOccupancyAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Occupancy attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Occupancy 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAbsMinHeatSetpointLimitAttribute(): Short? {val ATTRIBUTE_ID: UInt = 3u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readAbsMinHeatSetpointLimitAttribute(): Short? { + 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 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}") - } + 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) { - "Absminheatsetpointlimit attribute not found in response" - } + } + + requireNotNull(attributeData) { "Absminheatsetpointlimit attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeAbsMinHeatSetpointLimitAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Absminheatsetpointlimit attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Absminheatsetpointlimit attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAbsMaxHeatSetpointLimitAttribute(): Short? {val ATTRIBUTE_ID: UInt = 4u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readAbsMaxHeatSetpointLimitAttribute(): Short? { + 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 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}") - } + 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) { - "Absmaxheatsetpointlimit attribute not found in response" - } + } + + requireNotNull(attributeData) { "Absmaxheatsetpointlimit attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeAbsMaxHeatSetpointLimitAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Absmaxheatsetpointlimit attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Absmaxheatsetpointlimit attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAbsMinCoolSetpointLimitAttribute(): Short? {val ATTRIBUTE_ID: UInt = 5u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readAbsMinCoolSetpointLimitAttribute(): Short? { + 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 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}") - } + 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) { - "Absmincoolsetpointlimit attribute not found in response" - } + } + + requireNotNull(attributeData) { "Absmincoolsetpointlimit attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeAbsMinCoolSetpointLimitAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Absmincoolsetpointlimit attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Absmincoolsetpointlimit attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAbsMaxCoolSetpointLimitAttribute(): Short? {val ATTRIBUTE_ID: UInt = 6u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readAbsMaxCoolSetpointLimitAttribute(): Short? { + 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 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}") - } + 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) { - "Absmaxcoolsetpointlimit attribute not found in response" - } + } + + requireNotNull(attributeData) { "Absmaxcoolsetpointlimit attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeAbsMaxCoolSetpointLimitAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Absmaxcoolsetpointlimit attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Absmaxcoolsetpointlimit attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPICoolingDemandAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 7u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readPICoolingDemandAttribute(): UByte? { + 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 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}") - } + 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) { - "Picoolingdemand attribute not found in response" - } + } + + requireNotNull(attributeData) { "Picoolingdemand 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribePICoolingDemandAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Picoolingdemand attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Picoolingdemand 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPIHeatingDemandAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 8u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readPIHeatingDemandAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 8u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Piheatingdemand attribute not found in response" - } + } + + requireNotNull(attributeData) { "Piheatingdemand 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribePIHeatingDemandAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Piheatingdemand attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Piheatingdemand 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readHVACSystemTypeConfigurationAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 9u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readHVACSystemTypeConfigurationAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 9u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Hvacsystemtypeconfiguration attribute not found in response" - } + } + + requireNotNull(attributeData) { "Hvacsystemtypeconfiguration 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun writeHVACSystemTypeConfigurationAttribute( value: UByte, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 9u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -1664,127 +1544,122 @@ suspend fun readHVACSystemTypeConfigurationAttribute(): UByte? {val ATTRIBUTE_ID throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeHVACSystemTypeConfigurationAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Hvacsystemtypeconfiguration attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Hvacsystemtypeconfiguration 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readLocalTemperatureCalibrationAttribute(): Byte? {val ATTRIBUTE_ID: UInt = 16u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readLocalTemperatureCalibrationAttribute(): Byte? { + val ATTRIBUTE_ID: UInt = 16u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Localtemperaturecalibration attribute not found in response" - } + } + + requireNotNull(attributeData) { "Localtemperaturecalibration attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Byte? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByte(AnonymousTag) - } else { - null - } - + val decodedValue: Byte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun writeLocalTemperatureCalibrationAttribute( value: Byte, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 16u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -1805,127 +1680,122 @@ suspend fun readLocalTemperatureCalibrationAttribute(): Byte? {val ATTRIBUTE_ID: throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeLocalTemperatureCalibrationAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ByteSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ByteSubscriptionState.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) { - "Localtemperaturecalibration attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Localtemperaturecalibration attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Byte? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByte(AnonymousTag) - } else { - null - } + val decodedValue: Byte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readOccupiedCoolingSetpointAttribute(): Short? {val ATTRIBUTE_ID: UInt = 17u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readOccupiedCoolingSetpointAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 17u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Occupiedcoolingsetpoint attribute not found in response" - } + } + + requireNotNull(attributeData) { "Occupiedcoolingsetpoint attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun writeOccupiedCoolingSetpointAttribute( value: Short, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 17u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -1946,127 +1816,122 @@ suspend fun readOccupiedCoolingSetpointAttribute(): Short? {val ATTRIBUTE_ID: UI throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeOccupiedCoolingSetpointAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 17u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Occupiedcoolingsetpoint attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Occupiedcoolingsetpoint attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readOccupiedHeatingSetpointAttribute(): Short? {val ATTRIBUTE_ID: UInt = 18u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readOccupiedHeatingSetpointAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 18u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Occupiedheatingsetpoint attribute not found in response" - } + } + + requireNotNull(attributeData) { "Occupiedheatingsetpoint attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun writeOccupiedHeatingSetpointAttribute( value: Short, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 18u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -2087,127 +1952,122 @@ suspend fun readOccupiedHeatingSetpointAttribute(): Short? {val ATTRIBUTE_ID: UI throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeOccupiedHeatingSetpointAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 18u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Occupiedheatingsetpoint attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Occupiedheatingsetpoint attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readUnoccupiedCoolingSetpointAttribute(): Short? {val ATTRIBUTE_ID: UInt = 19u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readUnoccupiedCoolingSetpointAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 19u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Unoccupiedcoolingsetpoint attribute not found in response" - } + } + + requireNotNull(attributeData) { "Unoccupiedcoolingsetpoint attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun writeUnoccupiedCoolingSetpointAttribute( value: Short, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 19u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -2228,127 +2088,122 @@ suspend fun readUnoccupiedCoolingSetpointAttribute(): Short? {val ATTRIBUTE_ID: throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeUnoccupiedCoolingSetpointAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 19u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Unoccupiedcoolingsetpoint attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Unoccupiedcoolingsetpoint attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readUnoccupiedHeatingSetpointAttribute(): Short? {val ATTRIBUTE_ID: UInt = 20u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readUnoccupiedHeatingSetpointAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 20u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Unoccupiedheatingsetpoint attribute not found in response" - } + } + + requireNotNull(attributeData) { "Unoccupiedheatingsetpoint attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun writeUnoccupiedHeatingSetpointAttribute( value: Short, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 20u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -2369,127 +2224,122 @@ suspend fun readUnoccupiedHeatingSetpointAttribute(): Short? {val ATTRIBUTE_ID: throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeUnoccupiedHeatingSetpointAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 20u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Unoccupiedheatingsetpoint attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Unoccupiedheatingsetpoint attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMinHeatSetpointLimitAttribute(): Short? {val ATTRIBUTE_ID: UInt = 21u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readMinHeatSetpointLimitAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 21u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Minheatsetpointlimit attribute not found in response" - } + } + + requireNotNull(attributeData) { "Minheatsetpointlimit attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun writeMinHeatSetpointLimitAttribute( value: Short, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 21u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -2510,127 +2360,122 @@ suspend fun readMinHeatSetpointLimitAttribute(): Short? {val ATTRIBUTE_ID: UInt throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeMinHeatSetpointLimitAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 21u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Minheatsetpointlimit attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Minheatsetpointlimit attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMaxHeatSetpointLimitAttribute(): Short? {val ATTRIBUTE_ID: UInt = 22u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readMaxHeatSetpointLimitAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 22u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Maxheatsetpointlimit attribute not found in response" - } + } + + requireNotNull(attributeData) { "Maxheatsetpointlimit attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun writeMaxHeatSetpointLimitAttribute( value: Short, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 22u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -2651,127 +2496,122 @@ suspend fun readMaxHeatSetpointLimitAttribute(): Short? {val ATTRIBUTE_ID: UInt throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeMaxHeatSetpointLimitAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 22u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Maxheatsetpointlimit attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Maxheatsetpointlimit attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMinCoolSetpointLimitAttribute(): Short? {val ATTRIBUTE_ID: UInt = 23u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readMinCoolSetpointLimitAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 23u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Mincoolsetpointlimit attribute not found in response" - } + } + + requireNotNull(attributeData) { "Mincoolsetpointlimit attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun writeMinCoolSetpointLimitAttribute( value: Short, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 23u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -2792,127 +2632,122 @@ suspend fun readMinCoolSetpointLimitAttribute(): Short? {val ATTRIBUTE_ID: UInt throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeMinCoolSetpointLimitAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 23u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Mincoolsetpointlimit attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Mincoolsetpointlimit attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMaxCoolSetpointLimitAttribute(): Short? {val ATTRIBUTE_ID: UInt = 24u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readMaxCoolSetpointLimitAttribute(): Short? { + val ATTRIBUTE_ID: UInt = 24u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Maxcoolsetpointlimit attribute not found in response" - } + } + + requireNotNull(attributeData) { "Maxcoolsetpointlimit attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun writeMaxCoolSetpointLimitAttribute( value: Short, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 24u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -2933,127 +2768,119 @@ suspend fun readMaxCoolSetpointLimitAttribute(): Short? {val ATTRIBUTE_ID: UInt throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeMaxCoolSetpointLimitAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 24u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Maxcoolsetpointlimit attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Maxcoolsetpointlimit attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } + val decodedValue: Short? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMinSetpointDeadBandAttribute(): Byte? {val ATTRIBUTE_ID: UInt = 25u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readMinSetpointDeadBandAttribute(): Byte? { + val ATTRIBUTE_ID: UInt = 25u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Minsetpointdeadband attribute not found in response" - } + } + + requireNotNull(attributeData) { "Minsetpointdeadband attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Byte? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByte(AnonymousTag) - } else { - null - } - + val decodedValue: Byte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByte(AnonymousTag) + } else { + null + } return decodedValue } - suspend fun writeMinSetpointDeadBandAttribute( - value: Byte, - timedWriteTimeout: Duration? = null) { + suspend fun writeMinSetpointDeadBandAttribute(value: Byte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 25u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -3074,127 +2901,119 @@ suspend fun readMinSetpointDeadBandAttribute(): Byte? {val ATTRIBUTE_ID: UInt = throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeMinSetpointDeadBandAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 25u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ByteSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ByteSubscriptionState.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) { - "Minsetpointdeadband attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Minsetpointdeadband attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Byte? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByte(AnonymousTag) - } else { - null - } + val decodedValue: Byte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRemoteSensingAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 26u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRemoteSensingAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 26u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Remotesensing attribute not found in response" - } + } + + requireNotNull(attributeData) { "Remotesensing 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } - suspend fun writeRemoteSensingAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeRemoteSensingAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 26u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -3215,123 +3034,115 @@ suspend fun readRemoteSensingAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 26u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeRemoteSensingAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 26u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Remotesensing attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Remotesensing 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readControlSequenceOfOperationAttribute(): UByte {val ATTRIBUTE_ID: UInt = 27u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readControlSequenceOfOperationAttribute(): UByte { + val ATTRIBUTE_ID: UInt = 27u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Controlsequenceofoperation attribute not found in response" - } + } + + requireNotNull(attributeData) { "Controlsequenceofoperation 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 writeControlSequenceOfOperationAttribute( value: UByte, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 27u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -3352,42 +3163,46 @@ suspend fun readControlSequenceOfOperationAttribute(): UByte {val ATTRIBUTE_ID: throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeControlSequenceOfOperationAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 27u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Controlsequenceofoperation attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Controlsequenceofoperation attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -3400,68 +3215,57 @@ suspend fun readControlSequenceOfOperationAttribute(): UByte {val ATTRIBUTE_ID: emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readSystemModeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 28u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readSystemModeAttribute(): UByte { + val ATTRIBUTE_ID: UInt = 28u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Systemmode attribute not found in response" - } + } + + requireNotNull(attributeData) { "Systemmode 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 writeSystemModeAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeSystemModeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 28u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -3482,43 +3286,45 @@ suspend fun readSystemModeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 28u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeSystemModeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 28u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Systemmode attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Systemmode attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -3530,460 +3336,435 @@ suspend fun readSystemModeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 28u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readThermostatRunningModeAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 30u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readThermostatRunningModeAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 30u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Thermostatrunningmode attribute not found in response" - } + } + + requireNotNull(attributeData) { "Thermostatrunningmode 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeThermostatRunningModeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 30u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Thermostatrunningmode attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Thermostatrunningmode 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readStartOfWeekAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 32u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readStartOfWeekAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 32u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Startofweek attribute not found in response" - } + } + + requireNotNull(attributeData) { "Startofweek 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeStartOfWeekAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 32u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Startofweek attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Startofweek 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNumberOfWeeklyTransitionsAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 33u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNumberOfWeeklyTransitionsAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 33u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Numberofweeklytransitions attribute not found in response" - } + } + + requireNotNull(attributeData) { "Numberofweeklytransitions 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeNumberOfWeeklyTransitionsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 33u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Numberofweeklytransitions attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Numberofweeklytransitions 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNumberOfDailyTransitionsAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 34u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNumberOfDailyTransitionsAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 34u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Numberofdailytransitions attribute not found in response" - } + } + + requireNotNull(attributeData) { "Numberofdailytransitions 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeNumberOfDailyTransitionsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 34u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Numberofdailytransitions attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Numberofdailytransitions 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readTemperatureSetpointHoldAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 35u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readTemperatureSetpointHoldAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 35u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Temperaturesetpointhold attribute not found in response" - } + } + + requireNotNull(attributeData) { "Temperaturesetpointhold 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun writeTemperatureSetpointHoldAttribute( value: UByte, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 35u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -4004,132 +3785,130 @@ suspend fun readTemperatureSetpointHoldAttribute(): UByte? {val ATTRIBUTE_ID: UI throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeTemperatureSetpointHoldAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 35u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Temperaturesetpointhold attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Temperaturesetpointhold 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readTemperatureSetpointHoldDurationAttribute(): TemperatureSetpointHoldDurationAttribute {val ATTRIBUTE_ID: UInt = 36u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readTemperatureSetpointHoldDurationAttribute(): + TemperatureSetpointHoldDurationAttribute { + val ATTRIBUTE_ID: UInt = 36u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Temperaturesetpointholdduration attribute not found in response" + } + + requireNotNull(attributeData) { + "Temperaturesetpointholdduration attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return TemperatureSetpointHoldDurationAttribute(decodedValue) } suspend fun writeTemperatureSetpointHoldDurationAttribute( value: UShort, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 36u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -4150,132 +3929,131 @@ suspend fun readTemperatureSetpointHoldDurationAttribute(): TemperatureSetpointH throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeTemperatureSetpointHoldDurationAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 36u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(TemperatureSetpointHoldDurationAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + TemperatureSetpointHoldDurationAttributeSubscriptionState.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) { - "Temperaturesetpointholdduration attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Temperaturesetpointholdduration 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } decodedValue?.let { emit(TemperatureSetpointHoldDurationAttributeSubscriptionState.Success(it)) } - } SubscriptionState.SubscriptionEstablished -> { emit(TemperatureSetpointHoldDurationAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readThermostatProgrammingOperationModeAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 37u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readThermostatProgrammingOperationModeAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 37u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Thermostatprogrammingoperationmode attribute not found in response" + } + + requireNotNull(attributeData) { + "Thermostatprogrammingoperationmode 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun writeThermostatProgrammingOperationModeAttribute( value: UByte, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 37u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -4296,530 +4074,508 @@ suspend fun readThermostatProgrammingOperationModeAttribute(): UByte? {val ATTRI throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeThermostatProgrammingOperationModeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 37u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Thermostatprogrammingoperationmode attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Thermostatprogrammingoperationmode 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readThermostatRunningStateAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 41u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readThermostatRunningStateAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 41u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Thermostatrunningstate attribute not found in response" - } + } + + requireNotNull(attributeData) { "Thermostatrunningstate 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeThermostatRunningStateAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 41u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Thermostatrunningstate attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Thermostatrunningstate 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readSetpointChangeSourceAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 48u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readSetpointChangeSourceAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 48u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Setpointchangesource attribute not found in response" - } + } + + requireNotNull(attributeData) { "Setpointchangesource 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeSetpointChangeSourceAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 48u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Setpointchangesource attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Setpointchangesource 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readSetpointChangeAmountAttribute(): SetpointChangeAmountAttribute {val ATTRIBUTE_ID: UInt = 49u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readSetpointChangeAmountAttribute(): SetpointChangeAmountAttribute { + val ATTRIBUTE_ID: UInt = 49u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Setpointchangeamount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Setpointchangeamount attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Short? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return SetpointChangeAmountAttribute(decodedValue) } suspend fun subscribeSetpointChangeAmountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 49u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(SetpointChangeAmountAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + SetpointChangeAmountAttributeSubscriptionState.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) { - "Setpointchangeamount attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Setpointchangeamount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(SetpointChangeAmountAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Short? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(SetpointChangeAmountAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(SetpointChangeAmountAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readSetpointChangeSourceTimestampAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 50u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readSetpointChangeSourceTimestampAttribute(): UInt? { + val ATTRIBUTE_ID: UInt = 50u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Setpointchangesourcetimestamp attribute not found in response" + } + + requireNotNull(attributeData) { + "Setpointchangesourcetimestamp attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeSetpointChangeSourceTimestampAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 50u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Setpointchangesourcetimestamp attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Setpointchangesourcetimestamp attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readOccupiedSetbackAttribute(): OccupiedSetbackAttribute {val ATTRIBUTE_ID: UInt = 52u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readOccupiedSetbackAttribute(): OccupiedSetbackAttribute { + val ATTRIBUTE_ID: UInt = 52u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Occupiedsetback attribute not found in response" - } + } + + requireNotNull(attributeData) { "Occupiedsetback attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return OccupiedSetbackAttribute(decodedValue) } - suspend fun writeOccupiedSetbackAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeOccupiedSetbackAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 52u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -4840,351 +4596,335 @@ suspend fun readOccupiedSetbackAttribute(): OccupiedSetbackAttribute {val ATTRIB throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeOccupiedSetbackAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 52u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(OccupiedSetbackAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + OccupiedSetbackAttributeSubscriptionState.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) { - "Occupiedsetback attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Occupiedsetback 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(OccupiedSetbackAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(OccupiedSetbackAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(OccupiedSetbackAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readOccupiedSetbackMinAttribute(): OccupiedSetbackMinAttribute {val ATTRIBUTE_ID: UInt = 53u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readOccupiedSetbackMinAttribute(): OccupiedSetbackMinAttribute { + val ATTRIBUTE_ID: UInt = 53u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Occupiedsetbackmin attribute not found in response" - } + } + + requireNotNull(attributeData) { "Occupiedsetbackmin attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return OccupiedSetbackMinAttribute(decodedValue) } suspend fun subscribeOccupiedSetbackMinAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 53u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(OccupiedSetbackMinAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + OccupiedSetbackMinAttributeSubscriptionState.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) { - "Occupiedsetbackmin attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Occupiedsetbackmin 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(OccupiedSetbackMinAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(OccupiedSetbackMinAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(OccupiedSetbackMinAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readOccupiedSetbackMaxAttribute(): OccupiedSetbackMaxAttribute {val ATTRIBUTE_ID: UInt = 54u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readOccupiedSetbackMaxAttribute(): OccupiedSetbackMaxAttribute { + val ATTRIBUTE_ID: UInt = 54u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Occupiedsetbackmax attribute not found in response" - } + } + + requireNotNull(attributeData) { "Occupiedsetbackmax attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return OccupiedSetbackMaxAttribute(decodedValue) } suspend fun subscribeOccupiedSetbackMaxAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 54u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(OccupiedSetbackMaxAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + OccupiedSetbackMaxAttributeSubscriptionState.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) { - "Occupiedsetbackmax attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Occupiedsetbackmax 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(OccupiedSetbackMaxAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(OccupiedSetbackMaxAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(OccupiedSetbackMaxAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readUnoccupiedSetbackAttribute(): UnoccupiedSetbackAttribute {val ATTRIBUTE_ID: UInt = 55u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readUnoccupiedSetbackAttribute(): UnoccupiedSetbackAttribute { + val ATTRIBUTE_ID: UInt = 55u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Unoccupiedsetback attribute not found in response" - } + } + + requireNotNull(attributeData) { "Unoccupiedsetback attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return UnoccupiedSetbackAttribute(decodedValue) } - suspend fun writeUnoccupiedSetbackAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeUnoccupiedSetbackAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 55u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -5205,346 +4945,330 @@ suspend fun readUnoccupiedSetbackAttribute(): UnoccupiedSetbackAttribute {val AT throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeUnoccupiedSetbackAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 55u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(UnoccupiedSetbackAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + UnoccupiedSetbackAttributeSubscriptionState.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) { - "Unoccupiedsetback attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Unoccupiedsetback 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(UnoccupiedSetbackAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(UnoccupiedSetbackAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UnoccupiedSetbackAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readUnoccupiedSetbackMinAttribute(): UnoccupiedSetbackMinAttribute {val ATTRIBUTE_ID: UInt = 56u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readUnoccupiedSetbackMinAttribute(): UnoccupiedSetbackMinAttribute { + val ATTRIBUTE_ID: UInt = 56u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Unoccupiedsetbackmin attribute not found in response" - } + } + + requireNotNull(attributeData) { "Unoccupiedsetbackmin attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return UnoccupiedSetbackMinAttribute(decodedValue) } suspend fun subscribeUnoccupiedSetbackMinAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 56u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(UnoccupiedSetbackMinAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + UnoccupiedSetbackMinAttributeSubscriptionState.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) { - "Unoccupiedsetbackmin attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Unoccupiedsetbackmin 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(UnoccupiedSetbackMinAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(UnoccupiedSetbackMinAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UnoccupiedSetbackMinAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readUnoccupiedSetbackMaxAttribute(): UnoccupiedSetbackMaxAttribute {val ATTRIBUTE_ID: UInt = 57u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readUnoccupiedSetbackMaxAttribute(): UnoccupiedSetbackMaxAttribute { + val ATTRIBUTE_ID: UInt = 57u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Unoccupiedsetbackmax attribute not found in response" - } + } + + requireNotNull(attributeData) { "Unoccupiedsetbackmax attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return UnoccupiedSetbackMaxAttribute(decodedValue) } suspend fun subscribeUnoccupiedSetbackMaxAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 57u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(UnoccupiedSetbackMaxAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + UnoccupiedSetbackMaxAttributeSubscriptionState.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) { - "Unoccupiedsetbackmax attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Unoccupiedsetbackmax 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(UnoccupiedSetbackMaxAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(UnoccupiedSetbackMaxAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UnoccupiedSetbackMaxAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readEmergencyHeatDeltaAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 58u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readEmergencyHeatDeltaAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 58u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Emergencyheatdelta attribute not found in response" - } + } + + requireNotNull(attributeData) { "Emergencyheatdelta 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } - suspend fun writeEmergencyHeatDeltaAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeEmergencyHeatDeltaAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 58u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -5565,127 +5289,119 @@ suspend fun readEmergencyHeatDeltaAttribute(): UByte? {val ATTRIBUTE_ID: UInt = throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeEmergencyHeatDeltaAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 58u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Emergencyheatdelta attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Emergencyheatdelta 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readACTypeAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 64u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readACTypeAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 64u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Actype attribute not found in response" - } + } + + requireNotNull(attributeData) { "Actype 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } - suspend fun writeACTypeAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeACTypeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 64u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -5706,127 +5422,117 @@ suspend fun readACTypeAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 64u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeACTypeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 64u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Actype attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Actype 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readACCapacityAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 65u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readACCapacityAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 65u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Accapacity attribute not found in response" - } + } + + requireNotNull(attributeData) { "Accapacity 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } - suspend fun writeACCapacityAttribute( - value: UShort, - timedWriteTimeout: Duration? = null) { + suspend fun writeACCapacityAttribute(value: UShort, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 65u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -5847,127 +5553,117 @@ suspend fun readACCapacityAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 65u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeACCapacityAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Accapacity attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Accapacity 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readACRefrigerantTypeAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 66u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readACRefrigerantTypeAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 66u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Acrefrigeranttype attribute not found in response" - } + } + + requireNotNull(attributeData) { "Acrefrigeranttype 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } - suspend fun writeACRefrigerantTypeAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeACRefrigerantTypeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 66u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -5988,127 +5684,119 @@ suspend fun readACRefrigerantTypeAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 6 throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeACRefrigerantTypeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 66u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Acrefrigeranttype attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Acrefrigeranttype 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readACCompressorTypeAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 67u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readACCompressorTypeAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 67u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Accompressortype attribute not found in response" - } + } + + requireNotNull(attributeData) { "Accompressortype 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } - suspend fun writeACCompressorTypeAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeACCompressorTypeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 67u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -6129,127 +5817,119 @@ suspend fun readACCompressorTypeAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 67 throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeACCompressorTypeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 67u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Accompressortype attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Accompressortype 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readACErrorCodeAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 68u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readACErrorCodeAttribute(): UInt? { + val ATTRIBUTE_ID: UInt = 68u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Acerrorcode attribute not found in response" - } + } + + requireNotNull(attributeData) { "Acerrorcode attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } - suspend fun writeACErrorCodeAttribute( - value: UInt, - timedWriteTimeout: Duration? = null) { + suspend fun writeACErrorCodeAttribute(value: UInt, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 68u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -6270,127 +5950,117 @@ suspend fun readACErrorCodeAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 68u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeACErrorCodeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 68u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Acerrorcode attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Acerrorcode attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readACLouverPositionAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 69u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readACLouverPositionAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 69u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Aclouverposition attribute not found in response" - } + } + + requireNotNull(attributeData) { "Aclouverposition 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } - suspend fun writeACLouverPositionAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeACLouverPositionAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 69u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -6411,234 +6081,222 @@ suspend fun readACLouverPositionAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 69 throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeACLouverPositionAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 69u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Aclouverposition attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Aclouverposition 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readACCoilTemperatureAttribute(): ACCoilTemperatureAttribute {val ATTRIBUTE_ID: UInt = 70u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readACCoilTemperatureAttribute(): ACCoilTemperatureAttribute { + val ATTRIBUTE_ID: UInt = 70u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Accoiltemperature attribute not found in response" - } + } + + requireNotNull(attributeData) { "Accoiltemperature attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Short? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return ACCoilTemperatureAttribute(decodedValue) } suspend fun subscribeACCoilTemperatureAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 70u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ACCoilTemperatureAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ACCoilTemperatureAttributeSubscriptionState.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) { - "Accoiltemperature attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Accoiltemperature attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(ACCoilTemperatureAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Short? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(ACCoilTemperatureAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ACCoilTemperatureAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readACCapacityformatAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 71u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readACCapacityformatAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 71u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Accapacityformat attribute not found in response" - } + } + + requireNotNull(attributeData) { "Accapacityformat 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } - suspend fun writeACCapacityformatAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeACCapacityformatAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 71u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -6659,967 +6317,931 @@ suspend fun readACCapacityformatAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 71 throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeACCapacityformatAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 71u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Accapacityformat attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Accapacityformat 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPresetTypesAttribute(): PresetTypesAttribute {val ATTRIBUTE_ID: UInt = 72u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readPresetTypesAttribute(): PresetTypesAttribute { + val ATTRIBUTE_ID: UInt = 72u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Presettypes attribute not found in response" - } + } + + requireNotNull(attributeData) { "Presettypes attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(ThermostatClusterPresetTypeStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(ThermostatClusterPresetTypeStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null } - tlvReader.exitContainer() - } - } else { - null - } - return PresetTypesAttribute(decodedValue) } suspend fun subscribePresetTypesAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 72u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(PresetTypesAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + PresetTypesAttributeSubscriptionState.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) { - "Presettypes attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Presettypes attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(ThermostatClusterPresetTypeStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { - emit(PresetTypesAttributeSubscriptionState.Success(it)) - } - + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(ThermostatClusterPresetTypeStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { emit(PresetTypesAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(PresetTypesAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readScheduleTypesAttribute(): ScheduleTypesAttribute {val ATTRIBUTE_ID: UInt = 73u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readScheduleTypesAttribute(): ScheduleTypesAttribute { + val ATTRIBUTE_ID: UInt = 73u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Scheduletypes attribute not found in response" - } + } + + requireNotNull(attributeData) { "Scheduletypes attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(ThermostatClusterScheduleTypeStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(ThermostatClusterScheduleTypeStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null } - tlvReader.exitContainer() - } - } else { - null - } - return ScheduleTypesAttribute(decodedValue) } suspend fun subscribeScheduleTypesAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 73u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ScheduleTypesAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ScheduleTypesAttributeSubscriptionState.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) { - "Scheduletypes attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Scheduletypes attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(ThermostatClusterScheduleTypeStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { - emit(ScheduleTypesAttributeSubscriptionState.Success(it)) - } - + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(ThermostatClusterScheduleTypeStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { emit(ScheduleTypesAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ScheduleTypesAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNumberOfPresetsAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 74u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNumberOfPresetsAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 74u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Numberofpresets attribute not found in response" - } + } + + requireNotNull(attributeData) { "Numberofpresets 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeNumberOfPresetsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 74u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Numberofpresets attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Numberofpresets 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNumberOfSchedulesAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 75u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNumberOfSchedulesAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 75u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Numberofschedules attribute not found in response" - } + } + + requireNotNull(attributeData) { "Numberofschedules 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeNumberOfSchedulesAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 75u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Numberofschedules attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Numberofschedules 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNumberOfScheduleTransitionsAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 76u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNumberOfScheduleTransitionsAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 76u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Numberofscheduletransitions attribute not found in response" - } + } + + requireNotNull(attributeData) { "Numberofscheduletransitions 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeNumberOfScheduleTransitionsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 76u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Numberofscheduletransitions attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Numberofscheduletransitions 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNumberOfScheduleTransitionPerDayAttribute(): NumberOfScheduleTransitionPerDayAttribute {val ATTRIBUTE_ID: UInt = 77u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNumberOfScheduleTransitionPerDayAttribute(): + NumberOfScheduleTransitionPerDayAttribute { + val ATTRIBUTE_ID: UInt = 77u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Numberofscheduletransitionperday attribute not found in response" + } + + requireNotNull(attributeData) { + "Numberofscheduletransitionperday attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return NumberOfScheduleTransitionPerDayAttribute(decodedValue) } suspend fun subscribeNumberOfScheduleTransitionPerDayAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 77u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(NumberOfScheduleTransitionPerDayAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + NumberOfScheduleTransitionPerDayAttributeSubscriptionState.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) { - "Numberofscheduletransitionperday attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Numberofscheduletransitionperday 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } decodedValue?.let { emit(NumberOfScheduleTransitionPerDayAttributeSubscriptionState.Success(it)) } - } SubscriptionState.SubscriptionEstablished -> { emit(NumberOfScheduleTransitionPerDayAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readActivePresetHandleAttribute(): ActivePresetHandleAttribute {val ATTRIBUTE_ID: UInt = 78u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readActivePresetHandleAttribute(): ActivePresetHandleAttribute { + val ATTRIBUTE_ID: UInt = 78u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Activepresethandle attribute not found in response" - } + } + + requireNotNull(attributeData) { "Activepresethandle attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByteArray(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: ByteArray? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByteArray(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return ActivePresetHandleAttribute(decodedValue) } suspend fun subscribeActivePresetHandleAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 78u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ActivePresetHandleAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ActivePresetHandleAttributeSubscriptionState.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) { - "Activepresethandle attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Activepresethandle attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByteArray(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(ActivePresetHandleAttributeSubscriptionState.Success(it)) - } - + val decodedValue: ByteArray? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByteArray(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(ActivePresetHandleAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ActivePresetHandleAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readActiveScheduleHandleAttribute(): ActiveScheduleHandleAttribute {val ATTRIBUTE_ID: UInt = 79u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readActiveScheduleHandleAttribute(): ActiveScheduleHandleAttribute { + val ATTRIBUTE_ID: UInt = 79u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Activeschedulehandle attribute not found in response" - } + } + + requireNotNull(attributeData) { "Activeschedulehandle attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByteArray(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: ByteArray? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByteArray(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return ActiveScheduleHandleAttribute(decodedValue) } suspend fun subscribeActiveScheduleHandleAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 79u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ActiveScheduleHandleAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ActiveScheduleHandleAttributeSubscriptionState.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) { - "Activeschedulehandle attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Activeschedulehandle attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByteArray(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(ActiveScheduleHandleAttributeSubscriptionState.Success(it)) - } - + val decodedValue: ByteArray? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByteArray(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(ActiveScheduleHandleAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ActiveScheduleHandleAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPresetsAttribute(): PresetsAttribute {val ATTRIBUTE_ID: UInt = 80u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readPresetsAttribute(): PresetsAttribute { + val ATTRIBUTE_ID: UInt = 80u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Presets attribute not found in response" - } + } + + requireNotNull(attributeData) { "Presets attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(ThermostatClusterPresetStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(ThermostatClusterPresetStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null } - tlvReader.exitContainer() - } - } else { - null - } - return PresetsAttribute(decodedValue) } suspend fun writePresetsAttribute( value: List, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 80u val tlvWriter = TlvWriter() tlvWriter.startArray(AnonymousTag) - for (item in value.iterator()) { - item.toTlv(AnonymousTag, tlvWriter) - } - tlvWriter.endArray() + for (item in value.iterator()) { + item.toTlv(AnonymousTag, tlvWriter) + } + tlvWriter.endArray() val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -7640,143 +7262,136 @@ suspend fun readPresetsAttribute(): PresetsAttribute {val ATTRIBUTE_ID: UInt = 8 throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribePresetsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 80u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(PresetsAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + PresetsAttributeSubscriptionState.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) { - "Presets attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Presets attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(ThermostatClusterPresetStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { - emit(PresetsAttributeSubscriptionState.Success(it)) - } - + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(ThermostatClusterPresetStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { emit(PresetsAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(PresetsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readSchedulesAttribute(): SchedulesAttribute {val ATTRIBUTE_ID: UInt = 81u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readSchedulesAttribute(): SchedulesAttribute { + val ATTRIBUTE_ID: UInt = 81u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Schedules attribute not found in response" - } + } + + requireNotNull(attributeData) { "Schedules attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(ThermostatClusterScheduleStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(ThermostatClusterScheduleStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null } - tlvReader.exitContainer() - } - } else { - null - } - return SchedulesAttribute(decodedValue) } suspend fun writeSchedulesAttribute( value: List, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 81u val tlvWriter = TlvWriter() tlvWriter.startArray(AnonymousTag) - for (item in value.iterator()) { - item.toTlv(AnonymousTag, tlvWriter) - } - tlvWriter.endArray() + for (item in value.iterator()) { + item.toTlv(AnonymousTag, tlvWriter) + } + tlvWriter.endArray() val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -7797,265 +7412,262 @@ suspend fun readSchedulesAttribute(): SchedulesAttribute {val ATTRIBUTE_ID: UInt throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeSchedulesAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 81u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(SchedulesAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + SchedulesAttributeSubscriptionState.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) { - "Schedules attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Schedules attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(ThermostatClusterScheduleStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { - emit(SchedulesAttributeSubscriptionState.Success(it)) - } - + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(ThermostatClusterScheduleStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { emit(SchedulesAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(SchedulesAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readSetpointHoldExpiryTimestampAttribute(): SetpointHoldExpiryTimestampAttribute {val ATTRIBUTE_ID: UInt = 82u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readSetpointHoldExpiryTimestampAttribute(): SetpointHoldExpiryTimestampAttribute { + val ATTRIBUTE_ID: UInt = 82u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Setpointholdexpirytimestamp attribute not found in response" - } + } + + requireNotNull(attributeData) { "Setpointholdexpirytimestamp attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return SetpointHoldExpiryTimestampAttribute(decodedValue) } suspend fun subscribeSetpointHoldExpiryTimestampAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 82u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(SetpointHoldExpiryTimestampAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + SetpointHoldExpiryTimestampAttributeSubscriptionState.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) { - "Setpointholdexpirytimestamp attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Setpointholdexpirytimestamp attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } decodedValue?.let { emit(SetpointHoldExpiryTimestampAttributeSubscriptionState.Success(it)) } - } SubscriptionState.SubscriptionEstablished -> { emit(SetpointHoldExpiryTimestampAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65528u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -8063,97 +7675,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { emit(GeneratedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65529u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -8161,97 +7772,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va emit(AcceptedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt = 65530u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -8259,97 +7867,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt emit(EventListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ID: UInt = 65531u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -8357,81 +7962,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ emit(AttributeListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -8443,80 +8043,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 65533u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -8529,7 +8126,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/ThermostatUserInterfaceConfigurationCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/ThermostatUserInterfaceConfigurationCluster.kt index f766146a4a3b89..fb4c3e71c7a672 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/ThermostatUserInterfaceConfigurationCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/ThermostatUserInterfaceConfigurationCluster.kt @@ -17,160 +17,123 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse -import matter.controller.model.AttributePath -import matter.controller.model.CommandPath import matter.controller.cluster.structs.* +import matter.controller.model.AttributePath import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class ThermostatUserInterfaceConfigurationCluster(private val controller: MatterController, private val endpointId: UShort) {class GeneratedCommandListAttribute( - val value: List - ) +class ThermostatUserInterfaceConfigurationCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } -suspend fun readTemperatureDisplayModeAttribute(): 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) - ) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } + + suspend fun readTemperatureDisplayModeAttribute(): 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}") - } + 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) { - "Temperaturedisplaymode attribute not found in response" - } + } + + requireNotNull(attributeData) { "Temperaturedisplaymode 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 writeTemperatureDisplayModeAttribute( value: UByte, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -191,42 +154,46 @@ suspend fun readTemperatureDisplayModeAttribute(): UByte {val ATTRIBUTE_ID: UInt throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeTemperatureDisplayModeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Temperaturedisplaymode attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Temperaturedisplaymode attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -239,68 +206,57 @@ suspend fun readTemperatureDisplayModeAttribute(): UByte {val ATTRIBUTE_ID: UInt emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readKeypadLockoutAttribute(): 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) - ) - + + suspend fun readKeypadLockoutAttribute(): 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}") - } + 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) { - "Keypadlockout attribute not found in response" - } + } + + requireNotNull(attributeData) { "Keypadlockout 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 writeKeypadLockoutAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeKeypadLockoutAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 1u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -321,43 +277,45 @@ suspend fun readKeypadLockoutAttribute(): UByte {val ATTRIBUTE_ID: UInt = 1u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeKeypadLockoutAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Keypadlockout attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Keypadlockout attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -369,72 +327,67 @@ suspend fun readKeypadLockoutAttribute(): UByte {val ATTRIBUTE_ID: UInt = 1u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readScheduleProgrammingVisibilityAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readScheduleProgrammingVisibilityAttribute(): UByte? { + 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}") - } + 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) { - "Scheduleprogrammingvisibility attribute not found in response" + } + + requireNotNull(attributeData) { + "Scheduleprogrammingvisibility 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun writeScheduleProgrammingVisibilityAttribute( value: UByte, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 2u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -455,152 +408,153 @@ suspend fun readScheduleProgrammingVisibilityAttribute(): UByte? {val ATTRIBUTE_ throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeScheduleProgrammingVisibilityAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Scheduleprogrammingvisibility attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Scheduleprogrammingvisibility 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)) - } - + 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 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -608,97 +562,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -706,97 +659,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -804,97 +754,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -902,81 +849,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -988,80 +930,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1074,11 +1013,12 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { - private val logger = Logger.getLogger(ThermostatUserInterfaceConfigurationCluster::class.java.name) + private val logger = + Logger.getLogger(ThermostatUserInterfaceConfigurationCluster::class.java.name) const val CLUSTER_ID: UInt = 516u } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/ThreadBorderRouterManagementCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/ThreadBorderRouterManagementCluster.kt index 08d68ff29f3eda..efbb1b5baff7e4 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/ThreadBorderRouterManagementCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/ThreadBorderRouterManagementCluster.kt @@ -17,143 +17,110 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.BooleanSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest +import matter.controller.StringSubscriptionState import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState -import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.UShortSubscriptionState +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class ThreadBorderRouterManagementCluster(private val controller: MatterController, private val endpointId: UShort) { - class DatasetResponse( - val dataset: ByteArray - ) -class ActiveDatasetTimestampAttribute( - val value: ULong? - ) +class ThreadBorderRouterManagementCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class DatasetResponse(val dataset: ByteArray) + + class ActiveDatasetTimestampAttribute(val value: ULong?) sealed class ActiveDatasetTimestampAttributeSubscriptionState { - data class Success( - val value: ULong? - ) : ActiveDatasetTimestampAttributeSubscriptionState() - + data class Success(val value: ULong?) : ActiveDatasetTimestampAttributeSubscriptionState() + data class Error(val exception: Exception) : ActiveDatasetTimestampAttributeSubscriptionState() - object SubscriptionEstablished : ActiveDatasetTimestampAttributeSubscriptionState() - } -class PendingDatasetTimestampAttribute( - val value: ULong? - ) + object SubscriptionEstablished : ActiveDatasetTimestampAttributeSubscriptionState() + } + + class PendingDatasetTimestampAttribute(val value: ULong?) sealed class PendingDatasetTimestampAttributeSubscriptionState { - data class Success( - val value: ULong? - ) : PendingDatasetTimestampAttributeSubscriptionState() - - data class Error(val exception: Exception) : PendingDatasetTimestampAttributeSubscriptionState() - - object SubscriptionEstablished : PendingDatasetTimestampAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + data class Success(val value: ULong?) : PendingDatasetTimestampAttributeSubscriptionState() + + data class Error(val exception: Exception) : + PendingDatasetTimestampAttributeSubscriptionState() + + object SubscriptionEstablished : PendingDatasetTimestampAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } suspend fun getActiveDatasetRequest(timedInvokeTimeout: Duration? = null): DatasetResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -163,46 +130,38 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_DATASET: Int = 0 var dataset_decoded: ByteArray? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_DATASET)) {dataset_decoded = tlvReader.getByteArray(tag)} - - - else { + if (tag == ContextSpecificTag(TAG_DATASET)) { + dataset_decoded = tlvReader.getByteArray(tag) + } else { tlvReader.skipElement() } } - - if (dataset_decoded == null) { - throw IllegalStateException("dataset not found in TLV") + throw IllegalStateException("dataset not found in TLV") } - tlvReader.exitContainer() - return DatasetResponse( - dataset_decoded - ) + return DatasetResponse(dataset_decoded) } suspend fun getPendingDatasetRequest(timedInvokeTimeout: Duration? = null): DatasetResponse { val commandId: UInt = 1u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -212,37 +171,31 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_DATASET: Int = 0 var dataset_decoded: ByteArray? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_DATASET)) {dataset_decoded = tlvReader.getByteArray(tag)} - - - else { + if (tag == ContextSpecificTag(TAG_DATASET)) { + dataset_decoded = tlvReader.getByteArray(tag) + } else { tlvReader.skipElement() } } - - if (dataset_decoded == null) { - throw IllegalStateException("dataset not found in TLV") + throw IllegalStateException("dataset not found in TLV") } - tlvReader.exitContainer() - return DatasetResponse( - dataset_decoded - ) + return DatasetResponse(dataset_decoded) } - suspend fun setActiveDatasetRequest(activeDataset: ByteArray - ,breadcrumb: ULong? - ,timedInvokeTimeout: Duration? = null) { + suspend fun setActiveDatasetRequest( + activeDataset: ByteArray, + breadcrumb: ULong?, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 3u val tlvWriter = TlvWriter() @@ -252,115 +205,112 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_ACTIVE_DATASET_REQ), activeDataset) val TAG_BREADCRUMB_REQ: Int = 1 - breadcrumb?.let { - tlvWriter.put(ContextSpecificTag(TAG_BREADCRUMB_REQ), breadcrumb) - } + breadcrumb?.let { tlvWriter.put(ContextSpecificTag(TAG_BREADCRUMB_REQ), breadcrumb) } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun setPendingDatasetRequest(pendingDataset: ByteArray - ,timedInvokeTimeout: Duration? = null) { + suspend fun setPendingDatasetRequest( + pendingDataset: ByteArray, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 4u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_PENDING_DATASET_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_PENDING_DATASET_REQ), pendingDataset) + tlvWriter.put(ContextSpecificTag(TAG_PENDING_DATASET_REQ), pendingDataset) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } -suspend fun readBorderRouterNameAttribute(): String {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readBorderRouterNameAttribute(): String { + 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}") - } + 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) { - "Borderroutername attribute not found in response" - } + } + + requireNotNull(attributeData) { "Borderroutername attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: String = tlvReader.getString(AnonymousTag) - return decodedValue } suspend fun subscribeBorderRouterNameAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StringSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StringSubscriptionState.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) { - "Borderroutername attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Borderroutername attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -373,81 +323,76 @@ suspend fun readBorderRouterNameAttribute(): String {val ATTRIBUTE_ID: UInt = 0u emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readBorderAgentIDAttribute(): ByteArray {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readBorderAgentIDAttribute(): ByteArray { + 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}") - } + 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) { - "Borderagentid attribute not found in response" - } + } + + requireNotNull(attributeData) { "Borderagentid attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: ByteArray = tlvReader.getByteArray(AnonymousTag) - return decodedValue } suspend fun subscribeBorderAgentIDAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ByteArraySubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ByteArraySubscriptionState.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) { - "Borderagentid attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Borderagentid attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -459,81 +404,76 @@ suspend fun readBorderAgentIDAttribute(): ByteArray {val ATTRIBUTE_ID: UInt = 1u emit(ByteArraySubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readThreadVersionAttribute(): 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) - ) - + + suspend fun readThreadVersionAttribute(): 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}") - } + 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) { - "Threadversion attribute not found in response" - } + } + + requireNotNull(attributeData) { "Threadversion 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 subscribeThreadVersionAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Threadversion attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Threadversion attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -545,80 +485,77 @@ suspend fun readThreadVersionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 2u emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readInterfaceEnabledAttribute(): 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) - ) - + + suspend fun readInterfaceEnabledAttribute(): 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}") - } + 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) { - "Interfaceenabled attribute not found in response" - } + } + + requireNotNull(attributeData) { "Interfaceenabled attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Boolean = tlvReader.getBoolean(AnonymousTag) - return decodedValue } suspend fun subscribeInterfaceEnabledAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Interfaceenabled attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Interfaceenabled attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -631,295 +568,286 @@ suspend fun readInterfaceEnabledAttribute(): Boolean {val ATTRIBUTE_ID: UInt = 3 emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readActiveDatasetTimestampAttribute(): ActiveDatasetTimestampAttribute {val ATTRIBUTE_ID: UInt = 4u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readActiveDatasetTimestampAttribute(): ActiveDatasetTimestampAttribute { + 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}") - } + 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) { - "Activedatasettimestamp attribute not found in response" - } + } + + requireNotNull(attributeData) { "Activedatasettimestamp attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ULong? = if (!tlvReader.isNull()) { - tlvReader.getULong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: ULong? = + if (!tlvReader.isNull()) { + tlvReader.getULong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return ActiveDatasetTimestampAttribute(decodedValue) } suspend fun subscribeActiveDatasetTimestampAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ActiveDatasetTimestampAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ActiveDatasetTimestampAttributeSubscriptionState.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) { - "Activedatasettimestamp attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Activedatasettimestamp 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()) { - tlvReader.getULong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(ActiveDatasetTimestampAttributeSubscriptionState.Success(it)) - } - + val decodedValue: ULong? = + if (!tlvReader.isNull()) { + tlvReader.getULong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(ActiveDatasetTimestampAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ActiveDatasetTimestampAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPendingDatasetTimestampAttribute(): PendingDatasetTimestampAttribute {val ATTRIBUTE_ID: UInt = 5u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readPendingDatasetTimestampAttribute(): PendingDatasetTimestampAttribute { + 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}") - } + 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) { - "Pendingdatasettimestamp attribute not found in response" - } + } + + requireNotNull(attributeData) { "Pendingdatasettimestamp attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ULong? = if (!tlvReader.isNull()) { - tlvReader.getULong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: ULong? = + if (!tlvReader.isNull()) { + tlvReader.getULong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return PendingDatasetTimestampAttribute(decodedValue) } suspend fun subscribePendingDatasetTimestampAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(PendingDatasetTimestampAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + PendingDatasetTimestampAttributeSubscriptionState.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) { - "Pendingdatasettimestamp attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Pendingdatasettimestamp 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()) { - tlvReader.getULong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(PendingDatasetTimestampAttributeSubscriptionState.Success(it)) - } - + val decodedValue: ULong? = + if (!tlvReader.isNull()) { + tlvReader.getULong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(PendingDatasetTimestampAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(PendingDatasetTimestampAttributeSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -927,97 +855,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1025,97 +952,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1123,97 +1047,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1221,81 +1142,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1307,80 +1223,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1393,7 +1306,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/ThreadNetworkDiagnosticsCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/ThreadNetworkDiagnosticsCluster.kt index 865e7b62d0545d..4950900b057665 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/ThreadNetworkDiagnosticsCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/ThreadNetworkDiagnosticsCluster.kt @@ -17,1158 +17,1040 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState -import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.UShortSubscriptionState +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class ThreadNetworkDiagnosticsCluster(private val controller: MatterController, private val endpointId: UShort) {class ChannelAttribute( - val value: UShort? - ) +class ThreadNetworkDiagnosticsCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class ChannelAttribute(val value: UShort?) sealed class ChannelAttributeSubscriptionState { - data class Success( - val value: UShort? - ) : ChannelAttributeSubscriptionState() - + data class Success(val value: UShort?) : ChannelAttributeSubscriptionState() + data class Error(val exception: Exception) : ChannelAttributeSubscriptionState() - object SubscriptionEstablished : ChannelAttributeSubscriptionState() - } -class RoutingRoleAttribute( - val value: UByte? - ) + object SubscriptionEstablished : ChannelAttributeSubscriptionState() + } + + class RoutingRoleAttribute(val value: UByte?) sealed class RoutingRoleAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : RoutingRoleAttributeSubscriptionState() - + data class Success(val value: UByte?) : RoutingRoleAttributeSubscriptionState() + data class Error(val exception: Exception) : RoutingRoleAttributeSubscriptionState() - object SubscriptionEstablished : RoutingRoleAttributeSubscriptionState() - } -class NetworkNameAttribute( - val value: String? - ) + object SubscriptionEstablished : RoutingRoleAttributeSubscriptionState() + } + + class NetworkNameAttribute(val value: String?) sealed class NetworkNameAttributeSubscriptionState { - data class Success( - val value: String? - ) : NetworkNameAttributeSubscriptionState() - + data class Success(val value: String?) : NetworkNameAttributeSubscriptionState() + data class Error(val exception: Exception) : NetworkNameAttributeSubscriptionState() - object SubscriptionEstablished : NetworkNameAttributeSubscriptionState() - } -class PanIdAttribute( - val value: UShort? - ) + object SubscriptionEstablished : NetworkNameAttributeSubscriptionState() + } + + class PanIdAttribute(val value: UShort?) sealed class PanIdAttributeSubscriptionState { - data class Success( - val value: UShort? - ) : PanIdAttributeSubscriptionState() - + data class Success(val value: UShort?) : PanIdAttributeSubscriptionState() + data class Error(val exception: Exception) : PanIdAttributeSubscriptionState() - object SubscriptionEstablished : PanIdAttributeSubscriptionState() - } -class ExtendedPanIdAttribute( - val value: ULong? - ) + object SubscriptionEstablished : PanIdAttributeSubscriptionState() + } + + class ExtendedPanIdAttribute(val value: ULong?) sealed class ExtendedPanIdAttributeSubscriptionState { - data class Success( - val value: ULong? - ) : ExtendedPanIdAttributeSubscriptionState() - + data class Success(val value: ULong?) : ExtendedPanIdAttributeSubscriptionState() + data class Error(val exception: Exception) : ExtendedPanIdAttributeSubscriptionState() - object SubscriptionEstablished : ExtendedPanIdAttributeSubscriptionState() - } -class MeshLocalPrefixAttribute( - val value: ByteArray? - ) + object SubscriptionEstablished : ExtendedPanIdAttributeSubscriptionState() + } + + class MeshLocalPrefixAttribute(val value: ByteArray?) sealed class MeshLocalPrefixAttributeSubscriptionState { - data class Success( - val value: ByteArray? - ) : MeshLocalPrefixAttributeSubscriptionState() - + data class Success(val value: ByteArray?) : MeshLocalPrefixAttributeSubscriptionState() + data class Error(val exception: Exception) : MeshLocalPrefixAttributeSubscriptionState() - object SubscriptionEstablished : MeshLocalPrefixAttributeSubscriptionState() - } -class NeighborTableAttribute( - val value: List - ) + object SubscriptionEstablished : MeshLocalPrefixAttributeSubscriptionState() + } + + class NeighborTableAttribute(val value: List) sealed class NeighborTableAttributeSubscriptionState { - data class Success( - val value: List - ) : NeighborTableAttributeSubscriptionState() - + data class Success(val value: List) : + NeighborTableAttributeSubscriptionState() + data class Error(val exception: Exception) : NeighborTableAttributeSubscriptionState() - object SubscriptionEstablished : NeighborTableAttributeSubscriptionState() - } -class RouteTableAttribute( - val value: List - ) + object SubscriptionEstablished : NeighborTableAttributeSubscriptionState() + } + + class RouteTableAttribute(val value: List) sealed class RouteTableAttributeSubscriptionState { - data class Success( - val value: List - ) : RouteTableAttributeSubscriptionState() - + data class Success(val value: List) : + RouteTableAttributeSubscriptionState() + data class Error(val exception: Exception) : RouteTableAttributeSubscriptionState() - object SubscriptionEstablished : RouteTableAttributeSubscriptionState() - } -class PartitionIdAttribute( - val value: UInt? - ) + object SubscriptionEstablished : RouteTableAttributeSubscriptionState() + } + + class PartitionIdAttribute(val value: UInt?) sealed class PartitionIdAttributeSubscriptionState { - data class Success( - val value: UInt? - ) : PartitionIdAttributeSubscriptionState() - + data class Success(val value: UInt?) : PartitionIdAttributeSubscriptionState() + data class Error(val exception: Exception) : PartitionIdAttributeSubscriptionState() - object SubscriptionEstablished : PartitionIdAttributeSubscriptionState() - } -class WeightingAttribute( - val value: UShort? - ) + object SubscriptionEstablished : PartitionIdAttributeSubscriptionState() + } + + class WeightingAttribute(val value: UShort?) sealed class WeightingAttributeSubscriptionState { - data class Success( - val value: UShort? - ) : WeightingAttributeSubscriptionState() - + data class Success(val value: UShort?) : WeightingAttributeSubscriptionState() + data class Error(val exception: Exception) : WeightingAttributeSubscriptionState() - object SubscriptionEstablished : WeightingAttributeSubscriptionState() - } -class DataVersionAttribute( - val value: UShort? - ) + object SubscriptionEstablished : WeightingAttributeSubscriptionState() + } + + class DataVersionAttribute(val value: UShort?) sealed class DataVersionAttributeSubscriptionState { - data class Success( - val value: UShort? - ) : DataVersionAttributeSubscriptionState() - + data class Success(val value: UShort?) : DataVersionAttributeSubscriptionState() + data class Error(val exception: Exception) : DataVersionAttributeSubscriptionState() - object SubscriptionEstablished : DataVersionAttributeSubscriptionState() - } -class StableDataVersionAttribute( - val value: UShort? - ) + object SubscriptionEstablished : DataVersionAttributeSubscriptionState() + } + + class StableDataVersionAttribute(val value: UShort?) sealed class StableDataVersionAttributeSubscriptionState { - data class Success( - val value: UShort? - ) : StableDataVersionAttributeSubscriptionState() - + data class Success(val value: UShort?) : StableDataVersionAttributeSubscriptionState() + data class Error(val exception: Exception) : StableDataVersionAttributeSubscriptionState() - object SubscriptionEstablished : StableDataVersionAttributeSubscriptionState() - } -class LeaderRouterIdAttribute( - val value: UByte? - ) + object SubscriptionEstablished : StableDataVersionAttributeSubscriptionState() + } + + class LeaderRouterIdAttribute(val value: UByte?) sealed class LeaderRouterIdAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : LeaderRouterIdAttributeSubscriptionState() - + data class Success(val value: UByte?) : LeaderRouterIdAttributeSubscriptionState() + data class Error(val exception: Exception) : LeaderRouterIdAttributeSubscriptionState() - object SubscriptionEstablished : LeaderRouterIdAttributeSubscriptionState() - } -class ActiveTimestampAttribute( - val value: ULong? - ) + object SubscriptionEstablished : LeaderRouterIdAttributeSubscriptionState() + } + + class ActiveTimestampAttribute(val value: ULong?) sealed class ActiveTimestampAttributeSubscriptionState { - data class Success( - val value: ULong? - ) : ActiveTimestampAttributeSubscriptionState() - + data class Success(val value: ULong?) : ActiveTimestampAttributeSubscriptionState() + data class Error(val exception: Exception) : ActiveTimestampAttributeSubscriptionState() - object SubscriptionEstablished : ActiveTimestampAttributeSubscriptionState() - } -class PendingTimestampAttribute( - val value: ULong? - ) + object SubscriptionEstablished : ActiveTimestampAttributeSubscriptionState() + } + + class PendingTimestampAttribute(val value: ULong?) sealed class PendingTimestampAttributeSubscriptionState { - data class Success( - val value: ULong? - ) : PendingTimestampAttributeSubscriptionState() - + data class Success(val value: ULong?) : PendingTimestampAttributeSubscriptionState() + data class Error(val exception: Exception) : PendingTimestampAttributeSubscriptionState() - object SubscriptionEstablished : PendingTimestampAttributeSubscriptionState() - } -class DelayAttribute( - val value: UInt? - ) + object SubscriptionEstablished : PendingTimestampAttributeSubscriptionState() + } + + class DelayAttribute(val value: UInt?) sealed class DelayAttributeSubscriptionState { - data class Success( - val value: UInt? - ) : DelayAttributeSubscriptionState() - + data class Success(val value: UInt?) : DelayAttributeSubscriptionState() + data class Error(val exception: Exception) : DelayAttributeSubscriptionState() - object SubscriptionEstablished : DelayAttributeSubscriptionState() - } -class SecurityPolicyAttribute( - val value: ThreadNetworkDiagnosticsClusterSecurityPolicy? - ) + object SubscriptionEstablished : DelayAttributeSubscriptionState() + } + + class SecurityPolicyAttribute(val value: ThreadNetworkDiagnosticsClusterSecurityPolicy?) sealed class SecurityPolicyAttributeSubscriptionState { - data class Success( - val value: ThreadNetworkDiagnosticsClusterSecurityPolicy? - ) : SecurityPolicyAttributeSubscriptionState() - + data class Success(val value: ThreadNetworkDiagnosticsClusterSecurityPolicy?) : + SecurityPolicyAttributeSubscriptionState() + data class Error(val exception: Exception) : SecurityPolicyAttributeSubscriptionState() - object SubscriptionEstablished : SecurityPolicyAttributeSubscriptionState() - } -class ChannelPage0MaskAttribute( - val value: ByteArray? - ) + object SubscriptionEstablished : SecurityPolicyAttributeSubscriptionState() + } + + class ChannelPage0MaskAttribute(val value: ByteArray?) sealed class ChannelPage0MaskAttributeSubscriptionState { - data class Success( - val value: ByteArray? - ) : ChannelPage0MaskAttributeSubscriptionState() - + data class Success(val value: ByteArray?) : ChannelPage0MaskAttributeSubscriptionState() + data class Error(val exception: Exception) : ChannelPage0MaskAttributeSubscriptionState() - object SubscriptionEstablished : ChannelPage0MaskAttributeSubscriptionState() - } -class OperationalDatasetComponentsAttribute( + object SubscriptionEstablished : ChannelPage0MaskAttributeSubscriptionState() + } + + class OperationalDatasetComponentsAttribute( val value: ThreadNetworkDiagnosticsClusterOperationalDatasetComponents? ) sealed class OperationalDatasetComponentsAttributeSubscriptionState { - data class Success( - val value: ThreadNetworkDiagnosticsClusterOperationalDatasetComponents? - ) : OperationalDatasetComponentsAttributeSubscriptionState() - - data class Error(val exception: Exception) : OperationalDatasetComponentsAttributeSubscriptionState() - - object SubscriptionEstablished : OperationalDatasetComponentsAttributeSubscriptionState() - } -class ActiveNetworkFaultsListAttribute( - val value: List - ) + data class Success(val value: ThreadNetworkDiagnosticsClusterOperationalDatasetComponents?) : + OperationalDatasetComponentsAttributeSubscriptionState() + + data class Error(val exception: Exception) : + OperationalDatasetComponentsAttributeSubscriptionState() + + object SubscriptionEstablished : OperationalDatasetComponentsAttributeSubscriptionState() + } + + class ActiveNetworkFaultsListAttribute(val value: List) sealed class ActiveNetworkFaultsListAttributeSubscriptionState { - data class Success( - val value: List - ) : ActiveNetworkFaultsListAttributeSubscriptionState() - - data class Error(val exception: Exception) : ActiveNetworkFaultsListAttributeSubscriptionState() - - object SubscriptionEstablished : ActiveNetworkFaultsListAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + data class Success(val value: List) : + ActiveNetworkFaultsListAttributeSubscriptionState() + + data class Error(val exception: Exception) : + ActiveNetworkFaultsListAttributeSubscriptionState() + + object SubscriptionEstablished : ActiveNetworkFaultsListAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } suspend fun resetCounts(timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } -suspend fun readChannelAttribute(): ChannelAttribute {val ATTRIBUTE_ID: UInt = 0u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readChannelAttribute(): ChannelAttribute { + 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 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}") - } + 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) { - "Channel attribute not found in response" - } + } + + requireNotNull(attributeData) { "Channel attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = if (!tlvReader.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return ChannelAttribute(decodedValue) } suspend fun subscribeChannelAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ChannelAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ChannelAttributeSubscriptionState.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) { - "Channel attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Channel 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.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(ChannelAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ChannelAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ChannelAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRoutingRoleAttribute(): RoutingRoleAttribute {val ATTRIBUTE_ID: UInt = 1u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRoutingRoleAttribute(): RoutingRoleAttribute { + 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 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}") - } + 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) { - "Routingrole attribute not found in response" - } + } + + requireNotNull(attributeData) { "Routingrole attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return RoutingRoleAttribute(decodedValue) } suspend fun subscribeRoutingRoleAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(RoutingRoleAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + RoutingRoleAttributeSubscriptionState.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) { - "Routingrole attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Routingrole 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.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(RoutingRoleAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(RoutingRoleAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(RoutingRoleAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNetworkNameAttribute(): NetworkNameAttribute {val ATTRIBUTE_ID: UInt = 2u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNetworkNameAttribute(): NetworkNameAttribute { + 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 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}") - } + 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) { - "Networkname attribute not found in response" - } + } + + requireNotNull(attributeData) { "Networkname attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (!tlvReader.isNull()) { - tlvReader.getString(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: String? = + if (!tlvReader.isNull()) { + tlvReader.getString(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return NetworkNameAttribute(decodedValue) } suspend fun subscribeNetworkNameAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(NetworkNameAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + NetworkNameAttributeSubscriptionState.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) { - "Networkname attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Networkname attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (!tlvReader.isNull()) { - tlvReader.getString(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: String? = + if (!tlvReader.isNull()) { + tlvReader.getString(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(NetworkNameAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(NetworkNameAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(NetworkNameAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPanIdAttribute(): PanIdAttribute {val ATTRIBUTE_ID: UInt = 3u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readPanIdAttribute(): PanIdAttribute { + 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 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}") - } + 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) { - "Panid attribute not found in response" - } + } + + requireNotNull(attributeData) { "Panid attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = if (!tlvReader.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return PanIdAttribute(decodedValue) } suspend fun subscribePanIdAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(PanIdAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + PanIdAttributeSubscriptionState.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) { - "Panid attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Panid 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.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(PanIdAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(PanIdAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(PanIdAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readExtendedPanIdAttribute(): ExtendedPanIdAttribute {val ATTRIBUTE_ID: UInt = 4u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readExtendedPanIdAttribute(): ExtendedPanIdAttribute { + 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 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}") - } + 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) { - "Extendedpanid attribute not found in response" - } + } + + requireNotNull(attributeData) { "Extendedpanid attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ULong? = if (!tlvReader.isNull()) { - tlvReader.getULong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: ULong? = + if (!tlvReader.isNull()) { + tlvReader.getULong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return ExtendedPanIdAttribute(decodedValue) } suspend fun subscribeExtendedPanIdAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ExtendedPanIdAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ExtendedPanIdAttributeSubscriptionState.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) { - "Extendedpanid attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Extendedpanid 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()) { - tlvReader.getULong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ULong? = + if (!tlvReader.isNull()) { + tlvReader.getULong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(ExtendedPanIdAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ExtendedPanIdAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ExtendedPanIdAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMeshLocalPrefixAttribute(): MeshLocalPrefixAttribute {val ATTRIBUTE_ID: UInt = 5u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readMeshLocalPrefixAttribute(): MeshLocalPrefixAttribute { + 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 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}") - } + 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) { - "Meshlocalprefix attribute not found in response" - } + } + + requireNotNull(attributeData) { "Meshlocalprefix attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = if (!tlvReader.isNull()) { - tlvReader.getByteArray(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: ByteArray? = + if (!tlvReader.isNull()) { + tlvReader.getByteArray(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return MeshLocalPrefixAttribute(decodedValue) } suspend fun subscribeMeshLocalPrefixAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MeshLocalPrefixAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MeshLocalPrefixAttributeSubscriptionState.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) { - "Meshlocalprefix attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Meshlocalprefix attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = if (!tlvReader.isNull()) { - tlvReader.getByteArray(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ByteArray? = + if (!tlvReader.isNull()) { + tlvReader.getByteArray(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(MeshLocalPrefixAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(MeshLocalPrefixAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MeshLocalPrefixAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readOverrunCountAttribute(): ULong? {val ATTRIBUTE_ID: UInt = 6u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readOverrunCountAttribute(): ULong? { + 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 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}") - } + 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) { - "Overruncount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Overruncount attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ULong? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getULong(AnonymousTag) - } else { - null - } - + val decodedValue: ULong? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeOverrunCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ULongSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ULongSubscriptionState.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) { - "Overruncount attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Overruncount 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.isNextTag(AnonymousTag)) { - tlvReader.getULong(AnonymousTag) - } else { - null - } + val decodedValue: ULong? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(ULongSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ULongSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ULongSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNeighborTableAttribute(): NeighborTableAttribute {val ATTRIBUTE_ID: UInt = 7u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNeighborTableAttribute(): NeighborTableAttribute { + 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 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}") - } + 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) { - "Neighbortable attribute not found in response" - } + } + + requireNotNull(attributeData) { "Neighbortable 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(ThreadNetworkDiagnosticsClusterNeighborTableStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(ThreadNetworkDiagnosticsClusterNeighborTableStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return NeighborTableAttribute(decodedValue) } suspend fun subscribeNeighborTableAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(NeighborTableAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + NeighborTableAttributeSubscriptionState.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) { - "Neighbortable attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Neighbortable 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(ThreadNetworkDiagnosticsClusterNeighborTableStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add( + ThreadNetworkDiagnosticsClusterNeighborTableStruct.fromTlv( + AnonymousTag, + tlvReader, + ) + ) + } + tlvReader.exitContainer() + } emit(NeighborTableAttributeSubscriptionState.Success(decodedValue)) } @@ -1176,97 +1058,96 @@ suspend fun readNeighborTableAttribute(): NeighborTableAttribute {val ATTRIBUTE_ emit(NeighborTableAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRouteTableAttribute(): RouteTableAttribute {val ATTRIBUTE_ID: UInt = 8u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRouteTableAttribute(): RouteTableAttribute { + val ATTRIBUTE_ID: UInt = 8u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Routetable attribute not found in response" - } + } + + requireNotNull(attributeData) { "Routetable 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(ThreadNetworkDiagnosticsClusterRouteTableStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(ThreadNetworkDiagnosticsClusterRouteTableStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return RouteTableAttribute(decodedValue) } suspend fun subscribeRouteTableAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(RouteTableAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + RouteTableAttributeSubscriptionState.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) { - "Routetable attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Routetable 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(ThreadNetworkDiagnosticsClusterRouteTableStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add( + ThreadNetworkDiagnosticsClusterRouteTableStruct.fromTlv(AnonymousTag, tlvReader) + ) + } + tlvReader.exitContainer() + } emit(RouteTableAttributeSubscriptionState.Success(decodedValue)) } @@ -1274,5284 +1155,5046 @@ suspend fun readRouteTableAttribute(): RouteTableAttribute {val ATTRIBUTE_ID: UI emit(RouteTableAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPartitionIdAttribute(): PartitionIdAttribute {val ATTRIBUTE_ID: UInt = 9u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readPartitionIdAttribute(): PartitionIdAttribute { + val ATTRIBUTE_ID: UInt = 9u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Partitionid attribute not found in response" - } + } + + requireNotNull(attributeData) { "Partitionid attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - tlvReader.getUInt(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + tlvReader.getUInt(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return PartitionIdAttribute(decodedValue) } suspend fun subscribePartitionIdAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(PartitionIdAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + PartitionIdAttributeSubscriptionState.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) { - "Partitionid attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Partitionid attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - tlvReader.getUInt(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + tlvReader.getUInt(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(PartitionIdAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(PartitionIdAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(PartitionIdAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readWeightingAttribute(): WeightingAttribute {val ATTRIBUTE_ID: UInt = 10u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readWeightingAttribute(): WeightingAttribute { + val ATTRIBUTE_ID: UInt = 10u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Weighting attribute not found in response" - } + } + + requireNotNull(attributeData) { "Weighting attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = if (!tlvReader.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return WeightingAttribute(decodedValue) } suspend fun subscribeWeightingAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(WeightingAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + WeightingAttributeSubscriptionState.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) { - "Weighting attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Weighting 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.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(WeightingAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(WeightingAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(WeightingAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readDataVersionAttribute(): DataVersionAttribute {val ATTRIBUTE_ID: UInt = 11u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readDataVersionAttribute(): DataVersionAttribute { + val ATTRIBUTE_ID: UInt = 11u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Dataversion attribute not found in response" - } + } + + requireNotNull(attributeData) { "Dataversion attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = if (!tlvReader.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return DataVersionAttribute(decodedValue) } suspend fun subscribeDataVersionAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 11u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(DataVersionAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + DataVersionAttributeSubscriptionState.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) { - "Dataversion attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Dataversion 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.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(DataVersionAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(DataVersionAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(DataVersionAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readStableDataVersionAttribute(): StableDataVersionAttribute {val ATTRIBUTE_ID: UInt = 12u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readStableDataVersionAttribute(): StableDataVersionAttribute { + val ATTRIBUTE_ID: UInt = 12u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Stabledataversion attribute not found in response" - } + } + + requireNotNull(attributeData) { "Stabledataversion attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = if (!tlvReader.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return StableDataVersionAttribute(decodedValue) } suspend fun subscribeStableDataVersionAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 12u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StableDataVersionAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StableDataVersionAttributeSubscriptionState.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) { - "Stabledataversion attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Stabledataversion 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.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(StableDataVersionAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(StableDataVersionAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(StableDataVersionAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readLeaderRouterIdAttribute(): LeaderRouterIdAttribute {val ATTRIBUTE_ID: UInt = 13u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readLeaderRouterIdAttribute(): LeaderRouterIdAttribute { + val ATTRIBUTE_ID: UInt = 13u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Leaderrouterid attribute not found in response" - } + } + + requireNotNull(attributeData) { "Leaderrouterid attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return LeaderRouterIdAttribute(decodedValue) } suspend fun subscribeLeaderRouterIdAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 13u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(LeaderRouterIdAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + LeaderRouterIdAttributeSubscriptionState.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) { - "Leaderrouterid attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Leaderrouterid 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.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(LeaderRouterIdAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(LeaderRouterIdAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(LeaderRouterIdAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readDetachedRoleCountAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 14u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readDetachedRoleCountAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 14u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Detachedrolecount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Detachedrolecount 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeDetachedRoleCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 14u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Detachedrolecount attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Detachedrolecount 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readChildRoleCountAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 15u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readChildRoleCountAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 15u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Childrolecount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Childrolecount 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeChildRoleCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 15u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Childrolecount attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Childrolecount 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRouterRoleCountAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 16u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRouterRoleCountAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 16u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Routerrolecount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Routerrolecount 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeRouterRoleCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Routerrolecount attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Routerrolecount 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readLeaderRoleCountAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 17u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readLeaderRoleCountAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 17u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Leaderrolecount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Leaderrolecount 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeLeaderRoleCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 17u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Leaderrolecount attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Leaderrolecount 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAttachAttemptCountAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 18u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readAttachAttemptCountAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 18u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Attachattemptcount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Attachattemptcount 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeAttachAttemptCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 18u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Attachattemptcount attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Attachattemptcount 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPartitionIdChangeCountAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 19u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readPartitionIdChangeCountAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 19u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Partitionidchangecount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Partitionidchangecount 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribePartitionIdChangeCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 19u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Partitionidchangecount attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Partitionidchangecount 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readBetterPartitionAttachAttemptCountAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 20u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readBetterPartitionAttachAttemptCountAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 20u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Betterpartitionattachattemptcount attribute not found in response" + } + + requireNotNull(attributeData) { + "Betterpartitionattachattemptcount 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeBetterPartitionAttachAttemptCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 20u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Betterpartitionattachattemptcount attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Betterpartitionattachattemptcount 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readParentChangeCountAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 21u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readParentChangeCountAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 21u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Parentchangecount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Parentchangecount 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeParentChangeCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 21u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Parentchangecount attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Parentchangecount 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readTxTotalCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 22u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readTxTotalCountAttribute(): UInt? { + val ATTRIBUTE_ID: UInt = 22u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Txtotalcount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Txtotalcount attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeTxTotalCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 22u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Txtotalcount attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Txtotalcount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readTxUnicastCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 23u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readTxUnicastCountAttribute(): UInt? { + val ATTRIBUTE_ID: UInt = 23u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Txunicastcount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Txunicastcount attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeTxUnicastCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 23u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Txunicastcount attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Txunicastcount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readTxBroadcastCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 24u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readTxBroadcastCountAttribute(): UInt? { + val ATTRIBUTE_ID: UInt = 24u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Txbroadcastcount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Txbroadcastcount attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeTxBroadcastCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 24u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Txbroadcastcount attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Txbroadcastcount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readTxAckRequestedCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 25u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readTxAckRequestedCountAttribute(): UInt? { + val ATTRIBUTE_ID: UInt = 25u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Txackrequestedcount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Txackrequestedcount attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeTxAckRequestedCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 25u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Txackrequestedcount attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Txackrequestedcount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readTxAckedCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 26u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readTxAckedCountAttribute(): UInt? { + val ATTRIBUTE_ID: UInt = 26u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Txackedcount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Txackedcount attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeTxAckedCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 26u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Txackedcount attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Txackedcount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readTxNoAckRequestedCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 27u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readTxNoAckRequestedCountAttribute(): UInt? { + val ATTRIBUTE_ID: UInt = 27u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Txnoackrequestedcount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Txnoackrequestedcount attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeTxNoAckRequestedCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 27u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Txnoackrequestedcount attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Txnoackrequestedcount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readTxDataCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 28u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readTxDataCountAttribute(): UInt? { + val ATTRIBUTE_ID: UInt = 28u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Txdatacount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Txdatacount attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeTxDataCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 28u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Txdatacount attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Txdatacount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readTxDataPollCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 29u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readTxDataPollCountAttribute(): UInt? { + val ATTRIBUTE_ID: UInt = 29u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Txdatapollcount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Txdatapollcount attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeTxDataPollCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 29u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Txdatapollcount attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Txdatapollcount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readTxBeaconCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 30u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readTxBeaconCountAttribute(): UInt? { + val ATTRIBUTE_ID: UInt = 30u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Txbeaconcount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Txbeaconcount attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeTxBeaconCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 30u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Txbeaconcount attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Txbeaconcount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readTxBeaconRequestCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 31u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readTxBeaconRequestCountAttribute(): UInt? { + val ATTRIBUTE_ID: UInt = 31u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Txbeaconrequestcount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Txbeaconrequestcount attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeTxBeaconRequestCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 31u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Txbeaconrequestcount attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Txbeaconrequestcount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readTxOtherCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 32u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readTxOtherCountAttribute(): UInt? { + val ATTRIBUTE_ID: UInt = 32u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Txothercount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Txothercount attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeTxOtherCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 32u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Txothercount attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Txothercount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readTxRetryCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 33u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readTxRetryCountAttribute(): UInt? { + val ATTRIBUTE_ID: UInt = 33u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Txretrycount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Txretrycount attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeTxRetryCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 33u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Txretrycount attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Txretrycount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readTxDirectMaxRetryExpiryCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 34u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readTxDirectMaxRetryExpiryCountAttribute(): UInt? { + val ATTRIBUTE_ID: UInt = 34u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Txdirectmaxretryexpirycount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Txdirectmaxretryexpirycount attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeTxDirectMaxRetryExpiryCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 34u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Txdirectmaxretryexpirycount attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Txdirectmaxretryexpirycount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readTxIndirectMaxRetryExpiryCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 35u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readTxIndirectMaxRetryExpiryCountAttribute(): UInt? { + val ATTRIBUTE_ID: UInt = 35u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Txindirectmaxretryexpirycount attribute not found in response" + } + + requireNotNull(attributeData) { + "Txindirectmaxretryexpirycount attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeTxIndirectMaxRetryExpiryCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 35u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Txindirectmaxretryexpirycount attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Txindirectmaxretryexpirycount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readTxErrCcaCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 36u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readTxErrCcaCountAttribute(): UInt? { + val ATTRIBUTE_ID: UInt = 36u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Txerrccacount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Txerrccacount attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeTxErrCcaCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 36u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Txerrccacount attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Txerrccacount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readTxErrAbortCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 37u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readTxErrAbortCountAttribute(): UInt? { + val ATTRIBUTE_ID: UInt = 37u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Txerrabortcount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Txerrabortcount attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeTxErrAbortCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 37u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Txerrabortcount attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Txerrabortcount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readTxErrBusyChannelCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 38u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readTxErrBusyChannelCountAttribute(): UInt? { + val ATTRIBUTE_ID: UInt = 38u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Txerrbusychannelcount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Txerrbusychannelcount attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeTxErrBusyChannelCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 38u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Txerrbusychannelcount attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Txerrbusychannelcount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRxTotalCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 39u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRxTotalCountAttribute(): UInt? { + val ATTRIBUTE_ID: UInt = 39u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rxtotalcount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rxtotalcount attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeRxTotalCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 39u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Rxtotalcount attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Rxtotalcount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRxUnicastCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 40u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRxUnicastCountAttribute(): UInt? { + val ATTRIBUTE_ID: UInt = 40u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rxunicastcount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rxunicastcount attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeRxUnicastCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 40u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Rxunicastcount attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Rxunicastcount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRxBroadcastCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 41u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRxBroadcastCountAttribute(): UInt? { + val ATTRIBUTE_ID: UInt = 41u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rxbroadcastcount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rxbroadcastcount attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeRxBroadcastCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 41u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Rxbroadcastcount attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Rxbroadcastcount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRxDataCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 42u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRxDataCountAttribute(): UInt? { + val ATTRIBUTE_ID: UInt = 42u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rxdatacount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rxdatacount attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeRxDataCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 42u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Rxdatacount attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Rxdatacount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRxDataPollCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 43u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRxDataPollCountAttribute(): UInt? { + val ATTRIBUTE_ID: UInt = 43u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rxdatapollcount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rxdatapollcount attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeRxDataPollCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 43u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Rxdatapollcount attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Rxdatapollcount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRxBeaconCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 44u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRxBeaconCountAttribute(): UInt? { + val ATTRIBUTE_ID: UInt = 44u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rxbeaconcount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rxbeaconcount attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeRxBeaconCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 44u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Rxbeaconcount attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Rxbeaconcount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRxBeaconRequestCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 45u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRxBeaconRequestCountAttribute(): UInt? { + val ATTRIBUTE_ID: UInt = 45u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rxbeaconrequestcount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rxbeaconrequestcount attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeRxBeaconRequestCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 45u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Rxbeaconrequestcount attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Rxbeaconrequestcount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRxOtherCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 46u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRxOtherCountAttribute(): UInt? { + val ATTRIBUTE_ID: UInt = 46u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rxothercount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rxothercount attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeRxOtherCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 46u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Rxothercount attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Rxothercount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRxAddressFilteredCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 47u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRxAddressFilteredCountAttribute(): UInt? { + val ATTRIBUTE_ID: UInt = 47u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rxaddressfilteredcount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rxaddressfilteredcount attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeRxAddressFilteredCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 47u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Rxaddressfilteredcount attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Rxaddressfilteredcount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRxDestAddrFilteredCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 48u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRxDestAddrFilteredCountAttribute(): UInt? { + val ATTRIBUTE_ID: UInt = 48u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rxdestaddrfilteredcount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rxdestaddrfilteredcount attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeRxDestAddrFilteredCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 48u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Rxdestaddrfilteredcount attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Rxdestaddrfilteredcount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRxDuplicatedCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 49u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRxDuplicatedCountAttribute(): UInt? { + val ATTRIBUTE_ID: UInt = 49u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rxduplicatedcount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rxduplicatedcount attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeRxDuplicatedCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 49u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Rxduplicatedcount attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Rxduplicatedcount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRxErrNoFrameCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 50u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRxErrNoFrameCountAttribute(): UInt? { + val ATTRIBUTE_ID: UInt = 50u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rxerrnoframecount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rxerrnoframecount attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeRxErrNoFrameCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 50u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Rxerrnoframecount attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Rxerrnoframecount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRxErrUnknownNeighborCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 51u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRxErrUnknownNeighborCountAttribute(): UInt? { + val ATTRIBUTE_ID: UInt = 51u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rxerrunknownneighborcount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rxerrunknownneighborcount attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeRxErrUnknownNeighborCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 51u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Rxerrunknownneighborcount attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Rxerrunknownneighborcount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRxErrInvalidSrcAddrCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 52u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRxErrInvalidSrcAddrCountAttribute(): UInt? { + val ATTRIBUTE_ID: UInt = 52u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rxerrinvalidsrcaddrcount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rxerrinvalidsrcaddrcount attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeRxErrInvalidSrcAddrCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 52u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Rxerrinvalidsrcaddrcount attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Rxerrinvalidsrcaddrcount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRxErrSecCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 53u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRxErrSecCountAttribute(): UInt? { + val ATTRIBUTE_ID: UInt = 53u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rxerrseccount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rxerrseccount attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeRxErrSecCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 53u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Rxerrseccount attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Rxerrseccount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRxErrFcsCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 54u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRxErrFcsCountAttribute(): UInt? { + val ATTRIBUTE_ID: UInt = 54u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rxerrfcscount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rxerrfcscount attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeRxErrFcsCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 54u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Rxerrfcscount attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Rxerrfcscount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRxErrOtherCountAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 55u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRxErrOtherCountAttribute(): UInt? { + val ATTRIBUTE_ID: UInt = 55u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rxerrothercount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rxerrothercount attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeRxErrOtherCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 55u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Rxerrothercount attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Rxerrothercount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readActiveTimestampAttribute(): ActiveTimestampAttribute {val ATTRIBUTE_ID: UInt = 56u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readActiveTimestampAttribute(): ActiveTimestampAttribute { + val ATTRIBUTE_ID: UInt = 56u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Activetimestamp attribute not found in response" - } + } + + requireNotNull(attributeData) { "Activetimestamp 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 - } - + val decodedValue: ULong? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return ActiveTimestampAttribute(decodedValue) } suspend fun subscribeActiveTimestampAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 56u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ActiveTimestampAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ActiveTimestampAttributeSubscriptionState.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) { - "Activetimestamp attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Activetimestamp 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(ActiveTimestampAttributeSubscriptionState.Success(it)) - } - + val decodedValue: ULong? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(ActiveTimestampAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ActiveTimestampAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPendingTimestampAttribute(): PendingTimestampAttribute {val ATTRIBUTE_ID: UInt = 57u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readPendingTimestampAttribute(): PendingTimestampAttribute { + val ATTRIBUTE_ID: UInt = 57u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Pendingtimestamp attribute not found in response" - } + } + + requireNotNull(attributeData) { "Pendingtimestamp 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 - } - + val decodedValue: ULong? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return PendingTimestampAttribute(decodedValue) } suspend fun subscribePendingTimestampAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 57u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(PendingTimestampAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + PendingTimestampAttributeSubscriptionState.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) { - "Pendingtimestamp attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Pendingtimestamp 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(PendingTimestampAttributeSubscriptionState.Success(it)) - } - + val decodedValue: ULong? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(PendingTimestampAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(PendingTimestampAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readDelayAttribute(): DelayAttribute {val ATTRIBUTE_ID: UInt = 58u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readDelayAttribute(): DelayAttribute { + val ATTRIBUTE_ID: UInt = 58u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Delay attribute not found in response" - } + } + + requireNotNull(attributeData) { "Delay attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return DelayAttribute(decodedValue) } suspend fun subscribeDelayAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 58u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(DelayAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + DelayAttributeSubscriptionState.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) { - "Delay attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Delay attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(DelayAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(DelayAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(DelayAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readSecurityPolicyAttribute(): SecurityPolicyAttribute {val ATTRIBUTE_ID: UInt = 59u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readSecurityPolicyAttribute(): SecurityPolicyAttribute { + val ATTRIBUTE_ID: UInt = 59u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Securitypolicy attribute not found in response" - } + } + + requireNotNull(attributeData) { "Securitypolicy attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ThreadNetworkDiagnosticsClusterSecurityPolicy? = if (!tlvReader.isNull()) { - ThreadNetworkDiagnosticsClusterSecurityPolicy.fromTlv(AnonymousTag, tlvReader) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: ThreadNetworkDiagnosticsClusterSecurityPolicy? = + if (!tlvReader.isNull()) { + ThreadNetworkDiagnosticsClusterSecurityPolicy.fromTlv(AnonymousTag, tlvReader) + } else { + tlvReader.getNull(AnonymousTag) + null + } return SecurityPolicyAttribute(decodedValue) } suspend fun subscribeSecurityPolicyAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 59u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(SecurityPolicyAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + SecurityPolicyAttributeSubscriptionState.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) { - "Securitypolicy attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Securitypolicy attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ThreadNetworkDiagnosticsClusterSecurityPolicy? = if (!tlvReader.isNull()) { - ThreadNetworkDiagnosticsClusterSecurityPolicy.fromTlv(AnonymousTag, tlvReader) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ThreadNetworkDiagnosticsClusterSecurityPolicy? = + if (!tlvReader.isNull()) { + ThreadNetworkDiagnosticsClusterSecurityPolicy.fromTlv(AnonymousTag, tlvReader) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(SecurityPolicyAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(SecurityPolicyAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(SecurityPolicyAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readChannelPage0MaskAttribute(): ChannelPage0MaskAttribute {val ATTRIBUTE_ID: UInt = 60u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readChannelPage0MaskAttribute(): ChannelPage0MaskAttribute { + val ATTRIBUTE_ID: UInt = 60u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Channelpage0mask attribute not found in response" - } + } + + requireNotNull(attributeData) { "Channelpage0mask attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = if (!tlvReader.isNull()) { - tlvReader.getByteArray(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: ByteArray? = + if (!tlvReader.isNull()) { + tlvReader.getByteArray(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return ChannelPage0MaskAttribute(decodedValue) } suspend fun subscribeChannelPage0MaskAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 60u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ChannelPage0MaskAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ChannelPage0MaskAttributeSubscriptionState.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) { - "Channelpage0mask attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Channelpage0mask attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = if (!tlvReader.isNull()) { - tlvReader.getByteArray(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ByteArray? = + if (!tlvReader.isNull()) { + tlvReader.getByteArray(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(ChannelPage0MaskAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(ChannelPage0MaskAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ChannelPage0MaskAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readOperationalDatasetComponentsAttribute(): OperationalDatasetComponentsAttribute {val ATTRIBUTE_ID: UInt = 61u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readOperationalDatasetComponentsAttribute(): OperationalDatasetComponentsAttribute { + val ATTRIBUTE_ID: UInt = 61u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Operationaldatasetcomponents attribute not found in response" - } + } + + requireNotNull(attributeData) { "Operationaldatasetcomponents attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ThreadNetworkDiagnosticsClusterOperationalDatasetComponents? = if (!tlvReader.isNull()) { - ThreadNetworkDiagnosticsClusterOperationalDatasetComponents.fromTlv(AnonymousTag, tlvReader) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: ThreadNetworkDiagnosticsClusterOperationalDatasetComponents? = + if (!tlvReader.isNull()) { + ThreadNetworkDiagnosticsClusterOperationalDatasetComponents.fromTlv(AnonymousTag, tlvReader) + } else { + tlvReader.getNull(AnonymousTag) + null + } return OperationalDatasetComponentsAttribute(decodedValue) } suspend fun subscribeOperationalDatasetComponentsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 61u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(OperationalDatasetComponentsAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + OperationalDatasetComponentsAttributeSubscriptionState.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) { - "Operationaldatasetcomponents attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Operationaldatasetcomponents attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ThreadNetworkDiagnosticsClusterOperationalDatasetComponents? = if (!tlvReader.isNull()) { - ThreadNetworkDiagnosticsClusterOperationalDatasetComponents.fromTlv(AnonymousTag, tlvReader) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ThreadNetworkDiagnosticsClusterOperationalDatasetComponents? = + if (!tlvReader.isNull()) { + ThreadNetworkDiagnosticsClusterOperationalDatasetComponents.fromTlv( + AnonymousTag, + tlvReader, + ) + } else { + tlvReader.getNull(AnonymousTag) + null + } decodedValue?.let { emit(OperationalDatasetComponentsAttributeSubscriptionState.Success(it)) } - } SubscriptionState.SubscriptionEstablished -> { emit(OperationalDatasetComponentsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readActiveNetworkFaultsListAttribute(): ActiveNetworkFaultsListAttribute {val ATTRIBUTE_ID: UInt = 62u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readActiveNetworkFaultsListAttribute(): ActiveNetworkFaultsListAttribute { + val ATTRIBUTE_ID: UInt = 62u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Activenetworkfaultslist attribute not found in response" - } + } + + requireNotNull(attributeData) { "Activenetworkfaultslist 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.getUByte(AnonymousTag)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return ActiveNetworkFaultsListAttribute(decodedValue) } suspend fun subscribeActiveNetworkFaultsListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 62u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ActiveNetworkFaultsListAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ActiveNetworkFaultsListAttributeSubscriptionState.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) { - "Activenetworkfaultslist attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Activenetworkfaultslist 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.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(ActiveNetworkFaultsListAttributeSubscriptionState.Success(decodedValue)) } @@ -6559,97 +6202,96 @@ suspend fun readActiveNetworkFaultsListAttribute(): ActiveNetworkFaultsListAttri emit(ActiveNetworkFaultsListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65528u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -6657,97 +6299,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { emit(GeneratedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65529u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -6755,97 +6396,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va emit(AcceptedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt = 65530u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -6853,97 +6491,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt emit(EventListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ID: UInt = 65531u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -6951,81 +6586,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ emit(AttributeListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -7037,80 +6667,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 65533u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -7123,7 +6750,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/ThreadNetworkDirectoryCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/ThreadNetworkDirectoryCluster.kt index 6066a25d681365..ee5b2e9aea94ec 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/ThreadNetworkDirectoryCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/ThreadNetworkDirectoryCluster.kt @@ -17,191 +17,159 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class ThreadNetworkDirectoryCluster(private val controller: MatterController, private val endpointId: UShort) { - class OperationalDatasetResponse( - val operationalDataset: ByteArray - ) -class PreferredExtendedPanIDAttribute( - val value: ByteArray? - ) +class ThreadNetworkDirectoryCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class OperationalDatasetResponse(val operationalDataset: ByteArray) + + class PreferredExtendedPanIDAttribute(val value: ByteArray?) sealed class PreferredExtendedPanIDAttributeSubscriptionState { - data class Success( - val value: ByteArray? - ) : PreferredExtendedPanIDAttributeSubscriptionState() - + data class Success(val value: ByteArray?) : PreferredExtendedPanIDAttributeSubscriptionState() + data class Error(val exception: Exception) : PreferredExtendedPanIDAttributeSubscriptionState() - object SubscriptionEstablished : PreferredExtendedPanIDAttributeSubscriptionState() - } -class ThreadNetworksAttribute( - val value: List - ) + object SubscriptionEstablished : PreferredExtendedPanIDAttributeSubscriptionState() + } + + class ThreadNetworksAttribute(val value: List) sealed class ThreadNetworksAttributeSubscriptionState { - data class Success( - val value: List - ) : ThreadNetworksAttributeSubscriptionState() - + data class Success(val value: List) : + ThreadNetworksAttributeSubscriptionState() + data class Error(val exception: Exception) : ThreadNetworksAttributeSubscriptionState() - object SubscriptionEstablished : ThreadNetworksAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : ThreadNetworksAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun addNetwork(operationalDataset: ByteArray - ,timedInvokeTimeout: Duration) { + suspend fun addNetwork(operationalDataset: ByteArray, timedInvokeTimeout: Duration) { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_OPERATIONAL_DATASET_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_OPERATIONAL_DATASET_REQ), operationalDataset) + tlvWriter.put(ContextSpecificTag(TAG_OPERATIONAL_DATASET_REQ), operationalDataset) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun removeNetwork(extendedPanID: ByteArray - ,timedInvokeTimeout: Duration) { + suspend fun removeNetwork(extendedPanID: ByteArray, timedInvokeTimeout: Duration) { val commandId: UInt = 1u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_EXTENDED_PAN_ID_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_EXTENDED_PAN_ID_REQ), extendedPanID) + tlvWriter.put(ContextSpecificTag(TAG_EXTENDED_PAN_ID_REQ), extendedPanID) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun getOperationalDataset(extendedPanID: ByteArray - ,timedInvokeTimeout: Duration? = null): OperationalDatasetResponse { + suspend fun getOperationalDataset( + extendedPanID: ByteArray, + timedInvokeTimeout: Duration? = null, + ): OperationalDatasetResponse { val commandId: UInt = 2u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_EXTENDED_PAN_ID_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_EXTENDED_PAN_ID_REQ), extendedPanID) + tlvWriter.put(ContextSpecificTag(TAG_EXTENDED_PAN_ID_REQ), extendedPanID) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -211,98 +179,83 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_OPERATIONAL_DATASET: Int = 0 var operationalDataset_decoded: ByteArray? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_OPERATIONAL_DATASET)) {operationalDataset_decoded = tlvReader.getByteArray(tag)} - - - else { + if (tag == ContextSpecificTag(TAG_OPERATIONAL_DATASET)) { + operationalDataset_decoded = tlvReader.getByteArray(tag) + } else { tlvReader.skipElement() } } - - if (operationalDataset_decoded == null) { - throw IllegalStateException("operationalDataset not found in TLV") + throw IllegalStateException("operationalDataset not found in TLV") } - tlvReader.exitContainer() - return OperationalDatasetResponse( - operationalDataset_decoded - ) + return OperationalDatasetResponse(operationalDataset_decoded) } -suspend fun readPreferredExtendedPanIDAttribute(): PreferredExtendedPanIDAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readPreferredExtendedPanIDAttribute(): PreferredExtendedPanIDAttribute { + 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}") - } + 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) { - "Preferredextendedpanid attribute not found in response" - } + } + + requireNotNull(attributeData) { "Preferredextendedpanid attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = if (!tlvReader.isNull()) { - tlvReader.getByteArray(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: ByteArray? = + if (!tlvReader.isNull()) { + tlvReader.getByteArray(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return PreferredExtendedPanIDAttribute(decodedValue) } suspend fun writePreferredExtendedPanIDAttribute( value: ByteArray, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -323,153 +276,156 @@ suspend fun readPreferredExtendedPanIDAttribute(): PreferredExtendedPanIDAttribu throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribePreferredExtendedPanIDAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(PreferredExtendedPanIDAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + PreferredExtendedPanIDAttributeSubscriptionState.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) { - "Preferredextendedpanid attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Preferredextendedpanid attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = if (!tlvReader.isNull()) { - tlvReader.getByteArray(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(PreferredExtendedPanIDAttributeSubscriptionState.Success(it)) - } - + val decodedValue: ByteArray? = + if (!tlvReader.isNull()) { + tlvReader.getByteArray(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(PreferredExtendedPanIDAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(PreferredExtendedPanIDAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readThreadNetworksAttribute(): ThreadNetworksAttribute {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readThreadNetworksAttribute(): ThreadNetworksAttribute { + 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}") - } + 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) { - "Threadnetworks attribute not found in response" - } + } + + requireNotNull(attributeData) { "Threadnetworks 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(ThreadNetworkDirectoryClusterThreadNetworkStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(ThreadNetworkDirectoryClusterThreadNetworkStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return ThreadNetworksAttribute(decodedValue) } suspend fun subscribeThreadNetworksAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ThreadNetworksAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ThreadNetworksAttributeSubscriptionState.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) { - "Threadnetworks attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Threadnetworks 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(ThreadNetworkDirectoryClusterThreadNetworkStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add( + ThreadNetworkDirectoryClusterThreadNetworkStruct.fromTlv(AnonymousTag, tlvReader) + ) + } + tlvReader.exitContainer() + } emit(ThreadNetworksAttributeSubscriptionState.Success(decodedValue)) } @@ -477,80 +433,77 @@ suspend fun readThreadNetworksAttribute(): ThreadNetworksAttribute {val ATTRIBUT emit(ThreadNetworksAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readThreadNetworkTableSizeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readThreadNetworkTableSizeAttribute(): UByte { + 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}") - } + 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) { - "Threadnetworktablesize attribute not found in response" - } + } + + requireNotNull(attributeData) { "Threadnetworktablesize 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 subscribeThreadNetworkTableSizeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Threadnetworktablesize attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Threadnetworktablesize attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -563,97 +516,96 @@ suspend fun readThreadNetworkTableSizeAttribute(): UByte {val ATTRIBUTE_ID: UInt emit(UByteSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -661,97 +613,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -759,97 +710,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -857,97 +805,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -955,81 +900,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1041,80 +981,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1127,7 +1064,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/TimeFormatLocalizationCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/TimeFormatLocalizationCluster.kt index 0a6b84266fe5f8..f5f404c56a0534 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/TimeFormatLocalizationCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/TimeFormatLocalizationCluster.kt @@ -17,173 +17,131 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse -import matter.controller.model.AttributePath -import matter.controller.model.CommandPath import matter.controller.cluster.structs.* +import matter.controller.model.AttributePath import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class TimeFormatLocalizationCluster(private val controller: MatterController, private val endpointId: UShort) {class SupportedCalendarTypesAttribute( - val value: List? - ) +class TimeFormatLocalizationCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class SupportedCalendarTypesAttribute(val value: List?) sealed class SupportedCalendarTypesAttributeSubscriptionState { - data class Success( - val value: List? - ) : SupportedCalendarTypesAttributeSubscriptionState() - + data class Success(val value: List?) : + SupportedCalendarTypesAttributeSubscriptionState() + data class Error(val exception: Exception) : SupportedCalendarTypesAttributeSubscriptionState() - object SubscriptionEstablished : SupportedCalendarTypesAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : SupportedCalendarTypesAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } -suspend fun readHourFormatAttribute(): 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) - ) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } + + suspend fun readHourFormatAttribute(): 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}") - } + 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) { - "Hourformat attribute not found in response" - } + } + + requireNotNull(attributeData) { "Hourformat 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 writeHourFormatAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeHourFormatAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -204,43 +162,45 @@ suspend fun readHourFormatAttribute(): UByte {val ATTRIBUTE_ID: UInt = 0u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeHourFormatAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Hourformat attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Hourformat attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -252,72 +212,62 @@ suspend fun readHourFormatAttribute(): UByte {val ATTRIBUTE_ID: UInt = 0u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readActiveCalendarTypeAttribute(): 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) - ) - + + suspend fun readActiveCalendarTypeAttribute(): 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}") - } + 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) { - "Activecalendartype attribute not found in response" - } + } + + requireNotNull(attributeData) { "Activecalendartype 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } - suspend fun writeActiveCalendarTypeAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeActiveCalendarTypeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 1u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -338,261 +288,258 @@ suspend fun readActiveCalendarTypeAttribute(): UByte? {val ATTRIBUTE_ID: UInt = throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeActiveCalendarTypeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Activecalendartype attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Activecalendartype 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)) - } - + 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 readSupportedCalendarTypesAttribute(): SupportedCalendarTypesAttribute {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readSupportedCalendarTypesAttribute(): SupportedCalendarTypesAttribute { + 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}") - } + 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) { - "Supportedcalendartypes attribute not found in response" - } + } + + requireNotNull(attributeData) { "Supportedcalendartypes attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null } - tlvReader.exitContainer() - } - } else { - null - } - return SupportedCalendarTypesAttribute(decodedValue) } suspend fun subscribeSupportedCalendarTypesAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(SupportedCalendarTypesAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + SupportedCalendarTypesAttributeSubscriptionState.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) { - "Supportedcalendartypes attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Supportedcalendartypes attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { - emit(SupportedCalendarTypesAttributeSubscriptionState.Success(it)) - } - + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { emit(SupportedCalendarTypesAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(SupportedCalendarTypesAttributeSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -600,97 +547,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -698,97 +644,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -796,97 +739,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -894,81 +834,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -980,80 +915,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1066,7 +998,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/TimeSynchronizationCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/TimeSynchronizationCluster.kt index 56f5d04c0e1a03..c968311230c6cb 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/TimeSynchronizationCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/TimeSynchronizationCluster.kt @@ -17,187 +17,145 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration 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.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.UShortSubscriptionState +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class TimeSynchronizationCluster(private val controller: MatterController, private val endpointId: UShort) { - class SetTimeZoneResponse( - val DSTOffsetRequired: Boolean - ) -class UTCTimeAttribute( - val value: ULong? - ) +class TimeSynchronizationCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class SetTimeZoneResponse(val DSTOffsetRequired: Boolean) + + class UTCTimeAttribute(val value: ULong?) sealed class UTCTimeAttributeSubscriptionState { - data class Success( - val value: ULong? - ) : UTCTimeAttributeSubscriptionState() - + data class Success(val value: ULong?) : UTCTimeAttributeSubscriptionState() + data class Error(val exception: Exception) : UTCTimeAttributeSubscriptionState() - object SubscriptionEstablished : UTCTimeAttributeSubscriptionState() - } -class TrustedTimeSourceAttribute( - val value: TimeSynchronizationClusterTrustedTimeSourceStruct? - ) + object SubscriptionEstablished : UTCTimeAttributeSubscriptionState() + } + + class TrustedTimeSourceAttribute(val value: TimeSynchronizationClusterTrustedTimeSourceStruct?) sealed class TrustedTimeSourceAttributeSubscriptionState { - data class Success( - val value: TimeSynchronizationClusterTrustedTimeSourceStruct? - ) : TrustedTimeSourceAttributeSubscriptionState() - + data class Success(val value: TimeSynchronizationClusterTrustedTimeSourceStruct?) : + TrustedTimeSourceAttributeSubscriptionState() + data class Error(val exception: Exception) : TrustedTimeSourceAttributeSubscriptionState() - object SubscriptionEstablished : TrustedTimeSourceAttributeSubscriptionState() - } -class DefaultNTPAttribute( - val value: String? - ) + object SubscriptionEstablished : TrustedTimeSourceAttributeSubscriptionState() + } + + class DefaultNTPAttribute(val value: String?) sealed class DefaultNTPAttributeSubscriptionState { - data class Success( - val value: String? - ) : DefaultNTPAttributeSubscriptionState() - + data class Success(val value: String?) : DefaultNTPAttributeSubscriptionState() + data class Error(val exception: Exception) : DefaultNTPAttributeSubscriptionState() - object SubscriptionEstablished : DefaultNTPAttributeSubscriptionState() - } -class TimeZoneAttribute( - val value: List? - ) + object SubscriptionEstablished : DefaultNTPAttributeSubscriptionState() + } + + class TimeZoneAttribute(val value: List?) sealed class TimeZoneAttributeSubscriptionState { - data class Success( - val value: List? - ) : TimeZoneAttributeSubscriptionState() - + data class Success(val value: List?) : + TimeZoneAttributeSubscriptionState() + data class Error(val exception: Exception) : TimeZoneAttributeSubscriptionState() - object SubscriptionEstablished : TimeZoneAttributeSubscriptionState() - } -class DSTOffsetAttribute( - val value: List? - ) + object SubscriptionEstablished : TimeZoneAttributeSubscriptionState() + } + + class DSTOffsetAttribute(val value: List?) sealed class DSTOffsetAttributeSubscriptionState { - data class Success( - val value: List? - ) : DSTOffsetAttributeSubscriptionState() - + data class Success(val value: List?) : + DSTOffsetAttributeSubscriptionState() + data class Error(val exception: Exception) : DSTOffsetAttributeSubscriptionState() - object SubscriptionEstablished : DSTOffsetAttributeSubscriptionState() - } -class LocalTimeAttribute( - val value: ULong? - ) + object SubscriptionEstablished : DSTOffsetAttributeSubscriptionState() + } + + class LocalTimeAttribute(val value: ULong?) sealed class LocalTimeAttributeSubscriptionState { - data class Success( - val value: ULong? - ) : LocalTimeAttributeSubscriptionState() - + data class Success(val value: ULong?) : LocalTimeAttributeSubscriptionState() + data class Error(val exception: Exception) : LocalTimeAttributeSubscriptionState() - object SubscriptionEstablished : LocalTimeAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : LocalTimeAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun setUTCTime(UTCTime: ULong - ,granularity: UByte - ,timeSource: UByte? - ,timedInvokeTimeout: Duration? = null) { + suspend fun setUTCTime( + UTCTime: ULong, + granularity: UByte, + timeSource: UByte?, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 0u val tlvWriter = TlvWriter() @@ -210,24 +168,24 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_GRANULARITY_REQ), granularity) val TAG_TIME_SOURCE_REQ: Int = 2 - timeSource?.let { - tlvWriter.put(ContextSpecificTag(TAG_TIME_SOURCE_REQ), timeSource) - } + timeSource?.let { tlvWriter.put(ContextSpecificTag(TAG_TIME_SOURCE_REQ), timeSource) } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun setTrustedTimeSource(trustedTimeSource: TimeSynchronizationClusterFabricScopedTrustedTimeSourceStruct? - ,timedInvokeTimeout: Duration? = null) { + suspend fun setTrustedTimeSource( + trustedTimeSource: TimeSynchronizationClusterFabricScopedTrustedTimeSourceStruct?, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 1u val tlvWriter = TlvWriter() @@ -236,22 +194,24 @@ class AttributeListAttribute( val TAG_TRUSTED_TIME_SOURCE_REQ: Int = 0 trustedTimeSource?.let { trustedTimeSource.toTlv(ContextSpecificTag(TAG_TRUSTED_TIME_SOURCE_REQ), tlvWriter) - } + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun setTimeZone(timeZone: List - ,timedInvokeTimeout: Duration? = null): SetTimeZoneResponse { + suspend fun setTimeZone( + timeZone: List, + timedInvokeTimeout: Duration? = null, + ): SetTimeZoneResponse { val commandId: UInt = 2u val tlvWriter = TlvWriter() @@ -259,17 +219,17 @@ class AttributeListAttribute( val TAG_TIME_ZONE_REQ: Int = 0 tlvWriter.startArray(ContextSpecificTag(TAG_TIME_ZONE_REQ)) - for (item in timeZone.iterator()) { - item.toTlv(AnonymousTag, tlvWriter) - } - tlvWriter.endArray() + for (item in timeZone.iterator()) { + item.toTlv(AnonymousTag, tlvWriter) + } + tlvWriter.endArray() tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -279,36 +239,30 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_DST_OFFSET_REQUIRED: Int = 0 var DSTOffsetRequired_decoded: Boolean? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_DST_OFFSET_REQUIRED)) {DSTOffsetRequired_decoded = tlvReader.getBoolean(tag)} - - - else { + if (tag == ContextSpecificTag(TAG_DST_OFFSET_REQUIRED)) { + DSTOffsetRequired_decoded = tlvReader.getBoolean(tag) + } else { tlvReader.skipElement() } } - - if (DSTOffsetRequired_decoded == null) { - throw IllegalStateException("DSTOffsetRequired not found in TLV") + throw IllegalStateException("DSTOffsetRequired not found in TLV") } - tlvReader.exitContainer() - return SetTimeZoneResponse( - DSTOffsetRequired_decoded - ) + return SetTimeZoneResponse(DSTOffsetRequired_decoded) } - suspend fun setDSTOffset(DSTOffset: List - ,timedInvokeTimeout: Duration? = null) { + suspend fun setDSTOffset( + DSTOffset: List, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 4u val tlvWriter = TlvWriter() @@ -316,218 +270,204 @@ class AttributeListAttribute( val TAG_DST_OFFSET_REQ: Int = 0 tlvWriter.startArray(ContextSpecificTag(TAG_DST_OFFSET_REQ)) - for (item in DSTOffset.iterator()) { - item.toTlv(AnonymousTag, tlvWriter) - } - tlvWriter.endArray() + for (item in DSTOffset.iterator()) { + item.toTlv(AnonymousTag, tlvWriter) + } + tlvWriter.endArray() tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun setDefaultNTP(defaultNTP: String? - ,timedInvokeTimeout: Duration? = null) { + suspend fun setDefaultNTP(defaultNTP: String?, timedInvokeTimeout: Duration? = null) { val commandId: UInt = 5u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_DEFAULT_NTP_REQ: Int = 0 - defaultNTP?.let { - tlvWriter.put(ContextSpecificTag(TAG_DEFAULT_NTP_REQ), defaultNTP) - } + defaultNTP?.let { tlvWriter.put(ContextSpecificTag(TAG_DEFAULT_NTP_REQ), defaultNTP) } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } -suspend fun readUTCTimeAttribute(): UTCTimeAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readUTCTimeAttribute(): UTCTimeAttribute { + 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}") - } + 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) { - "Utctime attribute not found in response" - } + } + + requireNotNull(attributeData) { "Utctime attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ULong? = if (!tlvReader.isNull()) { - tlvReader.getULong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: ULong? = + if (!tlvReader.isNull()) { + tlvReader.getULong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return UTCTimeAttribute(decodedValue) } suspend fun subscribeUTCTimeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(UTCTimeAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + UTCTimeAttributeSubscriptionState.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) { - "Utctime attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Utctime 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()) { - tlvReader.getULong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(UTCTimeAttributeSubscriptionState.Success(it)) - } - + val decodedValue: ULong? = + if (!tlvReader.isNull()) { + tlvReader.getULong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(UTCTimeAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UTCTimeAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readGranularityAttribute(): 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) - ) - + + suspend fun readGranularityAttribute(): 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}") - } + 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) { - "Granularity attribute not found in response" - } + } + + requireNotNull(attributeData) { "Granularity 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 subscribeGranularityAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Granularity attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Granularity attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -539,1218 +479,1163 @@ suspend fun readGranularityAttribute(): UByte {val ATTRIBUTE_ID: UInt = 1u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readTimeSourceAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readTimeSourceAttribute(): UByte? { + 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}") - } + 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) { - "Timesource attribute not found in response" - } + } + + requireNotNull(attributeData) { "Timesource 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeTimeSourceAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Timesource attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Timesource 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)) - } - + 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 readTrustedTimeSourceAttribute(): TrustedTimeSourceAttribute {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readTrustedTimeSourceAttribute(): TrustedTimeSourceAttribute { + 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}") - } + 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) { - "Trustedtimesource attribute not found in response" - } + } + + requireNotNull(attributeData) { "Trustedtimesource attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: TimeSynchronizationClusterTrustedTimeSourceStruct? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - TimeSynchronizationClusterTrustedTimeSourceStruct.fromTlv(AnonymousTag, tlvReader) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: TimeSynchronizationClusterTrustedTimeSourceStruct? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + TimeSynchronizationClusterTrustedTimeSourceStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return TrustedTimeSourceAttribute(decodedValue) } suspend fun subscribeTrustedTimeSourceAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(TrustedTimeSourceAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + TrustedTimeSourceAttributeSubscriptionState.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) { - "Trustedtimesource attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Trustedtimesource attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: TimeSynchronizationClusterTrustedTimeSourceStruct? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - TimeSynchronizationClusterTrustedTimeSourceStruct.fromTlv(AnonymousTag, tlvReader) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(TrustedTimeSourceAttributeSubscriptionState.Success(it)) - } - + val decodedValue: TimeSynchronizationClusterTrustedTimeSourceStruct? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + TimeSynchronizationClusterTrustedTimeSourceStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(TrustedTimeSourceAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(TrustedTimeSourceAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readDefaultNTPAttribute(): DefaultNTPAttribute {val ATTRIBUTE_ID: UInt = 4u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readDefaultNTPAttribute(): DefaultNTPAttribute { + 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}") - } + 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) { - "Defaultntp attribute not found in response" - } + } + + requireNotNull(attributeData) { "Defaultntp attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: String? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return DefaultNTPAttribute(decodedValue) } suspend fun subscribeDefaultNTPAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(DefaultNTPAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + DefaultNTPAttributeSubscriptionState.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) { - "Defaultntp attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Defaultntp attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(DefaultNTPAttributeSubscriptionState.Success(it)) - } - + val decodedValue: String? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(DefaultNTPAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(DefaultNTPAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readTimeZoneAttribute(): TimeZoneAttribute {val ATTRIBUTE_ID: UInt = 5u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readTimeZoneAttribute(): TimeZoneAttribute { + 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}") - } + 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) { - "Timezone attribute not found in response" - } + } + + requireNotNull(attributeData) { "Timezone attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(TimeSynchronizationClusterTimeZoneStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(TimeSynchronizationClusterTimeZoneStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null } - tlvReader.exitContainer() - } - } else { - null - } - return TimeZoneAttribute(decodedValue) } suspend fun subscribeTimeZoneAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(TimeZoneAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + TimeZoneAttributeSubscriptionState.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) { - "Timezone attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Timezone attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(TimeSynchronizationClusterTimeZoneStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { - emit(TimeZoneAttributeSubscriptionState.Success(it)) - } - + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(TimeSynchronizationClusterTimeZoneStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { emit(TimeZoneAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(TimeZoneAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readDSTOffsetAttribute(): DSTOffsetAttribute {val ATTRIBUTE_ID: UInt = 6u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readDSTOffsetAttribute(): DSTOffsetAttribute { + 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}") - } + 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) { - "Dstoffset attribute not found in response" - } + } + + requireNotNull(attributeData) { "Dstoffset attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(TimeSynchronizationClusterDSTOffsetStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(TimeSynchronizationClusterDSTOffsetStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null } - tlvReader.exitContainer() - } - } else { - null - } - return DSTOffsetAttribute(decodedValue) } suspend fun subscribeDSTOffsetAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(DSTOffsetAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + DSTOffsetAttributeSubscriptionState.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) { - "Dstoffset attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Dstoffset attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: List? = if (tlvReader.isNextTag(AnonymousTag)) { - buildList { - tlvReader.enterArray(AnonymousTag) - while(!tlvReader.isEndOfContainer()) { - add(TimeSynchronizationClusterDSTOffsetStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null - } - - decodedValue?.let { - emit(DSTOffsetAttributeSubscriptionState.Success(it)) - } - + val decodedValue: List? = + if (tlvReader.isNextTag(AnonymousTag)) { + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(TimeSynchronizationClusterDSTOffsetStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + null + } + + decodedValue?.let { emit(DSTOffsetAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(DSTOffsetAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readLocalTimeAttribute(): LocalTimeAttribute {val ATTRIBUTE_ID: UInt = 7u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readLocalTimeAttribute(): LocalTimeAttribute { + 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}") - } + 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) { - "Localtime attribute not found in response" - } + } + + requireNotNull(attributeData) { "Localtime 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 - } - + val decodedValue: ULong? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return LocalTimeAttribute(decodedValue) } suspend fun subscribeLocalTimeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(LocalTimeAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + LocalTimeAttributeSubscriptionState.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) { - "Localtime attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Localtime 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(LocalTimeAttributeSubscriptionState.Success(it)) - } - + val decodedValue: ULong? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(LocalTimeAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(LocalTimeAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readTimeZoneDatabaseAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 8u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readTimeZoneDatabaseAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 8u + + 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}") - } + 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) { - "Timezonedatabase attribute not found in response" - } + } + + requireNotNull(attributeData) { "Timezonedatabase 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeTimeZoneDatabaseAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Timezonedatabase attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Timezonedatabase 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)) - } - + 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 readNTPServerAvailableAttribute(): Boolean? {val ATTRIBUTE_ID: UInt = 9u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readNTPServerAvailableAttribute(): Boolean? { + val ATTRIBUTE_ID: UInt = 9u + + 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}") - } + 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) { - "Ntpserveravailable attribute not found in response" - } + } + + requireNotNull(attributeData) { "Ntpserveravailable 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 - } - + val decodedValue: Boolean? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeNTPServerAvailableAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Ntpserveravailable attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Ntpserveravailable 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)) - } - + 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 readTimeZoneListMaxSizeAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 10u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readTimeZoneListMaxSizeAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 10u + + 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}") - } + 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) { - "Timezonelistmaxsize attribute not found in response" - } + } + + requireNotNull(attributeData) { "Timezonelistmaxsize 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeTimeZoneListMaxSizeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Timezonelistmaxsize attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Timezonelistmaxsize 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)) - } - + 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 readDSTOffsetListMaxSizeAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 11u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readDSTOffsetListMaxSizeAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 11u + + 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}") - } + 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) { - "Dstoffsetlistmaxsize attribute not found in response" - } + } + + requireNotNull(attributeData) { "Dstoffsetlistmaxsize 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeDSTOffsetListMaxSizeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 11u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Dstoffsetlistmaxsize attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Dstoffsetlistmaxsize 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)) - } - + 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 readSupportsDNSResolveAttribute(): Boolean? {val ATTRIBUTE_ID: UInt = 12u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readSupportsDNSResolveAttribute(): Boolean? { + val ATTRIBUTE_ID: UInt = 12u + + 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}") - } + 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) { - "Supportsdnsresolve attribute not found in response" - } + } + + requireNotNull(attributeData) { "Supportsdnsresolve 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 - } - + val decodedValue: Boolean? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeSupportsDNSResolveAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 12u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Supportsdnsresolve attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Supportsdnsresolve 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)) - } - + 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 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1758,97 +1643,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1856,97 +1740,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1954,97 +1835,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -2052,81 +1930,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -2138,80 +2011,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -2224,7 +2094,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/TimerCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/TimerCluster.kt index e974a2ed351918..3d87e60a1eb9f2 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/TimerCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/TimerCluster.kt @@ -17,117 +17,85 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.UShortSubscriptionState +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class TimerCluster(private val controller: MatterController, private val endpointId: UShort) {class GeneratedCommandListAttribute( - val value: List - ) +class TimerCluster(private val controller: MatterController, private val endpointId: UShort) { + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun setTimer(newTime: UInt - ,timedInvokeTimeout: Duration? = null) { + suspend fun setTimer(newTime: UInt, timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_NEW_TIME_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_NEW_TIME_REQ), newTime) + tlvWriter.put(ContextSpecificTag(TAG_NEW_TIME_REQ), newTime) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -138,136 +106,129 @@ class AttributeListAttribute( val commandId: UInt = 1u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun addTime(additionalTime: UInt - ,timedInvokeTimeout: Duration? = null) { + suspend fun addTime(additionalTime: UInt, timedInvokeTimeout: Duration? = null) { val commandId: UInt = 2u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_ADDITIONAL_TIME_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_ADDITIONAL_TIME_REQ), additionalTime) + tlvWriter.put(ContextSpecificTag(TAG_ADDITIONAL_TIME_REQ), additionalTime) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun reduceTime(timeReduction: UInt - ,timedInvokeTimeout: Duration? = null) { + suspend fun reduceTime(timeReduction: UInt, timedInvokeTimeout: Duration? = null) { val commandId: UInt = 3u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_TIME_REDUCTION_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_TIME_REDUCTION_REQ), timeReduction) + tlvWriter.put(ContextSpecificTag(TAG_TIME_REDUCTION_REQ), timeReduction) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } -suspend fun readSetTimeAttribute(): UInt {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readSetTimeAttribute(): UInt { + 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}") - } + 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) { - "Settime attribute not found in response" - } + } + + requireNotNull(attributeData) { "Settime 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 subscribeSetTimeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Settime attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Settime attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -279,81 +240,76 @@ suspend fun readSetTimeAttribute(): UInt {val ATTRIBUTE_ID: UInt = 0u emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readTimeRemainingAttribute(): UInt {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readTimeRemainingAttribute(): UInt { + 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}") - } + 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) { - "Timeremaining attribute not found in response" - } + } + + requireNotNull(attributeData) { "Timeremaining 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 subscribeTimeRemainingAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Timeremaining attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Timeremaining attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -365,81 +321,76 @@ suspend fun readTimeRemainingAttribute(): UInt {val ATTRIBUTE_ID: UInt = 1u emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readTimerStateAttribute(): UByte {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readTimerStateAttribute(): UByte { + 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}") - } + 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) { - "Timerstate attribute not found in response" - } + } + + requireNotNull(attributeData) { "Timerstate 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 subscribeTimerStateAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Timerstate attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Timerstate attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -451,97 +402,96 @@ suspend fun readTimerStateAttribute(): UByte {val ATTRIBUTE_ID: UInt = 2u emit(UByteSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -549,97 +499,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -647,97 +596,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -745,97 +691,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -843,81 +786,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -929,80 +867,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1015,7 +950,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/TotalVolatileOrganicCompoundsConcentrationMeasurementCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/TotalVolatileOrganicCompoundsConcentrationMeasurementCluster.kt index acddad214ee5bc..efa2e55b7b4ef9 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/TotalVolatileOrganicCompoundsConcentrationMeasurementCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/TotalVolatileOrganicCompoundsConcentrationMeasurementCluster.kt @@ -17,1371 +17,1273 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.FloatSubscriptionState import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse -import matter.controller.model.AttributePath -import matter.controller.model.CommandPath +import matter.controller.UShortSubscriptionState import matter.controller.cluster.structs.* +import matter.controller.model.AttributePath import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader -import matter.tlv.TlvWriter -class TotalVolatileOrganicCompoundsConcentrationMeasurementCluster(private val controller: MatterController, private val endpointId: UShort) {class MeasuredValueAttribute( - val value: Float? - ) +class TotalVolatileOrganicCompoundsConcentrationMeasurementCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class MeasuredValueAttribute(val value: Float?) sealed class MeasuredValueAttributeSubscriptionState { - data class Success( - val value: Float? - ) : MeasuredValueAttributeSubscriptionState() - + data class Success(val value: Float?) : MeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() - } -class MinMeasuredValueAttribute( - val value: Float? - ) + object SubscriptionEstablished : MeasuredValueAttributeSubscriptionState() + } + + class MinMeasuredValueAttribute(val value: Float?) sealed class MinMeasuredValueAttributeSubscriptionState { - data class Success( - val value: Float? - ) : MinMeasuredValueAttributeSubscriptionState() - + data class Success(val value: Float?) : MinMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MinMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() - } -class MaxMeasuredValueAttribute( - val value: Float? - ) + object SubscriptionEstablished : MinMeasuredValueAttributeSubscriptionState() + } + + class MaxMeasuredValueAttribute(val value: Float?) sealed class MaxMeasuredValueAttributeSubscriptionState { - data class Success( - val value: Float? - ) : MaxMeasuredValueAttributeSubscriptionState() - + data class Success(val value: Float?) : MaxMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : MaxMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() - } -class PeakMeasuredValueAttribute( - val value: Float? - ) + object SubscriptionEstablished : MaxMeasuredValueAttributeSubscriptionState() + } + + class PeakMeasuredValueAttribute(val value: Float?) sealed class PeakMeasuredValueAttributeSubscriptionState { - data class Success( - val value: Float? - ) : PeakMeasuredValueAttributeSubscriptionState() - + data class Success(val value: Float?) : PeakMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : PeakMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : PeakMeasuredValueAttributeSubscriptionState() - } -class AverageMeasuredValueAttribute( - val value: Float? - ) + object SubscriptionEstablished : PeakMeasuredValueAttributeSubscriptionState() + } + + class AverageMeasuredValueAttribute(val value: Float?) sealed class AverageMeasuredValueAttributeSubscriptionState { - data class Success( - val value: Float? - ) : AverageMeasuredValueAttributeSubscriptionState() - + data class Success(val value: Float?) : AverageMeasuredValueAttributeSubscriptionState() + data class Error(val exception: Exception) : AverageMeasuredValueAttributeSubscriptionState() - object SubscriptionEstablished : AverageMeasuredValueAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : AverageMeasuredValueAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } -suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } + + suspend fun readMeasuredValueAttribute(): MeasuredValueAttribute { + 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}") - } + 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) { - "Measuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Measuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return MeasuredValueAttribute(decodedValue) } suspend fun subscribeMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MeasuredValueAttributeSubscriptionState.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) { - "Measuredvalue attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Measuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMinMeasuredValueAttribute(): MinMeasuredValueAttribute { + 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}") - } + 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) { - "Minmeasuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Minmeasuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return MinMeasuredValueAttribute(decodedValue) } suspend fun subscribeMinMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MinMeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MinMeasuredValueAttributeSubscriptionState.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) { - "Minmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Minmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MinMeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MinMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMaxMeasuredValueAttribute(): MaxMeasuredValueAttribute { + 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}") - } + 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) { - "Maxmeasuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Maxmeasuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return MaxMeasuredValueAttribute(decodedValue) } suspend fun subscribeMaxMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(MaxMeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + MaxMeasuredValueAttributeSubscriptionState.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) { - "Maxmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Maxmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(MaxMeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(MaxMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPeakMeasuredValueAttribute(): PeakMeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readPeakMeasuredValueAttribute(): PeakMeasuredValueAttribute { + 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}") - } + 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) { - "Peakmeasuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Peakmeasuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return PeakMeasuredValueAttribute(decodedValue) } suspend fun subscribePeakMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(PeakMeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + PeakMeasuredValueAttributeSubscriptionState.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) { - "Peakmeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Peakmeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(PeakMeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(PeakMeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(PeakMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPeakMeasuredValueWindowAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 4u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readPeakMeasuredValueWindowAttribute(): UInt? { + 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}") - } + 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) { - "Peakmeasuredvaluewindow attribute not found in response" - } + } + + requireNotNull(attributeData) { "Peakmeasuredvaluewindow attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribePeakMeasuredValueWindowAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Peakmeasuredvaluewindow attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Peakmeasuredvaluewindow attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAverageMeasuredValueAttribute(): AverageMeasuredValueAttribute {val ATTRIBUTE_ID: UInt = 5u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readAverageMeasuredValueAttribute(): AverageMeasuredValueAttribute { + 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}") - } + 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) { - "Averagemeasuredvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Averagemeasuredvalue attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return AverageMeasuredValueAttribute(decodedValue) } suspend fun subscribeAverageMeasuredValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(AverageMeasuredValueAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + AverageMeasuredValueAttributeSubscriptionState.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) { - "Averagemeasuredvalue attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Averagemeasuredvalue attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(AverageMeasuredValueAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(AverageMeasuredValueAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(AverageMeasuredValueAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAverageMeasuredValueWindowAttribute(): UInt? {val ATTRIBUTE_ID: UInt = 6u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readAverageMeasuredValueWindowAttribute(): UInt? { + 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}") - } + 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) { - "Averagemeasuredvaluewindow attribute not found in response" - } + } + + requireNotNull(attributeData) { "Averagemeasuredvaluewindow attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeAverageMeasuredValueWindowAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Averagemeasuredvaluewindow attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Averagemeasuredvaluewindow attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(UIntSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(UIntSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readUncertaintyAttribute(): Float? {val ATTRIBUTE_ID: UInt = 7u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readUncertaintyAttribute(): Float? { + 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}") - } + 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) { - "Uncertainty attribute not found in response" - } + } + + requireNotNull(attributeData) { "Uncertainty attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - + val decodedValue: Float? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeUncertaintyAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(FloatSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + FloatSubscriptionState.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) { - "Uncertainty attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Uncertainty attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getFloat(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(FloatSubscriptionState.Success(it)) - } - + val decodedValue: Float? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getFloat(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(FloatSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(FloatSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMeasurementUnitAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 8u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMeasurementUnitAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 8u + + 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}") - } + 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) { - "Measurementunit attribute not found in response" - } + } + + requireNotNull(attributeData) { "Measurementunit 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeMeasurementUnitAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Measurementunit attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Measurementunit 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)) - } - + 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 readMeasurementMediumAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 9u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readMeasurementMediumAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 9u + + 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}") - } + 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) { - "Measurementmedium attribute not found in response" - } + } + + requireNotNull(attributeData) { "Measurementmedium 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeMeasurementMediumAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Measurementmedium attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Measurementmedium 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)) - } - + 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 readLevelValueAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 10u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readLevelValueAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 10u + + 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}") - } + 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) { - "Levelvalue attribute not found in response" - } + } + + requireNotNull(attributeData) { "Levelvalue 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeLevelValueAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Levelvalue attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Levelvalue 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)) - } - + 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 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1389,97 +1291,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1487,97 +1388,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1585,97 +1483,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1683,81 +1578,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1769,80 +1659,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1855,11 +1742,14 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { - private val logger = Logger.getLogger(TotalVolatileOrganicCompoundsConcentrationMeasurementCluster::class.java.name) + private val logger = + Logger.getLogger( + TotalVolatileOrganicCompoundsConcentrationMeasurementCluster::class.java.name + ) const val CLUSTER_ID: UInt = 1070u } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/UnitLocalizationCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/UnitLocalizationCluster.kt index 7d5cb6ca7abba9..af500e1b1cdce6 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/UnitLocalizationCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/UnitLocalizationCluster.kt @@ -17,164 +17,125 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse -import matter.controller.model.AttributePath -import matter.controller.model.CommandPath import matter.controller.cluster.structs.* +import matter.controller.model.AttributePath import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class UnitLocalizationCluster(private val controller: MatterController, private val endpointId: UShort) {class GeneratedCommandListAttribute( - val value: List - ) +class UnitLocalizationCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } -suspend fun readTemperatureUnitAttribute(): 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) - ) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } + + suspend fun readTemperatureUnitAttribute(): 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}") - } + 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) { - "Temperatureunit attribute not found in response" - } + } + + requireNotNull(attributeData) { "Temperatureunit 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } - suspend fun writeTemperatureUnitAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeTemperatureUnitAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -195,152 +156,153 @@ suspend fun readTemperatureUnitAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 0u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeTemperatureUnitAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Temperatureunit attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Temperatureunit 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)) - } - + 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 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -348,97 +310,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -446,97 +407,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -544,97 +502,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -642,81 +597,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -728,80 +678,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -814,7 +761,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/UnitTestingCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/UnitTestingCluster.kt index f62caafde01495..74402b19dcfdf3 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/UnitTestingCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/UnitTestingCluster.kt @@ -17,774 +17,616 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.BooleanSubscriptionState +import matter.controller.ByteArraySubscriptionState +import matter.controller.ByteSubscriptionState +import matter.controller.DoubleSubscriptionState +import matter.controller.FloatSubscriptionState +import matter.controller.IntSubscriptionState +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse +import matter.controller.LongSubscriptionState import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest +import matter.controller.ShortSubscriptionState +import matter.controller.StringSubscriptionState import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter class UnitTestingCluster(private val controller: MatterController, private val endpointId: UShort) { - class TestSpecificResponse( - val returnValue: UByte - ) + class TestSpecificResponse(val returnValue: UByte) - class TestAddArgumentsResponse( - val returnValue: UByte - ) + class TestAddArgumentsResponse(val returnValue: UByte) - class TestSimpleArgumentResponse( - val returnValue: Boolean - ) + class TestSimpleArgumentResponse(val returnValue: Boolean) class TestStructArrayArgumentResponse( - val arg1: List, - val arg2: List, - val arg3: List, - val arg4: List, - val arg5: UByte, - val arg6: Boolean + val arg1: List, + val arg2: List, + val arg3: List, + val arg4: List, + val arg5: UByte, + val arg6: Boolean, ) - class BooleanResponse( - val value: Boolean - ) + class BooleanResponse(val value: Boolean) - class TestListInt8UReverseResponse( - val arg1: List - ) + class TestListInt8UReverseResponse(val arg1: List) - class TestEnumsResponse( - val arg1: UShort, - val arg2: UByte - ) + class TestEnumsResponse(val arg1: UShort, val arg2: UByte) class TestNullableOptionalResponse( - val wasPresent: Boolean, - val wasNull: Boolean?, - val value: UByte?, - val originalValue: UByte? + val wasPresent: Boolean, + val wasNull: Boolean?, + val value: UByte?, + val originalValue: UByte?, ) class TestComplexNullableOptionalResponse( - val nullableIntWasNull: Boolean, - val nullableIntValue: UShort?, - val optionalIntWasPresent: Boolean, - val optionalIntValue: UShort?, - val nullableOptionalIntWasPresent: Boolean, - val nullableOptionalIntWasNull: Boolean?, - val nullableOptionalIntValue: UShort?, - val nullableStringWasNull: Boolean, - val nullableStringValue: String?, - val optionalStringWasPresent: Boolean, - val optionalStringValue: String?, - val nullableOptionalStringWasPresent: Boolean, - val nullableOptionalStringWasNull: Boolean?, - val nullableOptionalStringValue: String?, - val nullableStructWasNull: Boolean, - val nullableStructValue: UnitTestingClusterSimpleStruct?, - val optionalStructWasPresent: Boolean, - val optionalStructValue: UnitTestingClusterSimpleStruct?, - val nullableOptionalStructWasPresent: Boolean, - val nullableOptionalStructWasNull: Boolean?, - val nullableOptionalStructValue: UnitTestingClusterSimpleStruct?, - val nullableListWasNull: Boolean, - val nullableListValue: List?, - val optionalListWasPresent: Boolean, - val optionalListValue: List?, - val nullableOptionalListWasPresent: Boolean, - val nullableOptionalListWasNull: Boolean?, - val nullableOptionalListValue: List? + val nullableIntWasNull: Boolean, + val nullableIntValue: UShort?, + val optionalIntWasPresent: Boolean, + val optionalIntValue: UShort?, + val nullableOptionalIntWasPresent: Boolean, + val nullableOptionalIntWasNull: Boolean?, + val nullableOptionalIntValue: UShort?, + val nullableStringWasNull: Boolean, + val nullableStringValue: String?, + val optionalStringWasPresent: Boolean, + val optionalStringValue: String?, + val nullableOptionalStringWasPresent: Boolean, + val nullableOptionalStringWasNull: Boolean?, + val nullableOptionalStringValue: String?, + val nullableStructWasNull: Boolean, + val nullableStructValue: UnitTestingClusterSimpleStruct?, + val optionalStructWasPresent: Boolean, + val optionalStructValue: UnitTestingClusterSimpleStruct?, + val nullableOptionalStructWasPresent: Boolean, + val nullableOptionalStructWasNull: Boolean?, + val nullableOptionalStructValue: UnitTestingClusterSimpleStruct?, + val nullableListWasNull: Boolean, + val nullableListValue: List?, + val optionalListWasPresent: Boolean, + val optionalListValue: List?, + val nullableOptionalListWasPresent: Boolean, + val nullableOptionalListWasNull: Boolean?, + val nullableOptionalListValue: List?, ) - class SimpleStructResponse( - val arg1: UnitTestingClusterSimpleStruct - ) + class SimpleStructResponse(val arg1: UnitTestingClusterSimpleStruct) - class TestEmitTestEventResponse( - val value: ULong - ) + class TestEmitTestEventResponse(val value: ULong) - class TestEmitTestFabricScopedEventResponse( - val value: ULong - ) + class TestEmitTestFabricScopedEventResponse(val value: ULong) - class TestBatchHelperResponse( - val buffer: ByteArray - ) + class TestBatchHelperResponse(val buffer: ByteArray) - class StringEchoResponse( - val payload: ByteArray - ) + class StringEchoResponse(val payload: ByteArray) - class GlobalEchoResponse( - val field1: UnitTestingClusterTestGlobalStruct, - val field2: UByte - ) + class GlobalEchoResponse(val field1: UnitTestingClusterTestGlobalStruct, val field2: UByte) - class TestDifferentVendorMeiResponse( - val arg1: UByte, - val eventNumber: ULong - ) -class ListInt8uAttribute( - val value: List - ) + class TestDifferentVendorMeiResponse(val arg1: UByte, val eventNumber: ULong) + + class ListInt8uAttribute(val value: List) sealed class ListInt8uAttributeSubscriptionState { - data class Success( - val value: List - ) : ListInt8uAttributeSubscriptionState() - + data class Success(val value: List) : ListInt8uAttributeSubscriptionState() + data class Error(val exception: Exception) : ListInt8uAttributeSubscriptionState() - object SubscriptionEstablished : ListInt8uAttributeSubscriptionState() - } -class ListOctetStringAttribute( - val value: List - ) + object SubscriptionEstablished : ListInt8uAttributeSubscriptionState() + } + + class ListOctetStringAttribute(val value: List) sealed class ListOctetStringAttributeSubscriptionState { - data class Success( - val value: List - ) : ListOctetStringAttributeSubscriptionState() - + data class Success(val value: List) : ListOctetStringAttributeSubscriptionState() + data class Error(val exception: Exception) : ListOctetStringAttributeSubscriptionState() - object SubscriptionEstablished : ListOctetStringAttributeSubscriptionState() - } -class ListStructOctetStringAttribute( - val value: List - ) + object SubscriptionEstablished : ListOctetStringAttributeSubscriptionState() + } + + class ListStructOctetStringAttribute(val value: List) sealed class ListStructOctetStringAttributeSubscriptionState { - data class Success( - val value: List - ) : ListStructOctetStringAttributeSubscriptionState() - + data class Success(val value: List) : + ListStructOctetStringAttributeSubscriptionState() + data class Error(val exception: Exception) : ListStructOctetStringAttributeSubscriptionState() - object SubscriptionEstablished : ListStructOctetStringAttributeSubscriptionState() - } -class ListNullablesAndOptionalsStructAttribute( + object SubscriptionEstablished : ListStructOctetStringAttributeSubscriptionState() + } + + class ListNullablesAndOptionalsStructAttribute( val value: List ) sealed class ListNullablesAndOptionalsStructAttributeSubscriptionState { - data class Success( - val value: List - ) : ListNullablesAndOptionalsStructAttributeSubscriptionState() - - data class Error(val exception: Exception) : ListNullablesAndOptionalsStructAttributeSubscriptionState() - - object SubscriptionEstablished : ListNullablesAndOptionalsStructAttributeSubscriptionState() - } -class StructAttrAttribute( - val value: UnitTestingClusterSimpleStruct - ) + data class Success(val value: List) : + ListNullablesAndOptionalsStructAttributeSubscriptionState() + + data class Error(val exception: Exception) : + ListNullablesAndOptionalsStructAttributeSubscriptionState() + + object SubscriptionEstablished : ListNullablesAndOptionalsStructAttributeSubscriptionState() + } + + class StructAttrAttribute(val value: UnitTestingClusterSimpleStruct) sealed class StructAttrAttributeSubscriptionState { - data class Success( - val value: UnitTestingClusterSimpleStruct - ) : StructAttrAttributeSubscriptionState() - + data class Success(val value: UnitTestingClusterSimpleStruct) : + StructAttrAttributeSubscriptionState() + data class Error(val exception: Exception) : StructAttrAttributeSubscriptionState() - object SubscriptionEstablished : StructAttrAttributeSubscriptionState() - } -class ListLongOctetStringAttribute( - val value: List - ) + object SubscriptionEstablished : StructAttrAttributeSubscriptionState() + } + + class ListLongOctetStringAttribute(val value: List) sealed class ListLongOctetStringAttributeSubscriptionState { - data class Success( - val value: List - ) : ListLongOctetStringAttributeSubscriptionState() - + data class Success(val value: List) : + ListLongOctetStringAttributeSubscriptionState() + data class Error(val exception: Exception) : ListLongOctetStringAttributeSubscriptionState() - object SubscriptionEstablished : ListLongOctetStringAttributeSubscriptionState() - } -class ListFabricScopedAttribute( - val value: List - ) + object SubscriptionEstablished : ListLongOctetStringAttributeSubscriptionState() + } + + class ListFabricScopedAttribute(val value: List) sealed class ListFabricScopedAttributeSubscriptionState { - data class Success( - val value: List - ) : ListFabricScopedAttributeSubscriptionState() - + data class Success(val value: List) : + ListFabricScopedAttributeSubscriptionState() + data class Error(val exception: Exception) : ListFabricScopedAttributeSubscriptionState() - object SubscriptionEstablished : ListFabricScopedAttributeSubscriptionState() - } -class GlobalStructAttribute( - val value: UnitTestingClusterTestGlobalStruct - ) + object SubscriptionEstablished : ListFabricScopedAttributeSubscriptionState() + } + + class GlobalStructAttribute(val value: UnitTestingClusterTestGlobalStruct) sealed class GlobalStructAttributeSubscriptionState { - data class Success( - val value: UnitTestingClusterTestGlobalStruct - ) : GlobalStructAttributeSubscriptionState() - + data class Success(val value: UnitTestingClusterTestGlobalStruct) : + GlobalStructAttributeSubscriptionState() + data class Error(val exception: Exception) : GlobalStructAttributeSubscriptionState() - object SubscriptionEstablished : GlobalStructAttributeSubscriptionState() - } -class NullableBooleanAttribute( - val value: Boolean? - ) + object SubscriptionEstablished : GlobalStructAttributeSubscriptionState() + } + + class NullableBooleanAttribute(val value: Boolean?) sealed class NullableBooleanAttributeSubscriptionState { - data class Success( - val value: Boolean? - ) : NullableBooleanAttributeSubscriptionState() - + data class Success(val value: Boolean?) : NullableBooleanAttributeSubscriptionState() + data class Error(val exception: Exception) : NullableBooleanAttributeSubscriptionState() - object SubscriptionEstablished : NullableBooleanAttributeSubscriptionState() - } -class NullableBitmap8Attribute( - val value: UByte? - ) + object SubscriptionEstablished : NullableBooleanAttributeSubscriptionState() + } + + class NullableBitmap8Attribute(val value: UByte?) sealed class NullableBitmap8AttributeSubscriptionState { - data class Success( - val value: UByte? - ) : NullableBitmap8AttributeSubscriptionState() - + data class Success(val value: UByte?) : NullableBitmap8AttributeSubscriptionState() + data class Error(val exception: Exception) : NullableBitmap8AttributeSubscriptionState() - object SubscriptionEstablished : NullableBitmap8AttributeSubscriptionState() - } -class NullableBitmap16Attribute( - val value: UShort? - ) + object SubscriptionEstablished : NullableBitmap8AttributeSubscriptionState() + } + + class NullableBitmap16Attribute(val value: UShort?) sealed class NullableBitmap16AttributeSubscriptionState { - data class Success( - val value: UShort? - ) : NullableBitmap16AttributeSubscriptionState() - + data class Success(val value: UShort?) : NullableBitmap16AttributeSubscriptionState() + data class Error(val exception: Exception) : NullableBitmap16AttributeSubscriptionState() - object SubscriptionEstablished : NullableBitmap16AttributeSubscriptionState() - } -class NullableBitmap32Attribute( - val value: UInt? - ) + object SubscriptionEstablished : NullableBitmap16AttributeSubscriptionState() + } + + class NullableBitmap32Attribute(val value: UInt?) sealed class NullableBitmap32AttributeSubscriptionState { - data class Success( - val value: UInt? - ) : NullableBitmap32AttributeSubscriptionState() - + data class Success(val value: UInt?) : NullableBitmap32AttributeSubscriptionState() + data class Error(val exception: Exception) : NullableBitmap32AttributeSubscriptionState() - object SubscriptionEstablished : NullableBitmap32AttributeSubscriptionState() - } -class NullableBitmap64Attribute( - val value: ULong? - ) + object SubscriptionEstablished : NullableBitmap32AttributeSubscriptionState() + } + + class NullableBitmap64Attribute(val value: ULong?) sealed class NullableBitmap64AttributeSubscriptionState { - data class Success( - val value: ULong? - ) : NullableBitmap64AttributeSubscriptionState() - + data class Success(val value: ULong?) : NullableBitmap64AttributeSubscriptionState() + data class Error(val exception: Exception) : NullableBitmap64AttributeSubscriptionState() - object SubscriptionEstablished : NullableBitmap64AttributeSubscriptionState() - } -class NullableInt8uAttribute( - val value: UByte? - ) + object SubscriptionEstablished : NullableBitmap64AttributeSubscriptionState() + } + + class NullableInt8uAttribute(val value: UByte?) sealed class NullableInt8uAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : NullableInt8uAttributeSubscriptionState() - + data class Success(val value: UByte?) : NullableInt8uAttributeSubscriptionState() + data class Error(val exception: Exception) : NullableInt8uAttributeSubscriptionState() - object SubscriptionEstablished : NullableInt8uAttributeSubscriptionState() - } -class NullableInt16uAttribute( - val value: UShort? - ) + object SubscriptionEstablished : NullableInt8uAttributeSubscriptionState() + } + + class NullableInt16uAttribute(val value: UShort?) sealed class NullableInt16uAttributeSubscriptionState { - data class Success( - val value: UShort? - ) : NullableInt16uAttributeSubscriptionState() - + data class Success(val value: UShort?) : NullableInt16uAttributeSubscriptionState() + data class Error(val exception: Exception) : NullableInt16uAttributeSubscriptionState() - object SubscriptionEstablished : NullableInt16uAttributeSubscriptionState() - } -class NullableInt24uAttribute( - val value: UInt? - ) + object SubscriptionEstablished : NullableInt16uAttributeSubscriptionState() + } + + class NullableInt24uAttribute(val value: UInt?) sealed class NullableInt24uAttributeSubscriptionState { - data class Success( - val value: UInt? - ) : NullableInt24uAttributeSubscriptionState() - + data class Success(val value: UInt?) : NullableInt24uAttributeSubscriptionState() + data class Error(val exception: Exception) : NullableInt24uAttributeSubscriptionState() - object SubscriptionEstablished : NullableInt24uAttributeSubscriptionState() - } -class NullableInt32uAttribute( - val value: UInt? - ) + object SubscriptionEstablished : NullableInt24uAttributeSubscriptionState() + } + + class NullableInt32uAttribute(val value: UInt?) sealed class NullableInt32uAttributeSubscriptionState { - data class Success( - val value: UInt? - ) : NullableInt32uAttributeSubscriptionState() - + data class Success(val value: UInt?) : NullableInt32uAttributeSubscriptionState() + data class Error(val exception: Exception) : NullableInt32uAttributeSubscriptionState() - object SubscriptionEstablished : NullableInt32uAttributeSubscriptionState() - } -class NullableInt40uAttribute( - val value: ULong? - ) + object SubscriptionEstablished : NullableInt32uAttributeSubscriptionState() + } + + class NullableInt40uAttribute(val value: ULong?) sealed class NullableInt40uAttributeSubscriptionState { - data class Success( - val value: ULong? - ) : NullableInt40uAttributeSubscriptionState() - + data class Success(val value: ULong?) : NullableInt40uAttributeSubscriptionState() + data class Error(val exception: Exception) : NullableInt40uAttributeSubscriptionState() - object SubscriptionEstablished : NullableInt40uAttributeSubscriptionState() - } -class NullableInt48uAttribute( - val value: ULong? - ) + object SubscriptionEstablished : NullableInt40uAttributeSubscriptionState() + } + + class NullableInt48uAttribute(val value: ULong?) sealed class NullableInt48uAttributeSubscriptionState { - data class Success( - val value: ULong? - ) : NullableInt48uAttributeSubscriptionState() - + data class Success(val value: ULong?) : NullableInt48uAttributeSubscriptionState() + data class Error(val exception: Exception) : NullableInt48uAttributeSubscriptionState() - object SubscriptionEstablished : NullableInt48uAttributeSubscriptionState() - } -class NullableInt56uAttribute( - val value: ULong? - ) + object SubscriptionEstablished : NullableInt48uAttributeSubscriptionState() + } + + class NullableInt56uAttribute(val value: ULong?) sealed class NullableInt56uAttributeSubscriptionState { - data class Success( - val value: ULong? - ) : NullableInt56uAttributeSubscriptionState() - + data class Success(val value: ULong?) : NullableInt56uAttributeSubscriptionState() + data class Error(val exception: Exception) : NullableInt56uAttributeSubscriptionState() - object SubscriptionEstablished : NullableInt56uAttributeSubscriptionState() - } -class NullableInt64uAttribute( - val value: ULong? - ) + object SubscriptionEstablished : NullableInt56uAttributeSubscriptionState() + } + + class NullableInt64uAttribute(val value: ULong?) sealed class NullableInt64uAttributeSubscriptionState { - data class Success( - val value: ULong? - ) : NullableInt64uAttributeSubscriptionState() - + data class Success(val value: ULong?) : NullableInt64uAttributeSubscriptionState() + data class Error(val exception: Exception) : NullableInt64uAttributeSubscriptionState() - object SubscriptionEstablished : NullableInt64uAttributeSubscriptionState() - } -class NullableInt8sAttribute( - val value: Byte? - ) + object SubscriptionEstablished : NullableInt64uAttributeSubscriptionState() + } + + class NullableInt8sAttribute(val value: Byte?) sealed class NullableInt8sAttributeSubscriptionState { - data class Success( - val value: Byte? - ) : NullableInt8sAttributeSubscriptionState() - + data class Success(val value: Byte?) : NullableInt8sAttributeSubscriptionState() + data class Error(val exception: Exception) : NullableInt8sAttributeSubscriptionState() - object SubscriptionEstablished : NullableInt8sAttributeSubscriptionState() - } -class NullableInt16sAttribute( - val value: Short? - ) + object SubscriptionEstablished : NullableInt8sAttributeSubscriptionState() + } + + class NullableInt16sAttribute(val value: Short?) sealed class NullableInt16sAttributeSubscriptionState { - data class Success( - val value: Short? - ) : NullableInt16sAttributeSubscriptionState() - + data class Success(val value: Short?) : NullableInt16sAttributeSubscriptionState() + data class Error(val exception: Exception) : NullableInt16sAttributeSubscriptionState() - object SubscriptionEstablished : NullableInt16sAttributeSubscriptionState() - } -class NullableInt24sAttribute( - val value: Int? - ) + object SubscriptionEstablished : NullableInt16sAttributeSubscriptionState() + } + + class NullableInt24sAttribute(val value: Int?) sealed class NullableInt24sAttributeSubscriptionState { - data class Success( - val value: Int? - ) : NullableInt24sAttributeSubscriptionState() - + data class Success(val value: Int?) : NullableInt24sAttributeSubscriptionState() + data class Error(val exception: Exception) : NullableInt24sAttributeSubscriptionState() - object SubscriptionEstablished : NullableInt24sAttributeSubscriptionState() - } -class NullableInt32sAttribute( - val value: Int? - ) + object SubscriptionEstablished : NullableInt24sAttributeSubscriptionState() + } + + class NullableInt32sAttribute(val value: Int?) sealed class NullableInt32sAttributeSubscriptionState { - data class Success( - val value: Int? - ) : NullableInt32sAttributeSubscriptionState() - + data class Success(val value: Int?) : NullableInt32sAttributeSubscriptionState() + data class Error(val exception: Exception) : NullableInt32sAttributeSubscriptionState() - object SubscriptionEstablished : NullableInt32sAttributeSubscriptionState() - } -class NullableInt40sAttribute( - val value: Long? - ) + object SubscriptionEstablished : NullableInt32sAttributeSubscriptionState() + } + + class NullableInt40sAttribute(val value: Long?) sealed class NullableInt40sAttributeSubscriptionState { - data class Success( - val value: Long? - ) : NullableInt40sAttributeSubscriptionState() - + data class Success(val value: Long?) : NullableInt40sAttributeSubscriptionState() + data class Error(val exception: Exception) : NullableInt40sAttributeSubscriptionState() - object SubscriptionEstablished : NullableInt40sAttributeSubscriptionState() - } -class NullableInt48sAttribute( - val value: Long? - ) + object SubscriptionEstablished : NullableInt40sAttributeSubscriptionState() + } + + class NullableInt48sAttribute(val value: Long?) sealed class NullableInt48sAttributeSubscriptionState { - data class Success( - val value: Long? - ) : NullableInt48sAttributeSubscriptionState() - + data class Success(val value: Long?) : NullableInt48sAttributeSubscriptionState() + data class Error(val exception: Exception) : NullableInt48sAttributeSubscriptionState() - object SubscriptionEstablished : NullableInt48sAttributeSubscriptionState() - } -class NullableInt56sAttribute( - val value: Long? - ) + object SubscriptionEstablished : NullableInt48sAttributeSubscriptionState() + } + + class NullableInt56sAttribute(val value: Long?) sealed class NullableInt56sAttributeSubscriptionState { - data class Success( - val value: Long? - ) : NullableInt56sAttributeSubscriptionState() - + data class Success(val value: Long?) : NullableInt56sAttributeSubscriptionState() + data class Error(val exception: Exception) : NullableInt56sAttributeSubscriptionState() - object SubscriptionEstablished : NullableInt56sAttributeSubscriptionState() - } -class NullableInt64sAttribute( - val value: Long? - ) + object SubscriptionEstablished : NullableInt56sAttributeSubscriptionState() + } + + class NullableInt64sAttribute(val value: Long?) sealed class NullableInt64sAttributeSubscriptionState { - data class Success( - val value: Long? - ) : NullableInt64sAttributeSubscriptionState() - + data class Success(val value: Long?) : NullableInt64sAttributeSubscriptionState() + data class Error(val exception: Exception) : NullableInt64sAttributeSubscriptionState() - object SubscriptionEstablished : NullableInt64sAttributeSubscriptionState() - } -class NullableEnum8Attribute( - val value: UByte? - ) + object SubscriptionEstablished : NullableInt64sAttributeSubscriptionState() + } + + class NullableEnum8Attribute(val value: UByte?) sealed class NullableEnum8AttributeSubscriptionState { - data class Success( - val value: UByte? - ) : NullableEnum8AttributeSubscriptionState() - + data class Success(val value: UByte?) : NullableEnum8AttributeSubscriptionState() + data class Error(val exception: Exception) : NullableEnum8AttributeSubscriptionState() - object SubscriptionEstablished : NullableEnum8AttributeSubscriptionState() - } -class NullableEnum16Attribute( - val value: UShort? - ) + object SubscriptionEstablished : NullableEnum8AttributeSubscriptionState() + } + + class NullableEnum16Attribute(val value: UShort?) sealed class NullableEnum16AttributeSubscriptionState { - data class Success( - val value: UShort? - ) : NullableEnum16AttributeSubscriptionState() - + data class Success(val value: UShort?) : NullableEnum16AttributeSubscriptionState() + data class Error(val exception: Exception) : NullableEnum16AttributeSubscriptionState() - object SubscriptionEstablished : NullableEnum16AttributeSubscriptionState() - } -class NullableFloatSingleAttribute( - val value: Float? - ) + object SubscriptionEstablished : NullableEnum16AttributeSubscriptionState() + } + + class NullableFloatSingleAttribute(val value: Float?) sealed class NullableFloatSingleAttributeSubscriptionState { - data class Success( - val value: Float? - ) : NullableFloatSingleAttributeSubscriptionState() - + data class Success(val value: Float?) : NullableFloatSingleAttributeSubscriptionState() + data class Error(val exception: Exception) : NullableFloatSingleAttributeSubscriptionState() - object SubscriptionEstablished : NullableFloatSingleAttributeSubscriptionState() - } -class NullableFloatDoubleAttribute( - val value: Double? - ) + object SubscriptionEstablished : NullableFloatSingleAttributeSubscriptionState() + } + + class NullableFloatDoubleAttribute(val value: Double?) sealed class NullableFloatDoubleAttributeSubscriptionState { - data class Success( - val value: Double? - ) : NullableFloatDoubleAttributeSubscriptionState() - + data class Success(val value: Double?) : NullableFloatDoubleAttributeSubscriptionState() + data class Error(val exception: Exception) : NullableFloatDoubleAttributeSubscriptionState() - object SubscriptionEstablished : NullableFloatDoubleAttributeSubscriptionState() - } -class NullableOctetStringAttribute( - val value: ByteArray? - ) + object SubscriptionEstablished : NullableFloatDoubleAttributeSubscriptionState() + } + + class NullableOctetStringAttribute(val value: ByteArray?) sealed class NullableOctetStringAttributeSubscriptionState { - data class Success( - val value: ByteArray? - ) : NullableOctetStringAttributeSubscriptionState() - + data class Success(val value: ByteArray?) : NullableOctetStringAttributeSubscriptionState() + data class Error(val exception: Exception) : NullableOctetStringAttributeSubscriptionState() - object SubscriptionEstablished : NullableOctetStringAttributeSubscriptionState() - } -class NullableCharStringAttribute( - val value: String? - ) + object SubscriptionEstablished : NullableOctetStringAttributeSubscriptionState() + } + + class NullableCharStringAttribute(val value: String?) sealed class NullableCharStringAttributeSubscriptionState { - data class Success( - val value: String? - ) : NullableCharStringAttributeSubscriptionState() - + data class Success(val value: String?) : NullableCharStringAttributeSubscriptionState() + data class Error(val exception: Exception) : NullableCharStringAttributeSubscriptionState() - object SubscriptionEstablished : NullableCharStringAttributeSubscriptionState() - } -class NullableEnumAttrAttribute( - val value: UByte? - ) + object SubscriptionEstablished : NullableCharStringAttributeSubscriptionState() + } + + class NullableEnumAttrAttribute(val value: UByte?) sealed class NullableEnumAttrAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : NullableEnumAttrAttributeSubscriptionState() - + data class Success(val value: UByte?) : NullableEnumAttrAttributeSubscriptionState() + data class Error(val exception: Exception) : NullableEnumAttrAttributeSubscriptionState() - object SubscriptionEstablished : NullableEnumAttrAttributeSubscriptionState() - } -class NullableStructAttribute( - val value: UnitTestingClusterSimpleStruct? - ) + object SubscriptionEstablished : NullableEnumAttrAttributeSubscriptionState() + } + + class NullableStructAttribute(val value: UnitTestingClusterSimpleStruct?) sealed class NullableStructAttributeSubscriptionState { - data class Success( - val value: UnitTestingClusterSimpleStruct? - ) : NullableStructAttributeSubscriptionState() - + data class Success(val value: UnitTestingClusterSimpleStruct?) : + NullableStructAttributeSubscriptionState() + data class Error(val exception: Exception) : NullableStructAttributeSubscriptionState() - object SubscriptionEstablished : NullableStructAttributeSubscriptionState() - } -class NullableRangeRestrictedInt8uAttribute( - val value: UByte? - ) + object SubscriptionEstablished : NullableStructAttributeSubscriptionState() + } + + class NullableRangeRestrictedInt8uAttribute(val value: UByte?) sealed class NullableRangeRestrictedInt8uAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : NullableRangeRestrictedInt8uAttributeSubscriptionState() - - data class Error(val exception: Exception) : NullableRangeRestrictedInt8uAttributeSubscriptionState() - - object SubscriptionEstablished : NullableRangeRestrictedInt8uAttributeSubscriptionState() - } -class NullableRangeRestrictedInt8sAttribute( - val value: Byte? - ) + data class Success(val value: UByte?) : + NullableRangeRestrictedInt8uAttributeSubscriptionState() + + data class Error(val exception: Exception) : + NullableRangeRestrictedInt8uAttributeSubscriptionState() + + object SubscriptionEstablished : NullableRangeRestrictedInt8uAttributeSubscriptionState() + } + + class NullableRangeRestrictedInt8sAttribute(val value: Byte?) sealed class NullableRangeRestrictedInt8sAttributeSubscriptionState { - data class Success( - val value: Byte? - ) : NullableRangeRestrictedInt8sAttributeSubscriptionState() - - data class Error(val exception: Exception) : NullableRangeRestrictedInt8sAttributeSubscriptionState() - - object SubscriptionEstablished : NullableRangeRestrictedInt8sAttributeSubscriptionState() - } -class NullableRangeRestrictedInt16uAttribute( - val value: UShort? - ) + data class Success(val value: Byte?) : NullableRangeRestrictedInt8sAttributeSubscriptionState() + + data class Error(val exception: Exception) : + NullableRangeRestrictedInt8sAttributeSubscriptionState() + + object SubscriptionEstablished : NullableRangeRestrictedInt8sAttributeSubscriptionState() + } + + class NullableRangeRestrictedInt16uAttribute(val value: UShort?) sealed class NullableRangeRestrictedInt16uAttributeSubscriptionState { - data class Success( - val value: UShort? - ) : NullableRangeRestrictedInt16uAttributeSubscriptionState() - - data class Error(val exception: Exception) : NullableRangeRestrictedInt16uAttributeSubscriptionState() - - object SubscriptionEstablished : NullableRangeRestrictedInt16uAttributeSubscriptionState() - } -class NullableRangeRestrictedInt16sAttribute( - val value: Short? - ) + data class Success(val value: UShort?) : + NullableRangeRestrictedInt16uAttributeSubscriptionState() + + data class Error(val exception: Exception) : + NullableRangeRestrictedInt16uAttributeSubscriptionState() + + object SubscriptionEstablished : NullableRangeRestrictedInt16uAttributeSubscriptionState() + } + + class NullableRangeRestrictedInt16sAttribute(val value: Short?) sealed class NullableRangeRestrictedInt16sAttributeSubscriptionState { - data class Success( - val value: Short? - ) : NullableRangeRestrictedInt16sAttributeSubscriptionState() - - data class Error(val exception: Exception) : NullableRangeRestrictedInt16sAttributeSubscriptionState() - - object SubscriptionEstablished : NullableRangeRestrictedInt16sAttributeSubscriptionState() - } -class NullableGlobalEnumAttribute( - val value: UByte? - ) + data class Success(val value: Short?) : + NullableRangeRestrictedInt16sAttributeSubscriptionState() + + data class Error(val exception: Exception) : + NullableRangeRestrictedInt16sAttributeSubscriptionState() + + object SubscriptionEstablished : NullableRangeRestrictedInt16sAttributeSubscriptionState() + } + + class NullableGlobalEnumAttribute(val value: UByte?) sealed class NullableGlobalEnumAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : NullableGlobalEnumAttributeSubscriptionState() - + data class Success(val value: UByte?) : NullableGlobalEnumAttributeSubscriptionState() + data class Error(val exception: Exception) : NullableGlobalEnumAttributeSubscriptionState() - object SubscriptionEstablished : NullableGlobalEnumAttributeSubscriptionState() - } -class NullableGlobalStructAttribute( - val value: UnitTestingClusterTestGlobalStruct? - ) + object SubscriptionEstablished : NullableGlobalEnumAttributeSubscriptionState() + } + + class NullableGlobalStructAttribute(val value: UnitTestingClusterTestGlobalStruct?) sealed class NullableGlobalStructAttributeSubscriptionState { - data class Success( - val value: UnitTestingClusterTestGlobalStruct? - ) : NullableGlobalStructAttributeSubscriptionState() - + data class Success(val value: UnitTestingClusterTestGlobalStruct?) : + NullableGlobalStructAttributeSubscriptionState() + data class Error(val exception: Exception) : NullableGlobalStructAttributeSubscriptionState() - object SubscriptionEstablished : NullableGlobalStructAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : NullableGlobalStructAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } suspend fun test(timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -795,14 +637,14 @@ class AttributeListAttribute( val commandId: UInt = 1u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -813,14 +655,14 @@ class AttributeListAttribute( val commandId: UInt = 2u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -830,55 +672,49 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_RETURN_VALUE: Int = 0 var returnValue_decoded: UByte? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_RETURN_VALUE)) {returnValue_decoded = tlvReader.getUByte(tag)} - - - else { + if (tag == ContextSpecificTag(TAG_RETURN_VALUE)) { + returnValue_decoded = tlvReader.getUByte(tag) + } else { tlvReader.skipElement() } } - - if (returnValue_decoded == null) { - throw IllegalStateException("returnValue not found in TLV") + throw IllegalStateException("returnValue not found in TLV") } - tlvReader.exitContainer() - return TestSpecificResponse( - returnValue_decoded - ) + return TestSpecificResponse(returnValue_decoded) } suspend fun testUnknownCommand(timedInvokeTimeout: Duration? = null) { val commandId: UInt = 3u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun testAddArguments(arg1: UByte - ,arg2: UByte - ,timedInvokeTimeout: Duration? = null): TestAddArgumentsResponse { + suspend fun testAddArguments( + arg1: UByte, + arg2: UByte, + timedInvokeTimeout: Duration? = null, + ): TestAddArgumentsResponse { val commandId: UInt = 4u val tlvWriter = TlvWriter() @@ -888,14 +724,14 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_ARG1_REQ), arg1) val TAG_ARG2_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_ARG2_REQ), arg2) + tlvWriter.put(ContextSpecificTag(TAG_ARG2_REQ), arg2) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -905,50 +741,44 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_RETURN_VALUE: Int = 0 var returnValue_decoded: UByte? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_RETURN_VALUE)) {returnValue_decoded = tlvReader.getUByte(tag)} - - - else { + if (tag == ContextSpecificTag(TAG_RETURN_VALUE)) { + returnValue_decoded = tlvReader.getUByte(tag) + } else { tlvReader.skipElement() } } - - if (returnValue_decoded == null) { - throw IllegalStateException("returnValue not found in TLV") + throw IllegalStateException("returnValue not found in TLV") } - tlvReader.exitContainer() - return TestAddArgumentsResponse( - returnValue_decoded - ) + return TestAddArgumentsResponse(returnValue_decoded) } - suspend fun testSimpleArgumentRequest(arg1: Boolean - ,timedInvokeTimeout: Duration? = null): TestSimpleArgumentResponse { + suspend fun testSimpleArgumentRequest( + arg1: Boolean, + timedInvokeTimeout: Duration? = null, + ): TestSimpleArgumentResponse { val commandId: UInt = 5u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_ARG1_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_ARG1_REQ), arg1) + tlvWriter.put(ContextSpecificTag(TAG_ARG1_REQ), arg1) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -958,41 +788,35 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_RETURN_VALUE: Int = 0 var returnValue_decoded: Boolean? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_RETURN_VALUE)) {returnValue_decoded = tlvReader.getBoolean(tag)} - - - else { + if (tag == ContextSpecificTag(TAG_RETURN_VALUE)) { + returnValue_decoded = tlvReader.getBoolean(tag) + } else { tlvReader.skipElement() } } - - if (returnValue_decoded == null) { - throw IllegalStateException("returnValue not found in TLV") + throw IllegalStateException("returnValue not found in TLV") } - tlvReader.exitContainer() - return TestSimpleArgumentResponse( - returnValue_decoded - ) + return TestSimpleArgumentResponse(returnValue_decoded) } - suspend fun testStructArrayArgumentRequest(arg1: List - ,arg2: List - ,arg3: List - ,arg4: List - ,arg5: UByte - ,arg6: Boolean - ,timedInvokeTimeout: Duration? = null): TestStructArrayArgumentResponse { + suspend fun testStructArrayArgumentRequest( + arg1: List, + arg2: List, + arg3: List, + arg4: List, + arg5: UByte, + arg6: Boolean, + timedInvokeTimeout: Duration? = null, + ): TestStructArrayArgumentResponse { val commandId: UInt = 6u val tlvWriter = TlvWriter() @@ -1000,44 +824,44 @@ class AttributeListAttribute( val TAG_ARG1_REQ: Int = 0 tlvWriter.startArray(ContextSpecificTag(TAG_ARG1_REQ)) - for (item in arg1.iterator()) { - item.toTlv(AnonymousTag, tlvWriter) - } - tlvWriter.endArray() + for (item in arg1.iterator()) { + item.toTlv(AnonymousTag, tlvWriter) + } + tlvWriter.endArray() val TAG_ARG2_REQ: Int = 1 tlvWriter.startArray(ContextSpecificTag(TAG_ARG2_REQ)) - for (item in arg2.iterator()) { - item.toTlv(AnonymousTag, tlvWriter) - } - tlvWriter.endArray() + for (item in arg2.iterator()) { + item.toTlv(AnonymousTag, tlvWriter) + } + tlvWriter.endArray() val TAG_ARG3_REQ: Int = 2 tlvWriter.startArray(ContextSpecificTag(TAG_ARG3_REQ)) - for (item in arg3.iterator()) { - tlvWriter.put(AnonymousTag, item) - } - tlvWriter.endArray() + for (item in arg3.iterator()) { + tlvWriter.put(AnonymousTag, item) + } + tlvWriter.endArray() val TAG_ARG4_REQ: Int = 3 tlvWriter.startArray(ContextSpecificTag(TAG_ARG4_REQ)) - for (item in arg4.iterator()) { - tlvWriter.put(AnonymousTag, item) - } - tlvWriter.endArray() + for (item in arg4.iterator()) { + tlvWriter.put(AnonymousTag, item) + } + tlvWriter.endArray() val TAG_ARG5_REQ: Int = 4 tlvWriter.put(ContextSpecificTag(TAG_ARG5_REQ), arg5) val TAG_ARG6_REQ: Int = 5 - tlvWriter.put(ContextSpecificTag(TAG_ARG6_REQ), arg6) + tlvWriter.put(ContextSpecificTag(TAG_ARG6_REQ), arg6) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -1047,100 +871,103 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_ARG1: Int = 0 var arg1_decoded: List? = null - + val TAG_ARG2: Int = 1 var arg2_decoded: List? = null - + val TAG_ARG3: Int = 2 var arg3_decoded: List? = null - + val TAG_ARG4: Int = 3 var arg4_decoded: List? = null - + val TAG_ARG5: Int = 4 var arg5_decoded: UByte? = null - + val TAG_ARG6: Int = 5 var arg6_decoded: Boolean? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_ARG1)) {arg1_decoded = buildList { - tlvReader.enterArray(tag) - while(!tlvReader.isEndOfContainer()) { - add(UnitTestingClusterNestedStructList.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - }} - - if (tag == ContextSpecificTag(TAG_ARG2)) {arg2_decoded = buildList { - tlvReader.enterArray(tag) - while(!tlvReader.isEndOfContainer()) { - add(UnitTestingClusterSimpleStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - }} - - if (tag == ContextSpecificTag(TAG_ARG3)) {arg3_decoded = buildList { - tlvReader.enterArray(tag) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - }} - - if (tag == ContextSpecificTag(TAG_ARG4)) {arg4_decoded = buildList { - tlvReader.enterArray(tag) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getBoolean(AnonymousTag)) - } - tlvReader.exitContainer() - }} - - if (tag == ContextSpecificTag(TAG_ARG5)) {arg5_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_ARG6)) {arg6_decoded = tlvReader.getBoolean(tag)} - - - else { + if (tag == ContextSpecificTag(TAG_ARG1)) { + arg1_decoded = + buildList { + tlvReader.enterArray(tag) + while (!tlvReader.isEndOfContainer()) { + add(UnitTestingClusterNestedStructList.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } + + if (tag == ContextSpecificTag(TAG_ARG2)) { + arg2_decoded = + buildList { + tlvReader.enterArray(tag) + while (!tlvReader.isEndOfContainer()) { + add(UnitTestingClusterSimpleStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } + + if (tag == ContextSpecificTag(TAG_ARG3)) { + arg3_decoded = + buildList { + tlvReader.enterArray(tag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + } + + if (tag == ContextSpecificTag(TAG_ARG4)) { + arg4_decoded = + buildList { + tlvReader.enterArray(tag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getBoolean(AnonymousTag)) + } + tlvReader.exitContainer() + } + } + + if (tag == ContextSpecificTag(TAG_ARG5)) { + arg5_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_ARG6)) { + arg6_decoded = tlvReader.getBoolean(tag) + } else { tlvReader.skipElement() } } - - if (arg1_decoded == null) { - throw IllegalStateException("arg1 not found in TLV") + throw IllegalStateException("arg1 not found in TLV") } - - + if (arg2_decoded == null) { - throw IllegalStateException("arg2 not found in TLV") + throw IllegalStateException("arg2 not found in TLV") } - - + if (arg3_decoded == null) { - throw IllegalStateException("arg3 not found in TLV") + throw IllegalStateException("arg3 not found in TLV") } - - + if (arg4_decoded == null) { - throw IllegalStateException("arg4 not found in TLV") + throw IllegalStateException("arg4 not found in TLV") } - - + if (arg5_decoded == null) { - throw IllegalStateException("arg5 not found in TLV") + throw IllegalStateException("arg5 not found in TLV") } - - + if (arg6_decoded == null) { - throw IllegalStateException("arg6 not found in TLV") + throw IllegalStateException("arg6 not found in TLV") } - tlvReader.exitContainer() @@ -1150,26 +977,28 @@ class AttributeListAttribute( arg3_decoded, arg4_decoded, arg5_decoded, - arg6_decoded + arg6_decoded, ) } - suspend fun testStructArgumentRequest(arg1: UnitTestingClusterSimpleStruct - ,timedInvokeTimeout: Duration? = null): BooleanResponse { + suspend fun testStructArgumentRequest( + arg1: UnitTestingClusterSimpleStruct, + timedInvokeTimeout: Duration? = null, + ): BooleanResponse { val commandId: UInt = 7u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_ARG1_REQ: Int = 0 - arg1.toTlv(ContextSpecificTag(TAG_ARG1_REQ), tlvWriter) + arg1.toTlv(ContextSpecificTag(TAG_ARG1_REQ), tlvWriter) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -1179,50 +1008,44 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_VALUE: Int = 0 var value_decoded: Boolean? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_VALUE)) {value_decoded = tlvReader.getBoolean(tag)} - - - else { + if (tag == ContextSpecificTag(TAG_VALUE)) { + value_decoded = tlvReader.getBoolean(tag) + } else { tlvReader.skipElement() } } - - if (value_decoded == null) { - throw IllegalStateException("value not found in TLV") + throw IllegalStateException("value not found in TLV") } - tlvReader.exitContainer() - return BooleanResponse( - value_decoded - ) + return BooleanResponse(value_decoded) } - suspend fun testNestedStructArgumentRequest(arg1: UnitTestingClusterNestedStruct - ,timedInvokeTimeout: Duration? = null): BooleanResponse { + suspend fun testNestedStructArgumentRequest( + arg1: UnitTestingClusterNestedStruct, + timedInvokeTimeout: Duration? = null, + ): BooleanResponse { val commandId: UInt = 8u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_ARG1_REQ: Int = 0 - arg1.toTlv(ContextSpecificTag(TAG_ARG1_REQ), tlvWriter) + arg1.toTlv(ContextSpecificTag(TAG_ARG1_REQ), tlvWriter) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -1232,36 +1055,30 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_VALUE: Int = 0 var value_decoded: Boolean? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_VALUE)) {value_decoded = tlvReader.getBoolean(tag)} - - - else { + if (tag == ContextSpecificTag(TAG_VALUE)) { + value_decoded = tlvReader.getBoolean(tag) + } else { tlvReader.skipElement() } } - - if (value_decoded == null) { - throw IllegalStateException("value not found in TLV") + throw IllegalStateException("value not found in TLV") } - tlvReader.exitContainer() - return BooleanResponse( - value_decoded - ) + return BooleanResponse(value_decoded) } - suspend fun testListStructArgumentRequest(arg1: List - ,timedInvokeTimeout: Duration? = null): BooleanResponse { + suspend fun testListStructArgumentRequest( + arg1: List, + timedInvokeTimeout: Duration? = null, + ): BooleanResponse { val commandId: UInt = 9u val tlvWriter = TlvWriter() @@ -1269,17 +1086,17 @@ class AttributeListAttribute( val TAG_ARG1_REQ: Int = 0 tlvWriter.startArray(ContextSpecificTag(TAG_ARG1_REQ)) - for (item in arg1.iterator()) { - item.toTlv(AnonymousTag, tlvWriter) - } - tlvWriter.endArray() + for (item in arg1.iterator()) { + item.toTlv(AnonymousTag, tlvWriter) + } + tlvWriter.endArray() tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -1289,36 +1106,30 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_VALUE: Int = 0 var value_decoded: Boolean? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_VALUE)) {value_decoded = tlvReader.getBoolean(tag)} - - - else { + if (tag == ContextSpecificTag(TAG_VALUE)) { + value_decoded = tlvReader.getBoolean(tag) + } else { tlvReader.skipElement() } } - - if (value_decoded == null) { - throw IllegalStateException("value not found in TLV") + throw IllegalStateException("value not found in TLV") } - tlvReader.exitContainer() - return BooleanResponse( - value_decoded - ) + return BooleanResponse(value_decoded) } - suspend fun testListInt8UArgumentRequest(arg1: List - ,timedInvokeTimeout: Duration? = null): BooleanResponse { + suspend fun testListInt8UArgumentRequest( + arg1: List, + timedInvokeTimeout: Duration? = null, + ): BooleanResponse { val commandId: UInt = 10u val tlvWriter = TlvWriter() @@ -1326,17 +1137,17 @@ class AttributeListAttribute( val TAG_ARG1_REQ: Int = 0 tlvWriter.startArray(ContextSpecificTag(TAG_ARG1_REQ)) - for (item in arg1.iterator()) { - tlvWriter.put(AnonymousTag, item) - } - tlvWriter.endArray() + for (item in arg1.iterator()) { + tlvWriter.put(AnonymousTag, item) + } + tlvWriter.endArray() tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -1346,50 +1157,44 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_VALUE: Int = 0 var value_decoded: Boolean? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_VALUE)) {value_decoded = tlvReader.getBoolean(tag)} - - - else { + if (tag == ContextSpecificTag(TAG_VALUE)) { + value_decoded = tlvReader.getBoolean(tag) + } else { tlvReader.skipElement() } } - - if (value_decoded == null) { - throw IllegalStateException("value not found in TLV") + throw IllegalStateException("value not found in TLV") } - tlvReader.exitContainer() - return BooleanResponse( - value_decoded - ) + return BooleanResponse(value_decoded) } - suspend fun testNestedStructListArgumentRequest(arg1: UnitTestingClusterNestedStructList - ,timedInvokeTimeout: Duration? = null): BooleanResponse { + suspend fun testNestedStructListArgumentRequest( + arg1: UnitTestingClusterNestedStructList, + timedInvokeTimeout: Duration? = null, + ): BooleanResponse { val commandId: UInt = 11u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_ARG1_REQ: Int = 0 - arg1.toTlv(ContextSpecificTag(TAG_ARG1_REQ), tlvWriter) + arg1.toTlv(ContextSpecificTag(TAG_ARG1_REQ), tlvWriter) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -1399,36 +1204,30 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_VALUE: Int = 0 var value_decoded: Boolean? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_VALUE)) {value_decoded = tlvReader.getBoolean(tag)} - - - else { + if (tag == ContextSpecificTag(TAG_VALUE)) { + value_decoded = tlvReader.getBoolean(tag) + } else { tlvReader.skipElement() } } - - if (value_decoded == null) { - throw IllegalStateException("value not found in TLV") + throw IllegalStateException("value not found in TLV") } - tlvReader.exitContainer() - return BooleanResponse( - value_decoded - ) + return BooleanResponse(value_decoded) } - suspend fun testListNestedStructListArgumentRequest(arg1: List - ,timedInvokeTimeout: Duration? = null): BooleanResponse { + suspend fun testListNestedStructListArgumentRequest( + arg1: List, + timedInvokeTimeout: Duration? = null, + ): BooleanResponse { val commandId: UInt = 12u val tlvWriter = TlvWriter() @@ -1436,17 +1235,17 @@ class AttributeListAttribute( val TAG_ARG1_REQ: Int = 0 tlvWriter.startArray(ContextSpecificTag(TAG_ARG1_REQ)) - for (item in arg1.iterator()) { - item.toTlv(AnonymousTag, tlvWriter) - } - tlvWriter.endArray() + for (item in arg1.iterator()) { + item.toTlv(AnonymousTag, tlvWriter) + } + tlvWriter.endArray() tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -1456,36 +1255,30 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_VALUE: Int = 0 var value_decoded: Boolean? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_VALUE)) {value_decoded = tlvReader.getBoolean(tag)} - - - else { + if (tag == ContextSpecificTag(TAG_VALUE)) { + value_decoded = tlvReader.getBoolean(tag) + } else { tlvReader.skipElement() } } - - if (value_decoded == null) { - throw IllegalStateException("value not found in TLV") + throw IllegalStateException("value not found in TLV") } - tlvReader.exitContainer() - return BooleanResponse( - value_decoded - ) + return BooleanResponse(value_decoded) } - suspend fun testListInt8UReverseRequest(arg1: List - ,timedInvokeTimeout: Duration? = null): TestListInt8UReverseResponse { + suspend fun testListInt8UReverseRequest( + arg1: List, + timedInvokeTimeout: Duration? = null, + ): TestListInt8UReverseResponse { val commandId: UInt = 13u val tlvWriter = TlvWriter() @@ -1493,17 +1286,17 @@ class AttributeListAttribute( val TAG_ARG1_REQ: Int = 0 tlvWriter.startArray(ContextSpecificTag(TAG_ARG1_REQ)) - for (item in arg1.iterator()) { - tlvWriter.put(AnonymousTag, item) - } - tlvWriter.endArray() + for (item in arg1.iterator()) { + tlvWriter.put(AnonymousTag, item) + } + tlvWriter.endArray() tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -1513,43 +1306,38 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_ARG1: Int = 0 var arg1_decoded: List? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_ARG1)) {arg1_decoded = buildList { - tlvReader.enterArray(tag) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - }} - - - else { + if (tag == ContextSpecificTag(TAG_ARG1)) { + arg1_decoded = + buildList { + tlvReader.enterArray(tag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { tlvReader.skipElement() } } - - if (arg1_decoded == null) { - throw IllegalStateException("arg1 not found in TLV") + throw IllegalStateException("arg1 not found in TLV") } - tlvReader.exitContainer() - return TestListInt8UReverseResponse( - arg1_decoded - ) + return TestListInt8UReverseResponse(arg1_decoded) } - suspend fun testEnumsRequest(arg1: UShort - ,arg2: UByte - ,timedInvokeTimeout: Duration? = null): TestEnumsResponse { + suspend fun testEnumsRequest( + arg1: UShort, + arg2: UByte, + timedInvokeTimeout: Duration? = null, + ): TestEnumsResponse { val commandId: UInt = 14u val tlvWriter = TlvWriter() @@ -1559,14 +1347,14 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_ARG1_REQ), arg1) val TAG_ARG2_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_ARG2_REQ), arg2) + tlvWriter.put(ContextSpecificTag(TAG_ARG2_REQ), arg2) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -1576,63 +1364,55 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_ARG1: Int = 0 var arg1_decoded: UShort? = null - + val TAG_ARG2: Int = 1 var arg2_decoded: UByte? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_ARG1)) {arg1_decoded = tlvReader.getUShort(tag)} - - if (tag == ContextSpecificTag(TAG_ARG2)) {arg2_decoded = tlvReader.getUByte(tag)} - + if (tag == ContextSpecificTag(TAG_ARG1)) { + arg1_decoded = tlvReader.getUShort(tag) + } - else { + if (tag == ContextSpecificTag(TAG_ARG2)) { + arg2_decoded = tlvReader.getUByte(tag) + } else { tlvReader.skipElement() } } - - if (arg1_decoded == null) { - throw IllegalStateException("arg1 not found in TLV") + throw IllegalStateException("arg1 not found in TLV") } - - + if (arg2_decoded == null) { - throw IllegalStateException("arg2 not found in TLV") + throw IllegalStateException("arg2 not found in TLV") } - tlvReader.exitContainer() - return TestEnumsResponse( - arg1_decoded, - arg2_decoded - ) + return TestEnumsResponse(arg1_decoded, arg2_decoded) } - suspend fun testNullableOptionalRequest(arg1: UByte? - ,timedInvokeTimeout: Duration? = null): TestNullableOptionalResponse { + suspend fun testNullableOptionalRequest( + arg1: UByte?, + timedInvokeTimeout: Duration? = null, + ): TestNullableOptionalResponse { val commandId: UInt = 15u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_ARG1_REQ: Int = 0 - arg1?.let { - tlvWriter.put(ContextSpecificTag(TAG_ARG1_REQ), arg1) - } + arg1?.let { tlvWriter.put(ContextSpecificTag(TAG_ARG1_REQ), arg1) } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -1642,82 +1422,76 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_WAS_PRESENT: Int = 0 var wasPresent_decoded: Boolean? = null - + val TAG_WAS_NULL: Int = 1 var wasNull_decoded: Boolean? = null - + val TAG_VALUE: Int = 2 var value_decoded: UByte? = null - + val TAG_ORIGINAL_VALUE: Int = 3 var originalValue_decoded: UByte? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_WAS_PRESENT)) {wasPresent_decoded = tlvReader.getBoolean(tag)} - - if (tag == ContextSpecificTag(TAG_WAS_NULL)) {wasNull_decoded = + if (tag == ContextSpecificTag(TAG_WAS_PRESENT)) { + wasPresent_decoded = tlvReader.getBoolean(tag) + } + + if (tag == ContextSpecificTag(TAG_WAS_NULL)) { + wasNull_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getBoolean(tag) - } else { - null - } - }} - - if (tag == ContextSpecificTag(TAG_VALUE)) {value_decoded = + tlvReader.getBoolean(tag) + } else { + null + } + } + } + + if (tag == ContextSpecificTag(TAG_VALUE)) { + value_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getUByte(tag) - } else { - null - } - }} - - if (tag == ContextSpecificTag(TAG_ORIGINAL_VALUE)) {originalValue_decoded = + tlvReader.getUByte(tag) + } else { + null + } + } + } + + if (tag == ContextSpecificTag(TAG_ORIGINAL_VALUE)) { + originalValue_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(tag)) { - tlvReader.getUByte(tag) - } else { - null - } - } else { - tlvReader.getNull(tag) - null - } - }} - - - else { + if (tlvReader.isNextTag(tag)) { + tlvReader.getUByte(tag) + } else { + null + } + } else { + tlvReader.getNull(tag) + null + } + } + } else { tlvReader.skipElement() } } - - if (wasPresent_decoded == null) { - throw IllegalStateException("wasPresent not found in TLV") + throw IllegalStateException("wasPresent not found in TLV") } - - - - - - - tlvReader.exitContainer() @@ -1725,37 +1499,35 @@ class AttributeListAttribute( wasPresent_decoded, wasNull_decoded, value_decoded, - originalValue_decoded - ) - } - - suspend fun testComplexNullableOptionalRequest(nullableInt: UShort? - ,optionalInt: UShort? - ,nullableOptionalInt: UShort? - ,nullableString: String? - ,optionalString: String? - ,nullableOptionalString: String? - ,nullableStruct: UnitTestingClusterSimpleStruct? - ,optionalStruct: UnitTestingClusterSimpleStruct? - ,nullableOptionalStruct: UnitTestingClusterSimpleStruct? - ,nullableList: List? - ,optionalList: List? - ,nullableOptionalList: List? - ,timedInvokeTimeout: Duration? = null): TestComplexNullableOptionalResponse { + originalValue_decoded, + ) + } + + suspend fun testComplexNullableOptionalRequest( + nullableInt: UShort?, + optionalInt: UShort?, + nullableOptionalInt: UShort?, + nullableString: String?, + optionalString: String?, + nullableOptionalString: String?, + nullableStruct: UnitTestingClusterSimpleStruct?, + optionalStruct: UnitTestingClusterSimpleStruct?, + nullableOptionalStruct: UnitTestingClusterSimpleStruct?, + nullableList: List?, + optionalList: List?, + nullableOptionalList: List?, + timedInvokeTimeout: Duration? = null, + ): TestComplexNullableOptionalResponse { val commandId: UInt = 16u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_NULLABLE_INT_REQ: Int = 0 - nullableInt?.let { - tlvWriter.put(ContextSpecificTag(TAG_NULLABLE_INT_REQ), nullableInt) - } + nullableInt?.let { tlvWriter.put(ContextSpecificTag(TAG_NULLABLE_INT_REQ), nullableInt) } val TAG_OPTIONAL_INT_REQ: Int = 1 - optionalInt?.let { - tlvWriter.put(ContextSpecificTag(TAG_OPTIONAL_INT_REQ), optionalInt) - } + optionalInt?.let { tlvWriter.put(ContextSpecificTag(TAG_OPTIONAL_INT_REQ), optionalInt) } val TAG_NULLABLE_OPTIONAL_INT_REQ: Int = 2 nullableOptionalInt?.let { @@ -1817,14 +1589,14 @@ class AttributeListAttribute( tlvWriter.put(AnonymousTag, item) } tlvWriter.endArray() - } + } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -1834,426 +1606,431 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_NULLABLE_INT_WAS_NULL: Int = 0 var nullableIntWasNull_decoded: Boolean? = null - + val TAG_NULLABLE_INT_VALUE: Int = 1 var nullableIntValue_decoded: UShort? = null - + val TAG_OPTIONAL_INT_WAS_PRESENT: Int = 2 var optionalIntWasPresent_decoded: Boolean? = null - + val TAG_OPTIONAL_INT_VALUE: Int = 3 var optionalIntValue_decoded: UShort? = null - + val TAG_NULLABLE_OPTIONAL_INT_WAS_PRESENT: Int = 4 var nullableOptionalIntWasPresent_decoded: Boolean? = null - + val TAG_NULLABLE_OPTIONAL_INT_WAS_NULL: Int = 5 var nullableOptionalIntWasNull_decoded: Boolean? = null - + val TAG_NULLABLE_OPTIONAL_INT_VALUE: Int = 6 var nullableOptionalIntValue_decoded: UShort? = null - + val TAG_NULLABLE_STRING_WAS_NULL: Int = 7 var nullableStringWasNull_decoded: Boolean? = null - + val TAG_NULLABLE_STRING_VALUE: Int = 8 var nullableStringValue_decoded: String? = null - + val TAG_OPTIONAL_STRING_WAS_PRESENT: Int = 9 var optionalStringWasPresent_decoded: Boolean? = null - + val TAG_OPTIONAL_STRING_VALUE: Int = 10 var optionalStringValue_decoded: String? = null - + val TAG_NULLABLE_OPTIONAL_STRING_WAS_PRESENT: Int = 11 var nullableOptionalStringWasPresent_decoded: Boolean? = null - + val TAG_NULLABLE_OPTIONAL_STRING_WAS_NULL: Int = 12 var nullableOptionalStringWasNull_decoded: Boolean? = null - + val TAG_NULLABLE_OPTIONAL_STRING_VALUE: Int = 13 var nullableOptionalStringValue_decoded: String? = null - + val TAG_NULLABLE_STRUCT_WAS_NULL: Int = 14 var nullableStructWasNull_decoded: Boolean? = null - + val TAG_NULLABLE_STRUCT_VALUE: Int = 15 var nullableStructValue_decoded: UnitTestingClusterSimpleStruct? = null - + val TAG_OPTIONAL_STRUCT_WAS_PRESENT: Int = 16 var optionalStructWasPresent_decoded: Boolean? = null - + val TAG_OPTIONAL_STRUCT_VALUE: Int = 17 var optionalStructValue_decoded: UnitTestingClusterSimpleStruct? = null - + val TAG_NULLABLE_OPTIONAL_STRUCT_WAS_PRESENT: Int = 18 var nullableOptionalStructWasPresent_decoded: Boolean? = null - + val TAG_NULLABLE_OPTIONAL_STRUCT_WAS_NULL: Int = 19 var nullableOptionalStructWasNull_decoded: Boolean? = null - + val TAG_NULLABLE_OPTIONAL_STRUCT_VALUE: Int = 20 var nullableOptionalStructValue_decoded: UnitTestingClusterSimpleStruct? = null - + val TAG_NULLABLE_LIST_WAS_NULL: Int = 21 var nullableListWasNull_decoded: Boolean? = null - + val TAG_NULLABLE_LIST_VALUE: Int = 22 var nullableListValue_decoded: List? = null - + val TAG_OPTIONAL_LIST_WAS_PRESENT: Int = 23 var optionalListWasPresent_decoded: Boolean? = null - + val TAG_OPTIONAL_LIST_VALUE: Int = 24 var optionalListValue_decoded: List? = null - + val TAG_NULLABLE_OPTIONAL_LIST_WAS_PRESENT: Int = 25 var nullableOptionalListWasPresent_decoded: Boolean? = null - + val TAG_NULLABLE_OPTIONAL_LIST_WAS_NULL: Int = 26 var nullableOptionalListWasNull_decoded: Boolean? = null - + val TAG_NULLABLE_OPTIONAL_LIST_VALUE: Int = 27 var nullableOptionalListValue_decoded: List? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_NULLABLE_INT_WAS_NULL)) {nullableIntWasNull_decoded = tlvReader.getBoolean(tag)} - - if (tag == ContextSpecificTag(TAG_NULLABLE_INT_VALUE)) {nullableIntValue_decoded = + if (tag == ContextSpecificTag(TAG_NULLABLE_INT_WAS_NULL)) { + nullableIntWasNull_decoded = tlvReader.getBoolean(tag) + } + + if (tag == ContextSpecificTag(TAG_NULLABLE_INT_VALUE)) { + nullableIntValue_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getUShort(tag) - } else { - null - } - }} - - if (tag == ContextSpecificTag(TAG_OPTIONAL_INT_WAS_PRESENT)) {optionalIntWasPresent_decoded = tlvReader.getBoolean(tag)} - - if (tag == ContextSpecificTag(TAG_OPTIONAL_INT_VALUE)) {optionalIntValue_decoded = + tlvReader.getUShort(tag) + } else { + null + } + } + } + + if (tag == ContextSpecificTag(TAG_OPTIONAL_INT_WAS_PRESENT)) { + optionalIntWasPresent_decoded = tlvReader.getBoolean(tag) + } + + if (tag == ContextSpecificTag(TAG_OPTIONAL_INT_VALUE)) { + optionalIntValue_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getUShort(tag) - } else { - null - } - }} - - if (tag == ContextSpecificTag(TAG_NULLABLE_OPTIONAL_INT_WAS_PRESENT)) {nullableOptionalIntWasPresent_decoded = tlvReader.getBoolean(tag)} - - if (tag == ContextSpecificTag(TAG_NULLABLE_OPTIONAL_INT_WAS_NULL)) {nullableOptionalIntWasNull_decoded = + tlvReader.getUShort(tag) + } else { + null + } + } + } + + if (tag == ContextSpecificTag(TAG_NULLABLE_OPTIONAL_INT_WAS_PRESENT)) { + nullableOptionalIntWasPresent_decoded = tlvReader.getBoolean(tag) + } + + if (tag == ContextSpecificTag(TAG_NULLABLE_OPTIONAL_INT_WAS_NULL)) { + nullableOptionalIntWasNull_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getBoolean(tag) - } else { - null - } - }} - - if (tag == ContextSpecificTag(TAG_NULLABLE_OPTIONAL_INT_VALUE)) {nullableOptionalIntValue_decoded = + tlvReader.getBoolean(tag) + } else { + null + } + } + } + + if (tag == ContextSpecificTag(TAG_NULLABLE_OPTIONAL_INT_VALUE)) { + nullableOptionalIntValue_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getUShort(tag) - } else { - null - } - }} - - if (tag == ContextSpecificTag(TAG_NULLABLE_STRING_WAS_NULL)) {nullableStringWasNull_decoded = tlvReader.getBoolean(tag)} - - if (tag == ContextSpecificTag(TAG_NULLABLE_STRING_VALUE)) {nullableStringValue_decoded = + tlvReader.getUShort(tag) + } else { + null + } + } + } + + if (tag == ContextSpecificTag(TAG_NULLABLE_STRING_WAS_NULL)) { + nullableStringWasNull_decoded = tlvReader.getBoolean(tag) + } + + if (tag == ContextSpecificTag(TAG_NULLABLE_STRING_VALUE)) { + nullableStringValue_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - }} - - if (tag == ContextSpecificTag(TAG_OPTIONAL_STRING_WAS_PRESENT)) {optionalStringWasPresent_decoded = tlvReader.getBoolean(tag)} - - if (tag == ContextSpecificTag(TAG_OPTIONAL_STRING_VALUE)) {optionalStringValue_decoded = + tlvReader.getString(tag) + } else { + null + } + } + } + + if (tag == ContextSpecificTag(TAG_OPTIONAL_STRING_WAS_PRESENT)) { + optionalStringWasPresent_decoded = tlvReader.getBoolean(tag) + } + + if (tag == ContextSpecificTag(TAG_OPTIONAL_STRING_VALUE)) { + optionalStringValue_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - }} - - if (tag == ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRING_WAS_PRESENT)) {nullableOptionalStringWasPresent_decoded = tlvReader.getBoolean(tag)} - - if (tag == ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRING_WAS_NULL)) {nullableOptionalStringWasNull_decoded = + tlvReader.getString(tag) + } else { + null + } + } + } + + if (tag == ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRING_WAS_PRESENT)) { + nullableOptionalStringWasPresent_decoded = tlvReader.getBoolean(tag) + } + + if (tag == ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRING_WAS_NULL)) { + nullableOptionalStringWasNull_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getBoolean(tag) - } else { - null - } - }} - - if (tag == ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRING_VALUE)) {nullableOptionalStringValue_decoded = + tlvReader.getBoolean(tag) + } else { + null + } + } + } + + if (tag == ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRING_VALUE)) { + nullableOptionalStringValue_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - }} - - if (tag == ContextSpecificTag(TAG_NULLABLE_STRUCT_WAS_NULL)) {nullableStructWasNull_decoded = tlvReader.getBoolean(tag)} - - if (tag == ContextSpecificTag(TAG_NULLABLE_STRUCT_VALUE)) {nullableStructValue_decoded = + tlvReader.getString(tag) + } else { + null + } + } + } + + if (tag == ContextSpecificTag(TAG_NULLABLE_STRUCT_WAS_NULL)) { + nullableStructWasNull_decoded = tlvReader.getBoolean(tag) + } + + if (tag == ContextSpecificTag(TAG_NULLABLE_STRUCT_VALUE)) { + nullableStructValue_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - UnitTestingClusterSimpleStruct.fromTlv(tag, tlvReader) - } else { - null - } - }} - - if (tag == ContextSpecificTag(TAG_OPTIONAL_STRUCT_WAS_PRESENT)) {optionalStructWasPresent_decoded = tlvReader.getBoolean(tag)} - - if (tag == ContextSpecificTag(TAG_OPTIONAL_STRUCT_VALUE)) {optionalStructValue_decoded = + UnitTestingClusterSimpleStruct.fromTlv(tag, tlvReader) + } else { + null + } + } + } + + if (tag == ContextSpecificTag(TAG_OPTIONAL_STRUCT_WAS_PRESENT)) { + optionalStructWasPresent_decoded = tlvReader.getBoolean(tag) + } + + if (tag == ContextSpecificTag(TAG_OPTIONAL_STRUCT_VALUE)) { + optionalStructValue_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - UnitTestingClusterSimpleStruct.fromTlv(tag, tlvReader) - } else { - null - } - }} - - if (tag == ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRUCT_WAS_PRESENT)) {nullableOptionalStructWasPresent_decoded = tlvReader.getBoolean(tag)} - - if (tag == ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRUCT_WAS_NULL)) {nullableOptionalStructWasNull_decoded = + UnitTestingClusterSimpleStruct.fromTlv(tag, tlvReader) + } else { + null + } + } + } + + if (tag == ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRUCT_WAS_PRESENT)) { + nullableOptionalStructWasPresent_decoded = tlvReader.getBoolean(tag) + } + + if (tag == ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRUCT_WAS_NULL)) { + nullableOptionalStructWasNull_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getBoolean(tag) - } else { - null - } - }} - - if (tag == ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRUCT_VALUE)) {nullableOptionalStructValue_decoded = + tlvReader.getBoolean(tag) + } else { + null + } + } + } + + if (tag == ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRUCT_VALUE)) { + nullableOptionalStructValue_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - UnitTestingClusterSimpleStruct.fromTlv(tag, tlvReader) - } else { - null - } - }} - - if (tag == ContextSpecificTag(TAG_NULLABLE_LIST_WAS_NULL)) {nullableListWasNull_decoded = tlvReader.getBoolean(tag)} - - if (tag == ContextSpecificTag(TAG_NULLABLE_LIST_VALUE)) {nullableListValue_decoded = + UnitTestingClusterSimpleStruct.fromTlv(tag, tlvReader) + } else { + null + } + } + } + + if (tag == ContextSpecificTag(TAG_NULLABLE_LIST_WAS_NULL)) { + nullableListWasNull_decoded = tlvReader.getBoolean(tag) + } + + if (tag == ContextSpecificTag(TAG_NULLABLE_LIST_VALUE)) { + nullableListValue_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 - } - }} - - if (tag == ContextSpecificTag(TAG_OPTIONAL_LIST_WAS_PRESENT)) {optionalListWasPresent_decoded = tlvReader.getBoolean(tag)} - - if (tag == ContextSpecificTag(TAG_OPTIONAL_LIST_VALUE)) {optionalListValue_decoded = + buildList { + tlvReader.enterArray(tag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null + } + } + } + + if (tag == ContextSpecificTag(TAG_OPTIONAL_LIST_WAS_PRESENT)) { + optionalListWasPresent_decoded = tlvReader.getBoolean(tag) + } + + if (tag == ContextSpecificTag(TAG_OPTIONAL_LIST_VALUE)) { + optionalListValue_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 - } - }} - - if (tag == ContextSpecificTag(TAG_NULLABLE_OPTIONAL_LIST_WAS_PRESENT)) {nullableOptionalListWasPresent_decoded = tlvReader.getBoolean(tag)} - - if (tag == ContextSpecificTag(TAG_NULLABLE_OPTIONAL_LIST_WAS_NULL)) {nullableOptionalListWasNull_decoded = + buildList { + tlvReader.enterArray(tag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null + } + } + } + + if (tag == ContextSpecificTag(TAG_NULLABLE_OPTIONAL_LIST_WAS_PRESENT)) { + nullableOptionalListWasPresent_decoded = tlvReader.getBoolean(tag) + } + + if (tag == ContextSpecificTag(TAG_NULLABLE_OPTIONAL_LIST_WAS_NULL)) { + nullableOptionalListWasNull_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getBoolean(tag) - } else { - null - } - }} - - if (tag == ContextSpecificTag(TAG_NULLABLE_OPTIONAL_LIST_VALUE)) {nullableOptionalListValue_decoded = + tlvReader.getBoolean(tag) + } else { + null + } + } + } + + if (tag == ContextSpecificTag(TAG_NULLABLE_OPTIONAL_LIST_VALUE)) { + nullableOptionalListValue_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 { + if (tlvReader.isNextTag(tag)) { + buildList { + tlvReader.enterArray(tag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + null + } + } + } else { tlvReader.skipElement() } } - - if (nullableIntWasNull_decoded == null) { - throw IllegalStateException("nullableIntWasNull not found in TLV") + throw IllegalStateException("nullableIntWasNull not found in TLV") } - - - - + if (optionalIntWasPresent_decoded == null) { - throw IllegalStateException("optionalIntWasPresent not found in TLV") + throw IllegalStateException("optionalIntWasPresent not found in TLV") } - - - - + if (nullableOptionalIntWasPresent_decoded == null) { - throw IllegalStateException("nullableOptionalIntWasPresent not found in TLV") - } - - - - - - + throw IllegalStateException("nullableOptionalIntWasPresent not found in TLV") + } + if (nullableStringWasNull_decoded == null) { - throw IllegalStateException("nullableStringWasNull not found in TLV") + throw IllegalStateException("nullableStringWasNull not found in TLV") } - - - - + if (optionalStringWasPresent_decoded == null) { - throw IllegalStateException("optionalStringWasPresent not found in TLV") + throw IllegalStateException("optionalStringWasPresent not found in TLV") } - - - - + if (nullableOptionalStringWasPresent_decoded == null) { - throw IllegalStateException("nullableOptionalStringWasPresent not found in TLV") - } - - - - - - + throw IllegalStateException("nullableOptionalStringWasPresent not found in TLV") + } + if (nullableStructWasNull_decoded == null) { - throw IllegalStateException("nullableStructWasNull not found in TLV") + throw IllegalStateException("nullableStructWasNull not found in TLV") } - - - - + if (optionalStructWasPresent_decoded == null) { - throw IllegalStateException("optionalStructWasPresent not found in TLV") + throw IllegalStateException("optionalStructWasPresent not found in TLV") } - - - - + if (nullableOptionalStructWasPresent_decoded == null) { - throw IllegalStateException("nullableOptionalStructWasPresent not found in TLV") - } - - - - - - + throw IllegalStateException("nullableOptionalStructWasPresent not found in TLV") + } + if (nullableListWasNull_decoded == null) { - throw IllegalStateException("nullableListWasNull not found in TLV") + throw IllegalStateException("nullableListWasNull not found in TLV") } - - - - + if (optionalListWasPresent_decoded == null) { - throw IllegalStateException("optionalListWasPresent not found in TLV") + throw IllegalStateException("optionalListWasPresent not found in TLV") } - - - - + if (nullableOptionalListWasPresent_decoded == null) { - throw IllegalStateException("nullableOptionalListWasPresent not found in TLV") + throw IllegalStateException("nullableOptionalListWasPresent not found in TLV") } - - - - - tlvReader.exitContainer() @@ -2285,26 +2062,28 @@ class AttributeListAttribute( optionalListValue_decoded, nullableOptionalListWasPresent_decoded, nullableOptionalListWasNull_decoded, - nullableOptionalListValue_decoded + nullableOptionalListValue_decoded, ) } - suspend fun simpleStructEchoRequest(arg1: UnitTestingClusterSimpleStruct - ,timedInvokeTimeout: Duration? = null): SimpleStructResponse { + suspend fun simpleStructEchoRequest( + arg1: UnitTestingClusterSimpleStruct, + timedInvokeTimeout: Duration? = null, + ): SimpleStructResponse { val commandId: UInt = 17u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_ARG1_REQ: Int = 0 - arg1.toTlv(ContextSpecificTag(TAG_ARG1_REQ), tlvWriter) + arg1.toTlv(ContextSpecificTag(TAG_ARG1_REQ), tlvWriter) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -2314,80 +2093,74 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_ARG1: Int = 0 var arg1_decoded: UnitTestingClusterSimpleStruct? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_ARG1)) {arg1_decoded = UnitTestingClusterSimpleStruct.fromTlv(tag, tlvReader)} - - - else { + if (tag == ContextSpecificTag(TAG_ARG1)) { + arg1_decoded = UnitTestingClusterSimpleStruct.fromTlv(tag, tlvReader) + } else { tlvReader.skipElement() } } - - if (arg1_decoded == null) { - throw IllegalStateException("arg1 not found in TLV") + throw IllegalStateException("arg1 not found in TLV") } - tlvReader.exitContainer() - return SimpleStructResponse( - arg1_decoded - ) + return SimpleStructResponse(arg1_decoded) } suspend fun timedInvokeRequest(timedInvokeTimeout: Duration) { val commandId: UInt = 18u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun testSimpleOptionalArgumentRequest(arg1: Boolean? - ,timedInvokeTimeout: Duration? = null) { + suspend fun testSimpleOptionalArgumentRequest( + arg1: Boolean?, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 19u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_ARG1_REQ: Int = 0 - arg1?.let { - tlvWriter.put(ContextSpecificTag(TAG_ARG1_REQ), arg1) - } + arg1?.let { tlvWriter.put(ContextSpecificTag(TAG_ARG1_REQ), arg1) } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun testEmitTestEventRequest(arg1: UByte - ,arg2: UByte - ,arg3: Boolean - ,timedInvokeTimeout: Duration? = null): TestEmitTestEventResponse { + suspend fun testEmitTestEventRequest( + arg1: UByte, + arg2: UByte, + arg3: Boolean, + timedInvokeTimeout: Duration? = null, + ): TestEmitTestEventResponse { val commandId: UInt = 20u val tlvWriter = TlvWriter() @@ -2400,14 +2173,14 @@ class AttributeListAttribute( tlvWriter.put(ContextSpecificTag(TAG_ARG2_REQ), arg2) val TAG_ARG3_REQ: Int = 2 - tlvWriter.put(ContextSpecificTag(TAG_ARG3_REQ), arg3) + tlvWriter.put(ContextSpecificTag(TAG_ARG3_REQ), arg3) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -2417,50 +2190,44 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_VALUE: Int = 0 var value_decoded: ULong? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_VALUE)) {value_decoded = tlvReader.getULong(tag)} - - - else { + if (tag == ContextSpecificTag(TAG_VALUE)) { + value_decoded = tlvReader.getULong(tag) + } else { tlvReader.skipElement() } } - - if (value_decoded == null) { - throw IllegalStateException("value not found in TLV") + throw IllegalStateException("value not found in TLV") } - tlvReader.exitContainer() - return TestEmitTestEventResponse( - value_decoded - ) + return TestEmitTestEventResponse(value_decoded) } - suspend fun testEmitTestFabricScopedEventRequest(arg1: UByte - ,timedInvokeTimeout: Duration? = null): TestEmitTestFabricScopedEventResponse { + suspend fun testEmitTestFabricScopedEventRequest( + arg1: UByte, + timedInvokeTimeout: Duration? = null, + ): TestEmitTestFabricScopedEventResponse { val commandId: UInt = 21u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_ARG1_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_ARG1_REQ), arg1) + tlvWriter.put(ContextSpecificTag(TAG_ARG1_REQ), arg1) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -2470,58 +2237,55 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_VALUE: Int = 0 var value_decoded: ULong? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_VALUE)) {value_decoded = tlvReader.getULong(tag)} - - - else { + if (tag == ContextSpecificTag(TAG_VALUE)) { + value_decoded = tlvReader.getULong(tag) + } else { tlvReader.skipElement() } } - - if (value_decoded == null) { - throw IllegalStateException("value not found in TLV") + throw IllegalStateException("value not found in TLV") } - tlvReader.exitContainer() - return TestEmitTestFabricScopedEventResponse( - value_decoded - ) + return TestEmitTestFabricScopedEventResponse(value_decoded) } - suspend fun testBatchHelperRequest(sleepBeforeResponseTimeMs: UShort - ,sizeOfResponseBuffer: UShort - ,fillCharacter: UByte - ,timedInvokeTimeout: Duration? = null): TestBatchHelperResponse { + suspend fun testBatchHelperRequest( + sleepBeforeResponseTimeMs: UShort, + sizeOfResponseBuffer: UShort, + fillCharacter: UByte, + timedInvokeTimeout: Duration? = null, + ): TestBatchHelperResponse { val commandId: UInt = 22u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_SLEEP_BEFORE_RESPONSE_TIME_MS_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_SLEEP_BEFORE_RESPONSE_TIME_MS_REQ), sleepBeforeResponseTimeMs) + tlvWriter.put( + ContextSpecificTag(TAG_SLEEP_BEFORE_RESPONSE_TIME_MS_REQ), + sleepBeforeResponseTimeMs, + ) val TAG_SIZE_OF_RESPONSE_BUFFER_REQ: Int = 1 tlvWriter.put(ContextSpecificTag(TAG_SIZE_OF_RESPONSE_BUFFER_REQ), sizeOfResponseBuffer) val TAG_FILL_CHARACTER_REQ: Int = 2 - tlvWriter.put(ContextSpecificTag(TAG_FILL_CHARACTER_REQ), fillCharacter) + tlvWriter.put(ContextSpecificTag(TAG_FILL_CHARACTER_REQ), fillCharacter) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -2531,58 +2295,55 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_BUFFER: Int = 0 var buffer_decoded: ByteArray? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_BUFFER)) {buffer_decoded = tlvReader.getByteArray(tag)} - - - else { + if (tag == ContextSpecificTag(TAG_BUFFER)) { + buffer_decoded = tlvReader.getByteArray(tag) + } else { tlvReader.skipElement() } } - - if (buffer_decoded == null) { - throw IllegalStateException("buffer not found in TLV") + throw IllegalStateException("buffer not found in TLV") } - tlvReader.exitContainer() - return TestBatchHelperResponse( - buffer_decoded - ) + return TestBatchHelperResponse(buffer_decoded) } - suspend fun testSecondBatchHelperRequest(sleepBeforeResponseTimeMs: UShort - ,sizeOfResponseBuffer: UShort - ,fillCharacter: UByte - ,timedInvokeTimeout: Duration? = null): TestBatchHelperResponse { + suspend fun testSecondBatchHelperRequest( + sleepBeforeResponseTimeMs: UShort, + sizeOfResponseBuffer: UShort, + fillCharacter: UByte, + timedInvokeTimeout: Duration? = null, + ): TestBatchHelperResponse { val commandId: UInt = 23u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_SLEEP_BEFORE_RESPONSE_TIME_MS_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_SLEEP_BEFORE_RESPONSE_TIME_MS_REQ), sleepBeforeResponseTimeMs) + tlvWriter.put( + ContextSpecificTag(TAG_SLEEP_BEFORE_RESPONSE_TIME_MS_REQ), + sleepBeforeResponseTimeMs, + ) val TAG_SIZE_OF_RESPONSE_BUFFER_REQ: Int = 1 tlvWriter.put(ContextSpecificTag(TAG_SIZE_OF_RESPONSE_BUFFER_REQ), sizeOfResponseBuffer) val TAG_FILL_CHARACTER_REQ: Int = 2 - tlvWriter.put(ContextSpecificTag(TAG_FILL_CHARACTER_REQ), fillCharacter) + tlvWriter.put(ContextSpecificTag(TAG_FILL_CHARACTER_REQ), fillCharacter) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -2592,50 +2353,44 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_BUFFER: Int = 0 var buffer_decoded: ByteArray? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_BUFFER)) {buffer_decoded = tlvReader.getByteArray(tag)} - - - else { + if (tag == ContextSpecificTag(TAG_BUFFER)) { + buffer_decoded = tlvReader.getByteArray(tag) + } else { tlvReader.skipElement() } } - - if (buffer_decoded == null) { - throw IllegalStateException("buffer not found in TLV") + throw IllegalStateException("buffer not found in TLV") } - tlvReader.exitContainer() - return TestBatchHelperResponse( - buffer_decoded - ) + return TestBatchHelperResponse(buffer_decoded) } - suspend fun stringEchoRequest(payload: ByteArray - ,timedInvokeTimeout: Duration? = null): StringEchoResponse { + suspend fun stringEchoRequest( + payload: ByteArray, + timedInvokeTimeout: Duration? = null, + ): StringEchoResponse { val commandId: UInt = 24u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_PAYLOAD_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_PAYLOAD_REQ), payload) + tlvWriter.put(ContextSpecificTag(TAG_PAYLOAD_REQ), payload) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -2645,37 +2400,31 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_PAYLOAD: Int = 0 var payload_decoded: ByteArray? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_PAYLOAD)) {payload_decoded = tlvReader.getByteArray(tag)} - - - else { + if (tag == ContextSpecificTag(TAG_PAYLOAD)) { + payload_decoded = tlvReader.getByteArray(tag) + } else { tlvReader.skipElement() } } - - if (payload_decoded == null) { - throw IllegalStateException("payload not found in TLV") + throw IllegalStateException("payload not found in TLV") } - tlvReader.exitContainer() - return StringEchoResponse( - payload_decoded - ) + return StringEchoResponse(payload_decoded) } - suspend fun globalEchoRequest(field1: UnitTestingClusterTestGlobalStruct - ,field2: UByte - ,timedInvokeTimeout: Duration? = null): GlobalEchoResponse { + suspend fun globalEchoRequest( + field1: UnitTestingClusterTestGlobalStruct, + field2: UByte, + timedInvokeTimeout: Duration? = null, + ): GlobalEchoResponse { val commandId: UInt = 25u val tlvWriter = TlvWriter() @@ -2685,14 +2434,14 @@ class AttributeListAttribute( field1.toTlv(ContextSpecificTag(TAG_FIELD1_REQ), tlvWriter) val TAG_FIELD2_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_FIELD2_REQ), field2) + tlvWriter.put(ContextSpecificTag(TAG_FIELD2_REQ), field2) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -2702,61 +2451,55 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_FIELD1: Int = 0 var field1_decoded: UnitTestingClusterTestGlobalStruct? = null - + val TAG_FIELD2: Int = 1 var field2_decoded: UByte? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_FIELD1)) {field1_decoded = UnitTestingClusterTestGlobalStruct.fromTlv(tag, tlvReader)} - - if (tag == ContextSpecificTag(TAG_FIELD2)) {field2_decoded = tlvReader.getUByte(tag)} - + if (tag == ContextSpecificTag(TAG_FIELD1)) { + field1_decoded = UnitTestingClusterTestGlobalStruct.fromTlv(tag, tlvReader) + } - else { + if (tag == ContextSpecificTag(TAG_FIELD2)) { + field2_decoded = tlvReader.getUByte(tag) + } else { tlvReader.skipElement() } } - - if (field1_decoded == null) { - throw IllegalStateException("field1 not found in TLV") + throw IllegalStateException("field1 not found in TLV") } - - + if (field2_decoded == null) { - throw IllegalStateException("field2 not found in TLV") + throw IllegalStateException("field2 not found in TLV") } - tlvReader.exitContainer() - return GlobalEchoResponse( - field1_decoded, - field2_decoded - ) + return GlobalEchoResponse(field1_decoded, field2_decoded) } - suspend fun testDifferentVendorMeiRequest(arg1: UByte - ,timedInvokeTimeout: Duration? = null): TestDifferentVendorMeiResponse { + suspend fun testDifferentVendorMeiRequest( + arg1: UByte, + timedInvokeTimeout: Duration? = null, + ): TestDifferentVendorMeiResponse { val commandId: UInt = 4294049962u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_ARG1_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_ARG1_REQ), arg1) + tlvWriter.put(ContextSpecificTag(TAG_ARG1_REQ), arg1) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -2766,104 +2509,85 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_ARG1: Int = 0 var arg1_decoded: UByte? = null - + val TAG_EVENT_NUMBER: Int = 1 var eventNumber_decoded: ULong? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_ARG1)) {arg1_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_EVENT_NUMBER)) {eventNumber_decoded = tlvReader.getULong(tag)} - + if (tag == ContextSpecificTag(TAG_ARG1)) { + arg1_decoded = tlvReader.getUByte(tag) + } - else { + if (tag == ContextSpecificTag(TAG_EVENT_NUMBER)) { + eventNumber_decoded = tlvReader.getULong(tag) + } else { tlvReader.skipElement() } } - - if (arg1_decoded == null) { - throw IllegalStateException("arg1 not found in TLV") + throw IllegalStateException("arg1 not found in TLV") } - - + if (eventNumber_decoded == null) { - throw IllegalStateException("eventNumber not found in TLV") + throw IllegalStateException("eventNumber not found in TLV") } - tlvReader.exitContainer() - return TestDifferentVendorMeiResponse( - arg1_decoded, - eventNumber_decoded - ) + return TestDifferentVendorMeiResponse(arg1_decoded, eventNumber_decoded) } -suspend fun readBooleanAttribute(): Boolean {val ATTRIBUTE_ID: UInt = 0u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readBooleanAttribute(): Boolean { + 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 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}") - } + 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) { - "Boolean attribute not found in response" - } + } + + requireNotNull(attributeData) { "Boolean attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Boolean = tlvReader.getBoolean(AnonymousTag) - return decodedValue } - suspend fun writeBooleanAttribute( - value: Boolean, - timedWriteTimeout: Duration? = null) { + suspend fun writeBooleanAttribute(value: Boolean, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -2884,43 +2608,45 @@ suspend fun readBooleanAttribute(): Boolean {val ATTRIBUTE_ID: UInt = 0u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeBooleanAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Boolean attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Boolean attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -2932,68 +2658,57 @@ suspend fun readBooleanAttribute(): Boolean {val ATTRIBUTE_ID: UInt = 0u emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readBitmap8Attribute(): UByte {val ATTRIBUTE_ID: UInt = 1u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readBitmap8Attribute(): 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 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}") - } + 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) { - "Bitmap8 attribute not found in response" - } + } + + requireNotNull(attributeData) { "Bitmap8 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 writeBitmap8Attribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeBitmap8Attribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 1u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -3014,43 +2729,45 @@ suspend fun readBitmap8Attribute(): UByte {val ATTRIBUTE_ID: UInt = 1u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeBitmap8Attribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Bitmap8 attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Bitmap8 attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -3062,68 +2779,57 @@ suspend fun readBitmap8Attribute(): UByte {val ATTRIBUTE_ID: UInt = 1u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readBitmap16Attribute(): UShort {val ATTRIBUTE_ID: UInt = 2u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readBitmap16Attribute(): 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 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}") - } + 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) { - "Bitmap16 attribute not found in response" - } + } + + requireNotNull(attributeData) { "Bitmap16 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 writeBitmap16Attribute( - value: UShort, - timedWriteTimeout: Duration? = null) { + suspend fun writeBitmap16Attribute(value: UShort, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 2u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -3144,43 +2850,45 @@ suspend fun readBitmap16Attribute(): UShort {val ATTRIBUTE_ID: UInt = 2u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeBitmap16Attribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Bitmap16 attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Bitmap16 attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -3192,68 +2900,57 @@ suspend fun readBitmap16Attribute(): UShort {val ATTRIBUTE_ID: UInt = 2u emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readBitmap32Attribute(): UInt {val ATTRIBUTE_ID: UInt = 3u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readBitmap32Attribute(): UInt { + 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 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}") - } + 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) { - "Bitmap32 attribute not found in response" - } + } + + requireNotNull(attributeData) { "Bitmap32 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 writeBitmap32Attribute( - value: UInt, - timedWriteTimeout: Duration? = null) { + suspend fun writeBitmap32Attribute(value: UInt, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 3u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -3274,43 +2971,45 @@ suspend fun readBitmap32Attribute(): UInt {val ATTRIBUTE_ID: UInt = 3u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeBitmap32Attribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Bitmap32 attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Bitmap32 attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -3322,68 +3021,57 @@ suspend fun readBitmap32Attribute(): UInt {val ATTRIBUTE_ID: UInt = 3u emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readBitmap64Attribute(): ULong {val ATTRIBUTE_ID: UInt = 4u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readBitmap64Attribute(): ULong { + 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 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}") - } + 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) { - "Bitmap64 attribute not found in response" - } + } + + requireNotNull(attributeData) { "Bitmap64 attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: ULong = tlvReader.getULong(AnonymousTag) - return decodedValue } - suspend fun writeBitmap64Attribute( - value: ULong, - timedWriteTimeout: Duration? = null) { + suspend fun writeBitmap64Attribute(value: ULong, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 4u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -3404,43 +3092,45 @@ suspend fun readBitmap64Attribute(): ULong {val ATTRIBUTE_ID: UInt = 4u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeBitmap64Attribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ULongSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ULongSubscriptionState.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) { - "Bitmap64 attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Bitmap64 attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -3452,68 +3142,57 @@ suspend fun readBitmap64Attribute(): ULong {val ATTRIBUTE_ID: UInt = 4u emit(ULongSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readInt8uAttribute(): UByte {val ATTRIBUTE_ID: UInt = 5u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readInt8uAttribute(): UByte { + 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 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}") - } + 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) { - "Int8u attribute not found in response" - } + } + + requireNotNull(attributeData) { "Int8u 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 writeInt8uAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeInt8uAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 5u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -3534,43 +3213,45 @@ suspend fun readInt8uAttribute(): UByte {val ATTRIBUTE_ID: UInt = 5u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeInt8uAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Int8u attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Int8u attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -3582,68 +3263,57 @@ suspend fun readInt8uAttribute(): UByte {val ATTRIBUTE_ID: UInt = 5u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readInt16uAttribute(): UShort {val ATTRIBUTE_ID: UInt = 6u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readInt16uAttribute(): 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 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}") - } + 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) { - "Int16u attribute not found in response" - } + } + + requireNotNull(attributeData) { "Int16u 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 writeInt16uAttribute( - value: UShort, - timedWriteTimeout: Duration? = null) { + suspend fun writeInt16uAttribute(value: UShort, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 6u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -3664,43 +3334,45 @@ suspend fun readInt16uAttribute(): UShort {val ATTRIBUTE_ID: UInt = 6u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeInt16uAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Int16u attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Int16u attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -3712,68 +3384,57 @@ suspend fun readInt16uAttribute(): UShort {val ATTRIBUTE_ID: UInt = 6u emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readInt24uAttribute(): UInt {val ATTRIBUTE_ID: UInt = 7u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readInt24uAttribute(): UInt { + 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 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}") - } + 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) { - "Int24u attribute not found in response" - } + } + + requireNotNull(attributeData) { "Int24u 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 writeInt24uAttribute( - value: UInt, - timedWriteTimeout: Duration? = null) { + suspend fun writeInt24uAttribute(value: UInt, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 7u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -3794,43 +3455,45 @@ suspend fun readInt24uAttribute(): UInt {val ATTRIBUTE_ID: UInt = 7u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeInt24uAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Int24u attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Int24u attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -3842,68 +3505,57 @@ suspend fun readInt24uAttribute(): UInt {val ATTRIBUTE_ID: UInt = 7u emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readInt32uAttribute(): UInt {val ATTRIBUTE_ID: UInt = 8u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readInt32uAttribute(): UInt { + val ATTRIBUTE_ID: UInt = 8u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Int32u attribute not found in response" - } + } + + requireNotNull(attributeData) { "Int32u 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 writeInt32uAttribute( - value: UInt, - timedWriteTimeout: Duration? = null) { + suspend fun writeInt32uAttribute(value: UInt, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 8u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -3924,43 +3576,45 @@ suspend fun readInt32uAttribute(): UInt {val ATTRIBUTE_ID: UInt = 8u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeInt32uAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Int32u attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Int32u attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -3972,68 +3626,57 @@ suspend fun readInt32uAttribute(): UInt {val ATTRIBUTE_ID: UInt = 8u emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readInt40uAttribute(): ULong {val ATTRIBUTE_ID: UInt = 9u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readInt40uAttribute(): ULong { + val ATTRIBUTE_ID: UInt = 9u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Int40u attribute not found in response" - } + } + + requireNotNull(attributeData) { "Int40u attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: ULong = tlvReader.getULong(AnonymousTag) - return decodedValue } - suspend fun writeInt40uAttribute( - value: ULong, - timedWriteTimeout: Duration? = null) { + suspend fun writeInt40uAttribute(value: ULong, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 9u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -4054,43 +3697,45 @@ suspend fun readInt40uAttribute(): ULong {val ATTRIBUTE_ID: UInt = 9u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeInt40uAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ULongSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ULongSubscriptionState.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) { - "Int40u attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Int40u attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -4102,68 +3747,57 @@ suspend fun readInt40uAttribute(): ULong {val ATTRIBUTE_ID: UInt = 9u emit(ULongSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readInt48uAttribute(): ULong {val ATTRIBUTE_ID: UInt = 10u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readInt48uAttribute(): ULong { + val ATTRIBUTE_ID: UInt = 10u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Int48u attribute not found in response" - } + } + + requireNotNull(attributeData) { "Int48u attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: ULong = tlvReader.getULong(AnonymousTag) - return decodedValue } - suspend fun writeInt48uAttribute( - value: ULong, - timedWriteTimeout: Duration? = null) { + suspend fun writeInt48uAttribute(value: ULong, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 10u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -4184,43 +3818,45 @@ suspend fun readInt48uAttribute(): ULong {val ATTRIBUTE_ID: UInt = 10u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeInt48uAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ULongSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ULongSubscriptionState.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) { - "Int48u attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Int48u attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -4232,68 +3868,57 @@ suspend fun readInt48uAttribute(): ULong {val ATTRIBUTE_ID: UInt = 10u emit(ULongSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readInt56uAttribute(): ULong {val ATTRIBUTE_ID: UInt = 11u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readInt56uAttribute(): ULong { + val ATTRIBUTE_ID: UInt = 11u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Int56u attribute not found in response" - } + } + + requireNotNull(attributeData) { "Int56u attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: ULong = tlvReader.getULong(AnonymousTag) - return decodedValue } - suspend fun writeInt56uAttribute( - value: ULong, - timedWriteTimeout: Duration? = null) { + suspend fun writeInt56uAttribute(value: ULong, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 11u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -4314,43 +3939,45 @@ suspend fun readInt56uAttribute(): ULong {val ATTRIBUTE_ID: UInt = 11u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeInt56uAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 11u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ULongSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ULongSubscriptionState.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) { - "Int56u attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Int56u attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -4362,68 +3989,57 @@ suspend fun readInt56uAttribute(): ULong {val ATTRIBUTE_ID: UInt = 11u emit(ULongSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readInt64uAttribute(): ULong {val ATTRIBUTE_ID: UInt = 12u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readInt64uAttribute(): ULong { + val ATTRIBUTE_ID: UInt = 12u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Int64u attribute not found in response" - } + } + + requireNotNull(attributeData) { "Int64u attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: ULong = tlvReader.getULong(AnonymousTag) - return decodedValue } - suspend fun writeInt64uAttribute( - value: ULong, - timedWriteTimeout: Duration? = null) { + suspend fun writeInt64uAttribute(value: ULong, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 12u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -4444,43 +4060,45 @@ suspend fun readInt64uAttribute(): ULong {val ATTRIBUTE_ID: UInt = 12u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeInt64uAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 12u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ULongSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ULongSubscriptionState.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) { - "Int64u attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Int64u attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -4492,68 +4110,57 @@ suspend fun readInt64uAttribute(): ULong {val ATTRIBUTE_ID: UInt = 12u emit(ULongSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readInt8sAttribute(): Byte {val ATTRIBUTE_ID: UInt = 13u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readInt8sAttribute(): Byte { + val ATTRIBUTE_ID: UInt = 13u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Int8s attribute not found in response" - } + } + + requireNotNull(attributeData) { "Int8s attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Byte = tlvReader.getByte(AnonymousTag) - return decodedValue } - suspend fun writeInt8sAttribute( - value: Byte, - timedWriteTimeout: Duration? = null) { + suspend fun writeInt8sAttribute(value: Byte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 13u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -4574,43 +4181,45 @@ suspend fun readInt8sAttribute(): Byte {val ATTRIBUTE_ID: UInt = 13u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeInt8sAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 13u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ByteSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ByteSubscriptionState.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) { - "Int8s attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Int8s attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -4622,68 +4231,57 @@ suspend fun readInt8sAttribute(): Byte {val ATTRIBUTE_ID: UInt = 13u emit(ByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readInt16sAttribute(): Short {val ATTRIBUTE_ID: UInt = 14u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readInt16sAttribute(): Short { + val ATTRIBUTE_ID: UInt = 14u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Int16s attribute not found in response" - } + } + + requireNotNull(attributeData) { "Int16s attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Short = tlvReader.getShort(AnonymousTag) - return decodedValue } - suspend fun writeInt16sAttribute( - value: Short, - timedWriteTimeout: Duration? = null) { + suspend fun writeInt16sAttribute(value: Short, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 14u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -4704,43 +4302,45 @@ suspend fun readInt16sAttribute(): Short {val ATTRIBUTE_ID: UInt = 14u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeInt16sAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 14u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Int16s attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Int16s attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -4752,68 +4352,57 @@ suspend fun readInt16sAttribute(): Short {val ATTRIBUTE_ID: UInt = 14u emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readInt24sAttribute(): Int {val ATTRIBUTE_ID: UInt = 15u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readInt24sAttribute(): Int { + val ATTRIBUTE_ID: UInt = 15u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Int24s attribute not found in response" - } + } + + requireNotNull(attributeData) { "Int24s attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Int = tlvReader.getInt(AnonymousTag) - return decodedValue } - suspend fun writeInt24sAttribute( - value: Int, - timedWriteTimeout: Duration? = null) { + suspend fun writeInt24sAttribute(value: Int, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 15u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -4834,43 +4423,45 @@ suspend fun readInt24sAttribute(): Int {val ATTRIBUTE_ID: UInt = 15u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeInt24sAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 15u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(IntSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + IntSubscriptionState.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) { - "Int24s attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Int24s attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -4882,68 +4473,57 @@ suspend fun readInt24sAttribute(): Int {val ATTRIBUTE_ID: UInt = 15u emit(IntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readInt32sAttribute(): Int {val ATTRIBUTE_ID: UInt = 16u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readInt32sAttribute(): Int { + val ATTRIBUTE_ID: UInt = 16u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Int32s attribute not found in response" - } + } + + requireNotNull(attributeData) { "Int32s attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Int = tlvReader.getInt(AnonymousTag) - return decodedValue } - suspend fun writeInt32sAttribute( - value: Int, - timedWriteTimeout: Duration? = null) { + suspend fun writeInt32sAttribute(value: Int, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -4964,43 +4544,45 @@ suspend fun readInt32sAttribute(): Int {val ATTRIBUTE_ID: UInt = 16u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeInt32sAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(IntSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + IntSubscriptionState.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) { - "Int32s attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Int32s attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -5012,68 +4594,57 @@ suspend fun readInt32sAttribute(): Int {val ATTRIBUTE_ID: UInt = 16u emit(IntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readInt40sAttribute(): Long {val ATTRIBUTE_ID: UInt = 17u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readInt40sAttribute(): Long { + val ATTRIBUTE_ID: UInt = 17u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Int40s attribute not found in response" - } + } + + requireNotNull(attributeData) { "Int40s attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Long = tlvReader.getLong(AnonymousTag) - return decodedValue } - suspend fun writeInt40sAttribute( - value: Long, - timedWriteTimeout: Duration? = null) { + suspend fun writeInt40sAttribute(value: Long, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 17u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -5094,43 +4665,45 @@ suspend fun readInt40sAttribute(): Long {val ATTRIBUTE_ID: UInt = 17u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeInt40sAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 17u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(LongSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + LongSubscriptionState.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) { - "Int40s attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Int40s attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -5142,68 +4715,57 @@ suspend fun readInt40sAttribute(): Long {val ATTRIBUTE_ID: UInt = 17u emit(LongSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readInt48sAttribute(): Long {val ATTRIBUTE_ID: UInt = 18u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readInt48sAttribute(): Long { + val ATTRIBUTE_ID: UInt = 18u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Int48s attribute not found in response" - } + } + + requireNotNull(attributeData) { "Int48s attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Long = tlvReader.getLong(AnonymousTag) - return decodedValue } - suspend fun writeInt48sAttribute( - value: Long, - timedWriteTimeout: Duration? = null) { + suspend fun writeInt48sAttribute(value: Long, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 18u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -5224,43 +4786,45 @@ suspend fun readInt48sAttribute(): Long {val ATTRIBUTE_ID: UInt = 18u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeInt48sAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 18u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(LongSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + LongSubscriptionState.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) { - "Int48s attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Int48s attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -5272,68 +4836,57 @@ suspend fun readInt48sAttribute(): Long {val ATTRIBUTE_ID: UInt = 18u emit(LongSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readInt56sAttribute(): Long {val ATTRIBUTE_ID: UInt = 19u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readInt56sAttribute(): Long { + val ATTRIBUTE_ID: UInt = 19u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Int56s attribute not found in response" - } + } + + requireNotNull(attributeData) { "Int56s attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Long = tlvReader.getLong(AnonymousTag) - return decodedValue } - suspend fun writeInt56sAttribute( - value: Long, - timedWriteTimeout: Duration? = null) { + suspend fun writeInt56sAttribute(value: Long, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 19u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -5354,43 +4907,45 @@ suspend fun readInt56sAttribute(): Long {val ATTRIBUTE_ID: UInt = 19u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeInt56sAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 19u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(LongSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + LongSubscriptionState.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) { - "Int56s attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Int56s attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -5402,68 +4957,57 @@ suspend fun readInt56sAttribute(): Long {val ATTRIBUTE_ID: UInt = 19u emit(LongSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readInt64sAttribute(): Long {val ATTRIBUTE_ID: UInt = 20u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readInt64sAttribute(): Long { + val ATTRIBUTE_ID: UInt = 20u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Int64s attribute not found in response" - } + } + + requireNotNull(attributeData) { "Int64s attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Long = tlvReader.getLong(AnonymousTag) - return decodedValue } - suspend fun writeInt64sAttribute( - value: Long, - timedWriteTimeout: Duration? = null) { + suspend fun writeInt64sAttribute(value: Long, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 20u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -5484,43 +5028,45 @@ suspend fun readInt64sAttribute(): Long {val ATTRIBUTE_ID: UInt = 20u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeInt64sAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 20u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(LongSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + LongSubscriptionState.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) { - "Int64s attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Int64s attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -5532,68 +5078,57 @@ suspend fun readInt64sAttribute(): Long {val ATTRIBUTE_ID: UInt = 20u emit(LongSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readEnum8Attribute(): UByte {val ATTRIBUTE_ID: UInt = 21u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readEnum8Attribute(): UByte { + val ATTRIBUTE_ID: UInt = 21u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Enum8 attribute not found in response" - } + } + + requireNotNull(attributeData) { "Enum8 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 writeEnum8Attribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeEnum8Attribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 21u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -5614,43 +5149,45 @@ suspend fun readEnum8Attribute(): UByte {val ATTRIBUTE_ID: UInt = 21u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeEnum8Attribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 21u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Enum8 attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Enum8 attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -5662,68 +5199,57 @@ suspend fun readEnum8Attribute(): UByte {val ATTRIBUTE_ID: UInt = 21u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readEnum16Attribute(): UShort {val ATTRIBUTE_ID: UInt = 22u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readEnum16Attribute(): UShort { + val ATTRIBUTE_ID: UInt = 22u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Enum16 attribute not found in response" - } + } + + requireNotNull(attributeData) { "Enum16 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 writeEnum16Attribute( - value: UShort, - timedWriteTimeout: Duration? = null) { + suspend fun writeEnum16Attribute(value: UShort, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 22u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -5744,43 +5270,45 @@ suspend fun readEnum16Attribute(): UShort {val ATTRIBUTE_ID: UInt = 22u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeEnum16Attribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 22u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Enum16 attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Enum16 attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -5792,68 +5320,57 @@ suspend fun readEnum16Attribute(): UShort {val ATTRIBUTE_ID: UInt = 22u emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readFloatSingleAttribute(): Float {val ATTRIBUTE_ID: UInt = 23u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readFloatSingleAttribute(): Float { + val ATTRIBUTE_ID: UInt = 23u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Floatsingle attribute not found in response" - } + } + + requireNotNull(attributeData) { "Floatsingle attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Float = tlvReader.getFloat(AnonymousTag) - return decodedValue } - suspend fun writeFloatSingleAttribute( - value: Float, - timedWriteTimeout: Duration? = null) { + suspend fun writeFloatSingleAttribute(value: Float, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 23u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -5874,43 +5391,45 @@ suspend fun readFloatSingleAttribute(): Float {val ATTRIBUTE_ID: UInt = 23u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeFloatSingleAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 23u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(FloatSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + FloatSubscriptionState.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) { - "Floatsingle attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Floatsingle attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -5922,68 +5441,57 @@ suspend fun readFloatSingleAttribute(): Float {val ATTRIBUTE_ID: UInt = 23u emit(FloatSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readFloatDoubleAttribute(): Double {val ATTRIBUTE_ID: UInt = 24u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readFloatDoubleAttribute(): Double { + val ATTRIBUTE_ID: UInt = 24u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Floatdouble attribute not found in response" - } + } + + requireNotNull(attributeData) { "Floatdouble attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Double = tlvReader.getDouble(AnonymousTag) - return decodedValue } - suspend fun writeFloatDoubleAttribute( - value: Double, - timedWriteTimeout: Duration? = null) { + suspend fun writeFloatDoubleAttribute(value: Double, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 24u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -6004,43 +5512,45 @@ suspend fun readFloatDoubleAttribute(): Double {val ATTRIBUTE_ID: UInt = 24u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeFloatDoubleAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 24u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(DoubleSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + DoubleSubscriptionState.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) { - "Floatdouble attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Floatdouble attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -6052,68 +5562,57 @@ suspend fun readFloatDoubleAttribute(): Double {val ATTRIBUTE_ID: UInt = 24u emit(DoubleSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readOctetStringAttribute(): ByteArray {val ATTRIBUTE_ID: UInt = 25u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readOctetStringAttribute(): ByteArray { + val ATTRIBUTE_ID: UInt = 25u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Octetstring attribute not found in response" - } + } + + requireNotNull(attributeData) { "Octetstring attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: ByteArray = tlvReader.getByteArray(AnonymousTag) - return decodedValue } - suspend fun writeOctetStringAttribute( - value: ByteArray, - timedWriteTimeout: Duration? = null) { + suspend fun writeOctetStringAttribute(value: ByteArray, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 25u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -6134,43 +5633,45 @@ suspend fun readOctetStringAttribute(): ByteArray {val ATTRIBUTE_ID: UInt = 25u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeOctetStringAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 25u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ByteArraySubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ByteArraySubscriptionState.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) { - "Octetstring attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Octetstring attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -6182,78 +5683,68 @@ suspend fun readOctetStringAttribute(): ByteArray {val ATTRIBUTE_ID: UInt = 25u emit(ByteArraySubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readListInt8uAttribute(): ListInt8uAttribute {val ATTRIBUTE_ID: UInt = 26u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readListInt8uAttribute(): ListInt8uAttribute { + val ATTRIBUTE_ID: UInt = 26u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Listint8u attribute not found in response" - } + } + + requireNotNull(attributeData) { "Listint8u 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.getUByte(AnonymousTag)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return ListInt8uAttribute(decodedValue) } - suspend fun writeListInt8uAttribute( - value: List, - timedWriteTimeout: Duration? = null) { + suspend fun writeListInt8uAttribute(value: List, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 26u val tlvWriter = TlvWriter() tlvWriter.startArray(AnonymousTag) - for (item in value.iterator()) { - tlvWriter.put(AnonymousTag, item) - } - tlvWriter.endArray() + for (item in value.iterator()) { + tlvWriter.put(AnonymousTag, item) + } + tlvWriter.endArray() val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -6274,53 +5765,56 @@ suspend fun readListInt8uAttribute(): ListInt8uAttribute {val ATTRIBUTE_ID: UInt throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeListInt8uAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 26u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ListInt8uAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ListInt8uAttributeSubscriptionState.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) { - "Listint8u attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Listint8u 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.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(ListInt8uAttributeSubscriptionState.Success(decodedValue)) } @@ -6328,78 +5822,71 @@ suspend fun readListInt8uAttribute(): ListInt8uAttribute {val ATTRIBUTE_ID: UInt emit(ListInt8uAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readListOctetStringAttribute(): ListOctetStringAttribute {val ATTRIBUTE_ID: UInt = 27u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readListOctetStringAttribute(): ListOctetStringAttribute { + val ATTRIBUTE_ID: UInt = 27u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Listoctetstring attribute not found in response" - } + } + + requireNotNull(attributeData) { "Listoctetstring 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.getByteArray(AnonymousTag)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getByteArray(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return ListOctetStringAttribute(decodedValue) } suspend fun writeListOctetStringAttribute( value: List, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 27u val tlvWriter = TlvWriter() tlvWriter.startArray(AnonymousTag) - for (item in value.iterator()) { - tlvWriter.put(AnonymousTag, item) - } - tlvWriter.endArray() + for (item in value.iterator()) { + tlvWriter.put(AnonymousTag, item) + } + tlvWriter.endArray() val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -6420,53 +5907,58 @@ suspend fun readListOctetStringAttribute(): ListOctetStringAttribute {val ATTRIB throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeListOctetStringAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 27u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ListOctetStringAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ListOctetStringAttributeSubscriptionState.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) { - "Listoctetstring attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Listoctetstring 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.getByteArray(AnonymousTag)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getByteArray(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(ListOctetStringAttributeSubscriptionState.Success(decodedValue)) } @@ -6474,78 +5966,71 @@ suspend fun readListOctetStringAttribute(): ListOctetStringAttribute {val ATTRIB emit(ListOctetStringAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readListStructOctetStringAttribute(): ListStructOctetStringAttribute {val ATTRIBUTE_ID: UInt = 28u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readListStructOctetStringAttribute(): ListStructOctetStringAttribute { + val ATTRIBUTE_ID: UInt = 28u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Liststructoctetstring attribute not found in response" - } + } + + requireNotNull(attributeData) { "Liststructoctetstring 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(UnitTestingClusterTestListStructOctet.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(UnitTestingClusterTestListStructOctet.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return ListStructOctetStringAttribute(decodedValue) } suspend fun writeListStructOctetStringAttribute( value: List, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 28u val tlvWriter = TlvWriter() tlvWriter.startArray(AnonymousTag) - for (item in value.iterator()) { - item.toTlv(AnonymousTag, tlvWriter) - } - tlvWriter.endArray() + for (item in value.iterator()) { + item.toTlv(AnonymousTag, tlvWriter) + } + tlvWriter.endArray() val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -6566,53 +6051,58 @@ suspend fun readListStructOctetStringAttribute(): ListStructOctetStringAttribute throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeListStructOctetStringAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 28u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ListStructOctetStringAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ListStructOctetStringAttributeSubscriptionState.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) { - "Liststructoctetstring attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Liststructoctetstring 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(UnitTestingClusterTestListStructOctet.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(UnitTestingClusterTestListStructOctet.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(ListStructOctetStringAttributeSubscriptionState.Success(decodedValue)) } @@ -6620,68 +6110,57 @@ suspend fun readListStructOctetStringAttribute(): ListStructOctetStringAttribute emit(ListStructOctetStringAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readLongOctetStringAttribute(): ByteArray {val ATTRIBUTE_ID: UInt = 29u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readLongOctetStringAttribute(): ByteArray { + val ATTRIBUTE_ID: UInt = 29u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Longoctetstring attribute not found in response" - } + } + + requireNotNull(attributeData) { "Longoctetstring attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: ByteArray = tlvReader.getByteArray(AnonymousTag) - return decodedValue } - suspend fun writeLongOctetStringAttribute( - value: ByteArray, - timedWriteTimeout: Duration? = null) { + suspend fun writeLongOctetStringAttribute(value: ByteArray, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 29u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -6702,42 +6181,46 @@ suspend fun readLongOctetStringAttribute(): ByteArray {val ATTRIBUTE_ID: UInt = throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeLongOctetStringAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 29u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ByteArraySubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ByteArraySubscriptionState.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) { - "Longoctetstring attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Longoctetstring attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -6750,68 +6233,57 @@ suspend fun readLongOctetStringAttribute(): ByteArray {val ATTRIBUTE_ID: UInt = emit(ByteArraySubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCharStringAttribute(): String {val ATTRIBUTE_ID: UInt = 30u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readCharStringAttribute(): String { + val ATTRIBUTE_ID: UInt = 30u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Charstring attribute not found in response" - } + } + + requireNotNull(attributeData) { "Charstring attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: String = tlvReader.getString(AnonymousTag) - return decodedValue } - suspend fun writeCharStringAttribute( - value: String, - timedWriteTimeout: Duration? = null) { + suspend fun writeCharStringAttribute(value: String, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 30u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -6832,43 +6304,45 @@ suspend fun readCharStringAttribute(): String {val ATTRIBUTE_ID: UInt = 30u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeCharStringAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 30u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StringSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StringSubscriptionState.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) { - "Charstring attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Charstring attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -6880,68 +6354,57 @@ suspend fun readCharStringAttribute(): String {val ATTRIBUTE_ID: UInt = 30u emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readLongCharStringAttribute(): String {val ATTRIBUTE_ID: UInt = 31u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readLongCharStringAttribute(): String { + val ATTRIBUTE_ID: UInt = 31u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Longcharstring attribute not found in response" - } + } + + requireNotNull(attributeData) { "Longcharstring attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: String = tlvReader.getString(AnonymousTag) - return decodedValue } - suspend fun writeLongCharStringAttribute( - value: String, - timedWriteTimeout: Duration? = null) { + suspend fun writeLongCharStringAttribute(value: String, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 31u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -6962,42 +6425,46 @@ suspend fun readLongCharStringAttribute(): String {val ATTRIBUTE_ID: UInt = 31u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeLongCharStringAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 31u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StringSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StringSubscriptionState.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) { - "Longcharstring attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Longcharstring attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -7010,68 +6477,57 @@ suspend fun readLongCharStringAttribute(): String {val ATTRIBUTE_ID: UInt = 31u emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readEpochUsAttribute(): ULong {val ATTRIBUTE_ID: UInt = 32u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readEpochUsAttribute(): ULong { + val ATTRIBUTE_ID: UInt = 32u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Epochus attribute not found in response" - } + } + + requireNotNull(attributeData) { "Epochus attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: ULong = tlvReader.getULong(AnonymousTag) - return decodedValue } - suspend fun writeEpochUsAttribute( - value: ULong, - timedWriteTimeout: Duration? = null) { + suspend fun writeEpochUsAttribute(value: ULong, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 32u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -7092,43 +6548,45 @@ suspend fun readEpochUsAttribute(): ULong {val ATTRIBUTE_ID: UInt = 32u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeEpochUsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 32u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ULongSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ULongSubscriptionState.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) { - "Epochus attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Epochus attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -7140,68 +6598,57 @@ suspend fun readEpochUsAttribute(): ULong {val ATTRIBUTE_ID: UInt = 32u emit(ULongSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readEpochSAttribute(): UInt {val ATTRIBUTE_ID: UInt = 33u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readEpochSAttribute(): UInt { + val ATTRIBUTE_ID: UInt = 33u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Epochs attribute not found in response" - } + } + + requireNotNull(attributeData) { "Epochs 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 writeEpochSAttribute( - value: UInt, - timedWriteTimeout: Duration? = null) { + suspend fun writeEpochSAttribute(value: UInt, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 33u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -7222,43 +6669,45 @@ suspend fun readEpochSAttribute(): UInt {val ATTRIBUTE_ID: UInt = 33u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeEpochSAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 33u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Epochs attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Epochs attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -7270,68 +6719,57 @@ suspend fun readEpochSAttribute(): UInt {val ATTRIBUTE_ID: UInt = 33u emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readVendorIdAttribute(): UShort {val ATTRIBUTE_ID: UInt = 34u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readVendorIdAttribute(): UShort { + val ATTRIBUTE_ID: UInt = 34u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Vendorid attribute not found in response" - } + } + + requireNotNull(attributeData) { "Vendorid 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 writeVendorIdAttribute( - value: UShort, - timedWriteTimeout: Duration? = null) { + suspend fun writeVendorIdAttribute(value: UShort, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 34u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -7352,43 +6790,45 @@ suspend fun readVendorIdAttribute(): UShort {val ATTRIBUTE_ID: UInt = 34u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeVendorIdAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 34u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Vendorid attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Vendorid attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -7400,78 +6840,74 @@ suspend fun readVendorIdAttribute(): UShort {val ATTRIBUTE_ID: UInt = 34u emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readListNullablesAndOptionalsStructAttribute(): ListNullablesAndOptionalsStructAttribute {val ATTRIBUTE_ID: UInt = 35u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readListNullablesAndOptionalsStructAttribute(): + ListNullablesAndOptionalsStructAttribute { + val ATTRIBUTE_ID: UInt = 35u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Listnullablesandoptionalsstruct attribute not found in response" + } + + requireNotNull(attributeData) { + "Listnullablesandoptionalsstruct 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(UnitTestingClusterNullablesAndOptionalsStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(UnitTestingClusterNullablesAndOptionalsStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return ListNullablesAndOptionalsStructAttribute(decodedValue) } suspend fun writeListNullablesAndOptionalsStructAttribute( value: List, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 35u val tlvWriter = TlvWriter() tlvWriter.startArray(AnonymousTag) - for (item in value.iterator()) { - item.toTlv(AnonymousTag, tlvWriter) - } - tlvWriter.endArray() + for (item in value.iterator()) { + item.toTlv(AnonymousTag, tlvWriter) + } + tlvWriter.endArray() val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -7492,53 +6928,58 @@ suspend fun readListNullablesAndOptionalsStructAttribute(): ListNullablesAndOpti throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeListNullablesAndOptionalsStructAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 35u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ListNullablesAndOptionalsStructAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ListNullablesAndOptionalsStructAttributeSubscriptionState.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) { - "Listnullablesandoptionalsstruct attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Listnullablesandoptionalsstruct 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(UnitTestingClusterNullablesAndOptionalsStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(UnitTestingClusterNullablesAndOptionalsStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(ListNullablesAndOptionalsStructAttributeSubscriptionState.Success(decodedValue)) } @@ -7546,68 +6987,57 @@ suspend fun readListNullablesAndOptionalsStructAttribute(): ListNullablesAndOpti emit(ListNullablesAndOptionalsStructAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readEnumAttrAttribute(): UByte {val ATTRIBUTE_ID: UInt = 36u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readEnumAttrAttribute(): UByte { + val ATTRIBUTE_ID: UInt = 36u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Enumattr attribute not found in response" - } + } + + requireNotNull(attributeData) { "Enumattr 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 writeEnumAttrAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeEnumAttrAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 36u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -7628,43 +7058,45 @@ suspend fun readEnumAttrAttribute(): UByte {val ATTRIBUTE_ID: UInt = 36u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeEnumAttrAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 36u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Enumattr attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Enumattr attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -7676,68 +7108,61 @@ suspend fun readEnumAttrAttribute(): UByte {val ATTRIBUTE_ID: UInt = 36u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readStructAttrAttribute(): StructAttrAttribute {val ATTRIBUTE_ID: UInt = 37u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readStructAttrAttribute(): StructAttrAttribute { + val ATTRIBUTE_ID: UInt = 37u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Structattr attribute not found in response" - } + } + + requireNotNull(attributeData) { "Structattr attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UnitTestingClusterSimpleStruct = UnitTestingClusterSimpleStruct.fromTlv(AnonymousTag, tlvReader) - + val decodedValue: UnitTestingClusterSimpleStruct = + UnitTestingClusterSimpleStruct.fromTlv(AnonymousTag, tlvReader) return StructAttrAttribute(decodedValue) } suspend fun writeStructAttrAttribute( value: UnitTestingClusterSimpleStruct, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 37u val tlvWriter = TlvWriter() - value.toTlv(AnonymousTag, tlvWriter) + value.toTlv(AnonymousTag, tlvWriter) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -7758,47 +7183,50 @@ suspend fun readStructAttrAttribute(): StructAttrAttribute {val ATTRIBUTE_ID: UI throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeStructAttrAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 37u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StructAttrAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StructAttrAttributeSubscriptionState.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) { - "Structattr attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Structattr attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UnitTestingClusterSimpleStruct = UnitTestingClusterSimpleStruct.fromTlv(AnonymousTag, tlvReader) + val decodedValue: UnitTestingClusterSimpleStruct = + UnitTestingClusterSimpleStruct.fromTlv(AnonymousTag, tlvReader) emit(StructAttrAttributeSubscriptionState.Success(decodedValue)) } @@ -7806,68 +7234,60 @@ suspend fun readStructAttrAttribute(): StructAttrAttribute {val ATTRIBUTE_ID: UI emit(StructAttrAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRangeRestrictedInt8uAttribute(): UByte {val ATTRIBUTE_ID: UInt = 38u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRangeRestrictedInt8uAttribute(): UByte { + val ATTRIBUTE_ID: UInt = 38u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rangerestrictedint8u attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rangerestrictedint8u 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 writeRangeRestrictedInt8uAttribute( value: UByte, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 38u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -7888,42 +7308,46 @@ suspend fun readRangeRestrictedInt8uAttribute(): UByte {val ATTRIBUTE_ID: UInt = throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeRangeRestrictedInt8uAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 38u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Rangerestrictedint8u attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Rangerestrictedint8u attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -7936,68 +7360,57 @@ suspend fun readRangeRestrictedInt8uAttribute(): UByte {val ATTRIBUTE_ID: UInt = emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRangeRestrictedInt8sAttribute(): Byte {val ATTRIBUTE_ID: UInt = 39u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRangeRestrictedInt8sAttribute(): Byte { + val ATTRIBUTE_ID: UInt = 39u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rangerestrictedint8s attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rangerestrictedint8s attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Byte = tlvReader.getByte(AnonymousTag) - return decodedValue } - suspend fun writeRangeRestrictedInt8sAttribute( - value: Byte, - timedWriteTimeout: Duration? = null) { + suspend fun writeRangeRestrictedInt8sAttribute(value: Byte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 39u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -8018,42 +7431,46 @@ suspend fun readRangeRestrictedInt8sAttribute(): Byte {val ATTRIBUTE_ID: UInt = throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeRangeRestrictedInt8sAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 39u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ByteSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ByteSubscriptionState.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) { - "Rangerestrictedint8s attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Rangerestrictedint8s attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -8066,68 +7483,60 @@ suspend fun readRangeRestrictedInt8sAttribute(): Byte {val ATTRIBUTE_ID: UInt = emit(ByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRangeRestrictedInt16uAttribute(): UShort {val ATTRIBUTE_ID: UInt = 40u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRangeRestrictedInt16uAttribute(): UShort { + val ATTRIBUTE_ID: UInt = 40u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rangerestrictedint16u attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rangerestrictedint16u 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 writeRangeRestrictedInt16uAttribute( value: UShort, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 40u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -8148,42 +7557,46 @@ suspend fun readRangeRestrictedInt16uAttribute(): UShort {val ATTRIBUTE_ID: UInt throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeRangeRestrictedInt16uAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 40u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Rangerestrictedint16u attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Rangerestrictedint16u attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -8196,68 +7609,60 @@ suspend fun readRangeRestrictedInt16uAttribute(): UShort {val ATTRIBUTE_ID: UInt emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRangeRestrictedInt16sAttribute(): Short {val ATTRIBUTE_ID: UInt = 41u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readRangeRestrictedInt16sAttribute(): Short { + val ATTRIBUTE_ID: UInt = 41u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Rangerestrictedint16s attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rangerestrictedint16s attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Short = tlvReader.getShort(AnonymousTag) - return decodedValue } suspend fun writeRangeRestrictedInt16sAttribute( value: Short, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 41u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -8278,42 +7683,46 @@ suspend fun readRangeRestrictedInt16sAttribute(): Short {val ATTRIBUTE_ID: UInt throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeRangeRestrictedInt16sAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 41u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ShortSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ShortSubscriptionState.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) { - "Rangerestrictedint16s attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Rangerestrictedint16s attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -8326,78 +7735,71 @@ suspend fun readRangeRestrictedInt16sAttribute(): Short {val ATTRIBUTE_ID: UInt emit(ShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readListLongOctetStringAttribute(): ListLongOctetStringAttribute {val ATTRIBUTE_ID: UInt = 42u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readListLongOctetStringAttribute(): ListLongOctetStringAttribute { + val ATTRIBUTE_ID: UInt = 42u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Listlongoctetstring attribute not found in response" - } + } + + requireNotNull(attributeData) { "Listlongoctetstring 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.getByteArray(AnonymousTag)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getByteArray(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return ListLongOctetStringAttribute(decodedValue) } suspend fun writeListLongOctetStringAttribute( value: List, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 42u val tlvWriter = TlvWriter() tlvWriter.startArray(AnonymousTag) - for (item in value.iterator()) { - tlvWriter.put(AnonymousTag, item) - } - tlvWriter.endArray() + for (item in value.iterator()) { + tlvWriter.put(AnonymousTag, item) + } + tlvWriter.endArray() val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -8418,53 +7820,58 @@ suspend fun readListLongOctetStringAttribute(): ListLongOctetStringAttribute {va throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeListLongOctetStringAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 42u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ListLongOctetStringAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ListLongOctetStringAttributeSubscriptionState.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) { - "Listlongoctetstring attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Listlongoctetstring 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.getByteArray(AnonymousTag)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getByteArray(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(ListLongOctetStringAttributeSubscriptionState.Success(decodedValue)) } @@ -8472,78 +7879,71 @@ suspend fun readListLongOctetStringAttribute(): ListLongOctetStringAttribute {va emit(ListLongOctetStringAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readListFabricScopedAttribute(): ListFabricScopedAttribute {val ATTRIBUTE_ID: UInt = 43u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readListFabricScopedAttribute(): ListFabricScopedAttribute { + val ATTRIBUTE_ID: UInt = 43u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Listfabricscoped attribute not found in response" - } + } + + requireNotNull(attributeData) { "Listfabricscoped 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(UnitTestingClusterTestFabricScoped.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(UnitTestingClusterTestFabricScoped.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return ListFabricScopedAttribute(decodedValue) } suspend fun writeListFabricScopedAttribute( value: List, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 43u val tlvWriter = TlvWriter() tlvWriter.startArray(AnonymousTag) - for (item in value.iterator()) { - item.toTlv(AnonymousTag, tlvWriter) - } - tlvWriter.endArray() + for (item in value.iterator()) { + item.toTlv(AnonymousTag, tlvWriter) + } + tlvWriter.endArray() val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -8564,53 +7964,58 @@ suspend fun readListFabricScopedAttribute(): ListFabricScopedAttribute {val ATTR throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeListFabricScopedAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 43u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ListFabricScopedAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ListFabricScopedAttributeSubscriptionState.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) { - "Listfabricscoped attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Listfabricscoped 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(UnitTestingClusterTestFabricScoped.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(UnitTestingClusterTestFabricScoped.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(ListFabricScopedAttributeSubscriptionState.Success(decodedValue)) } @@ -8618,68 +8023,57 @@ suspend fun readListFabricScopedAttribute(): ListFabricScopedAttribute {val ATTR emit(ListFabricScopedAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readTimedWriteBooleanAttribute(): Boolean {val ATTRIBUTE_ID: UInt = 48u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readTimedWriteBooleanAttribute(): Boolean { + val ATTRIBUTE_ID: UInt = 48u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Timedwriteboolean attribute not found in response" - } + } + + requireNotNull(attributeData) { "Timedwriteboolean attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Boolean = tlvReader.getBoolean(AnonymousTag) - return decodedValue } - suspend fun writeTimedWriteBooleanAttribute( - value: Boolean, - timedWriteTimeout: Duration) { + suspend fun writeTimedWriteBooleanAttribute(value: Boolean, timedWriteTimeout: Duration) { val ATTRIBUTE_ID: UInt = 48u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -8700,42 +8094,46 @@ suspend fun readTimedWriteBooleanAttribute(): Boolean {val ATTRIBUTE_ID: UInt = throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeTimedWriteBooleanAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 48u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Timedwriteboolean attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Timedwriteboolean attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -8748,68 +8146,60 @@ suspend fun readTimedWriteBooleanAttribute(): Boolean {val ATTRIBUTE_ID: UInt = emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readGeneralErrorBooleanAttribute(): Boolean {val ATTRIBUTE_ID: UInt = 49u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readGeneralErrorBooleanAttribute(): Boolean { + val ATTRIBUTE_ID: UInt = 49u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Generalerrorboolean attribute not found in response" - } + } + + requireNotNull(attributeData) { "Generalerrorboolean attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Boolean = tlvReader.getBoolean(AnonymousTag) - return decodedValue } suspend fun writeGeneralErrorBooleanAttribute( value: Boolean, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 49u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -8830,42 +8220,46 @@ suspend fun readGeneralErrorBooleanAttribute(): Boolean {val ATTRIBUTE_ID: UInt throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeGeneralErrorBooleanAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 49u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Generalerrorboolean attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Generalerrorboolean attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -8878,68 +8272,60 @@ suspend fun readGeneralErrorBooleanAttribute(): Boolean {val ATTRIBUTE_ID: UInt emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readClusterErrorBooleanAttribute(): Boolean {val ATTRIBUTE_ID: UInt = 50u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readClusterErrorBooleanAttribute(): Boolean { + val ATTRIBUTE_ID: UInt = 50u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Clustererrorboolean attribute not found in response" - } + } + + requireNotNull(attributeData) { "Clustererrorboolean attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) val decodedValue: Boolean = tlvReader.getBoolean(AnonymousTag) - return decodedValue } suspend fun writeClusterErrorBooleanAttribute( value: Boolean, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 50u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -8960,42 +8346,46 @@ suspend fun readClusterErrorBooleanAttribute(): Boolean {val ATTRIBUTE_ID: UInt throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeClusterErrorBooleanAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 50u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Clustererrorboolean attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Clustererrorboolean attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -9008,68 +8398,57 @@ suspend fun readClusterErrorBooleanAttribute(): Boolean {val ATTRIBUTE_ID: UInt emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readGlobalEnumAttribute(): UByte {val ATTRIBUTE_ID: UInt = 51u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readGlobalEnumAttribute(): UByte { + val ATTRIBUTE_ID: UInt = 51u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Globalenum attribute not found in response" - } + } + + requireNotNull(attributeData) { "Globalenum 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 writeGlobalEnumAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeGlobalEnumAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 51u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -9090,43 +8469,45 @@ suspend fun readGlobalEnumAttribute(): UByte {val ATTRIBUTE_ID: UInt = 51u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeGlobalEnumAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 51u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Globalenum attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Globalenum attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -9138,68 +8519,61 @@ suspend fun readGlobalEnumAttribute(): UByte {val ATTRIBUTE_ID: UInt = 51u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readGlobalStructAttribute(): GlobalStructAttribute {val ATTRIBUTE_ID: UInt = 52u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readGlobalStructAttribute(): GlobalStructAttribute { + val ATTRIBUTE_ID: UInt = 52u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Globalstruct attribute not found in response" - } + } + + requireNotNull(attributeData) { "Globalstruct attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UnitTestingClusterTestGlobalStruct = UnitTestingClusterTestGlobalStruct.fromTlv(AnonymousTag, tlvReader) - + val decodedValue: UnitTestingClusterTestGlobalStruct = + UnitTestingClusterTestGlobalStruct.fromTlv(AnonymousTag, tlvReader) return GlobalStructAttribute(decodedValue) } suspend fun writeGlobalStructAttribute( value: UnitTestingClusterTestGlobalStruct, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 52u val tlvWriter = TlvWriter() - value.toTlv(AnonymousTag, tlvWriter) + value.toTlv(AnonymousTag, tlvWriter) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -9220,47 +8594,50 @@ suspend fun readGlobalStructAttribute(): GlobalStructAttribute {val ATTRIBUTE_ID throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeGlobalStructAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 52u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(GlobalStructAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + GlobalStructAttributeSubscriptionState.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) { - "Globalstruct attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Globalstruct attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UnitTestingClusterTestGlobalStruct = UnitTestingClusterTestGlobalStruct.fromTlv(AnonymousTag, tlvReader) + val decodedValue: UnitTestingClusterTestGlobalStruct = + UnitTestingClusterTestGlobalStruct.fromTlv(AnonymousTag, tlvReader) emit(GlobalStructAttributeSubscriptionState.Success(decodedValue)) } @@ -9268,72 +8645,62 @@ suspend fun readGlobalStructAttribute(): GlobalStructAttribute {val ATTRIBUTE_ID emit(GlobalStructAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readUnsupportedAttribute(): Boolean? {val ATTRIBUTE_ID: UInt = 255u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readUnsupportedAttribute(): Boolean? { + val ATTRIBUTE_ID: UInt = 255u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Unsupported attribute not found in response" - } + } + + requireNotNull(attributeData) { "Unsupported 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 - } - + val decodedValue: Boolean? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } return decodedValue } - suspend fun writeUnsupportedAttribute( - value: Boolean, - timedWriteTimeout: Duration? = null) { + suspend fun writeUnsupportedAttribute(value: Boolean, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 255u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -9354,128 +8721,118 @@ suspend fun readUnsupportedAttribute(): Boolean? {val ATTRIBUTE_ID: UInt = 255u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeUnsupportedAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 255u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Unsupported attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Unsupported 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 - } + val decodedValue: Boolean? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getBoolean(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(BooleanSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(BooleanSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(BooleanSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNullableBooleanAttribute(): NullableBooleanAttribute {val ATTRIBUTE_ID: UInt = 16384u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNullableBooleanAttribute(): NullableBooleanAttribute { + val ATTRIBUTE_ID: UInt = 16384u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Nullableboolean attribute not found in response" - } + } + + requireNotNull(attributeData) { "Nullableboolean attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Boolean? = if (!tlvReader.isNull()) { - tlvReader.getBoolean(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Boolean? = + if (!tlvReader.isNull()) { + tlvReader.getBoolean(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return NullableBooleanAttribute(decodedValue) } - suspend fun writeNullableBooleanAttribute( - value: Boolean, - timedWriteTimeout: Duration? = null) { + suspend fun writeNullableBooleanAttribute(value: Boolean, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16384u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -9496,129 +8853,121 @@ suspend fun readNullableBooleanAttribute(): NullableBooleanAttribute {val ATTRIB throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableBooleanAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16384u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(NullableBooleanAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + NullableBooleanAttributeSubscriptionState.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) { - "Nullableboolean attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Nullableboolean 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.isNull()) { - tlvReader.getBoolean(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Boolean? = + if (!tlvReader.isNull()) { + tlvReader.getBoolean(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(NullableBooleanAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(NullableBooleanAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(NullableBooleanAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNullableBitmap8Attribute(): NullableBitmap8Attribute {val ATTRIBUTE_ID: UInt = 16385u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNullableBitmap8Attribute(): NullableBitmap8Attribute { + val ATTRIBUTE_ID: UInt = 16385u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Nullablebitmap8 attribute not found in response" - } + } + + requireNotNull(attributeData) { "Nullablebitmap8 attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return NullableBitmap8Attribute(decodedValue) } - suspend fun writeNullableBitmap8Attribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeNullableBitmap8Attribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16385u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -9639,129 +8988,121 @@ suspend fun readNullableBitmap8Attribute(): NullableBitmap8Attribute {val ATTRIB throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableBitmap8Attribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16385u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(NullableBitmap8AttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + NullableBitmap8AttributeSubscriptionState.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) { - "Nullablebitmap8 attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Nullablebitmap8 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.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(NullableBitmap8AttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(NullableBitmap8AttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(NullableBitmap8AttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNullableBitmap16Attribute(): NullableBitmap16Attribute {val ATTRIBUTE_ID: UInt = 16386u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNullableBitmap16Attribute(): NullableBitmap16Attribute { + val ATTRIBUTE_ID: UInt = 16386u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Nullablebitmap16 attribute not found in response" - } + } + + requireNotNull(attributeData) { "Nullablebitmap16 attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = if (!tlvReader.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return NullableBitmap16Attribute(decodedValue) } - suspend fun writeNullableBitmap16Attribute( - value: UShort, - timedWriteTimeout: Duration? = null) { + suspend fun writeNullableBitmap16Attribute(value: UShort, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16386u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -9782,129 +9123,121 @@ suspend fun readNullableBitmap16Attribute(): NullableBitmap16Attribute {val ATTR throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableBitmap16Attribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16386u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(NullableBitmap16AttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + NullableBitmap16AttributeSubscriptionState.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) { - "Nullablebitmap16 attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Nullablebitmap16 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.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(NullableBitmap16AttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(NullableBitmap16AttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(NullableBitmap16AttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNullableBitmap32Attribute(): NullableBitmap32Attribute {val ATTRIBUTE_ID: UInt = 16387u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNullableBitmap32Attribute(): NullableBitmap32Attribute { + val ATTRIBUTE_ID: UInt = 16387u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Nullablebitmap32 attribute not found in response" - } + } + + requireNotNull(attributeData) { "Nullablebitmap32 attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - tlvReader.getUInt(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + tlvReader.getUInt(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return NullableBitmap32Attribute(decodedValue) } - suspend fun writeNullableBitmap32Attribute( - value: UInt, - timedWriteTimeout: Duration? = null) { + suspend fun writeNullableBitmap32Attribute(value: UInt, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16387u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -9925,129 +9258,121 @@ suspend fun readNullableBitmap32Attribute(): NullableBitmap32Attribute {val ATTR throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableBitmap32Attribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16387u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(NullableBitmap32AttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + NullableBitmap32AttributeSubscriptionState.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) { - "Nullablebitmap32 attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Nullablebitmap32 attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - tlvReader.getUInt(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + tlvReader.getUInt(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(NullableBitmap32AttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(NullableBitmap32AttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(NullableBitmap32AttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNullableBitmap64Attribute(): NullableBitmap64Attribute {val ATTRIBUTE_ID: UInt = 16388u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNullableBitmap64Attribute(): NullableBitmap64Attribute { + val ATTRIBUTE_ID: UInt = 16388u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Nullablebitmap64 attribute not found in response" - } + } + + requireNotNull(attributeData) { "Nullablebitmap64 attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ULong? = if (!tlvReader.isNull()) { - tlvReader.getULong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: ULong? = + if (!tlvReader.isNull()) { + tlvReader.getULong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return NullableBitmap64Attribute(decodedValue) } - suspend fun writeNullableBitmap64Attribute( - value: ULong, - timedWriteTimeout: Duration? = null) { + suspend fun writeNullableBitmap64Attribute(value: ULong, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16388u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -10068,129 +9393,121 @@ suspend fun readNullableBitmap64Attribute(): NullableBitmap64Attribute {val ATTR throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableBitmap64Attribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16388u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(NullableBitmap64AttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + NullableBitmap64AttributeSubscriptionState.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) { - "Nullablebitmap64 attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Nullablebitmap64 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()) { - tlvReader.getULong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ULong? = + if (!tlvReader.isNull()) { + tlvReader.getULong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(NullableBitmap64AttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(NullableBitmap64AttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(NullableBitmap64AttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNullableInt8uAttribute(): NullableInt8uAttribute {val ATTRIBUTE_ID: UInt = 16389u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNullableInt8uAttribute(): NullableInt8uAttribute { + val ATTRIBUTE_ID: UInt = 16389u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Nullableint8u attribute not found in response" - } + } + + requireNotNull(attributeData) { "Nullableint8u attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return NullableInt8uAttribute(decodedValue) } - suspend fun writeNullableInt8uAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeNullableInt8uAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16389u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -10211,129 +9528,119 @@ suspend fun readNullableInt8uAttribute(): NullableInt8uAttribute {val ATTRIBUTE_ throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableInt8uAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16389u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(NullableInt8uAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + NullableInt8uAttributeSubscriptionState.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) { - "Nullableint8u attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Nullableint8u 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.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(NullableInt8uAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(NullableInt8uAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(NullableInt8uAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNullableInt16uAttribute(): NullableInt16uAttribute {val ATTRIBUTE_ID: UInt = 16390u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNullableInt16uAttribute(): NullableInt16uAttribute { + val ATTRIBUTE_ID: UInt = 16390u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Nullableint16u attribute not found in response" - } + } + + requireNotNull(attributeData) { "Nullableint16u attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = if (!tlvReader.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return NullableInt16uAttribute(decodedValue) } - suspend fun writeNullableInt16uAttribute( - value: UShort, - timedWriteTimeout: Duration? = null) { + suspend fun writeNullableInt16uAttribute(value: UShort, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16390u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -10354,129 +9661,121 @@ suspend fun readNullableInt16uAttribute(): NullableInt16uAttribute {val ATTRIBUT throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableInt16uAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16390u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(NullableInt16uAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + NullableInt16uAttributeSubscriptionState.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) { - "Nullableint16u attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Nullableint16u 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.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(NullableInt16uAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(NullableInt16uAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(NullableInt16uAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNullableInt24uAttribute(): NullableInt24uAttribute {val ATTRIBUTE_ID: UInt = 16391u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNullableInt24uAttribute(): NullableInt24uAttribute { + val ATTRIBUTE_ID: UInt = 16391u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Nullableint24u attribute not found in response" - } + } + + requireNotNull(attributeData) { "Nullableint24u attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - tlvReader.getUInt(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + tlvReader.getUInt(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return NullableInt24uAttribute(decodedValue) } - suspend fun writeNullableInt24uAttribute( - value: UInt, - timedWriteTimeout: Duration? = null) { + suspend fun writeNullableInt24uAttribute(value: UInt, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16391u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -10497,129 +9796,121 @@ suspend fun readNullableInt24uAttribute(): NullableInt24uAttribute {val ATTRIBUT throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableInt24uAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16391u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(NullableInt24uAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + NullableInt24uAttributeSubscriptionState.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) { - "Nullableint24u attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Nullableint24u attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - tlvReader.getUInt(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + tlvReader.getUInt(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(NullableInt24uAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(NullableInt24uAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(NullableInt24uAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNullableInt32uAttribute(): NullableInt32uAttribute {val ATTRIBUTE_ID: UInt = 16392u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNullableInt32uAttribute(): NullableInt32uAttribute { + val ATTRIBUTE_ID: UInt = 16392u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Nullableint32u attribute not found in response" - } + } + + requireNotNull(attributeData) { "Nullableint32u attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - tlvReader.getUInt(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + tlvReader.getUInt(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return NullableInt32uAttribute(decodedValue) } - suspend fun writeNullableInt32uAttribute( - value: UInt, - timedWriteTimeout: Duration? = null) { + suspend fun writeNullableInt32uAttribute(value: UInt, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16392u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -10640,129 +9931,121 @@ suspend fun readNullableInt32uAttribute(): NullableInt32uAttribute {val ATTRIBUT throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableInt32uAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16392u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(NullableInt32uAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + NullableInt32uAttributeSubscriptionState.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) { - "Nullableint32u attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Nullableint32u attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - tlvReader.getUInt(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + tlvReader.getUInt(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(NullableInt32uAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(NullableInt32uAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(NullableInt32uAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNullableInt40uAttribute(): NullableInt40uAttribute {val ATTRIBUTE_ID: UInt = 16393u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNullableInt40uAttribute(): NullableInt40uAttribute { + val ATTRIBUTE_ID: UInt = 16393u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Nullableint40u attribute not found in response" - } + } + + requireNotNull(attributeData) { "Nullableint40u attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ULong? = if (!tlvReader.isNull()) { - tlvReader.getULong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: ULong? = + if (!tlvReader.isNull()) { + tlvReader.getULong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return NullableInt40uAttribute(decodedValue) } - suspend fun writeNullableInt40uAttribute( - value: ULong, - timedWriteTimeout: Duration? = null) { + suspend fun writeNullableInt40uAttribute(value: ULong, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16393u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -10783,129 +10066,121 @@ suspend fun readNullableInt40uAttribute(): NullableInt40uAttribute {val ATTRIBUT throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableInt40uAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16393u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(NullableInt40uAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + NullableInt40uAttributeSubscriptionState.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) { - "Nullableint40u attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Nullableint40u 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()) { - tlvReader.getULong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ULong? = + if (!tlvReader.isNull()) { + tlvReader.getULong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(NullableInt40uAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(NullableInt40uAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(NullableInt40uAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNullableInt48uAttribute(): NullableInt48uAttribute {val ATTRIBUTE_ID: UInt = 16394u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNullableInt48uAttribute(): NullableInt48uAttribute { + val ATTRIBUTE_ID: UInt = 16394u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Nullableint48u attribute not found in response" - } + } + + requireNotNull(attributeData) { "Nullableint48u attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ULong? = if (!tlvReader.isNull()) { - tlvReader.getULong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: ULong? = + if (!tlvReader.isNull()) { + tlvReader.getULong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return NullableInt48uAttribute(decodedValue) } - suspend fun writeNullableInt48uAttribute( - value: ULong, - timedWriteTimeout: Duration? = null) { + suspend fun writeNullableInt48uAttribute(value: ULong, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16394u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -10926,129 +10201,121 @@ suspend fun readNullableInt48uAttribute(): NullableInt48uAttribute {val ATTRIBUT throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableInt48uAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16394u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(NullableInt48uAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + NullableInt48uAttributeSubscriptionState.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) { - "Nullableint48u attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Nullableint48u 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()) { - tlvReader.getULong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ULong? = + if (!tlvReader.isNull()) { + tlvReader.getULong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(NullableInt48uAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(NullableInt48uAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(NullableInt48uAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNullableInt56uAttribute(): NullableInt56uAttribute {val ATTRIBUTE_ID: UInt = 16395u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNullableInt56uAttribute(): NullableInt56uAttribute { + val ATTRIBUTE_ID: UInt = 16395u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Nullableint56u attribute not found in response" - } + } + + requireNotNull(attributeData) { "Nullableint56u attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ULong? = if (!tlvReader.isNull()) { - tlvReader.getULong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: ULong? = + if (!tlvReader.isNull()) { + tlvReader.getULong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return NullableInt56uAttribute(decodedValue) } - suspend fun writeNullableInt56uAttribute( - value: ULong, - timedWriteTimeout: Duration? = null) { + suspend fun writeNullableInt56uAttribute(value: ULong, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16395u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -11069,129 +10336,121 @@ suspend fun readNullableInt56uAttribute(): NullableInt56uAttribute {val ATTRIBUT throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableInt56uAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16395u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(NullableInt56uAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + NullableInt56uAttributeSubscriptionState.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) { - "Nullableint56u attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Nullableint56u 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()) { - tlvReader.getULong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ULong? = + if (!tlvReader.isNull()) { + tlvReader.getULong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(NullableInt56uAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(NullableInt56uAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(NullableInt56uAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNullableInt64uAttribute(): NullableInt64uAttribute {val ATTRIBUTE_ID: UInt = 16396u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNullableInt64uAttribute(): NullableInt64uAttribute { + val ATTRIBUTE_ID: UInt = 16396u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Nullableint64u attribute not found in response" - } + } + + requireNotNull(attributeData) { "Nullableint64u attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ULong? = if (!tlvReader.isNull()) { - tlvReader.getULong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: ULong? = + if (!tlvReader.isNull()) { + tlvReader.getULong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return NullableInt64uAttribute(decodedValue) } - suspend fun writeNullableInt64uAttribute( - value: ULong, - timedWriteTimeout: Duration? = null) { + suspend fun writeNullableInt64uAttribute(value: ULong, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16396u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -11212,129 +10471,121 @@ suspend fun readNullableInt64uAttribute(): NullableInt64uAttribute {val ATTRIBUT throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableInt64uAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16396u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(NullableInt64uAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + NullableInt64uAttributeSubscriptionState.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) { - "Nullableint64u attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Nullableint64u 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()) { - tlvReader.getULong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ULong? = + if (!tlvReader.isNull()) { + tlvReader.getULong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(NullableInt64uAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(NullableInt64uAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(NullableInt64uAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNullableInt8sAttribute(): NullableInt8sAttribute {val ATTRIBUTE_ID: UInt = 16397u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNullableInt8sAttribute(): NullableInt8sAttribute { + val ATTRIBUTE_ID: UInt = 16397u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Nullableint8s attribute not found in response" - } + } + + requireNotNull(attributeData) { "Nullableint8s attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Byte? = if (!tlvReader.isNull()) { - tlvReader.getByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Byte? = + if (!tlvReader.isNull()) { + tlvReader.getByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return NullableInt8sAttribute(decodedValue) } - suspend fun writeNullableInt8sAttribute( - value: Byte, - timedWriteTimeout: Duration? = null) { + suspend fun writeNullableInt8sAttribute(value: Byte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16397u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -11355,129 +10606,119 @@ suspend fun readNullableInt8sAttribute(): NullableInt8sAttribute {val ATTRIBUTE_ throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableInt8sAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16397u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(NullableInt8sAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + NullableInt8sAttributeSubscriptionState.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) { - "Nullableint8s attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Nullableint8s attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Byte? = if (!tlvReader.isNull()) { - tlvReader.getByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Byte? = + if (!tlvReader.isNull()) { + tlvReader.getByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(NullableInt8sAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(NullableInt8sAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(NullableInt8sAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNullableInt16sAttribute(): NullableInt16sAttribute {val ATTRIBUTE_ID: UInt = 16398u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNullableInt16sAttribute(): NullableInt16sAttribute { + val ATTRIBUTE_ID: UInt = 16398u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Nullableint16s attribute not found in response" - } + } + + requireNotNull(attributeData) { "Nullableint16s attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (!tlvReader.isNull()) { - tlvReader.getShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Short? = + if (!tlvReader.isNull()) { + tlvReader.getShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return NullableInt16sAttribute(decodedValue) } - suspend fun writeNullableInt16sAttribute( - value: Short, - timedWriteTimeout: Duration? = null) { + suspend fun writeNullableInt16sAttribute(value: Short, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16398u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -11498,129 +10739,121 @@ suspend fun readNullableInt16sAttribute(): NullableInt16sAttribute {val ATTRIBUT throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableInt16sAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16398u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(NullableInt16sAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + NullableInt16sAttributeSubscriptionState.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) { - "Nullableint16s attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Nullableint16s attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (!tlvReader.isNull()) { - tlvReader.getShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Short? = + if (!tlvReader.isNull()) { + tlvReader.getShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(NullableInt16sAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(NullableInt16sAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(NullableInt16sAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNullableInt24sAttribute(): NullableInt24sAttribute {val ATTRIBUTE_ID: UInt = 16399u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNullableInt24sAttribute(): NullableInt24sAttribute { + val ATTRIBUTE_ID: UInt = 16399u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Nullableint24s attribute not found in response" - } + } + + requireNotNull(attributeData) { "Nullableint24s attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Int? = if (!tlvReader.isNull()) { - tlvReader.getInt(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Int? = + if (!tlvReader.isNull()) { + tlvReader.getInt(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return NullableInt24sAttribute(decodedValue) } - suspend fun writeNullableInt24sAttribute( - value: Int, - timedWriteTimeout: Duration? = null) { + suspend fun writeNullableInt24sAttribute(value: Int, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16399u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -11641,129 +10874,121 @@ suspend fun readNullableInt24sAttribute(): NullableInt24sAttribute {val ATTRIBUT throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableInt24sAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16399u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(NullableInt24sAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + NullableInt24sAttributeSubscriptionState.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) { - "Nullableint24s attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Nullableint24s attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Int? = if (!tlvReader.isNull()) { - tlvReader.getInt(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Int? = + if (!tlvReader.isNull()) { + tlvReader.getInt(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(NullableInt24sAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(NullableInt24sAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(NullableInt24sAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNullableInt32sAttribute(): NullableInt32sAttribute {val ATTRIBUTE_ID: UInt = 16400u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNullableInt32sAttribute(): NullableInt32sAttribute { + val ATTRIBUTE_ID: UInt = 16400u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Nullableint32s attribute not found in response" - } + } + + requireNotNull(attributeData) { "Nullableint32s attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Int? = if (!tlvReader.isNull()) { - tlvReader.getInt(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Int? = + if (!tlvReader.isNull()) { + tlvReader.getInt(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return NullableInt32sAttribute(decodedValue) } - suspend fun writeNullableInt32sAttribute( - value: Int, - timedWriteTimeout: Duration? = null) { + suspend fun writeNullableInt32sAttribute(value: Int, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16400u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -11784,129 +11009,121 @@ suspend fun readNullableInt32sAttribute(): NullableInt32sAttribute {val ATTRIBUT throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableInt32sAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16400u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(NullableInt32sAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + NullableInt32sAttributeSubscriptionState.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) { - "Nullableint32s attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Nullableint32s attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Int? = if (!tlvReader.isNull()) { - tlvReader.getInt(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Int? = + if (!tlvReader.isNull()) { + tlvReader.getInt(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(NullableInt32sAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(NullableInt32sAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(NullableInt32sAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNullableInt40sAttribute(): NullableInt40sAttribute {val ATTRIBUTE_ID: UInt = 16401u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNullableInt40sAttribute(): NullableInt40sAttribute { + val ATTRIBUTE_ID: UInt = 16401u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Nullableint40s attribute not found in response" - } + } + + requireNotNull(attributeData) { "Nullableint40s attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = if (!tlvReader.isNull()) { - tlvReader.getLong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Long? = + if (!tlvReader.isNull()) { + tlvReader.getLong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return NullableInt40sAttribute(decodedValue) } - suspend fun writeNullableInt40sAttribute( - value: Long, - timedWriteTimeout: Duration? = null) { + suspend fun writeNullableInt40sAttribute(value: Long, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16401u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -11927,129 +11144,121 @@ suspend fun readNullableInt40sAttribute(): NullableInt40sAttribute {val ATTRIBUT throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableInt40sAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16401u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(NullableInt40sAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + NullableInt40sAttributeSubscriptionState.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) { - "Nullableint40s attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Nullableint40s attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = if (!tlvReader.isNull()) { - tlvReader.getLong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Long? = + if (!tlvReader.isNull()) { + tlvReader.getLong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(NullableInt40sAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(NullableInt40sAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(NullableInt40sAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNullableInt48sAttribute(): NullableInt48sAttribute {val ATTRIBUTE_ID: UInt = 16402u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNullableInt48sAttribute(): NullableInt48sAttribute { + val ATTRIBUTE_ID: UInt = 16402u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Nullableint48s attribute not found in response" - } + } + + requireNotNull(attributeData) { "Nullableint48s attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = if (!tlvReader.isNull()) { - tlvReader.getLong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Long? = + if (!tlvReader.isNull()) { + tlvReader.getLong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return NullableInt48sAttribute(decodedValue) } - suspend fun writeNullableInt48sAttribute( - value: Long, - timedWriteTimeout: Duration? = null) { + suspend fun writeNullableInt48sAttribute(value: Long, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16402u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -12070,129 +11279,121 @@ suspend fun readNullableInt48sAttribute(): NullableInt48sAttribute {val ATTRIBUT throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableInt48sAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16402u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(NullableInt48sAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + NullableInt48sAttributeSubscriptionState.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) { - "Nullableint48s attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Nullableint48s attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = if (!tlvReader.isNull()) { - tlvReader.getLong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Long? = + if (!tlvReader.isNull()) { + tlvReader.getLong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(NullableInt48sAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(NullableInt48sAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(NullableInt48sAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNullableInt56sAttribute(): NullableInt56sAttribute {val ATTRIBUTE_ID: UInt = 16403u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNullableInt56sAttribute(): NullableInt56sAttribute { + val ATTRIBUTE_ID: UInt = 16403u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Nullableint56s attribute not found in response" - } + } + + requireNotNull(attributeData) { "Nullableint56s attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = if (!tlvReader.isNull()) { - tlvReader.getLong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Long? = + if (!tlvReader.isNull()) { + tlvReader.getLong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return NullableInt56sAttribute(decodedValue) } - suspend fun writeNullableInt56sAttribute( - value: Long, - timedWriteTimeout: Duration? = null) { + suspend fun writeNullableInt56sAttribute(value: Long, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16403u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -12213,129 +11414,121 @@ suspend fun readNullableInt56sAttribute(): NullableInt56sAttribute {val ATTRIBUT throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableInt56sAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16403u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(NullableInt56sAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + NullableInt56sAttributeSubscriptionState.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) { - "Nullableint56s attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Nullableint56s attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = if (!tlvReader.isNull()) { - tlvReader.getLong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Long? = + if (!tlvReader.isNull()) { + tlvReader.getLong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(NullableInt56sAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(NullableInt56sAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(NullableInt56sAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNullableInt64sAttribute(): NullableInt64sAttribute {val ATTRIBUTE_ID: UInt = 16404u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNullableInt64sAttribute(): NullableInt64sAttribute { + val ATTRIBUTE_ID: UInt = 16404u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Nullableint64s attribute not found in response" - } + } + + requireNotNull(attributeData) { "Nullableint64s attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = if (!tlvReader.isNull()) { - tlvReader.getLong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Long? = + if (!tlvReader.isNull()) { + tlvReader.getLong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return NullableInt64sAttribute(decodedValue) } - suspend fun writeNullableInt64sAttribute( - value: Long, - timedWriteTimeout: Duration? = null) { + suspend fun writeNullableInt64sAttribute(value: Long, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16404u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -12356,129 +11549,121 @@ suspend fun readNullableInt64sAttribute(): NullableInt64sAttribute {val ATTRIBUT throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableInt64sAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16404u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(NullableInt64sAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + NullableInt64sAttributeSubscriptionState.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) { - "Nullableint64s attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Nullableint64s attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = if (!tlvReader.isNull()) { - tlvReader.getLong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Long? = + if (!tlvReader.isNull()) { + tlvReader.getLong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(NullableInt64sAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(NullableInt64sAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(NullableInt64sAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNullableEnum8Attribute(): NullableEnum8Attribute {val ATTRIBUTE_ID: UInt = 16405u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNullableEnum8Attribute(): NullableEnum8Attribute { + val ATTRIBUTE_ID: UInt = 16405u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Nullableenum8 attribute not found in response" - } + } + + requireNotNull(attributeData) { "Nullableenum8 attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return NullableEnum8Attribute(decodedValue) } - suspend fun writeNullableEnum8Attribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeNullableEnum8Attribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16405u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -12499,129 +11684,119 @@ suspend fun readNullableEnum8Attribute(): NullableEnum8Attribute {val ATTRIBUTE_ throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableEnum8Attribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16405u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(NullableEnum8AttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + NullableEnum8AttributeSubscriptionState.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) { - "Nullableenum8 attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Nullableenum8 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.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(NullableEnum8AttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(NullableEnum8AttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(NullableEnum8AttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNullableEnum16Attribute(): NullableEnum16Attribute {val ATTRIBUTE_ID: UInt = 16406u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNullableEnum16Attribute(): NullableEnum16Attribute { + val ATTRIBUTE_ID: UInt = 16406u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Nullableenum16 attribute not found in response" - } + } + + requireNotNull(attributeData) { "Nullableenum16 attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = if (!tlvReader.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return NullableEnum16Attribute(decodedValue) } - suspend fun writeNullableEnum16Attribute( - value: UShort, - timedWriteTimeout: Duration? = null) { + suspend fun writeNullableEnum16Attribute(value: UShort, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16406u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -12642,129 +11817,121 @@ suspend fun readNullableEnum16Attribute(): NullableEnum16Attribute {val ATTRIBUT throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableEnum16Attribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16406u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(NullableEnum16AttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + NullableEnum16AttributeSubscriptionState.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) { - "Nullableenum16 attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Nullableenum16 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.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(NullableEnum16AttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(NullableEnum16AttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(NullableEnum16AttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNullableFloatSingleAttribute(): NullableFloatSingleAttribute {val ATTRIBUTE_ID: UInt = 16407u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNullableFloatSingleAttribute(): NullableFloatSingleAttribute { + val ATTRIBUTE_ID: UInt = 16407u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Nullablefloatsingle attribute not found in response" - } + } + + requireNotNull(attributeData) { "Nullablefloatsingle attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - tlvReader.getFloat(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Float? = + if (!tlvReader.isNull()) { + tlvReader.getFloat(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return NullableFloatSingleAttribute(decodedValue) } - suspend fun writeNullableFloatSingleAttribute( - value: Float, - timedWriteTimeout: Duration? = null) { + suspend fun writeNullableFloatSingleAttribute(value: Float, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16407u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -12785,129 +11952,124 @@ suspend fun readNullableFloatSingleAttribute(): NullableFloatSingleAttribute {va throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableFloatSingleAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16407u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(NullableFloatSingleAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + NullableFloatSingleAttributeSubscriptionState.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) { - "Nullablefloatsingle attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Nullablefloatsingle attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Float? = if (!tlvReader.isNull()) { - tlvReader.getFloat(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Float? = + if (!tlvReader.isNull()) { + tlvReader.getFloat(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(NullableFloatSingleAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(NullableFloatSingleAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(NullableFloatSingleAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNullableFloatDoubleAttribute(): NullableFloatDoubleAttribute {val ATTRIBUTE_ID: UInt = 16408u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNullableFloatDoubleAttribute(): NullableFloatDoubleAttribute { + val ATTRIBUTE_ID: UInt = 16408u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Nullablefloatdouble attribute not found in response" - } + } + + requireNotNull(attributeData) { "Nullablefloatdouble attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Double? = if (!tlvReader.isNull()) { - tlvReader.getDouble(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Double? = + if (!tlvReader.isNull()) { + tlvReader.getDouble(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return NullableFloatDoubleAttribute(decodedValue) } suspend fun writeNullableFloatDoubleAttribute( value: Double, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 16408u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -12928,129 +12090,124 @@ suspend fun readNullableFloatDoubleAttribute(): NullableFloatDoubleAttribute {va throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableFloatDoubleAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16408u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(NullableFloatDoubleAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + NullableFloatDoubleAttributeSubscriptionState.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) { - "Nullablefloatdouble attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Nullablefloatdouble attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Double? = if (!tlvReader.isNull()) { - tlvReader.getDouble(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Double? = + if (!tlvReader.isNull()) { + tlvReader.getDouble(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(NullableFloatDoubleAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(NullableFloatDoubleAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(NullableFloatDoubleAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNullableOctetStringAttribute(): NullableOctetStringAttribute {val ATTRIBUTE_ID: UInt = 16409u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNullableOctetStringAttribute(): NullableOctetStringAttribute { + val ATTRIBUTE_ID: UInt = 16409u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Nullableoctetstring attribute not found in response" - } + } + + requireNotNull(attributeData) { "Nullableoctetstring attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = if (!tlvReader.isNull()) { - tlvReader.getByteArray(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: ByteArray? = + if (!tlvReader.isNull()) { + tlvReader.getByteArray(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return NullableOctetStringAttribute(decodedValue) } suspend fun writeNullableOctetStringAttribute( value: ByteArray, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 16409u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -13071,129 +12228,121 @@ suspend fun readNullableOctetStringAttribute(): NullableOctetStringAttribute {va throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableOctetStringAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16409u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(NullableOctetStringAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + NullableOctetStringAttributeSubscriptionState.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) { - "Nullableoctetstring attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Nullableoctetstring attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = if (!tlvReader.isNull()) { - tlvReader.getByteArray(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: ByteArray? = + if (!tlvReader.isNull()) { + tlvReader.getByteArray(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(NullableOctetStringAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(NullableOctetStringAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(NullableOctetStringAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNullableCharStringAttribute(): NullableCharStringAttribute {val ATTRIBUTE_ID: UInt = 16414u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNullableCharStringAttribute(): NullableCharStringAttribute { + val ATTRIBUTE_ID: UInt = 16414u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Nullablecharstring attribute not found in response" - } + } + + requireNotNull(attributeData) { "Nullablecharstring attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (!tlvReader.isNull()) { - tlvReader.getString(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: String? = + if (!tlvReader.isNull()) { + tlvReader.getString(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return NullableCharStringAttribute(decodedValue) } - suspend fun writeNullableCharStringAttribute( - value: String, - timedWriteTimeout: Duration? = null) { + suspend fun writeNullableCharStringAttribute(value: String, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16414u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -13214,129 +12363,121 @@ suspend fun readNullableCharStringAttribute(): NullableCharStringAttribute {val throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableCharStringAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16414u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(NullableCharStringAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + NullableCharStringAttributeSubscriptionState.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) { - "Nullablecharstring attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Nullablecharstring attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (!tlvReader.isNull()) { - tlvReader.getString(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: String? = + if (!tlvReader.isNull()) { + tlvReader.getString(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(NullableCharStringAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(NullableCharStringAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(NullableCharStringAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNullableEnumAttrAttribute(): NullableEnumAttrAttribute {val ATTRIBUTE_ID: UInt = 16420u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNullableEnumAttrAttribute(): NullableEnumAttrAttribute { + val ATTRIBUTE_ID: UInt = 16420u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Nullableenumattr attribute not found in response" - } + } + + requireNotNull(attributeData) { "Nullableenumattr attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return NullableEnumAttrAttribute(decodedValue) } - suspend fun writeNullableEnumAttrAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeNullableEnumAttrAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16420u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -13357,129 +12498,124 @@ suspend fun readNullableEnumAttrAttribute(): NullableEnumAttrAttribute {val ATTR throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableEnumAttrAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16420u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(NullableEnumAttrAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + NullableEnumAttrAttributeSubscriptionState.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) { - "Nullableenumattr attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Nullableenumattr 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.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(NullableEnumAttrAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(NullableEnumAttrAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(NullableEnumAttrAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNullableStructAttribute(): NullableStructAttribute {val ATTRIBUTE_ID: UInt = 16421u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNullableStructAttribute(): NullableStructAttribute { + val ATTRIBUTE_ID: UInt = 16421u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Nullablestruct attribute not found in response" - } + } + + requireNotNull(attributeData) { "Nullablestruct attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UnitTestingClusterSimpleStruct? = if (!tlvReader.isNull()) { - UnitTestingClusterSimpleStruct.fromTlv(AnonymousTag, tlvReader) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UnitTestingClusterSimpleStruct? = + if (!tlvReader.isNull()) { + UnitTestingClusterSimpleStruct.fromTlv(AnonymousTag, tlvReader) + } else { + tlvReader.getNull(AnonymousTag) + null + } return NullableStructAttribute(decodedValue) } suspend fun writeNullableStructAttribute( value: UnitTestingClusterSimpleStruct, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 16421u val tlvWriter = TlvWriter() - value.toTlv(AnonymousTag, tlvWriter) + value.toTlv(AnonymousTag, tlvWriter) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -13500,129 +12636,124 @@ suspend fun readNullableStructAttribute(): NullableStructAttribute {val ATTRIBUT throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableStructAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16421u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(NullableStructAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + NullableStructAttributeSubscriptionState.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) { - "Nullablestruct attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Nullablestruct attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UnitTestingClusterSimpleStruct? = if (!tlvReader.isNull()) { - UnitTestingClusterSimpleStruct.fromTlv(AnonymousTag, tlvReader) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UnitTestingClusterSimpleStruct? = + if (!tlvReader.isNull()) { + UnitTestingClusterSimpleStruct.fromTlv(AnonymousTag, tlvReader) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(NullableStructAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(NullableStructAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(NullableStructAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNullableRangeRestrictedInt8uAttribute(): NullableRangeRestrictedInt8uAttribute {val ATTRIBUTE_ID: UInt = 16422u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNullableRangeRestrictedInt8uAttribute(): NullableRangeRestrictedInt8uAttribute { + val ATTRIBUTE_ID: UInt = 16422u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Nullablerangerestrictedint8u attribute not found in response" - } + } + + requireNotNull(attributeData) { "Nullablerangerestrictedint8u attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return NullableRangeRestrictedInt8uAttribute(decodedValue) } suspend fun writeNullableRangeRestrictedInt8uAttribute( value: UByte, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 16422u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -13643,129 +12774,126 @@ suspend fun readNullableRangeRestrictedInt8uAttribute(): NullableRangeRestricted throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableRangeRestrictedInt8uAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16422u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(NullableRangeRestrictedInt8uAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + NullableRangeRestrictedInt8uAttributeSubscriptionState.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) { - "Nullablerangerestrictedint8u attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Nullablerangerestrictedint8u 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.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } decodedValue?.let { emit(NullableRangeRestrictedInt8uAttributeSubscriptionState.Success(it)) } - } SubscriptionState.SubscriptionEstablished -> { emit(NullableRangeRestrictedInt8uAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNullableRangeRestrictedInt8sAttribute(): NullableRangeRestrictedInt8sAttribute {val ATTRIBUTE_ID: UInt = 16423u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNullableRangeRestrictedInt8sAttribute(): NullableRangeRestrictedInt8sAttribute { + val ATTRIBUTE_ID: UInt = 16423u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Nullablerangerestrictedint8s attribute not found in response" - } + } + + requireNotNull(attributeData) { "Nullablerangerestrictedint8s attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Byte? = if (!tlvReader.isNull()) { - tlvReader.getByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Byte? = + if (!tlvReader.isNull()) { + tlvReader.getByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return NullableRangeRestrictedInt8sAttribute(decodedValue) } suspend fun writeNullableRangeRestrictedInt8sAttribute( value: Byte, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 16423u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -13786,129 +12914,128 @@ suspend fun readNullableRangeRestrictedInt8sAttribute(): NullableRangeRestricted throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableRangeRestrictedInt8sAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16423u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(NullableRangeRestrictedInt8sAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + NullableRangeRestrictedInt8sAttributeSubscriptionState.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) { - "Nullablerangerestrictedint8s attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Nullablerangerestrictedint8s attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Byte? = if (!tlvReader.isNull()) { - tlvReader.getByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Byte? = + if (!tlvReader.isNull()) { + tlvReader.getByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } decodedValue?.let { emit(NullableRangeRestrictedInt8sAttributeSubscriptionState.Success(it)) } - } SubscriptionState.SubscriptionEstablished -> { emit(NullableRangeRestrictedInt8sAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNullableRangeRestrictedInt16uAttribute(): NullableRangeRestrictedInt16uAttribute {val ATTRIBUTE_ID: UInt = 16424u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNullableRangeRestrictedInt16uAttribute(): NullableRangeRestrictedInt16uAttribute { + val ATTRIBUTE_ID: UInt = 16424u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Nullablerangerestrictedint16u attribute not found in response" + } + + requireNotNull(attributeData) { + "Nullablerangerestrictedint16u attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = if (!tlvReader.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return NullableRangeRestrictedInt16uAttribute(decodedValue) } suspend fun writeNullableRangeRestrictedInt16uAttribute( value: UShort, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 16424u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -13929,129 +13056,128 @@ suspend fun readNullableRangeRestrictedInt16uAttribute(): NullableRangeRestricte throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableRangeRestrictedInt16uAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16424u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(NullableRangeRestrictedInt16uAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + NullableRangeRestrictedInt16uAttributeSubscriptionState.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) { - "Nullablerangerestrictedint16u attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Nullablerangerestrictedint16u 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.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } decodedValue?.let { emit(NullableRangeRestrictedInt16uAttributeSubscriptionState.Success(it)) } - } SubscriptionState.SubscriptionEstablished -> { emit(NullableRangeRestrictedInt16uAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNullableRangeRestrictedInt16sAttribute(): NullableRangeRestrictedInt16sAttribute {val ATTRIBUTE_ID: UInt = 16425u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNullableRangeRestrictedInt16sAttribute(): NullableRangeRestrictedInt16sAttribute { + val ATTRIBUTE_ID: UInt = 16425u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Nullablerangerestrictedint16s attribute not found in response" + } + + requireNotNull(attributeData) { + "Nullablerangerestrictedint16s attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (!tlvReader.isNull()) { - tlvReader.getShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Short? = + if (!tlvReader.isNull()) { + tlvReader.getShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return NullableRangeRestrictedInt16sAttribute(decodedValue) } suspend fun writeNullableRangeRestrictedInt16sAttribute( value: Short, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 16425u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -14072,128 +13198,122 @@ suspend fun readNullableRangeRestrictedInt16sAttribute(): NullableRangeRestricte throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableRangeRestrictedInt16sAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16425u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(NullableRangeRestrictedInt16sAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + NullableRangeRestrictedInt16sAttributeSubscriptionState.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) { - "Nullablerangerestrictedint16s attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Nullablerangerestrictedint16s attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Short? = if (!tlvReader.isNull()) { - tlvReader.getShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: Short? = + if (!tlvReader.isNull()) { + tlvReader.getShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } decodedValue?.let { emit(NullableRangeRestrictedInt16sAttributeSubscriptionState.Success(it)) } - } SubscriptionState.SubscriptionEstablished -> { emit(NullableRangeRestrictedInt16sAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readWriteOnlyInt8uAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 16426u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readWriteOnlyInt8uAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 16426u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Writeonlyint8u attribute not found in response" - } + } + + requireNotNull(attributeData) { "Writeonlyint8u 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } - suspend fun writeWriteOnlyInt8uAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeWriteOnlyInt8uAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16426u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -14214,128 +13334,120 @@ suspend fun readWriteOnlyInt8uAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 1642 throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeWriteOnlyInt8uAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16426u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Writeonlyint8u attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Writeonlyint8u 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 - } + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UByteSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNullableGlobalEnumAttribute(): NullableGlobalEnumAttribute {val ATTRIBUTE_ID: UInt = 16435u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNullableGlobalEnumAttribute(): NullableGlobalEnumAttribute { + val ATTRIBUTE_ID: UInt = 16435u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Nullableglobalenum attribute not found in response" - } + } + + requireNotNull(attributeData) { "Nullableglobalenum attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return NullableGlobalEnumAttribute(decodedValue) } - suspend fun writeNullableGlobalEnumAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeNullableGlobalEnumAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 16435u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -14356,129 +13468,124 @@ suspend fun readNullableGlobalEnumAttribute(): NullableGlobalEnumAttribute {val throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableGlobalEnumAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16435u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(NullableGlobalEnumAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + NullableGlobalEnumAttributeSubscriptionState.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) { - "Nullableglobalenum attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Nullableglobalenum 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.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(NullableGlobalEnumAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(NullableGlobalEnumAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(NullableGlobalEnumAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNullableGlobalStructAttribute(): NullableGlobalStructAttribute {val ATTRIBUTE_ID: UInt = 16436u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNullableGlobalStructAttribute(): NullableGlobalStructAttribute { + val ATTRIBUTE_ID: UInt = 16436u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Nullableglobalstruct attribute not found in response" - } + } + + requireNotNull(attributeData) { "Nullableglobalstruct attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UnitTestingClusterTestGlobalStruct? = if (!tlvReader.isNull()) { - UnitTestingClusterTestGlobalStruct.fromTlv(AnonymousTag, tlvReader) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UnitTestingClusterTestGlobalStruct? = + if (!tlvReader.isNull()) { + UnitTestingClusterTestGlobalStruct.fromTlv(AnonymousTag, tlvReader) + } else { + tlvReader.getNull(AnonymousTag) + null + } return NullableGlobalStructAttribute(decodedValue) } suspend fun writeNullableGlobalStructAttribute( value: UnitTestingClusterTestGlobalStruct, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 16436u val tlvWriter = TlvWriter() - value.toTlv(AnonymousTag, tlvWriter) + value.toTlv(AnonymousTag, tlvWriter) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -14499,124 +13606,115 @@ suspend fun readNullableGlobalStructAttribute(): NullableGlobalStructAttribute { throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeNullableGlobalStructAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16436u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(NullableGlobalStructAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + NullableGlobalStructAttributeSubscriptionState.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) { - "Nullableglobalstruct attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Nullableglobalstruct attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UnitTestingClusterTestGlobalStruct? = if (!tlvReader.isNull()) { - UnitTestingClusterTestGlobalStruct.fromTlv(AnonymousTag, tlvReader) - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UnitTestingClusterTestGlobalStruct? = + if (!tlvReader.isNull()) { + UnitTestingClusterTestGlobalStruct.fromTlv(AnonymousTag, tlvReader) + } else { + tlvReader.getNull(AnonymousTag) + null + } - decodedValue?.let { - emit(NullableGlobalStructAttributeSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(NullableGlobalStructAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(NullableGlobalStructAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readMeiInt8uAttribute(): UByte {val ATTRIBUTE_ID: UInt = 4294070017u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readMeiInt8uAttribute(): UByte { + val ATTRIBUTE_ID: UInt = 4294070017u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Meiint8u attribute not found in response" - } + } + + requireNotNull(attributeData) { "Meiint8u 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 writeMeiInt8uAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeMeiInt8uAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 4294070017u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -14637,43 +13735,45 @@ suspend fun readMeiInt8uAttribute(): UByte {val ATTRIBUTE_ID: UInt = 4294070017u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeMeiInt8uAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4294070017u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Meiint8u attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Meiint8u attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -14685,97 +13785,96 @@ suspend fun readMeiInt8uAttribute(): UByte {val ATTRIBUTE_ID: UInt = 4294070017u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65528u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -14783,97 +13882,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { emit(GeneratedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65529u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -14881,97 +13979,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va emit(AcceptedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt = 65530u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -14979,97 +14074,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt emit(EventListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ID: UInt = 65531u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -15077,81 +14169,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ emit(AttributeListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -15163,80 +14250,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 65533u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -15249,7 +14333,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/UserLabelCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/UserLabelCluster.kt index b7fb44b39973dc..db94a02ff8ae52 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/UserLabelCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/UserLabelCluster.kt @@ -17,183 +17,141 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState -import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse -import matter.controller.model.AttributePath -import matter.controller.model.CommandPath import matter.controller.cluster.structs.* +import matter.controller.model.AttributePath import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class UserLabelCluster(private val controller: MatterController, private val endpointId: UShort) {class LabelListAttribute( - val value: List - ) +class UserLabelCluster(private val controller: MatterController, private val endpointId: UShort) { + class LabelListAttribute(val value: List) sealed class LabelListAttributeSubscriptionState { - data class Success( - val value: List - ) : LabelListAttributeSubscriptionState() - + data class Success(val value: List) : + LabelListAttributeSubscriptionState() + data class Error(val exception: Exception) : LabelListAttributeSubscriptionState() - object SubscriptionEstablished : LabelListAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : LabelListAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } -suspend fun readLabelListAttribute(): LabelListAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } + + suspend fun readLabelListAttribute(): LabelListAttribute { + 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}") - } + 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) { - "Labellist attribute not found in response" - } + } + + requireNotNull(attributeData) { "Labellist 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(UserLabelClusterLabelStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(UserLabelClusterLabelStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return LabelListAttribute(decodedValue) } suspend fun writeLabelListAttribute( value: List, - timedWriteTimeout: Duration? = null) { + timedWriteTimeout: Duration? = null, + ) { val ATTRIBUTE_ID: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startArray(AnonymousTag) - for (item in value.iterator()) { - item.toTlv(AnonymousTag, tlvWriter) - } - tlvWriter.endArray() + for (item in value.iterator()) { + item.toTlv(AnonymousTag, tlvWriter) + } + tlvWriter.endArray() val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -214,53 +172,56 @@ suspend fun readLabelListAttribute(): LabelListAttribute {val ATTRIBUTE_ID: UInt throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeLabelListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(LabelListAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + LabelListAttributeSubscriptionState.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) { - "Labellist attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Labellist 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(UserLabelClusterLabelStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(UserLabelClusterLabelStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(LabelListAttributeSubscriptionState.Success(decodedValue)) } @@ -268,97 +229,96 @@ suspend fun readLabelListAttribute(): LabelListAttribute {val ATTRIBUTE_ID: UInt emit(LabelListAttributeSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -366,97 +326,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -464,97 +423,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -562,97 +518,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -660,81 +613,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -746,80 +694,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -832,7 +777,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/ValveConfigurationAndControlCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/ValveConfigurationAndControlCluster.kt index b4b18cde045376..9c6f8bbec2843c 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/ValveConfigurationAndControlCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/ValveConfigurationAndControlCluster.kt @@ -17,229 +17,174 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class ValveConfigurationAndControlCluster(private val controller: MatterController, private val endpointId: UShort) {class OpenDurationAttribute( - val value: UInt? - ) +class ValveConfigurationAndControlCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class OpenDurationAttribute(val value: UInt?) sealed class OpenDurationAttributeSubscriptionState { - data class Success( - val value: UInt? - ) : OpenDurationAttributeSubscriptionState() - + data class Success(val value: UInt?) : OpenDurationAttributeSubscriptionState() + data class Error(val exception: Exception) : OpenDurationAttributeSubscriptionState() - object SubscriptionEstablished : OpenDurationAttributeSubscriptionState() - } -class DefaultOpenDurationAttribute( - val value: UInt? - ) + object SubscriptionEstablished : OpenDurationAttributeSubscriptionState() + } + + class DefaultOpenDurationAttribute(val value: UInt?) sealed class DefaultOpenDurationAttributeSubscriptionState { - data class Success( - val value: UInt? - ) : DefaultOpenDurationAttributeSubscriptionState() - + data class Success(val value: UInt?) : DefaultOpenDurationAttributeSubscriptionState() + data class Error(val exception: Exception) : DefaultOpenDurationAttributeSubscriptionState() - object SubscriptionEstablished : DefaultOpenDurationAttributeSubscriptionState() - } -class AutoCloseTimeAttribute( - val value: ULong? - ) + object SubscriptionEstablished : DefaultOpenDurationAttributeSubscriptionState() + } + + class AutoCloseTimeAttribute(val value: ULong?) sealed class AutoCloseTimeAttributeSubscriptionState { - data class Success( - val value: ULong? - ) : AutoCloseTimeAttributeSubscriptionState() - + data class Success(val value: ULong?) : AutoCloseTimeAttributeSubscriptionState() + data class Error(val exception: Exception) : AutoCloseTimeAttributeSubscriptionState() - object SubscriptionEstablished : AutoCloseTimeAttributeSubscriptionState() - } -class RemainingDurationAttribute( - val value: UInt? - ) + object SubscriptionEstablished : AutoCloseTimeAttributeSubscriptionState() + } + + class RemainingDurationAttribute(val value: UInt?) sealed class RemainingDurationAttributeSubscriptionState { - data class Success( - val value: UInt? - ) : RemainingDurationAttributeSubscriptionState() - + data class Success(val value: UInt?) : RemainingDurationAttributeSubscriptionState() + data class Error(val exception: Exception) : RemainingDurationAttributeSubscriptionState() - object SubscriptionEstablished : RemainingDurationAttributeSubscriptionState() - } -class CurrentStateAttribute( - val value: UByte? - ) + object SubscriptionEstablished : RemainingDurationAttributeSubscriptionState() + } + + class CurrentStateAttribute(val value: UByte?) sealed class CurrentStateAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : CurrentStateAttributeSubscriptionState() - + data class Success(val value: UByte?) : CurrentStateAttributeSubscriptionState() + data class Error(val exception: Exception) : CurrentStateAttributeSubscriptionState() - object SubscriptionEstablished : CurrentStateAttributeSubscriptionState() - } -class TargetStateAttribute( - val value: UByte? - ) + object SubscriptionEstablished : CurrentStateAttributeSubscriptionState() + } + + class TargetStateAttribute(val value: UByte?) sealed class TargetStateAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : TargetStateAttributeSubscriptionState() - + data class Success(val value: UByte?) : TargetStateAttributeSubscriptionState() + data class Error(val exception: Exception) : TargetStateAttributeSubscriptionState() - object SubscriptionEstablished : TargetStateAttributeSubscriptionState() - } -class CurrentLevelAttribute( - val value: UByte? - ) + object SubscriptionEstablished : TargetStateAttributeSubscriptionState() + } + + class CurrentLevelAttribute(val value: UByte?) sealed class CurrentLevelAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : CurrentLevelAttributeSubscriptionState() - + data class Success(val value: UByte?) : CurrentLevelAttributeSubscriptionState() + data class Error(val exception: Exception) : CurrentLevelAttributeSubscriptionState() - object SubscriptionEstablished : CurrentLevelAttributeSubscriptionState() - } -class TargetLevelAttribute( - val value: UByte? - ) + object SubscriptionEstablished : CurrentLevelAttributeSubscriptionState() + } + + class TargetLevelAttribute(val value: UByte?) sealed class TargetLevelAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : TargetLevelAttributeSubscriptionState() - + data class Success(val value: UByte?) : TargetLevelAttributeSubscriptionState() + data class Error(val exception: Exception) : TargetLevelAttributeSubscriptionState() - object SubscriptionEstablished : TargetLevelAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : TargetLevelAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun open(openDuration: UInt? - ,targetLevel: UByte? - ,timedInvokeTimeout: Duration? = null) { + suspend fun open(openDuration: UInt?, targetLevel: UByte?, timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_OPEN_DURATION_REQ: Int = 0 - openDuration?.let { - tlvWriter.put(ContextSpecificTag(TAG_OPEN_DURATION_REQ), openDuration) - } + openDuration?.let { tlvWriter.put(ContextSpecificTag(TAG_OPEN_DURATION_REQ), openDuration) } val TAG_TARGET_LEVEL_REQ: Int = 1 - targetLevel?.let { - tlvWriter.put(ContextSpecificTag(TAG_TARGET_LEVEL_REQ), targetLevel) - } + targetLevel?.let { tlvWriter.put(ContextSpecificTag(TAG_TARGET_LEVEL_REQ), targetLevel) } tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -250,183 +195,167 @@ class AttributeListAttribute( val commandId: UInt = 1u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } -suspend fun readOpenDurationAttribute(): OpenDurationAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readOpenDurationAttribute(): OpenDurationAttribute { + 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}") - } + 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) { - "Openduration attribute not found in response" - } + } + + requireNotNull(attributeData) { "Openduration attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - tlvReader.getUInt(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + tlvReader.getUInt(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return OpenDurationAttribute(decodedValue) } suspend fun subscribeOpenDurationAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(OpenDurationAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + OpenDurationAttributeSubscriptionState.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) { - "Openduration attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Openduration attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - tlvReader.getUInt(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(OpenDurationAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + tlvReader.getUInt(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(OpenDurationAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(OpenDurationAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readDefaultOpenDurationAttribute(): DefaultOpenDurationAttribute {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readDefaultOpenDurationAttribute(): DefaultOpenDurationAttribute { + 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}") - } + 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) { - "Defaultopenduration attribute not found in response" - } + } + + requireNotNull(attributeData) { "Defaultopenduration attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - tlvReader.getUInt(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + tlvReader.getUInt(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return DefaultOpenDurationAttribute(decodedValue) } - suspend fun writeDefaultOpenDurationAttribute( - value: UInt, - timedWriteTimeout: Duration? = null) { + suspend fun writeDefaultOpenDurationAttribute(value: UInt, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 1u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -447,746 +376,704 @@ suspend fun readDefaultOpenDurationAttribute(): DefaultOpenDurationAttribute {va throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeDefaultOpenDurationAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(DefaultOpenDurationAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + DefaultOpenDurationAttributeSubscriptionState.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) { - "Defaultopenduration attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Defaultopenduration attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - tlvReader.getUInt(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(DefaultOpenDurationAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + tlvReader.getUInt(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(DefaultOpenDurationAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(DefaultOpenDurationAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAutoCloseTimeAttribute(): AutoCloseTimeAttribute {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readAutoCloseTimeAttribute(): AutoCloseTimeAttribute { + 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}") - } + 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) { - "Autoclosetime attribute not found in response" - } + } + + requireNotNull(attributeData) { "Autoclosetime 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 - } - + val decodedValue: ULong? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return AutoCloseTimeAttribute(decodedValue) } suspend fun subscribeAutoCloseTimeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(AutoCloseTimeAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + AutoCloseTimeAttributeSubscriptionState.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) { - "Autoclosetime attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Autoclosetime 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(AutoCloseTimeAttributeSubscriptionState.Success(it)) - } - + val decodedValue: ULong? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(AutoCloseTimeAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(AutoCloseTimeAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRemainingDurationAttribute(): RemainingDurationAttribute {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readRemainingDurationAttribute(): RemainingDurationAttribute { + 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}") - } + 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) { - "Remainingduration attribute not found in response" - } + } + + requireNotNull(attributeData) { "Remainingduration attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - tlvReader.getUInt(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + tlvReader.getUInt(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return RemainingDurationAttribute(decodedValue) } suspend fun subscribeRemainingDurationAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(RemainingDurationAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + RemainingDurationAttributeSubscriptionState.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) { - "Remainingduration attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Remainingduration attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - tlvReader.getUInt(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(RemainingDurationAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + tlvReader.getUInt(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(RemainingDurationAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(RemainingDurationAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCurrentStateAttribute(): CurrentStateAttribute {val ATTRIBUTE_ID: UInt = 4u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readCurrentStateAttribute(): CurrentStateAttribute { + 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}") - } + 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) { - "Currentstate attribute not found in response" - } + } + + requireNotNull(attributeData) { "Currentstate attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return CurrentStateAttribute(decodedValue) } suspend fun subscribeCurrentStateAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(CurrentStateAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + CurrentStateAttributeSubscriptionState.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) { - "Currentstate attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Currentstate 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.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(CurrentStateAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(CurrentStateAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(CurrentStateAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readTargetStateAttribute(): TargetStateAttribute {val ATTRIBUTE_ID: UInt = 5u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readTargetStateAttribute(): TargetStateAttribute { + 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}") - } + 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) { - "Targetstate attribute not found in response" - } + } + + requireNotNull(attributeData) { "Targetstate attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return TargetStateAttribute(decodedValue) } suspend fun subscribeTargetStateAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(TargetStateAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + TargetStateAttributeSubscriptionState.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) { - "Targetstate attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Targetstate 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.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(TargetStateAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(TargetStateAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(TargetStateAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCurrentLevelAttribute(): CurrentLevelAttribute {val ATTRIBUTE_ID: UInt = 6u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readCurrentLevelAttribute(): CurrentLevelAttribute { + 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}") - } + 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) { - "Currentlevel attribute not found in response" - } + } + + requireNotNull(attributeData) { "Currentlevel attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return CurrentLevelAttribute(decodedValue) } suspend fun subscribeCurrentLevelAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(CurrentLevelAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + CurrentLevelAttributeSubscriptionState.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) { - "Currentlevel attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Currentlevel 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(CurrentLevelAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(CurrentLevelAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(CurrentLevelAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readTargetLevelAttribute(): TargetLevelAttribute {val ATTRIBUTE_ID: UInt = 7u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readTargetLevelAttribute(): TargetLevelAttribute { + 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}") - } + 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) { - "Targetlevel attribute not found in response" - } + } + + requireNotNull(attributeData) { "Targetlevel attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return TargetLevelAttribute(decodedValue) } suspend fun subscribeTargetLevelAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(TargetLevelAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + TargetLevelAttributeSubscriptionState.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) { - "Targetlevel attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Targetlevel 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(TargetLevelAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(TargetLevelAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(TargetLevelAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readDefaultOpenLevelAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 8u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readDefaultOpenLevelAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 8u + + 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}") - } + 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) { - "Defaultopenlevel attribute not found in response" - } + } + + requireNotNull(attributeData) { "Defaultopenlevel 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } - suspend fun writeDefaultOpenLevelAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeDefaultOpenLevelAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 8u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -1207,346 +1094,335 @@ suspend fun readDefaultOpenLevelAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 8u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeDefaultOpenLevelAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Defaultopenlevel attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Defaultopenlevel 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)) - } - + 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 readValveFaultAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 9u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readValveFaultAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 9u + + 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}") - } + 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) { - "Valvefault attribute not found in response" - } + } + + requireNotNull(attributeData) { "Valvefault 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeValveFaultAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Valvefault attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Valvefault 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)) - } - + 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 readLevelStepAttribute(): UByte? {val ATTRIBUTE_ID: UInt = 10u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readLevelStepAttribute(): UByte? { + val ATTRIBUTE_ID: UInt = 10u + + 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}") - } + 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) { - "Levelstep attribute not found in response" - } + } + + requireNotNull(attributeData) { "Levelstep 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeLevelStepAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Levelstep attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Levelstep 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)) - } - + 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 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1554,97 +1430,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1652,97 +1527,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1750,97 +1622,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1848,81 +1717,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1934,80 +1798,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -2020,7 +1881,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/WakeOnLanCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/WakeOnLanCluster.kt index 18d648654b3557..100775120b96aa 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/WakeOnLanCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/WakeOnLanCluster.kt @@ -17,383 +17,337 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.ByteArraySubscriptionState import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest +import matter.controller.StringSubscriptionState import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState -import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse -import matter.controller.model.AttributePath -import matter.controller.model.CommandPath +import matter.controller.UShortSubscriptionState import matter.controller.cluster.structs.* +import matter.controller.model.AttributePath import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader -import matter.tlv.TlvWriter -class WakeOnLanCluster(private val controller: MatterController, private val endpointId: UShort) {class GeneratedCommandListAttribute( - val value: List - ) +class WakeOnLanCluster(private val controller: MatterController, private val endpointId: UShort) { + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } -suspend fun readMACAddressAttribute(): String? {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } + + suspend fun readMACAddressAttribute(): String? { + 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}") - } + 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) { - "Macaddress attribute not found in response" - } + } + + requireNotNull(attributeData) { "Macaddress attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeMACAddressAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StringSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StringSubscriptionState.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) { - "Macaddress attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Macaddress attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: String? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getString(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(StringSubscriptionState.Success(it)) - } - + val decodedValue: String? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getString(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(StringSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(StringSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readLinkLocalAddressAttribute(): ByteArray? {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readLinkLocalAddressAttribute(): ByteArray? { + 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}") - } + 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) { - "Linklocaladdress attribute not found in response" - } + } + + requireNotNull(attributeData) { "Linklocaladdress attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByteArray(AnonymousTag) - } else { - null - } - + val decodedValue: ByteArray? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByteArray(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeLinkLocalAddressAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ByteArraySubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ByteArraySubscriptionState.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) { - "Linklocaladdress attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Linklocaladdress attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getByteArray(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(ByteArraySubscriptionState.Success(it)) - } - + val decodedValue: ByteArray? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getByteArray(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(ByteArraySubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ByteArraySubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -401,97 +355,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -499,97 +452,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -597,97 +547,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -695,81 +642,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -781,80 +723,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -867,7 +806,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/WaterHeaterManagementCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/WaterHeaterManagementCluster.kt index a54c5d393204d4..5f7fb25dd58f77 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/WaterHeaterManagementCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/WaterHeaterManagementCluster.kt @@ -17,117 +17,92 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse +import matter.controller.LongSubscriptionState import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.UShortSubscriptionState +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class WaterHeaterManagementCluster(private val controller: MatterController, private val endpointId: UShort) {class GeneratedCommandListAttribute( - val value: List - ) +class WaterHeaterManagementCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun boost(boostInfo: WaterHeaterManagementClusterWaterHeaterBoostInfoStruct - ,timedInvokeTimeout: Duration? = null) { + suspend fun boost( + boostInfo: WaterHeaterManagementClusterWaterHeaterBoostInfoStruct, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_BOOST_INFO_REQ: Int = 0 - boostInfo.toTlv(ContextSpecificTag(TAG_BOOST_INFO_REQ), tlvWriter) + boostInfo.toTlv(ContextSpecificTag(TAG_BOOST_INFO_REQ), tlvWriter) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -138,92 +113,87 @@ class AttributeListAttribute( val commandId: UInt = 1u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } -suspend fun readHeaterTypesAttribute(): 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) - ) - + + suspend fun readHeaterTypesAttribute(): 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}") - } + 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) { - "Heatertypes attribute not found in response" - } + } + + requireNotNull(attributeData) { "Heatertypes 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 subscribeHeaterTypesAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Heatertypes attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Heatertypes attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -235,81 +205,76 @@ suspend fun readHeaterTypesAttribute(): UByte {val ATTRIBUTE_ID: UInt = 0u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readHeatDemandAttribute(): 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) - ) - + + suspend fun readHeatDemandAttribute(): 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}") - } + 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) { - "Heatdemand attribute not found in response" - } + } + + requireNotNull(attributeData) { "Heatdemand 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 subscribeHeatDemandAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Heatdemand attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Heatdemand attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -321,372 +286,353 @@ suspend fun readHeatDemandAttribute(): UByte {val ATTRIBUTE_ID: UInt = 1u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readTankVolumeAttribute(): 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) - ) - + + suspend fun readTankVolumeAttribute(): 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}") - } + 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) { - "Tankvolume attribute not found in response" - } + } + + requireNotNull(attributeData) { "Tankvolume 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeTankVolumeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Tankvolume attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Tankvolume 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)) - } - + 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 readEstimatedHeatRequiredAttribute(): Long? {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readEstimatedHeatRequiredAttribute(): Long? { + 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}") - } + 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) { - "Estimatedheatrequired attribute not found in response" - } + } + + requireNotNull(attributeData) { "Estimatedheatrequired attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - + val decodedValue: Long? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeEstimatedHeatRequiredAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(LongSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + LongSubscriptionState.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) { - "Estimatedheatrequired attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Estimatedheatrequired attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Long? = if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getLong(AnonymousTag) - } else { - null - } - - decodedValue?.let { - emit(LongSubscriptionState.Success(it)) - } - + val decodedValue: Long? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getLong(AnonymousTag) + } else { + null + } + + decodedValue?.let { emit(LongSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(LongSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readTankPercentageAttribute(): 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) - ) - + + suspend fun readTankPercentageAttribute(): 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}") - } + 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) { - "Tankpercentage attribute not found in response" - } + } + + requireNotNull(attributeData) { "Tankpercentage 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 - } - + val decodedValue: UByte? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeTankPercentageAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Tankpercentage attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Tankpercentage 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)) - } - + 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 readBoostStateAttribute(): UByte {val ATTRIBUTE_ID: UInt = 5u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readBoostStateAttribute(): UByte { + 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}") - } + 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) { - "Booststate attribute not found in response" - } + } + + requireNotNull(attributeData) { "Booststate 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 subscribeBoostStateAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Booststate attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Booststate attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -698,97 +644,96 @@ suspend fun readBoostStateAttribute(): UByte {val ATTRIBUTE_ID: UInt = 5u emit(UByteSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -796,97 +741,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -894,97 +838,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -992,97 +933,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1090,81 +1028,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1176,80 +1109,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1262,7 +1192,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/WaterHeaterModeCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/WaterHeaterModeCluster.kt index a651926d7366df..27352644935c8a 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/WaterHeaterModeCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/WaterHeaterModeCluster.kt @@ -17,161 +17,127 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class WaterHeaterModeCluster(private val controller: MatterController, private val endpointId: UShort) { - class ChangeToModeResponse( - val status: UByte, - val statusText: String? - ) -class SupportedModesAttribute( - val value: List - ) +class WaterHeaterModeCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class ChangeToModeResponse(val status: UByte, val statusText: String?) + + class SupportedModesAttribute(val value: List) sealed class SupportedModesAttributeSubscriptionState { - data class Success( - val value: List - ) : SupportedModesAttributeSubscriptionState() - + data class Success(val value: List) : + SupportedModesAttributeSubscriptionState() + data class Error(val exception: Exception) : SupportedModesAttributeSubscriptionState() - object SubscriptionEstablished : SupportedModesAttributeSubscriptionState() - } -class StartUpModeAttribute( - val value: UByte? - ) + object SubscriptionEstablished : SupportedModesAttributeSubscriptionState() + } + + class StartUpModeAttribute(val value: UByte?) sealed class StartUpModeAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : StartUpModeAttributeSubscriptionState() - + data class Success(val value: UByte?) : StartUpModeAttributeSubscriptionState() + data class Error(val exception: Exception) : StartUpModeAttributeSubscriptionState() - object SubscriptionEstablished : StartUpModeAttributeSubscriptionState() - } -class OnModeAttribute( - val value: UByte? - ) + object SubscriptionEstablished : StartUpModeAttributeSubscriptionState() + } + + class OnModeAttribute(val value: UByte?) sealed class OnModeAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : OnModeAttributeSubscriptionState() - + data class Success(val value: UByte?) : OnModeAttributeSubscriptionState() + data class Error(val exception: Exception) : OnModeAttributeSubscriptionState() - object SubscriptionEstablished : OnModeAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : OnModeAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun changeToMode(newMode: UByte - ,timedInvokeTimeout: Duration? = null): ChangeToModeResponse { + suspend fun changeToMode( + newMode: UByte, + timedInvokeTimeout: Duration? = null, + ): ChangeToModeResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_NEW_MODE_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_NEW_MODE_REQ), newMode) + tlvWriter.put(ContextSpecificTag(TAG_NEW_MODE_REQ), newMode) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -181,140 +147,130 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_STATUS: Int = 0 var status_decoded: UByte? = null - + val TAG_STATUS_TEXT: Int = 1 var statusText_decoded: String? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_STATUS)) {status_decoded = tlvReader.getUByte(tag)} - - if (tag == ContextSpecificTag(TAG_STATUS_TEXT)) {statusText_decoded = + if (tag == ContextSpecificTag(TAG_STATUS)) { + status_decoded = tlvReader.getUByte(tag) + } + + if (tag == ContextSpecificTag(TAG_STATUS_TEXT)) { + statusText_decoded = if (tlvReader.isNull()) { tlvReader.getNull(tag) null } else { if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - }} - - - else { + tlvReader.getString(tag) + } else { + null + } + } + } else { tlvReader.skipElement() } } - - if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") + throw IllegalStateException("status not found in TLV") } - - - tlvReader.exitContainer() - return ChangeToModeResponse( - status_decoded, - statusText_decoded - ) + return ChangeToModeResponse(status_decoded, statusText_decoded) } -suspend fun readSupportedModesAttribute(): SupportedModesAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readSupportedModesAttribute(): SupportedModesAttribute { + 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}") - } + 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) { - "Supportedmodes attribute not found in response" - } + } + + requireNotNull(attributeData) { "Supportedmodes 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(WaterHeaterModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(WaterHeaterModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return SupportedModesAttribute(decodedValue) } suspend fun subscribeSupportedModesAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(SupportedModesAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + SupportedModesAttributeSubscriptionState.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) { - "Supportedmodes attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Supportedmodes 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(WaterHeaterModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(WaterHeaterModeClusterModeOptionStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } emit(SupportedModesAttributeSubscriptionState.Success(decodedValue)) } @@ -322,81 +278,76 @@ suspend fun readSupportedModesAttribute(): SupportedModesAttribute {val ATTRIBUT emit(SupportedModesAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCurrentModeAttribute(): 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) - ) - + + suspend fun readCurrentModeAttribute(): 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}") - } + 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) { - "Currentmode attribute not found in response" - } + } + + requireNotNull(attributeData) { "Currentmode 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 subscribeCurrentModeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Currentmode attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Currentmode attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -408,77 +359,67 @@ suspend fun readCurrentModeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 1u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readStartUpModeAttribute(): StartUpModeAttribute {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readStartUpModeAttribute(): StartUpModeAttribute { + 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}") - } + 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) { - "Startupmode attribute not found in response" - } + } + + requireNotNull(attributeData) { "Startupmode attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return StartUpModeAttribute(decodedValue) } - suspend fun writeStartUpModeAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeStartUpModeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 2u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -499,137 +440,127 @@ suspend fun readStartUpModeAttribute(): StartUpModeAttribute {val ATTRIBUTE_ID: throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeStartUpModeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(StartUpModeAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + StartUpModeAttributeSubscriptionState.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) { - "Startupmode attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Startupmode 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(StartUpModeAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(StartUpModeAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(StartUpModeAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readOnModeAttribute(): OnModeAttribute {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readOnModeAttribute(): OnModeAttribute { + 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}") - } + 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) { - "Onmode attribute not found in response" - } + } + + requireNotNull(attributeData) { "Onmode attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return OnModeAttribute(decodedValue) } - suspend fun writeOnModeAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeOnModeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 3u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -650,157 +581,156 @@ suspend fun readOnModeAttribute(): OnModeAttribute {val ATTRIBUTE_ID: UInt = 3u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeOnModeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(OnModeAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + OnModeAttributeSubscriptionState.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) { - "Onmode attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Onmode 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(OnModeAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(OnModeAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(OnModeAttributeSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -808,97 +738,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -906,97 +835,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1004,97 +930,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -1102,81 +1025,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -1188,80 +1106,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -1274,7 +1189,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/WiFiNetworkDiagnosticsCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/WiFiNetworkDiagnosticsCluster.kt index a863a7bdcbe2f5..ff7d2ed278ca7f 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/WiFiNetworkDiagnosticsCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/WiFiNetworkDiagnosticsCluster.kt @@ -17,1727 +17,1591 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState -import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.UShortSubscriptionState +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class WiFiNetworkDiagnosticsCluster(private val controller: MatterController, private val endpointId: UShort) {class BssidAttribute( - val value: ByteArray? - ) +class WiFiNetworkDiagnosticsCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class BssidAttribute(val value: ByteArray?) sealed class BssidAttributeSubscriptionState { - data class Success( - val value: ByteArray? - ) : BssidAttributeSubscriptionState() - + data class Success(val value: ByteArray?) : BssidAttributeSubscriptionState() + data class Error(val exception: Exception) : BssidAttributeSubscriptionState() - object SubscriptionEstablished : BssidAttributeSubscriptionState() - } -class SecurityTypeAttribute( - val value: UByte? - ) + object SubscriptionEstablished : BssidAttributeSubscriptionState() + } + + class SecurityTypeAttribute(val value: UByte?) sealed class SecurityTypeAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : SecurityTypeAttributeSubscriptionState() - + data class Success(val value: UByte?) : SecurityTypeAttributeSubscriptionState() + data class Error(val exception: Exception) : SecurityTypeAttributeSubscriptionState() - object SubscriptionEstablished : SecurityTypeAttributeSubscriptionState() - } -class WiFiVersionAttribute( - val value: UByte? - ) + object SubscriptionEstablished : SecurityTypeAttributeSubscriptionState() + } + + class WiFiVersionAttribute(val value: UByte?) sealed class WiFiVersionAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : WiFiVersionAttributeSubscriptionState() - + data class Success(val value: UByte?) : WiFiVersionAttributeSubscriptionState() + data class Error(val exception: Exception) : WiFiVersionAttributeSubscriptionState() - object SubscriptionEstablished : WiFiVersionAttributeSubscriptionState() - } -class ChannelNumberAttribute( - val value: UShort? - ) + object SubscriptionEstablished : WiFiVersionAttributeSubscriptionState() + } + + class ChannelNumberAttribute(val value: UShort?) sealed class ChannelNumberAttributeSubscriptionState { - data class Success( - val value: UShort? - ) : ChannelNumberAttributeSubscriptionState() - + data class Success(val value: UShort?) : ChannelNumberAttributeSubscriptionState() + data class Error(val exception: Exception) : ChannelNumberAttributeSubscriptionState() - object SubscriptionEstablished : ChannelNumberAttributeSubscriptionState() - } -class RssiAttribute( - val value: Byte? - ) + object SubscriptionEstablished : ChannelNumberAttributeSubscriptionState() + } + + class RssiAttribute(val value: Byte?) sealed class RssiAttributeSubscriptionState { - data class Success( - val value: Byte? - ) : RssiAttributeSubscriptionState() - + data class Success(val value: Byte?) : RssiAttributeSubscriptionState() + data class Error(val exception: Exception) : RssiAttributeSubscriptionState() - object SubscriptionEstablished : RssiAttributeSubscriptionState() - } -class BeaconLostCountAttribute( - val value: UInt? - ) + object SubscriptionEstablished : RssiAttributeSubscriptionState() + } + + class BeaconLostCountAttribute(val value: UInt?) sealed class BeaconLostCountAttributeSubscriptionState { - data class Success( - val value: UInt? - ) : BeaconLostCountAttributeSubscriptionState() - + data class Success(val value: UInt?) : BeaconLostCountAttributeSubscriptionState() + data class Error(val exception: Exception) : BeaconLostCountAttributeSubscriptionState() - object SubscriptionEstablished : BeaconLostCountAttributeSubscriptionState() - } -class BeaconRxCountAttribute( - val value: UInt? - ) + object SubscriptionEstablished : BeaconLostCountAttributeSubscriptionState() + } + + class BeaconRxCountAttribute(val value: UInt?) sealed class BeaconRxCountAttributeSubscriptionState { - data class Success( - val value: UInt? - ) : BeaconRxCountAttributeSubscriptionState() - + data class Success(val value: UInt?) : BeaconRxCountAttributeSubscriptionState() + data class Error(val exception: Exception) : BeaconRxCountAttributeSubscriptionState() - object SubscriptionEstablished : BeaconRxCountAttributeSubscriptionState() - } -class PacketMulticastRxCountAttribute( - val value: UInt? - ) + object SubscriptionEstablished : BeaconRxCountAttributeSubscriptionState() + } + + class PacketMulticastRxCountAttribute(val value: UInt?) sealed class PacketMulticastRxCountAttributeSubscriptionState { - data class Success( - val value: UInt? - ) : PacketMulticastRxCountAttributeSubscriptionState() - + data class Success(val value: UInt?) : PacketMulticastRxCountAttributeSubscriptionState() + data class Error(val exception: Exception) : PacketMulticastRxCountAttributeSubscriptionState() - object SubscriptionEstablished : PacketMulticastRxCountAttributeSubscriptionState() - } -class PacketMulticastTxCountAttribute( - val value: UInt? - ) + object SubscriptionEstablished : PacketMulticastRxCountAttributeSubscriptionState() + } + + class PacketMulticastTxCountAttribute(val value: UInt?) sealed class PacketMulticastTxCountAttributeSubscriptionState { - data class Success( - val value: UInt? - ) : PacketMulticastTxCountAttributeSubscriptionState() - + data class Success(val value: UInt?) : PacketMulticastTxCountAttributeSubscriptionState() + data class Error(val exception: Exception) : PacketMulticastTxCountAttributeSubscriptionState() - object SubscriptionEstablished : PacketMulticastTxCountAttributeSubscriptionState() - } -class PacketUnicastRxCountAttribute( - val value: UInt? - ) + object SubscriptionEstablished : PacketMulticastTxCountAttributeSubscriptionState() + } + + class PacketUnicastRxCountAttribute(val value: UInt?) sealed class PacketUnicastRxCountAttributeSubscriptionState { - data class Success( - val value: UInt? - ) : PacketUnicastRxCountAttributeSubscriptionState() - + data class Success(val value: UInt?) : PacketUnicastRxCountAttributeSubscriptionState() + data class Error(val exception: Exception) : PacketUnicastRxCountAttributeSubscriptionState() - object SubscriptionEstablished : PacketUnicastRxCountAttributeSubscriptionState() - } -class PacketUnicastTxCountAttribute( - val value: UInt? - ) + object SubscriptionEstablished : PacketUnicastRxCountAttributeSubscriptionState() + } + + class PacketUnicastTxCountAttribute(val value: UInt?) sealed class PacketUnicastTxCountAttributeSubscriptionState { - data class Success( - val value: UInt? - ) : PacketUnicastTxCountAttributeSubscriptionState() - + data class Success(val value: UInt?) : PacketUnicastTxCountAttributeSubscriptionState() + data class Error(val exception: Exception) : PacketUnicastTxCountAttributeSubscriptionState() - object SubscriptionEstablished : PacketUnicastTxCountAttributeSubscriptionState() - } -class CurrentMaxRateAttribute( - val value: ULong? - ) + object SubscriptionEstablished : PacketUnicastTxCountAttributeSubscriptionState() + } + + class CurrentMaxRateAttribute(val value: ULong?) sealed class CurrentMaxRateAttributeSubscriptionState { - data class Success( - val value: ULong? - ) : CurrentMaxRateAttributeSubscriptionState() - + data class Success(val value: ULong?) : CurrentMaxRateAttributeSubscriptionState() + data class Error(val exception: Exception) : CurrentMaxRateAttributeSubscriptionState() - object SubscriptionEstablished : CurrentMaxRateAttributeSubscriptionState() - } -class OverrunCountAttribute( - val value: ULong? - ) + object SubscriptionEstablished : CurrentMaxRateAttributeSubscriptionState() + } + + class OverrunCountAttribute(val value: ULong?) sealed class OverrunCountAttributeSubscriptionState { - data class Success( - val value: ULong? - ) : OverrunCountAttributeSubscriptionState() - + data class Success(val value: ULong?) : OverrunCountAttributeSubscriptionState() + data class Error(val exception: Exception) : OverrunCountAttributeSubscriptionState() - object SubscriptionEstablished : OverrunCountAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : OverrunCountAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } suspend fun resetCounts(timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } -suspend fun readBssidAttribute(): BssidAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readBssidAttribute(): BssidAttribute { + 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}") - } + 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) { - "Bssid attribute not found in response" - } + } + + requireNotNull(attributeData) { "Bssid attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = if (!tlvReader.isNull()) { - tlvReader.getByteArray(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: ByteArray? = + if (!tlvReader.isNull()) { + tlvReader.getByteArray(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return BssidAttribute(decodedValue) } suspend fun subscribeBssidAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(BssidAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + BssidAttributeSubscriptionState.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) { - "Bssid attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Bssid attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = if (!tlvReader.isNull()) { - tlvReader.getByteArray(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(BssidAttributeSubscriptionState.Success(it)) - } - + val decodedValue: ByteArray? = + if (!tlvReader.isNull()) { + tlvReader.getByteArray(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(BssidAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(BssidAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readSecurityTypeAttribute(): SecurityTypeAttribute {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readSecurityTypeAttribute(): SecurityTypeAttribute { + 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}") - } + 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) { - "Securitytype attribute not found in response" - } + } + + requireNotNull(attributeData) { "Securitytype attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return SecurityTypeAttribute(decodedValue) } suspend fun subscribeSecurityTypeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(SecurityTypeAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + SecurityTypeAttributeSubscriptionState.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) { - "Securitytype attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Securitytype 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.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(SecurityTypeAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(SecurityTypeAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(SecurityTypeAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readWiFiVersionAttribute(): WiFiVersionAttribute {val ATTRIBUTE_ID: UInt = 2u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readWiFiVersionAttribute(): WiFiVersionAttribute { + 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}") - } + 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) { - "Wifiversion attribute not found in response" - } + } + + requireNotNull(attributeData) { "Wifiversion attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return WiFiVersionAttribute(decodedValue) } suspend fun subscribeWiFiVersionAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(WiFiVersionAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + WiFiVersionAttributeSubscriptionState.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) { - "Wifiversion attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Wifiversion 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.isNull()) { - tlvReader.getUByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(WiFiVersionAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + tlvReader.getUByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(WiFiVersionAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(WiFiVersionAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readChannelNumberAttribute(): ChannelNumberAttribute {val ATTRIBUTE_ID: UInt = 3u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readChannelNumberAttribute(): ChannelNumberAttribute { + 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}") - } + 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) { - "Channelnumber attribute not found in response" - } + } + + requireNotNull(attributeData) { "Channelnumber attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = if (!tlvReader.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return ChannelNumberAttribute(decodedValue) } suspend fun subscribeChannelNumberAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(ChannelNumberAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + ChannelNumberAttributeSubscriptionState.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) { - "Channelnumber attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Channelnumber 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.isNull()) { - tlvReader.getUShort(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(ChannelNumberAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + tlvReader.getUShort(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(ChannelNumberAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(ChannelNumberAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readRssiAttribute(): RssiAttribute {val ATTRIBUTE_ID: UInt = 4u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readRssiAttribute(): RssiAttribute { + 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}") - } + 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) { - "Rssi attribute not found in response" - } + } + + requireNotNull(attributeData) { "Rssi attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Byte? = if (!tlvReader.isNull()) { - tlvReader.getByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: Byte? = + if (!tlvReader.isNull()) { + tlvReader.getByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return RssiAttribute(decodedValue) } suspend fun subscribeRssiAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(RssiAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + RssiAttributeSubscriptionState.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) { - "Rssi attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Rssi attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: Byte? = if (!tlvReader.isNull()) { - tlvReader.getByte(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(RssiAttributeSubscriptionState.Success(it)) - } - + val decodedValue: Byte? = + if (!tlvReader.isNull()) { + tlvReader.getByte(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(RssiAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(RssiAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readBeaconLostCountAttribute(): BeaconLostCountAttribute {val ATTRIBUTE_ID: UInt = 5u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readBeaconLostCountAttribute(): BeaconLostCountAttribute { + 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}") - } + 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) { - "Beaconlostcount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Beaconlostcount attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return BeaconLostCountAttribute(decodedValue) } suspend fun subscribeBeaconLostCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(BeaconLostCountAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + BeaconLostCountAttributeSubscriptionState.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) { - "Beaconlostcount attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Beaconlostcount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(BeaconLostCountAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(BeaconLostCountAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(BeaconLostCountAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readBeaconRxCountAttribute(): BeaconRxCountAttribute {val ATTRIBUTE_ID: UInt = 6u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readBeaconRxCountAttribute(): BeaconRxCountAttribute { + 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}") - } + 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) { - "Beaconrxcount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Beaconrxcount attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return BeaconRxCountAttribute(decodedValue) } suspend fun subscribeBeaconRxCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(BeaconRxCountAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + BeaconRxCountAttributeSubscriptionState.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) { - "Beaconrxcount attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Beaconrxcount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(BeaconRxCountAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(BeaconRxCountAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(BeaconRxCountAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPacketMulticastRxCountAttribute(): PacketMulticastRxCountAttribute {val ATTRIBUTE_ID: UInt = 7u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readPacketMulticastRxCountAttribute(): PacketMulticastRxCountAttribute { + 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}") - } + 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) { - "Packetmulticastrxcount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Packetmulticastrxcount attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return PacketMulticastRxCountAttribute(decodedValue) } suspend fun subscribePacketMulticastRxCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(PacketMulticastRxCountAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + PacketMulticastRxCountAttributeSubscriptionState.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) { - "Packetmulticastrxcount attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Packetmulticastrxcount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(PacketMulticastRxCountAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(PacketMulticastRxCountAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(PacketMulticastRxCountAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPacketMulticastTxCountAttribute(): PacketMulticastTxCountAttribute {val ATTRIBUTE_ID: UInt = 8u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readPacketMulticastTxCountAttribute(): PacketMulticastTxCountAttribute { + val ATTRIBUTE_ID: UInt = 8u + + 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}") - } + 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) { - "Packetmulticasttxcount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Packetmulticasttxcount attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return PacketMulticastTxCountAttribute(decodedValue) } suspend fun subscribePacketMulticastTxCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(PacketMulticastTxCountAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + PacketMulticastTxCountAttributeSubscriptionState.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) { - "Packetmulticasttxcount attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Packetmulticasttxcount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(PacketMulticastTxCountAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(PacketMulticastTxCountAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(PacketMulticastTxCountAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPacketUnicastRxCountAttribute(): PacketUnicastRxCountAttribute {val ATTRIBUTE_ID: UInt = 9u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readPacketUnicastRxCountAttribute(): PacketUnicastRxCountAttribute { + val ATTRIBUTE_ID: UInt = 9u + + 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}") - } + 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) { - "Packetunicastrxcount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Packetunicastrxcount attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return PacketUnicastRxCountAttribute(decodedValue) } suspend fun subscribePacketUnicastRxCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(PacketUnicastRxCountAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + PacketUnicastRxCountAttributeSubscriptionState.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) { - "Packetunicastrxcount attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Packetunicastrxcount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(PacketUnicastRxCountAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(PacketUnicastRxCountAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(PacketUnicastRxCountAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPacketUnicastTxCountAttribute(): PacketUnicastTxCountAttribute {val ATTRIBUTE_ID: UInt = 10u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readPacketUnicastTxCountAttribute(): PacketUnicastTxCountAttribute { + val ATTRIBUTE_ID: UInt = 10u + + 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}") - } + 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) { - "Packetunicasttxcount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Packetunicasttxcount attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return PacketUnicastTxCountAttribute(decodedValue) } suspend fun subscribePacketUnicastTxCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(PacketUnicastTxCountAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + PacketUnicastTxCountAttributeSubscriptionState.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) { - "Packetunicasttxcount attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Packetunicasttxcount attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUInt(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(PacketUnicastTxCountAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UInt? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUInt(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(PacketUnicastTxCountAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(PacketUnicastTxCountAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCurrentMaxRateAttribute(): CurrentMaxRateAttribute {val ATTRIBUTE_ID: UInt = 11u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readCurrentMaxRateAttribute(): CurrentMaxRateAttribute { + val ATTRIBUTE_ID: UInt = 11u + + 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}") - } + 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) { - "Currentmaxrate attribute not found in response" - } + } + + requireNotNull(attributeData) { "Currentmaxrate 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 - } - + val decodedValue: ULong? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return CurrentMaxRateAttribute(decodedValue) } suspend fun subscribeCurrentMaxRateAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 11u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(CurrentMaxRateAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + CurrentMaxRateAttributeSubscriptionState.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) { - "Currentmaxrate attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Currentmaxrate 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(CurrentMaxRateAttributeSubscriptionState.Success(it)) - } - + val decodedValue: ULong? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(CurrentMaxRateAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(CurrentMaxRateAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readOverrunCountAttribute(): OverrunCountAttribute {val ATTRIBUTE_ID: UInt = 12u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readOverrunCountAttribute(): OverrunCountAttribute { + val ATTRIBUTE_ID: UInt = 12u + + 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}") - } + 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) { - "Overruncount attribute not found in response" - } + } + + requireNotNull(attributeData) { "Overruncount 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 - } - + val decodedValue: ULong? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return OverrunCountAttribute(decodedValue) } suspend fun subscribeOverrunCountAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 12u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(OverrunCountAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + OverrunCountAttributeSubscriptionState.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) { - "Overruncount attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Overruncount 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(OverrunCountAttributeSubscriptionState.Success(it)) - } - + val decodedValue: ULong? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getULong(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(OverrunCountAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(OverrunCountAttributeSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1745,97 +1609,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -1843,97 +1706,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -1941,97 +1801,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -2039,81 +1896,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -2125,80 +1977,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -2211,7 +2060,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/WiFiNetworkManagementCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/WiFiNetworkManagementCluster.kt index 4b65842446ee0e..48efb1cea1f4b2 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/WiFiNetworkManagementCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/WiFiNetworkManagementCluster.kt @@ -17,143 +17,108 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState -import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState -import matter.controller.WriteRequest -import matter.controller.WriteRequests -import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.UShortSubscriptionState +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class WiFiNetworkManagementCluster(private val controller: MatterController, private val endpointId: UShort) { - class NetworkPassphraseResponse( - val passphrase: ByteArray - ) -class SsidAttribute( - val value: ByteArray? - ) +class WiFiNetworkManagementCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class NetworkPassphraseResponse(val passphrase: ByteArray) + + class SsidAttribute(val value: ByteArray?) sealed class SsidAttributeSubscriptionState { - data class Success( - val value: ByteArray? - ) : SsidAttributeSubscriptionState() - + data class Success(val value: ByteArray?) : SsidAttributeSubscriptionState() + data class Error(val exception: Exception) : SsidAttributeSubscriptionState() - object SubscriptionEstablished : SsidAttributeSubscriptionState() - } -class PassphraseSurrogateAttribute( - val value: ULong? - ) + object SubscriptionEstablished : SsidAttributeSubscriptionState() + } + + class PassphraseSurrogateAttribute(val value: ULong?) sealed class PassphraseSurrogateAttributeSubscriptionState { - data class Success( - val value: ULong? - ) : PassphraseSurrogateAttributeSubscriptionState() - + data class Success(val value: ULong?) : PassphraseSurrogateAttributeSubscriptionState() + data class Error(val exception: Exception) : PassphraseSurrogateAttributeSubscriptionState() - object SubscriptionEstablished : PassphraseSurrogateAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : PassphraseSurrogateAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } - suspend fun networkPassphraseRequest(timedInvokeTimeout: Duration? = null): NetworkPassphraseResponse { + suspend fun networkPassphraseRequest( + timedInvokeTimeout: Duration? = null + ): NetworkPassphraseResponse { val commandId: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -163,320 +128,301 @@ class AttributeListAttribute( tlvReader.enterStructure(AnonymousTag) val TAG_PASSPHRASE: Int = 0 var passphrase_decoded: ByteArray? = null - while (!tlvReader.isEndOfContainer()) { val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_PASSPHRASE)) {passphrase_decoded = tlvReader.getByteArray(tag)} - - - else { + if (tag == ContextSpecificTag(TAG_PASSPHRASE)) { + passphrase_decoded = tlvReader.getByteArray(tag) + } else { tlvReader.skipElement() } } - - if (passphrase_decoded == null) { - throw IllegalStateException("passphrase not found in TLV") + throw IllegalStateException("passphrase not found in TLV") } - tlvReader.exitContainer() - return NetworkPassphraseResponse( - passphrase_decoded - ) + return NetworkPassphraseResponse(passphrase_decoded) } -suspend fun readSsidAttribute(): SsidAttribute {val ATTRIBUTE_ID: UInt = 0u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readSsidAttribute(): SsidAttribute { + 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}") - } + 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) { - "Ssid attribute not found in response" - } + } + + requireNotNull(attributeData) { "Ssid attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = if (!tlvReader.isNull()) { - tlvReader.getByteArray(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: ByteArray? = + if (!tlvReader.isNull()) { + tlvReader.getByteArray(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return SsidAttribute(decodedValue) } suspend fun subscribeSsidAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(SsidAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + SsidAttributeSubscriptionState.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) { - "Ssid attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Ssid attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ByteArray? = if (!tlvReader.isNull()) { - tlvReader.getByteArray(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(SsidAttributeSubscriptionState.Success(it)) - } - + val decodedValue: ByteArray? = + if (!tlvReader.isNull()) { + tlvReader.getByteArray(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(SsidAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(SsidAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPassphraseSurrogateAttribute(): PassphraseSurrogateAttribute {val ATTRIBUTE_ID: UInt = 1u - - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) - - val readRequest = ReadRequest( - eventPaths = emptyList(), - attributePaths = listOf(attributePath) - ) - + + suspend fun readPassphraseSurrogateAttribute(): PassphraseSurrogateAttribute { + 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}") - } + 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) { - "Passphrasesurrogate attribute not found in response" - } + } + + requireNotNull(attributeData) { "Passphrasesurrogate attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: ULong? = if (!tlvReader.isNull()) { - tlvReader.getULong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: ULong? = + if (!tlvReader.isNull()) { + tlvReader.getULong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } return PassphraseSurrogateAttribute(decodedValue) } suspend fun subscribePassphraseSurrogateAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(PassphraseSurrogateAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + PassphraseSurrogateAttributeSubscriptionState.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) { - "Passphrasesurrogate attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Passphrasesurrogate 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()) { - tlvReader.getULong(AnonymousTag) - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(PassphraseSurrogateAttributeSubscriptionState.Success(it)) - } - + val decodedValue: ULong? = + if (!tlvReader.isNull()) { + tlvReader.getULong(AnonymousTag) + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(PassphraseSurrogateAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(PassphraseSurrogateAttributeSubscriptionState.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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -484,97 +430,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -582,97 +527,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -680,97 +622,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt 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) - ) - + + 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -778,81 +717,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -864,80 +798,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u 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) - ) - + + 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -950,7 +881,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/WindowCoveringCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/WindowCoveringCluster.kt index d47645e5b75dca..6c0b93c6a67575 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/WindowCoveringCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/WindowCoveringCluster.kt @@ -17,217 +17,180 @@ package matter.controller.cluster.clusters +import java.time.Duration import java.util.logging.Level import java.util.logging.Logger -import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse import matter.controller.MatterController -import matter.controller.ReadRequest import matter.controller.ReadData -import matter.controller.ReadFailure -import matter.controller.ReadResponse +import matter.controller.ReadRequest import matter.controller.SubscribeRequest import matter.controller.SubscriptionState -import matter.controller.ByteSubscriptionState -import matter.controller.ShortSubscriptionState -import matter.controller.IntSubscriptionState -import matter.controller.LongSubscriptionState -import matter.controller.FloatSubscriptionState -import matter.controller.DoubleSubscriptionState -import matter.controller.CharSubscriptionState -import matter.controller.BooleanSubscriptionState import matter.controller.UByteSubscriptionState -import matter.controller.UShortSubscriptionState import matter.controller.UIntSubscriptionState -import matter.controller.ULongSubscriptionState -import matter.controller.StringSubscriptionState -import matter.controller.ByteArraySubscriptionState +import matter.controller.UShortSubscriptionState import matter.controller.WriteRequest import matter.controller.WriteRequests import matter.controller.WriteResponse -import matter.controller.AttributeWriteError -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse +import matter.controller.cluster.structs.* import matter.controller.model.AttributePath import matter.controller.model.CommandPath -import matter.controller.cluster.structs.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvParsingException import matter.tlv.TlvReader import matter.tlv.TlvWriter -class WindowCoveringCluster(private val controller: MatterController, private val endpointId: UShort) {class CurrentPositionLiftAttribute( - val value: UShort? - ) +class WindowCoveringCluster( + private val controller: MatterController, + private val endpointId: UShort, +) { + class CurrentPositionLiftAttribute(val value: UShort?) sealed class CurrentPositionLiftAttributeSubscriptionState { - data class Success( - val value: UShort? - ) : CurrentPositionLiftAttributeSubscriptionState() - + data class Success(val value: UShort?) : CurrentPositionLiftAttributeSubscriptionState() + data class Error(val exception: Exception) : CurrentPositionLiftAttributeSubscriptionState() - object SubscriptionEstablished : CurrentPositionLiftAttributeSubscriptionState() - } -class CurrentPositionTiltAttribute( - val value: UShort? - ) + object SubscriptionEstablished : CurrentPositionLiftAttributeSubscriptionState() + } + + class CurrentPositionTiltAttribute(val value: UShort?) sealed class CurrentPositionTiltAttributeSubscriptionState { - data class Success( - val value: UShort? - ) : CurrentPositionTiltAttributeSubscriptionState() - + data class Success(val value: UShort?) : CurrentPositionTiltAttributeSubscriptionState() + data class Error(val exception: Exception) : CurrentPositionTiltAttributeSubscriptionState() - object SubscriptionEstablished : CurrentPositionTiltAttributeSubscriptionState() - } -class CurrentPositionLiftPercentageAttribute( - val value: UByte? - ) + object SubscriptionEstablished : CurrentPositionTiltAttributeSubscriptionState() + } + + class CurrentPositionLiftPercentageAttribute(val value: UByte?) sealed class CurrentPositionLiftPercentageAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : CurrentPositionLiftPercentageAttributeSubscriptionState() - - data class Error(val exception: Exception) : CurrentPositionLiftPercentageAttributeSubscriptionState() - - object SubscriptionEstablished : CurrentPositionLiftPercentageAttributeSubscriptionState() - } -class CurrentPositionTiltPercentageAttribute( - val value: UByte? - ) + data class Success(val value: UByte?) : + CurrentPositionLiftPercentageAttributeSubscriptionState() + + data class Error(val exception: Exception) : + CurrentPositionLiftPercentageAttributeSubscriptionState() + + object SubscriptionEstablished : CurrentPositionLiftPercentageAttributeSubscriptionState() + } + + class CurrentPositionTiltPercentageAttribute(val value: UByte?) sealed class CurrentPositionTiltPercentageAttributeSubscriptionState { - data class Success( - val value: UByte? - ) : CurrentPositionTiltPercentageAttributeSubscriptionState() - - data class Error(val exception: Exception) : CurrentPositionTiltPercentageAttributeSubscriptionState() - - object SubscriptionEstablished : CurrentPositionTiltPercentageAttributeSubscriptionState() - } -class TargetPositionLiftPercent100thsAttribute( - val value: UShort? - ) + data class Success(val value: UByte?) : + CurrentPositionTiltPercentageAttributeSubscriptionState() + + data class Error(val exception: Exception) : + CurrentPositionTiltPercentageAttributeSubscriptionState() + + object SubscriptionEstablished : CurrentPositionTiltPercentageAttributeSubscriptionState() + } + + class TargetPositionLiftPercent100thsAttribute(val value: UShort?) sealed class TargetPositionLiftPercent100thsAttributeSubscriptionState { - data class Success( - val value: UShort? - ) : TargetPositionLiftPercent100thsAttributeSubscriptionState() - - data class Error(val exception: Exception) : TargetPositionLiftPercent100thsAttributeSubscriptionState() - - object SubscriptionEstablished : TargetPositionLiftPercent100thsAttributeSubscriptionState() - } -class TargetPositionTiltPercent100thsAttribute( - val value: UShort? - ) + data class Success(val value: UShort?) : + TargetPositionLiftPercent100thsAttributeSubscriptionState() + + data class Error(val exception: Exception) : + TargetPositionLiftPercent100thsAttributeSubscriptionState() + + object SubscriptionEstablished : TargetPositionLiftPercent100thsAttributeSubscriptionState() + } + + class TargetPositionTiltPercent100thsAttribute(val value: UShort?) sealed class TargetPositionTiltPercent100thsAttributeSubscriptionState { - data class Success( - val value: UShort? - ) : TargetPositionTiltPercent100thsAttributeSubscriptionState() - - data class Error(val exception: Exception) : TargetPositionTiltPercent100thsAttributeSubscriptionState() - - object SubscriptionEstablished : TargetPositionTiltPercent100thsAttributeSubscriptionState() - } -class CurrentPositionLiftPercent100thsAttribute( - val value: UShort? - ) + data class Success(val value: UShort?) : + TargetPositionTiltPercent100thsAttributeSubscriptionState() + + data class Error(val exception: Exception) : + TargetPositionTiltPercent100thsAttributeSubscriptionState() + + object SubscriptionEstablished : TargetPositionTiltPercent100thsAttributeSubscriptionState() + } + + class CurrentPositionLiftPercent100thsAttribute(val value: UShort?) sealed class CurrentPositionLiftPercent100thsAttributeSubscriptionState { - data class Success( - val value: UShort? - ) : CurrentPositionLiftPercent100thsAttributeSubscriptionState() - - data class Error(val exception: Exception) : CurrentPositionLiftPercent100thsAttributeSubscriptionState() - - object SubscriptionEstablished : CurrentPositionLiftPercent100thsAttributeSubscriptionState() - } -class CurrentPositionTiltPercent100thsAttribute( - val value: UShort? - ) + data class Success(val value: UShort?) : + CurrentPositionLiftPercent100thsAttributeSubscriptionState() + + data class Error(val exception: Exception) : + CurrentPositionLiftPercent100thsAttributeSubscriptionState() + + object SubscriptionEstablished : CurrentPositionLiftPercent100thsAttributeSubscriptionState() + } + + class CurrentPositionTiltPercent100thsAttribute(val value: UShort?) sealed class CurrentPositionTiltPercent100thsAttributeSubscriptionState { - data class Success( - val value: UShort? - ) : CurrentPositionTiltPercent100thsAttributeSubscriptionState() - - data class Error(val exception: Exception) : CurrentPositionTiltPercent100thsAttributeSubscriptionState() - - object SubscriptionEstablished : CurrentPositionTiltPercent100thsAttributeSubscriptionState() - } -class GeneratedCommandListAttribute( - val value: List - ) + data class Success(val value: UShort?) : + CurrentPositionTiltPercent100thsAttributeSubscriptionState() + + data class Error(val exception: Exception) : + CurrentPositionTiltPercent100thsAttributeSubscriptionState() + + object SubscriptionEstablished : CurrentPositionTiltPercent100thsAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : GeneratedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } -class AcceptedCommandListAttribute( - val value: List - ) + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success( - val value: List - ) : AcceptedCommandListAttributeSubscriptionState() - + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } -class EventListAttribute( - val value: List - ) + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) sealed class EventListAttributeSubscriptionState { - data class Success( - val value: List - ) : EventListAttributeSubscriptionState() - + data class Success(val value: List) : EventListAttributeSubscriptionState() + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } -class AttributeListAttribute( - val value: List - ) + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) sealed class AttributeListAttributeSubscriptionState { - data class Success( - val value: List - ) : AttributeListAttributeSubscriptionState() - + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } suspend fun upOrOpen(timedInvokeTimeout: Duration? = null) { val commandId: UInt = 0u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -238,14 +201,14 @@ class AttributeListAttribute( val commandId: UInt = 1u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) @@ -256,180 +219,177 @@ class AttributeListAttribute( val commandId: UInt = 2u val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) + tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun goToLiftValue(liftValue: UShort - ,timedInvokeTimeout: Duration? = null) { + suspend fun goToLiftValue(liftValue: UShort, timedInvokeTimeout: Duration? = null) { val commandId: UInt = 4u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_LIFT_VALUE_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_LIFT_VALUE_REQ), liftValue) + tlvWriter.put(ContextSpecificTag(TAG_LIFT_VALUE_REQ), liftValue) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun goToLiftPercentage(liftPercent100thsValue: UShort - ,timedInvokeTimeout: Duration? = null) { + suspend fun goToLiftPercentage( + liftPercent100thsValue: UShort, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 5u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_LIFT_PERCENT100THS_VALUE_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_LIFT_PERCENT100THS_VALUE_REQ), liftPercent100thsValue) + tlvWriter.put(ContextSpecificTag(TAG_LIFT_PERCENT100THS_VALUE_REQ), liftPercent100thsValue) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun goToTiltValue(tiltValue: UShort - ,timedInvokeTimeout: Duration? = null) { + suspend fun goToTiltValue(tiltValue: UShort, timedInvokeTimeout: Duration? = null) { val commandId: UInt = 7u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_TILT_VALUE_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_TILT_VALUE_REQ), tiltValue) + tlvWriter.put(ContextSpecificTag(TAG_TILT_VALUE_REQ), tiltValue) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } - suspend fun goToTiltPercentage(tiltPercent100thsValue: UShort - ,timedInvokeTimeout: Duration? = null) { + suspend fun goToTiltPercentage( + tiltPercent100thsValue: UShort, + timedInvokeTimeout: Duration? = null, + ) { val commandId: UInt = 8u val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) val TAG_TILT_PERCENT100THS_VALUE_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_TILT_PERCENT100THS_VALUE_REQ), tiltPercent100thsValue) + tlvWriter.put(ContextSpecificTag(TAG_TILT_PERCENT100THS_VALUE_REQ), tiltPercent100thsValue) tlvWriter.endStructure() val request: InvokeRequest = InvokeRequest( CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout + timedRequest = timedInvokeTimeout, ) val response: InvokeResponse = controller.invoke(request) logger.log(Level.FINE, "Invoke command succeeded: ${response}") } -suspend fun readTypeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 0u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readTypeAttribute(): 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 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}") - } + 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) { - "Type attribute not found in response" - } + } + + requireNotNull(attributeData) { "Type 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 subscribeTypeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 0u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Type attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Type attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -441,683 +401,654 @@ suspend fun readTypeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 0u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPhysicalClosedLimitLiftAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 1u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readPhysicalClosedLimitLiftAttribute(): UShort? { + 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 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}") - } + 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) { - "Physicalclosedlimitlift attribute not found in response" - } + } + + requireNotNull(attributeData) { "Physicalclosedlimitlift 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribePhysicalClosedLimitLiftAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 1u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Physicalclosedlimitlift attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Physicalclosedlimitlift 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readPhysicalClosedLimitTiltAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 2u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readPhysicalClosedLimitTiltAttribute(): 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 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}") - } + 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) { - "Physicalclosedlimittilt attribute not found in response" - } + } + + requireNotNull(attributeData) { "Physicalclosedlimittilt 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribePhysicalClosedLimitTiltAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 2u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Physicalclosedlimittilt attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Physicalclosedlimittilt 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCurrentPositionLiftAttribute(): CurrentPositionLiftAttribute {val ATTRIBUTE_ID: UInt = 3u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readCurrentPositionLiftAttribute(): CurrentPositionLiftAttribute { + 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 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}") - } + 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) { - "Currentpositionlift attribute not found in response" - } + } + + requireNotNull(attributeData) { "Currentpositionlift attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return CurrentPositionLiftAttribute(decodedValue) } suspend fun subscribeCurrentPositionLiftAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 3u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(CurrentPositionLiftAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + CurrentPositionLiftAttributeSubscriptionState.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) { - "Currentpositionlift attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Currentpositionlift 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(CurrentPositionLiftAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(CurrentPositionLiftAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(CurrentPositionLiftAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCurrentPositionTiltAttribute(): CurrentPositionTiltAttribute {val ATTRIBUTE_ID: UInt = 4u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readCurrentPositionTiltAttribute(): CurrentPositionTiltAttribute { + 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 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}") - } + 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) { - "Currentpositiontilt attribute not found in response" - } + } + + requireNotNull(attributeData) { "Currentpositiontilt attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return CurrentPositionTiltAttribute(decodedValue) } suspend fun subscribeCurrentPositionTiltAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 4u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(CurrentPositionTiltAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + CurrentPositionTiltAttributeSubscriptionState.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) { - "Currentpositiontilt attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Currentpositiontilt 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { - emit(CurrentPositionTiltAttributeSubscriptionState.Success(it)) - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + decodedValue?.let { emit(CurrentPositionTiltAttributeSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(CurrentPositionTiltAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNumberOfActuationsLiftAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 5u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNumberOfActuationsLiftAttribute(): UShort? { + 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 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}") - } + 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) { - "Numberofactuationslift attribute not found in response" - } + } + + requireNotNull(attributeData) { "Numberofactuationslift 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeNumberOfActuationsLiftAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 5u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Numberofactuationslift attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Numberofactuationslift 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readNumberOfActuationsTiltAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 6u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readNumberOfActuationsTiltAttribute(): 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 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}") - } + 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) { - "Numberofactuationstilt attribute not found in response" - } + } + + requireNotNull(attributeData) { "Numberofactuationstilt 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeNumberOfActuationsTiltAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 6u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Numberofactuationstilt attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Numberofactuationstilt 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readConfigStatusAttribute(): UByte {val ATTRIBUTE_ID: UInt = 7u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readConfigStatusAttribute(): UByte { + 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 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}") - } + 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) { - "Configstatus attribute not found in response" - } + } + + requireNotNull(attributeData) { "Configstatus 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 subscribeConfigStatusAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 7u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Configstatus attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Configstatus attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -1129,294 +1060,291 @@ suspend fun readConfigStatusAttribute(): UByte {val ATTRIBUTE_ID: UInt = 7u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCurrentPositionLiftPercentageAttribute(): CurrentPositionLiftPercentageAttribute {val ATTRIBUTE_ID: UInt = 8u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readCurrentPositionLiftPercentageAttribute(): CurrentPositionLiftPercentageAttribute { + val ATTRIBUTE_ID: UInt = 8u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Currentpositionliftpercentage attribute not found in response" + } + + requireNotNull(attributeData) { + "Currentpositionliftpercentage attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return CurrentPositionLiftPercentageAttribute(decodedValue) } suspend fun subscribeCurrentPositionLiftPercentageAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 8u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(CurrentPositionLiftPercentageAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + CurrentPositionLiftPercentageAttributeSubscriptionState.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) { - "Currentpositionliftpercentage attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Currentpositionliftpercentage 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } decodedValue?.let { emit(CurrentPositionLiftPercentageAttributeSubscriptionState.Success(it)) } - } SubscriptionState.SubscriptionEstablished -> { emit(CurrentPositionLiftPercentageAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCurrentPositionTiltPercentageAttribute(): CurrentPositionTiltPercentageAttribute {val ATTRIBUTE_ID: UInt = 9u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readCurrentPositionTiltPercentageAttribute(): CurrentPositionTiltPercentageAttribute { + val ATTRIBUTE_ID: UInt = 9u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Currentpositiontiltpercentage attribute not found in response" + } + + requireNotNull(attributeData) { + "Currentpositiontiltpercentage attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return CurrentPositionTiltPercentageAttribute(decodedValue) } suspend fun subscribeCurrentPositionTiltPercentageAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 9u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(CurrentPositionTiltPercentageAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + CurrentPositionTiltPercentageAttributeSubscriptionState.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) { - "Currentpositiontiltpercentage attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Currentpositiontiltpercentage 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UByte? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUByte(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } decodedValue?.let { emit(CurrentPositionTiltPercentageAttributeSubscriptionState.Success(it)) } - } SubscriptionState.SubscriptionEstablished -> { emit(CurrentPositionTiltPercentageAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readOperationalStatusAttribute(): UByte {val ATTRIBUTE_ID: UInt = 10u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readOperationalStatusAttribute(): UByte { + val ATTRIBUTE_ID: UInt = 10u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Operationalstatus attribute not found in response" - } + } + + requireNotNull(attributeData) { "Operationalstatus 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 subscribeOperationalStatusAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 10u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Operationalstatus attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Operationalstatus attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -1429,294 +1357,293 @@ suspend fun readOperationalStatusAttribute(): UByte {val ATTRIBUTE_ID: UInt = 10 emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readTargetPositionLiftPercent100thsAttribute(): TargetPositionLiftPercent100thsAttribute {val ATTRIBUTE_ID: UInt = 11u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readTargetPositionLiftPercent100thsAttribute(): + TargetPositionLiftPercent100thsAttribute { + val ATTRIBUTE_ID: UInt = 11u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Targetpositionliftpercent100ths attribute not found in response" + } + + requireNotNull(attributeData) { + "Targetpositionliftpercent100ths attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return TargetPositionLiftPercent100thsAttribute(decodedValue) } suspend fun subscribeTargetPositionLiftPercent100thsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 11u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(TargetPositionLiftPercent100thsAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + TargetPositionLiftPercent100thsAttributeSubscriptionState.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) { - "Targetpositionliftpercent100ths attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Targetpositionliftpercent100ths 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } decodedValue?.let { emit(TargetPositionLiftPercent100thsAttributeSubscriptionState.Success(it)) } - } SubscriptionState.SubscriptionEstablished -> { emit(TargetPositionLiftPercent100thsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readTargetPositionTiltPercent100thsAttribute(): TargetPositionTiltPercent100thsAttribute {val ATTRIBUTE_ID: UInt = 12u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readTargetPositionTiltPercent100thsAttribute(): + TargetPositionTiltPercent100thsAttribute { + val ATTRIBUTE_ID: UInt = 12u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Targetpositiontiltpercent100ths attribute not found in response" - } - - // Decode the TLV data into the appropriate type - val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null + } + + requireNotNull(attributeData) { + "Targetpositiontiltpercent100ths attribute not found in response" } + // Decode the TLV data into the appropriate type + val tlvReader = TlvReader(attributeData.data) + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return TargetPositionTiltPercent100thsAttribute(decodedValue) } suspend fun subscribeTargetPositionTiltPercent100thsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 12u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(TargetPositionTiltPercent100thsAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + TargetPositionTiltPercent100thsAttributeSubscriptionState.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) { - "Targetpositiontiltpercent100ths attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Targetpositiontiltpercent100ths 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } decodedValue?.let { emit(TargetPositionTiltPercent100thsAttributeSubscriptionState.Success(it)) } - } SubscriptionState.SubscriptionEstablished -> { emit(TargetPositionTiltPercent100thsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readEndProductTypeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 13u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readEndProductTypeAttribute(): UByte { + val ATTRIBUTE_ID: UInt = 13u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Endproducttype attribute not found in response" - } + } + + requireNotNull(attributeData) { "Endproducttype 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 subscribeEndProductTypeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 13u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Endproducttype attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Endproducttype attribute not found in Node State update" } // Decode the TLV data into the appropriate type @@ -1729,670 +1656,645 @@ suspend fun readEndProductTypeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 13u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCurrentPositionLiftPercent100thsAttribute(): CurrentPositionLiftPercent100thsAttribute {val ATTRIBUTE_ID: UInt = 14u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readCurrentPositionLiftPercent100thsAttribute(): + CurrentPositionLiftPercent100thsAttribute { + val ATTRIBUTE_ID: UInt = 14u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Currentpositionliftpercent100ths attribute not found in response" + } + + requireNotNull(attributeData) { + "Currentpositionliftpercent100ths attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return CurrentPositionLiftPercent100thsAttribute(decodedValue) } suspend fun subscribeCurrentPositionLiftPercent100thsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 14u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(CurrentPositionLiftPercent100thsAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + CurrentPositionLiftPercent100thsAttributeSubscriptionState.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) { - "Currentpositionliftpercent100ths attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Currentpositionliftpercent100ths 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } decodedValue?.let { emit(CurrentPositionLiftPercent100thsAttributeSubscriptionState.Success(it)) } - } SubscriptionState.SubscriptionEstablished -> { emit(CurrentPositionLiftPercent100thsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readCurrentPositionTiltPercent100thsAttribute(): CurrentPositionTiltPercent100thsAttribute {val ATTRIBUTE_ID: UInt = 15u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readCurrentPositionTiltPercent100thsAttribute(): + CurrentPositionTiltPercent100thsAttribute { + val ATTRIBUTE_ID: UInt = 15u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Currentpositiontiltpercent100ths attribute not found in response" + } + + requireNotNull(attributeData) { + "Currentpositiontiltpercent100ths attribute not found in response" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } return CurrentPositionTiltPercent100thsAttribute(decodedValue) } suspend fun subscribeCurrentPositionTiltPercent100thsAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 15u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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(CurrentPositionTiltPercent100thsAttributeSubscriptionState.Error(Exception("Subscription terminated with error code: ${subscriptionState.terminationCause}"))) + emit( + CurrentPositionTiltPercent100thsAttributeSubscriptionState.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) { - "Currentpositiontiltpercent100ths attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Currentpositiontiltpercent100ths 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.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } + val decodedValue: UShort? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } decodedValue?.let { emit(CurrentPositionTiltPercent100thsAttributeSubscriptionState.Success(it)) } - } SubscriptionState.SubscriptionEstablished -> { emit(CurrentPositionTiltPercent100thsAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readInstalledOpenLimitLiftAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 16u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readInstalledOpenLimitLiftAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 16u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Installedopenlimitlift attribute not found in response" - } + } + + requireNotNull(attributeData) { "Installedopenlimitlift 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeInstalledOpenLimitLiftAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 16u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Installedopenlimitlift attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Installedopenlimitlift 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readInstalledClosedLimitLiftAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 17u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readInstalledClosedLimitLiftAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 17u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Installedclosedlimitlift attribute not found in response" - } + } + + requireNotNull(attributeData) { "Installedclosedlimitlift 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeInstalledClosedLimitLiftAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 17u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Installedclosedlimitlift attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Installedclosedlimitlift 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readInstalledOpenLimitTiltAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 18u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readInstalledOpenLimitTiltAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 18u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Installedopenlimittilt attribute not found in response" - } + } + + requireNotNull(attributeData) { "Installedopenlimittilt 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeInstalledOpenLimitTiltAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 18u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Installedopenlimittilt attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Installedopenlimittilt 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readInstalledClosedLimitTiltAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 19u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readInstalledClosedLimitTiltAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 19u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Installedclosedlimittilt attribute not found in response" - } + } + + requireNotNull(attributeData) { "Installedclosedlimittilt 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeInstalledClosedLimitTiltAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 19u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Installedclosedlimittilt attribute not found in Node State update" + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Installedclosedlimittilt 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readModeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 23u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readModeAttribute(): UByte { + val ATTRIBUTE_ID: UInt = 23u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Mode attribute not found in response" - } + } + + requireNotNull(attributeData) { "Mode 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 writeModeAttribute( - value: UByte, - timedWriteTimeout: Duration? = null) { + suspend fun writeModeAttribute(value: UByte, timedWriteTimeout: Duration? = null) { val ATTRIBUTE_ID: UInt = 23u val tlvWriter = TlvWriter() - tlvWriter.put(AnonymousTag, value) + tlvWriter.put(AnonymousTag, value) val writeRequests: WriteRequests = WriteRequests( - requests = listOf( - WriteRequest( - attributePath = AttributePath( - endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ), - tlvPayload = tlvWriter.getEncoded() - ) - ), - timedRequest = timedWriteTimeout + requests = + listOf( + WriteRequest( + attributePath = + AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID), + tlvPayload = tlvWriter.getEncoded(), + ) + ), + timedRequest = timedWriteTimeout, ) val response: WriteResponse = controller.write(writeRequests) @@ -2413,43 +2315,45 @@ suspend fun readModeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 23u throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage") } - } + } } suspend fun subscribeModeAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 23u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Mode attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Mode attribute not found in Node State update" } // Decode the TLV data into the appropriate type val tlvReader = TlvReader(attributeData.data) @@ -2461,194 +2365,187 @@ suspend fun readModeAttribute(): UByte {val ATTRIBUTE_ID: UInt = 23u emit(UByteSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readSafetyStatusAttribute(): UShort? {val ATTRIBUTE_ID: UInt = 26u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + suspend fun readSafetyStatusAttribute(): UShort? { + val ATTRIBUTE_ID: UInt = 26u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - 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}") - } + 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) { - "Safetystatus attribute not found in response" - } + } + + requireNotNull(attributeData) { "Safetystatus 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 - } - + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } return decodedValue } suspend fun subscribeSafetyStatusAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 26u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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) { - "Safetystatus attribute not found in Node State update" - } + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Safetystatus 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 - } + val decodedValue: UShort? = + if (tlvReader.isNextTag(AnonymousTag)) { + tlvReader.getUShort(AnonymousTag) + } else { + null + } - decodedValue?.let { - emit(UShortSubscriptionState.Success(it)) - } - + decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } } SubscriptionState.SubscriptionEstablished -> { emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65528u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return GeneratedCommandListAttribute(decodedValue) } suspend fun subscribeGeneratedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -2656,97 +2553,96 @@ suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { emit(GeneratedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {val ATTRIBUTE_ID: UInt = 65529u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AcceptedCommandListAttribute(decodedValue) } suspend fun subscribeAcceptedCommandListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) } @@ -2754,97 +2650,94 @@ suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute {va emit(AcceptedCommandListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt = 65530u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return EventListAttribute(decodedValue) } suspend fun subscribeEventListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(EventListAttributeSubscriptionState.Success(decodedValue)) } @@ -2852,97 +2745,94 @@ suspend fun readEventListAttribute(): EventListAttribute {val ATTRIBUTE_ID: UInt emit(EventListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ID: UInt = 65531u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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)) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - return AttributeListAttribute(decodedValue) } suspend fun subscribeAttributeListAttribute( minInterval: Int, - maxInterval: Int + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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() - } + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) } @@ -2950,81 +2840,76 @@ suspend fun readAttributeListAttribute(): AttributeListAttribute {val ATTRIBUTE_ emit(AttributeListAttributeSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" - } + 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) @@ -3036,80 +2921,77 @@ suspend fun readFeatureMapAttribute(): UInt {val ATTRIBUTE_ID: UInt = 65532u emit(UIntSubscriptionState.SubscriptionEstablished) } } - } + } } -suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 65533u - val attributePath = AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID - ) + 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 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}") - } + 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" - } + } + + 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 + maxInterval: Int, ): Flow { val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = listOf( - AttributePath( - endpointId = endpointId, - clusterId = CLUSTER_ID, - attributeId = ATTRIBUTE_ID + 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()) - ) + 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}"))) + 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" + 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 @@ -3122,7 +3004,7 @@ suspend fun readClusterRevisionAttribute(): UShort {val ATTRIBUTE_ID: UInt = 655 emit(UShortSubscriptionState.SubscriptionEstablished) } } - } + } } companion object { diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/AccessControlClusterAccessControlEntryChangedEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/AccessControlClusterAccessControlEntryChangedEvent.kt index 2fdbf26e1294da..2ac4b28ebebcb9 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/AccessControlClusterAccessControlEntryChangedEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/AccessControlClusterAccessControlEntryChangedEvent.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -29,7 +27,7 @@ class AccessControlClusterAccessControlEntryChangedEvent( val adminPasscodeID: UShort?, val changeType: UByte, val latestValue: matter.controller.cluster.structs.AccessControlClusterAccessControlEntryStruct?, - val fabricIndex: UByte + val fabricIndex: UByte, ) { override fun toString(): String = buildString { append("AccessControlClusterAccessControlEntryChangedEvent {\n") @@ -72,32 +70,47 @@ class AccessControlClusterAccessControlEntryChangedEvent( private const val TAG_LATEST_VALUE = 4 private const val TAG_FABRIC_INDEX = 254 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : AccessControlClusterAccessControlEntryChangedEvent { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): AccessControlClusterAccessControlEntryChangedEvent { tlvReader.enterStructure(tlvTag) - val adminNodeID = if (!tlvReader.isNull()) { - tlvReader.getULong(ContextSpecificTag(TAG_ADMIN_NODE_ID)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_ADMIN_NODE_ID)) - null - } - val adminPasscodeID = if (!tlvReader.isNull()) { - tlvReader.getUShort(ContextSpecificTag(TAG_ADMIN_PASSCODE_ID)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_ADMIN_PASSCODE_ID)) - null - } + val adminNodeID = + if (!tlvReader.isNull()) { + tlvReader.getULong(ContextSpecificTag(TAG_ADMIN_NODE_ID)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_ADMIN_NODE_ID)) + null + } + val adminPasscodeID = + if (!tlvReader.isNull()) { + tlvReader.getUShort(ContextSpecificTag(TAG_ADMIN_PASSCODE_ID)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_ADMIN_PASSCODE_ID)) + null + } val changeType = tlvReader.getUByte(ContextSpecificTag(TAG_CHANGE_TYPE)) - val latestValue = if (!tlvReader.isNull()) { - matter.controller.cluster.structs.AccessControlClusterAccessControlEntryStruct.fromTlv(ContextSpecificTag(TAG_LATEST_VALUE), tlvReader) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_LATEST_VALUE)) - null - } + val latestValue = + if (!tlvReader.isNull()) { + matter.controller.cluster.structs.AccessControlClusterAccessControlEntryStruct.fromTlv( + ContextSpecificTag(TAG_LATEST_VALUE), + tlvReader, + ) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_LATEST_VALUE)) + null + } val fabricIndex = tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) - + tlvReader.exitContainer() - return AccessControlClusterAccessControlEntryChangedEvent(adminNodeID, adminPasscodeID, changeType, latestValue, fabricIndex) + return AccessControlClusterAccessControlEntryChangedEvent( + adminNodeID, + adminPasscodeID, + changeType, + latestValue, + fabricIndex, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/AccessControlClusterAccessControlExtensionChangedEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/AccessControlClusterAccessControlExtensionChangedEvent.kt index b99c69451dc1c4..668ee86be2e380 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/AccessControlClusterAccessControlExtensionChangedEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/AccessControlClusterAccessControlExtensionChangedEvent.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -28,8 +26,9 @@ class AccessControlClusterAccessControlExtensionChangedEvent( val adminNodeID: ULong?, val adminPasscodeID: UShort?, val changeType: UByte, - val latestValue: matter.controller.cluster.structs.AccessControlClusterAccessControlExtensionStruct?, - val fabricIndex: UByte + val latestValue: + matter.controller.cluster.structs.AccessControlClusterAccessControlExtensionStruct?, + val fabricIndex: UByte, ) { override fun toString(): String = buildString { append("AccessControlClusterAccessControlExtensionChangedEvent {\n") @@ -72,32 +71,45 @@ class AccessControlClusterAccessControlExtensionChangedEvent( private const val TAG_LATEST_VALUE = 4 private const val TAG_FABRIC_INDEX = 254 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : AccessControlClusterAccessControlExtensionChangedEvent { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): AccessControlClusterAccessControlExtensionChangedEvent { tlvReader.enterStructure(tlvTag) - val adminNodeID = if (!tlvReader.isNull()) { - tlvReader.getULong(ContextSpecificTag(TAG_ADMIN_NODE_ID)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_ADMIN_NODE_ID)) - null - } - val adminPasscodeID = if (!tlvReader.isNull()) { - tlvReader.getUShort(ContextSpecificTag(TAG_ADMIN_PASSCODE_ID)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_ADMIN_PASSCODE_ID)) - null - } + val adminNodeID = + if (!tlvReader.isNull()) { + tlvReader.getULong(ContextSpecificTag(TAG_ADMIN_NODE_ID)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_ADMIN_NODE_ID)) + null + } + val adminPasscodeID = + if (!tlvReader.isNull()) { + tlvReader.getUShort(ContextSpecificTag(TAG_ADMIN_PASSCODE_ID)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_ADMIN_PASSCODE_ID)) + null + } val changeType = tlvReader.getUByte(ContextSpecificTag(TAG_CHANGE_TYPE)) - val latestValue = if (!tlvReader.isNull()) { - matter.controller.cluster.structs.AccessControlClusterAccessControlExtensionStruct.fromTlv(ContextSpecificTag(TAG_LATEST_VALUE), tlvReader) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_LATEST_VALUE)) - null - } + val latestValue = + if (!tlvReader.isNull()) { + matter.controller.cluster.structs.AccessControlClusterAccessControlExtensionStruct + .fromTlv(ContextSpecificTag(TAG_LATEST_VALUE), tlvReader) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_LATEST_VALUE)) + null + } val fabricIndex = tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) - + tlvReader.exitContainer() - return AccessControlClusterAccessControlExtensionChangedEvent(adminNodeID, adminPasscodeID, changeType, latestValue, fabricIndex) + return AccessControlClusterAccessControlExtensionChangedEvent( + adminNodeID, + adminPasscodeID, + changeType, + latestValue, + fabricIndex, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/AccessControlClusterAccessRestrictionEntryChangedEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/AccessControlClusterAccessRestrictionEntryChangedEvent.kt index 19b74788bb9582..8a272f8854ae12 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/AccessControlClusterAccessRestrictionEntryChangedEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/AccessControlClusterAccessRestrictionEntryChangedEvent.kt @@ -16,17 +16,13 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional 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 AccessControlClusterAccessRestrictionEntryChangedEvent( - val fabricIndex: UByte -) { +class AccessControlClusterAccessRestrictionEntryChangedEvent(val fabricIndex: UByte) { override fun toString(): String = buildString { append("AccessControlClusterAccessRestrictionEntryChangedEvent {\n") append("\tfabricIndex : $fabricIndex\n") @@ -44,10 +40,13 @@ class AccessControlClusterAccessRestrictionEntryChangedEvent( companion object { private const val TAG_FABRIC_INDEX = 254 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : AccessControlClusterAccessRestrictionEntryChangedEvent { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): AccessControlClusterAccessRestrictionEntryChangedEvent { tlvReader.enterStructure(tlvTag) val fabricIndex = tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) - + tlvReader.exitContainer() return AccessControlClusterAccessRestrictionEntryChangedEvent(fabricIndex) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/AccessControlClusterFabricRestrictionReviewUpdateEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/AccessControlClusterFabricRestrictionReviewUpdateEvent.kt index fae7081a36d9db..6bf03e6afc8c13 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/AccessControlClusterFabricRestrictionReviewUpdateEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/AccessControlClusterFabricRestrictionReviewUpdateEvent.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -28,7 +26,7 @@ class AccessControlClusterFabricRestrictionReviewUpdateEvent( val token: ULong, val instruction: String?, val redirectURL: String?, - val fabricIndex: UByte + val fabricIndex: UByte, ) { override fun toString(): String = buildString { append("AccessControlClusterFabricRestrictionReviewUpdateEvent {\n") @@ -64,26 +62,36 @@ class AccessControlClusterFabricRestrictionReviewUpdateEvent( private const val TAG_REDIRECT_URL = 2 private const val TAG_FABRIC_INDEX = 254 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : AccessControlClusterFabricRestrictionReviewUpdateEvent { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): AccessControlClusterFabricRestrictionReviewUpdateEvent { tlvReader.enterStructure(tlvTag) val token = tlvReader.getULong(ContextSpecificTag(TAG_TOKEN)) - val instruction = if (!tlvReader.isNull()) { - tlvReader.getString(ContextSpecificTag(TAG_INSTRUCTION)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_INSTRUCTION)) - null - } - val redirectURL = if (!tlvReader.isNull()) { - tlvReader.getString(ContextSpecificTag(TAG_REDIRECT_URL)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_REDIRECT_URL)) - null - } + val instruction = + if (!tlvReader.isNull()) { + tlvReader.getString(ContextSpecificTag(TAG_INSTRUCTION)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_INSTRUCTION)) + null + } + val redirectURL = + if (!tlvReader.isNull()) { + tlvReader.getString(ContextSpecificTag(TAG_REDIRECT_URL)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_REDIRECT_URL)) + null + } val fabricIndex = tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) - + tlvReader.exitContainer() - return AccessControlClusterFabricRestrictionReviewUpdateEvent(token, instruction, redirectURL, fabricIndex) + return AccessControlClusterFabricRestrictionReviewUpdateEvent( + token, + instruction, + redirectURL, + fabricIndex, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/AccountLoginClusterLoggedOutEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/AccountLoginClusterLoggedOutEvent.kt index 4adc0b113c8e01..81e55baf4fe4f7 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/AccountLoginClusterLoggedOutEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/AccountLoginClusterLoggedOutEvent.kt @@ -18,15 +18,12 @@ package matter.controller.cluster.eventstructs import java.util.Optional 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 AccountLoginClusterLoggedOutEvent( - val node: Optional -) { +class AccountLoginClusterLoggedOutEvent(val node: Optional) { override fun toString(): String = buildString { append("AccountLoginClusterLoggedOutEvent {\n") append("\tnode : $node\n") @@ -47,14 +44,15 @@ class AccountLoginClusterLoggedOutEvent( companion object { private const val TAG_NODE = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : AccountLoginClusterLoggedOutEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): AccountLoginClusterLoggedOutEvent { tlvReader.enterStructure(tlvTag) - val node = if (tlvReader.isNextTag(ContextSpecificTag(TAG_NODE))) { - Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_NODE))) - } else { - Optional.empty() - } - + val node = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_NODE))) { + Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_NODE))) + } else { + Optional.empty() + } + tlvReader.exitContainer() return AccountLoginClusterLoggedOutEvent(node) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ActionsClusterActionFailedEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ActionsClusterActionFailedEvent.kt index 014d77c3f2ecc7..a1fe90125f5e61 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ActionsClusterActionFailedEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ActionsClusterActionFailedEvent.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -28,7 +26,7 @@ class ActionsClusterActionFailedEvent( val actionID: UShort, val invokeID: UInt, val newState: UByte, - val error: UByte + val error: UByte, ) { override fun toString(): String = buildString { append("ActionsClusterActionFailedEvent {\n") @@ -56,13 +54,13 @@ class ActionsClusterActionFailedEvent( private const val TAG_NEW_STATE = 2 private const val TAG_ERROR = 3 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : ActionsClusterActionFailedEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ActionsClusterActionFailedEvent { tlvReader.enterStructure(tlvTag) val actionID = tlvReader.getUShort(ContextSpecificTag(TAG_ACTION_ID)) val invokeID = tlvReader.getUInt(ContextSpecificTag(TAG_INVOKE_ID)) val newState = tlvReader.getUByte(ContextSpecificTag(TAG_NEW_STATE)) val error = tlvReader.getUByte(ContextSpecificTag(TAG_ERROR)) - + tlvReader.exitContainer() return ActionsClusterActionFailedEvent(actionID, invokeID, newState, error) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ActionsClusterStateChangedEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ActionsClusterStateChangedEvent.kt index c4d49cc015a6e5..8fdefb84b1b3ba 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ActionsClusterStateChangedEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ActionsClusterStateChangedEvent.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -27,7 +25,7 @@ import matter.tlv.TlvWriter class ActionsClusterStateChangedEvent( val actionID: UShort, val invokeID: UInt, - val newState: UByte + val newState: UByte, ) { override fun toString(): String = buildString { append("ActionsClusterStateChangedEvent {\n") @@ -52,12 +50,12 @@ class ActionsClusterStateChangedEvent( private const val TAG_INVOKE_ID = 1 private const val TAG_NEW_STATE = 2 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : ActionsClusterStateChangedEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ActionsClusterStateChangedEvent { tlvReader.enterStructure(tlvTag) val actionID = tlvReader.getUShort(ContextSpecificTag(TAG_ACTION_ID)) val invokeID = tlvReader.getUInt(ContextSpecificTag(TAG_INVOKE_ID)) val newState = tlvReader.getUByte(ContextSpecificTag(TAG_NEW_STATE)) - + tlvReader.exitContainer() return ActionsClusterStateChangedEvent(actionID, invokeID, newState) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BasicInformationClusterLeaveEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BasicInformationClusterLeaveEvent.kt index 2b909a62b20b6f..ea0e7e1e1004c4 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BasicInformationClusterLeaveEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BasicInformationClusterLeaveEvent.kt @@ -16,17 +16,13 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional 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 BasicInformationClusterLeaveEvent( - val fabricIndex: UByte -) { +class BasicInformationClusterLeaveEvent(val fabricIndex: UByte) { override fun toString(): String = buildString { append("BasicInformationClusterLeaveEvent {\n") append("\tfabricIndex : $fabricIndex\n") @@ -44,10 +40,10 @@ class BasicInformationClusterLeaveEvent( companion object { private const val TAG_FABRIC_INDEX = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : BasicInformationClusterLeaveEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): BasicInformationClusterLeaveEvent { tlvReader.enterStructure(tlvTag) val fabricIndex = tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) - + tlvReader.exitContainer() return BasicInformationClusterLeaveEvent(fabricIndex) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BasicInformationClusterReachableChangedEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BasicInformationClusterReachableChangedEvent.kt index 4bacfa94d86ef9..a6924b859aa024 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BasicInformationClusterReachableChangedEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BasicInformationClusterReachableChangedEvent.kt @@ -16,17 +16,13 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional 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 BasicInformationClusterReachableChangedEvent( - val reachableNewValue: Boolean -) { +class BasicInformationClusterReachableChangedEvent(val reachableNewValue: Boolean) { override fun toString(): String = buildString { append("BasicInformationClusterReachableChangedEvent {\n") append("\treachableNewValue : $reachableNewValue\n") @@ -44,10 +40,10 @@ class BasicInformationClusterReachableChangedEvent( companion object { private const val TAG_REACHABLE_NEW_VALUE = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : BasicInformationClusterReachableChangedEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): BasicInformationClusterReachableChangedEvent { tlvReader.enterStructure(tlvTag) val reachableNewValue = tlvReader.getBoolean(ContextSpecificTag(TAG_REACHABLE_NEW_VALUE)) - + tlvReader.exitContainer() return BasicInformationClusterReachableChangedEvent(reachableNewValue) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BasicInformationClusterStartUpEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BasicInformationClusterStartUpEvent.kt index 949ae5f92688a0..fff1d76a1fa86e 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BasicInformationClusterStartUpEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BasicInformationClusterStartUpEvent.kt @@ -16,17 +16,13 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional 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 BasicInformationClusterStartUpEvent( - val softwareVersion: UInt -) { +class BasicInformationClusterStartUpEvent(val softwareVersion: UInt) { override fun toString(): String = buildString { append("BasicInformationClusterStartUpEvent {\n") append("\tsoftwareVersion : $softwareVersion\n") @@ -44,10 +40,10 @@ class BasicInformationClusterStartUpEvent( companion object { private const val TAG_SOFTWARE_VERSION = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : BasicInformationClusterStartUpEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): BasicInformationClusterStartUpEvent { tlvReader.enterStructure(tlvTag) val softwareVersion = tlvReader.getUInt(ContextSpecificTag(TAG_SOFTWARE_VERSION)) - + tlvReader.exitContainer() return BasicInformationClusterStartUpEvent(softwareVersion) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BooleanStateClusterStateChangeEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BooleanStateClusterStateChangeEvent.kt index 50b4494eebdc0d..82db9ecdb2a8f4 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BooleanStateClusterStateChangeEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BooleanStateClusterStateChangeEvent.kt @@ -16,17 +16,13 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional 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 BooleanStateClusterStateChangeEvent( - val stateValue: Boolean -) { +class BooleanStateClusterStateChangeEvent(val stateValue: Boolean) { override fun toString(): String = buildString { append("BooleanStateClusterStateChangeEvent {\n") append("\tstateValue : $stateValue\n") @@ -44,10 +40,10 @@ class BooleanStateClusterStateChangeEvent( companion object { private const val TAG_STATE_VALUE = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : BooleanStateClusterStateChangeEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): BooleanStateClusterStateChangeEvent { tlvReader.enterStructure(tlvTag) val stateValue = tlvReader.getBoolean(ContextSpecificTag(TAG_STATE_VALUE)) - + tlvReader.exitContainer() return BooleanStateClusterStateChangeEvent(stateValue) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BooleanStateConfigurationClusterAlarmsStateChangedEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BooleanStateConfigurationClusterAlarmsStateChangedEvent.kt index 14d64045516493..0a221d724b4cc1 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BooleanStateConfigurationClusterAlarmsStateChangedEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BooleanStateConfigurationClusterAlarmsStateChangedEvent.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.eventstructs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +25,7 @@ import matter.tlv.TlvWriter class BooleanStateConfigurationClusterAlarmsStateChangedEvent( val alarmsActive: UByte, - val alarmsSuppressed: Optional + val alarmsSuppressed: Optional, ) { override fun toString(): String = buildString { append("BooleanStateConfigurationClusterAlarmsStateChangedEvent {\n") @@ -51,15 +50,19 @@ class BooleanStateConfigurationClusterAlarmsStateChangedEvent( private const val TAG_ALARMS_ACTIVE = 0 private const val TAG_ALARMS_SUPPRESSED = 1 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : BooleanStateConfigurationClusterAlarmsStateChangedEvent { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): BooleanStateConfigurationClusterAlarmsStateChangedEvent { tlvReader.enterStructure(tlvTag) val alarmsActive = tlvReader.getUByte(ContextSpecificTag(TAG_ALARMS_ACTIVE)) - val alarmsSuppressed = if (tlvReader.isNextTag(ContextSpecificTag(TAG_ALARMS_SUPPRESSED))) { - Optional.of(tlvReader.getUByte(ContextSpecificTag(TAG_ALARMS_SUPPRESSED))) - } else { - Optional.empty() - } - + val alarmsSuppressed = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_ALARMS_SUPPRESSED))) { + Optional.of(tlvReader.getUByte(ContextSpecificTag(TAG_ALARMS_SUPPRESSED))) + } else { + Optional.empty() + } + tlvReader.exitContainer() return BooleanStateConfigurationClusterAlarmsStateChangedEvent(alarmsActive, alarmsSuppressed) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BooleanStateConfigurationClusterSensorFaultEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BooleanStateConfigurationClusterSensorFaultEvent.kt index 750d449968ba98..cce18515d5a10a 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BooleanStateConfigurationClusterSensorFaultEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BooleanStateConfigurationClusterSensorFaultEvent.kt @@ -16,17 +16,13 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional 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 BooleanStateConfigurationClusterSensorFaultEvent( - val sensorFault: UShort -) { +class BooleanStateConfigurationClusterSensorFaultEvent(val sensorFault: UShort) { override fun toString(): String = buildString { append("BooleanStateConfigurationClusterSensorFaultEvent {\n") append("\tsensorFault : $sensorFault\n") @@ -44,10 +40,13 @@ class BooleanStateConfigurationClusterSensorFaultEvent( companion object { private const val TAG_SENSOR_FAULT = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : BooleanStateConfigurationClusterSensorFaultEvent { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): BooleanStateConfigurationClusterSensorFaultEvent { tlvReader.enterStructure(tlvTag) val sensorFault = tlvReader.getUShort(ContextSpecificTag(TAG_SENSOR_FAULT)) - + tlvReader.exitContainer() return BooleanStateConfigurationClusterSensorFaultEvent(sensorFault) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BridgedDeviceBasicInformationClusterActiveChangedEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BridgedDeviceBasicInformationClusterActiveChangedEvent.kt index cbfb8d7b65dc40..7713cb0faf07b3 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BridgedDeviceBasicInformationClusterActiveChangedEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BridgedDeviceBasicInformationClusterActiveChangedEvent.kt @@ -16,17 +16,13 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional 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 BridgedDeviceBasicInformationClusterActiveChangedEvent( - val promisedActiveDuration: UInt -) { +class BridgedDeviceBasicInformationClusterActiveChangedEvent(val promisedActiveDuration: UInt) { override fun toString(): String = buildString { append("BridgedDeviceBasicInformationClusterActiveChangedEvent {\n") append("\tpromisedActiveDuration : $promisedActiveDuration\n") @@ -44,10 +40,14 @@ class BridgedDeviceBasicInformationClusterActiveChangedEvent( companion object { private const val TAG_PROMISED_ACTIVE_DURATION = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : BridgedDeviceBasicInformationClusterActiveChangedEvent { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): BridgedDeviceBasicInformationClusterActiveChangedEvent { tlvReader.enterStructure(tlvTag) - val promisedActiveDuration = tlvReader.getUInt(ContextSpecificTag(TAG_PROMISED_ACTIVE_DURATION)) - + val promisedActiveDuration = + tlvReader.getUInt(ContextSpecificTag(TAG_PROMISED_ACTIVE_DURATION)) + tlvReader.exitContainer() return BridgedDeviceBasicInformationClusterActiveChangedEvent(promisedActiveDuration) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BridgedDeviceBasicInformationClusterReachableChangedEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BridgedDeviceBasicInformationClusterReachableChangedEvent.kt index 5bd65929e12bdc..bd259a290a3bde 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BridgedDeviceBasicInformationClusterReachableChangedEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BridgedDeviceBasicInformationClusterReachableChangedEvent.kt @@ -16,17 +16,13 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional 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 BridgedDeviceBasicInformationClusterReachableChangedEvent( - val reachableNewValue: Boolean -) { +class BridgedDeviceBasicInformationClusterReachableChangedEvent(val reachableNewValue: Boolean) { override fun toString(): String = buildString { append("BridgedDeviceBasicInformationClusterReachableChangedEvent {\n") append("\treachableNewValue : $reachableNewValue\n") @@ -44,10 +40,13 @@ class BridgedDeviceBasicInformationClusterReachableChangedEvent( companion object { private const val TAG_REACHABLE_NEW_VALUE = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : BridgedDeviceBasicInformationClusterReachableChangedEvent { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): BridgedDeviceBasicInformationClusterReachableChangedEvent { tlvReader.enterStructure(tlvTag) val reachableNewValue = tlvReader.getBoolean(ContextSpecificTag(TAG_REACHABLE_NEW_VALUE)) - + tlvReader.exitContainer() return BridgedDeviceBasicInformationClusterReachableChangedEvent(reachableNewValue) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BridgedDeviceBasicInformationClusterStartUpEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BridgedDeviceBasicInformationClusterStartUpEvent.kt index 67aa89e3788154..41e4f4e2d0003d 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BridgedDeviceBasicInformationClusterStartUpEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/BridgedDeviceBasicInformationClusterStartUpEvent.kt @@ -16,17 +16,13 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional 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 BridgedDeviceBasicInformationClusterStartUpEvent( - val softwareVersion: UInt -) { +class BridgedDeviceBasicInformationClusterStartUpEvent(val softwareVersion: UInt) { override fun toString(): String = buildString { append("BridgedDeviceBasicInformationClusterStartUpEvent {\n") append("\tsoftwareVersion : $softwareVersion\n") @@ -44,10 +40,13 @@ class BridgedDeviceBasicInformationClusterStartUpEvent( companion object { private const val TAG_SOFTWARE_VERSION = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : BridgedDeviceBasicInformationClusterStartUpEvent { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): BridgedDeviceBasicInformationClusterStartUpEvent { tlvReader.enterStructure(tlvTag) val softwareVersion = tlvReader.getUInt(ContextSpecificTag(TAG_SOFTWARE_VERSION)) - + tlvReader.exitContainer() return BridgedDeviceBasicInformationClusterStartUpEvent(softwareVersion) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/CommissionerControlClusterCommissioningRequestResultEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/CommissionerControlClusterCommissioningRequestResultEvent.kt index d7df65fa518b14..c8947776269773 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/CommissionerControlClusterCommissioningRequestResultEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/CommissionerControlClusterCommissioningRequestResultEvent.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -28,7 +26,7 @@ class CommissionerControlClusterCommissioningRequestResultEvent( val requestId: ULong, val clientNodeId: ULong, val statusCode: UByte, - val fabricIndex: UByte + val fabricIndex: UByte, ) { override fun toString(): String = buildString { append("CommissionerControlClusterCommissioningRequestResultEvent {\n") @@ -56,16 +54,24 @@ class CommissionerControlClusterCommissioningRequestResultEvent( private const val TAG_STATUS_CODE = 2 private const val TAG_FABRIC_INDEX = 254 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : CommissionerControlClusterCommissioningRequestResultEvent { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): CommissionerControlClusterCommissioningRequestResultEvent { tlvReader.enterStructure(tlvTag) val requestId = tlvReader.getULong(ContextSpecificTag(TAG_REQUEST_ID)) val clientNodeId = tlvReader.getULong(ContextSpecificTag(TAG_CLIENT_NODE_ID)) val statusCode = tlvReader.getUByte(ContextSpecificTag(TAG_STATUS_CODE)) val fabricIndex = tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) - + tlvReader.exitContainer() - return CommissionerControlClusterCommissioningRequestResultEvent(requestId, clientNodeId, statusCode, fabricIndex) + return CommissionerControlClusterCommissioningRequestResultEvent( + requestId, + clientNodeId, + statusCode, + fabricIndex, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DemandResponseLoadControlClusterLoadControlEventStatusChangeEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DemandResponseLoadControlClusterLoadControlEventStatusChangeEvent.kt index 0132fbc3c34698..d5e263249bd4c4 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DemandResponseLoadControlClusterLoadControlEventStatusChangeEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DemandResponseLoadControlClusterLoadControlEventStatusChangeEvent.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.eventstructs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -30,11 +29,26 @@ class DemandResponseLoadControlClusterLoadControlEventStatusChangeEvent( val status: UByte, val criticality: UByte, val control: UShort, - val temperatureControl: Optional?, - val averageLoadControl: Optional?, - val dutyCycleControl: Optional?, - val powerSavingsControl: Optional?, - val heatingSourceControl: Optional? + val temperatureControl: + Optional< + matter.controller.cluster.structs.DemandResponseLoadControlClusterTemperatureControlStruct + >?, + val averageLoadControl: + Optional< + matter.controller.cluster.structs.DemandResponseLoadControlClusterAverageLoadControlStruct + >?, + val dutyCycleControl: + Optional< + matter.controller.cluster.structs.DemandResponseLoadControlClusterDutyCycleControlStruct + >?, + val powerSavingsControl: + Optional< + matter.controller.cluster.structs.DemandResponseLoadControlClusterPowerSavingsControlStruct + >?, + val heatingSourceControl: + Optional< + matter.controller.cluster.structs.DemandResponseLoadControlClusterHeatingSourceControlStruct + >?, ) { override fun toString(): String = buildString { append("DemandResponseLoadControlClusterLoadControlEventStatusChangeEvent {\n") @@ -65,41 +79,41 @@ class DemandResponseLoadControlClusterLoadControlEventStatusChangeEvent( put(ContextSpecificTag(TAG_CONTROL), control) if (temperatureControl != null) { if (temperatureControl.isPresent) { - val opttemperatureControl = temperatureControl.get() - opttemperatureControl.toTlv(ContextSpecificTag(TAG_TEMPERATURE_CONTROL), this) - } + val opttemperatureControl = temperatureControl.get() + opttemperatureControl.toTlv(ContextSpecificTag(TAG_TEMPERATURE_CONTROL), this) + } } else { putNull(ContextSpecificTag(TAG_TEMPERATURE_CONTROL)) } if (averageLoadControl != null) { if (averageLoadControl.isPresent) { - val optaverageLoadControl = averageLoadControl.get() - optaverageLoadControl.toTlv(ContextSpecificTag(TAG_AVERAGE_LOAD_CONTROL), this) - } + val optaverageLoadControl = averageLoadControl.get() + optaverageLoadControl.toTlv(ContextSpecificTag(TAG_AVERAGE_LOAD_CONTROL), this) + } } else { putNull(ContextSpecificTag(TAG_AVERAGE_LOAD_CONTROL)) } if (dutyCycleControl != null) { if (dutyCycleControl.isPresent) { - val optdutyCycleControl = dutyCycleControl.get() - optdutyCycleControl.toTlv(ContextSpecificTag(TAG_DUTY_CYCLE_CONTROL), this) - } + val optdutyCycleControl = dutyCycleControl.get() + optdutyCycleControl.toTlv(ContextSpecificTag(TAG_DUTY_CYCLE_CONTROL), this) + } } else { putNull(ContextSpecificTag(TAG_DUTY_CYCLE_CONTROL)) } if (powerSavingsControl != null) { if (powerSavingsControl.isPresent) { - val optpowerSavingsControl = powerSavingsControl.get() - optpowerSavingsControl.toTlv(ContextSpecificTag(TAG_POWER_SAVINGS_CONTROL), this) - } + val optpowerSavingsControl = powerSavingsControl.get() + optpowerSavingsControl.toTlv(ContextSpecificTag(TAG_POWER_SAVINGS_CONTROL), this) + } } else { putNull(ContextSpecificTag(TAG_POWER_SAVINGS_CONTROL)) } if (heatingSourceControl != null) { if (heatingSourceControl.isPresent) { - val optheatingSourceControl = heatingSourceControl.get() - optheatingSourceControl.toTlv(ContextSpecificTag(TAG_HEATING_SOURCE_CONTROL), this) - } + val optheatingSourceControl = heatingSourceControl.get() + optheatingSourceControl.toTlv(ContextSpecificTag(TAG_HEATING_SOURCE_CONTROL), this) + } } else { putNull(ContextSpecificTag(TAG_HEATING_SOURCE_CONTROL)) } @@ -119,72 +133,112 @@ class DemandResponseLoadControlClusterLoadControlEventStatusChangeEvent( private const val TAG_POWER_SAVINGS_CONTROL = 8 private const val TAG_HEATING_SOURCE_CONTROL = 9 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : DemandResponseLoadControlClusterLoadControlEventStatusChangeEvent { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): DemandResponseLoadControlClusterLoadControlEventStatusChangeEvent { tlvReader.enterStructure(tlvTag) val eventID = tlvReader.getByteArray(ContextSpecificTag(TAG_EVENT_ID)) - val transitionIndex = if (!tlvReader.isNull()) { - tlvReader.getUByte(ContextSpecificTag(TAG_TRANSITION_INDEX)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_TRANSITION_INDEX)) - null - } + val transitionIndex = + if (!tlvReader.isNull()) { + tlvReader.getUByte(ContextSpecificTag(TAG_TRANSITION_INDEX)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_TRANSITION_INDEX)) + null + } val status = tlvReader.getUByte(ContextSpecificTag(TAG_STATUS)) val criticality = tlvReader.getUByte(ContextSpecificTag(TAG_CRITICALITY)) val control = tlvReader.getUShort(ContextSpecificTag(TAG_CONTROL)) - val temperatureControl = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_TEMPERATURE_CONTROL))) { - Optional.of(matter.controller.cluster.structs.DemandResponseLoadControlClusterTemperatureControlStruct.fromTlv(ContextSpecificTag(TAG_TEMPERATURE_CONTROL), tlvReader)) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_TEMPERATURE_CONTROL)) - null - } - val averageLoadControl = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_AVERAGE_LOAD_CONTROL))) { - Optional.of(matter.controller.cluster.structs.DemandResponseLoadControlClusterAverageLoadControlStruct.fromTlv(ContextSpecificTag(TAG_AVERAGE_LOAD_CONTROL), tlvReader)) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_AVERAGE_LOAD_CONTROL)) - null - } - val dutyCycleControl = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_DUTY_CYCLE_CONTROL))) { - Optional.of(matter.controller.cluster.structs.DemandResponseLoadControlClusterDutyCycleControlStruct.fromTlv(ContextSpecificTag(TAG_DUTY_CYCLE_CONTROL), tlvReader)) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_DUTY_CYCLE_CONTROL)) - null - } - val powerSavingsControl = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_POWER_SAVINGS_CONTROL))) { - Optional.of(matter.controller.cluster.structs.DemandResponseLoadControlClusterPowerSavingsControlStruct.fromTlv(ContextSpecificTag(TAG_POWER_SAVINGS_CONTROL), tlvReader)) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_POWER_SAVINGS_CONTROL)) - null - } - val heatingSourceControl = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_HEATING_SOURCE_CONTROL))) { - Optional.of(matter.controller.cluster.structs.DemandResponseLoadControlClusterHeatingSourceControlStruct.fromTlv(ContextSpecificTag(TAG_HEATING_SOURCE_CONTROL), tlvReader)) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_HEATING_SOURCE_CONTROL)) - null - } - + val temperatureControl = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_TEMPERATURE_CONTROL))) { + Optional.of( + matter.controller.cluster.structs + .DemandResponseLoadControlClusterTemperatureControlStruct + .fromTlv(ContextSpecificTag(TAG_TEMPERATURE_CONTROL), tlvReader) + ) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_TEMPERATURE_CONTROL)) + null + } + val averageLoadControl = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_AVERAGE_LOAD_CONTROL))) { + Optional.of( + matter.controller.cluster.structs + .DemandResponseLoadControlClusterAverageLoadControlStruct + .fromTlv(ContextSpecificTag(TAG_AVERAGE_LOAD_CONTROL), tlvReader) + ) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_AVERAGE_LOAD_CONTROL)) + null + } + val dutyCycleControl = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_DUTY_CYCLE_CONTROL))) { + Optional.of( + matter.controller.cluster.structs + .DemandResponseLoadControlClusterDutyCycleControlStruct + .fromTlv(ContextSpecificTag(TAG_DUTY_CYCLE_CONTROL), tlvReader) + ) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_DUTY_CYCLE_CONTROL)) + null + } + val powerSavingsControl = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_POWER_SAVINGS_CONTROL))) { + Optional.of( + matter.controller.cluster.structs + .DemandResponseLoadControlClusterPowerSavingsControlStruct + .fromTlv(ContextSpecificTag(TAG_POWER_SAVINGS_CONTROL), tlvReader) + ) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_POWER_SAVINGS_CONTROL)) + null + } + val heatingSourceControl = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_HEATING_SOURCE_CONTROL))) { + Optional.of( + matter.controller.cluster.structs + .DemandResponseLoadControlClusterHeatingSourceControlStruct + .fromTlv(ContextSpecificTag(TAG_HEATING_SOURCE_CONTROL), tlvReader) + ) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_HEATING_SOURCE_CONTROL)) + null + } + tlvReader.exitContainer() - return DemandResponseLoadControlClusterLoadControlEventStatusChangeEvent(eventID, transitionIndex, status, criticality, control, temperatureControl, averageLoadControl, dutyCycleControl, powerSavingsControl, heatingSourceControl) + return DemandResponseLoadControlClusterLoadControlEventStatusChangeEvent( + eventID, + transitionIndex, + status, + criticality, + control, + temperatureControl, + averageLoadControl, + dutyCycleControl, + powerSavingsControl, + heatingSourceControl, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DeviceEnergyManagementClusterPowerAdjustEndEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DeviceEnergyManagementClusterPowerAdjustEndEvent.kt index e05ca8e86ba704..556666715883df 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DeviceEnergyManagementClusterPowerAdjustEndEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DeviceEnergyManagementClusterPowerAdjustEndEvent.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -27,7 +25,7 @@ import matter.tlv.TlvWriter class DeviceEnergyManagementClusterPowerAdjustEndEvent( val cause: UByte, val duration: UInt, - val energyUse: Long + val energyUse: Long, ) { override fun toString(): String = buildString { append("DeviceEnergyManagementClusterPowerAdjustEndEvent {\n") @@ -52,12 +50,15 @@ class DeviceEnergyManagementClusterPowerAdjustEndEvent( private const val TAG_DURATION = 1 private const val TAG_ENERGY_USE = 2 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : DeviceEnergyManagementClusterPowerAdjustEndEvent { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): DeviceEnergyManagementClusterPowerAdjustEndEvent { tlvReader.enterStructure(tlvTag) val cause = tlvReader.getUByte(ContextSpecificTag(TAG_CAUSE)) val duration = tlvReader.getUInt(ContextSpecificTag(TAG_DURATION)) val energyUse = tlvReader.getLong(ContextSpecificTag(TAG_ENERGY_USE)) - + tlvReader.exitContainer() return DeviceEnergyManagementClusterPowerAdjustEndEvent(cause, duration, energyUse) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DeviceEnergyManagementClusterResumedEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DeviceEnergyManagementClusterResumedEvent.kt index 8d103f74e33de4..db5219f72dba0e 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DeviceEnergyManagementClusterResumedEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DeviceEnergyManagementClusterResumedEvent.kt @@ -16,17 +16,13 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional 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 DeviceEnergyManagementClusterResumedEvent( - val cause: UByte -) { +class DeviceEnergyManagementClusterResumedEvent(val cause: UByte) { override fun toString(): String = buildString { append("DeviceEnergyManagementClusterResumedEvent {\n") append("\tcause : $cause\n") @@ -44,10 +40,10 @@ class DeviceEnergyManagementClusterResumedEvent( companion object { private const val TAG_CAUSE = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : DeviceEnergyManagementClusterResumedEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): DeviceEnergyManagementClusterResumedEvent { tlvReader.enterStructure(tlvTag) val cause = tlvReader.getUByte(ContextSpecificTag(TAG_CAUSE)) - + tlvReader.exitContainer() return DeviceEnergyManagementClusterResumedEvent(cause) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DishwasherAlarmClusterNotifyEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DishwasherAlarmClusterNotifyEvent.kt index e17f43ed147ae0..a9ad126e50db5d 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DishwasherAlarmClusterNotifyEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DishwasherAlarmClusterNotifyEvent.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -28,7 +26,7 @@ class DishwasherAlarmClusterNotifyEvent( val active: UInt, val inactive: UInt, val state: UInt, - val mask: UInt + val mask: UInt, ) { override fun toString(): String = buildString { append("DishwasherAlarmClusterNotifyEvent {\n") @@ -56,13 +54,13 @@ class DishwasherAlarmClusterNotifyEvent( private const val TAG_STATE = 2 private const val TAG_MASK = 3 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : DishwasherAlarmClusterNotifyEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): DishwasherAlarmClusterNotifyEvent { tlvReader.enterStructure(tlvTag) val active = tlvReader.getUInt(ContextSpecificTag(TAG_ACTIVE)) val inactive = tlvReader.getUInt(ContextSpecificTag(TAG_INACTIVE)) val state = tlvReader.getUInt(ContextSpecificTag(TAG_STATE)) val mask = tlvReader.getUInt(ContextSpecificTag(TAG_MASK)) - + tlvReader.exitContainer() return DishwasherAlarmClusterNotifyEvent(active, inactive, state, mask) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DoorLockClusterDoorLockAlarmEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DoorLockClusterDoorLockAlarmEvent.kt index a04df8246a437e..233130a2371a2e 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DoorLockClusterDoorLockAlarmEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DoorLockClusterDoorLockAlarmEvent.kt @@ -16,17 +16,13 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional 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 DoorLockClusterDoorLockAlarmEvent( - val alarmCode: UByte -) { +class DoorLockClusterDoorLockAlarmEvent(val alarmCode: UByte) { override fun toString(): String = buildString { append("DoorLockClusterDoorLockAlarmEvent {\n") append("\talarmCode : $alarmCode\n") @@ -44,10 +40,10 @@ class DoorLockClusterDoorLockAlarmEvent( companion object { private const val TAG_ALARM_CODE = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : DoorLockClusterDoorLockAlarmEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): DoorLockClusterDoorLockAlarmEvent { tlvReader.enterStructure(tlvTag) val alarmCode = tlvReader.getUByte(ContextSpecificTag(TAG_ALARM_CODE)) - + tlvReader.exitContainer() return DoorLockClusterDoorLockAlarmEvent(alarmCode) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DoorLockClusterDoorStateChangeEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DoorLockClusterDoorStateChangeEvent.kt index c0dd0441ac3010..92d04f6662dffe 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DoorLockClusterDoorStateChangeEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DoorLockClusterDoorStateChangeEvent.kt @@ -16,17 +16,13 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional 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 DoorLockClusterDoorStateChangeEvent( - val doorState: UByte -) { +class DoorLockClusterDoorStateChangeEvent(val doorState: UByte) { override fun toString(): String = buildString { append("DoorLockClusterDoorStateChangeEvent {\n") append("\tdoorState : $doorState\n") @@ -44,10 +40,10 @@ class DoorLockClusterDoorStateChangeEvent( companion object { private const val TAG_DOOR_STATE = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : DoorLockClusterDoorStateChangeEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): DoorLockClusterDoorStateChangeEvent { tlvReader.enterStructure(tlvTag) val doorState = tlvReader.getUByte(ContextSpecificTag(TAG_DOOR_STATE)) - + tlvReader.exitContainer() return DoorLockClusterDoorStateChangeEvent(doorState) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DoorLockClusterLockOperationErrorEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DoorLockClusterLockOperationErrorEvent.kt index af031bad313f8f..4208a2059d32d2 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DoorLockClusterLockOperationErrorEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DoorLockClusterLockOperationErrorEvent.kt @@ -31,7 +31,8 @@ class DoorLockClusterLockOperationErrorEvent( val userIndex: UShort?, val fabricIndex: UByte?, val sourceNode: ULong?, - val credentials: Optional>? + val credentials: + Optional>?, ) { override fun toString(): String = buildString { append("DoorLockClusterLockOperationErrorEvent {\n") @@ -68,13 +69,13 @@ class DoorLockClusterLockOperationErrorEvent( } if (credentials != null) { if (credentials.isPresent) { - val optcredentials = credentials.get() - startArray(ContextSpecificTag(TAG_CREDENTIALS)) - for (item in optcredentials.iterator()) { - item.toTlv(AnonymousTag, this) - } - endArray() - } + val optcredentials = credentials.get() + startArray(ContextSpecificTag(TAG_CREDENTIALS)) + for (item in optcredentials.iterator()) { + item.toTlv(AnonymousTag, this) + } + endArray() + } } else { putNull(ContextSpecificTag(TAG_CREDENTIALS)) } @@ -91,49 +92,68 @@ class DoorLockClusterLockOperationErrorEvent( private const val TAG_SOURCE_NODE = 5 private const val TAG_CREDENTIALS = 6 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : DoorLockClusterLockOperationErrorEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): DoorLockClusterLockOperationErrorEvent { tlvReader.enterStructure(tlvTag) val lockOperationType = tlvReader.getUByte(ContextSpecificTag(TAG_LOCK_OPERATION_TYPE)) val operationSource = tlvReader.getUByte(ContextSpecificTag(TAG_OPERATION_SOURCE)) val operationError = tlvReader.getUByte(ContextSpecificTag(TAG_OPERATION_ERROR)) - val userIndex = if (!tlvReader.isNull()) { - tlvReader.getUShort(ContextSpecificTag(TAG_USER_INDEX)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_USER_INDEX)) - null - } - val fabricIndex = if (!tlvReader.isNull()) { - tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_FABRIC_INDEX)) - null - } - val sourceNode = if (!tlvReader.isNull()) { - tlvReader.getULong(ContextSpecificTag(TAG_SOURCE_NODE)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_SOURCE_NODE)) - null - } - val credentials = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_CREDENTIALS))) { - Optional.of(buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_CREDENTIALS)) - while(!tlvReader.isEndOfContainer()) { - this.add(matter.controller.cluster.structs.DoorLockClusterCredentialStruct.fromTlv(AnonymousTag, tlvReader)) + val userIndex = + if (!tlvReader.isNull()) { + tlvReader.getUShort(ContextSpecificTag(TAG_USER_INDEX)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_USER_INDEX)) + null } - tlvReader.exitContainer() - }) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_CREDENTIALS)) - null - } - + val fabricIndex = + if (!tlvReader.isNull()) { + tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_FABRIC_INDEX)) + null + } + val sourceNode = + if (!tlvReader.isNull()) { + tlvReader.getULong(ContextSpecificTag(TAG_SOURCE_NODE)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_SOURCE_NODE)) + null + } + val credentials = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_CREDENTIALS))) { + Optional.of( + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_CREDENTIALS)) + while (!tlvReader.isEndOfContainer()) { + this.add( + matter.controller.cluster.structs.DoorLockClusterCredentialStruct.fromTlv( + AnonymousTag, + tlvReader, + ) + ) + } + tlvReader.exitContainer() + } + ) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_CREDENTIALS)) + null + } + tlvReader.exitContainer() - return DoorLockClusterLockOperationErrorEvent(lockOperationType, operationSource, operationError, userIndex, fabricIndex, sourceNode, credentials) + return DoorLockClusterLockOperationErrorEvent( + lockOperationType, + operationSource, + operationError, + userIndex, + fabricIndex, + sourceNode, + credentials, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DoorLockClusterLockOperationEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DoorLockClusterLockOperationEvent.kt index d47734e612adc8..c5cf52060b6dff 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DoorLockClusterLockOperationEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DoorLockClusterLockOperationEvent.kt @@ -30,7 +30,8 @@ class DoorLockClusterLockOperationEvent( val userIndex: UShort?, val fabricIndex: UByte?, val sourceNode: ULong?, - val credentials: Optional>? + val credentials: + Optional>?, ) { override fun toString(): String = buildString { append("DoorLockClusterLockOperationEvent {\n") @@ -65,13 +66,13 @@ class DoorLockClusterLockOperationEvent( } if (credentials != null) { if (credentials.isPresent) { - val optcredentials = credentials.get() - startArray(ContextSpecificTag(TAG_CREDENTIALS)) - for (item in optcredentials.iterator()) { - item.toTlv(AnonymousTag, this) - } - endArray() - } + val optcredentials = credentials.get() + startArray(ContextSpecificTag(TAG_CREDENTIALS)) + for (item in optcredentials.iterator()) { + item.toTlv(AnonymousTag, this) + } + endArray() + } } else { putNull(ContextSpecificTag(TAG_CREDENTIALS)) } @@ -87,48 +88,66 @@ class DoorLockClusterLockOperationEvent( private const val TAG_SOURCE_NODE = 4 private const val TAG_CREDENTIALS = 5 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : DoorLockClusterLockOperationEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): DoorLockClusterLockOperationEvent { tlvReader.enterStructure(tlvTag) val lockOperationType = tlvReader.getUByte(ContextSpecificTag(TAG_LOCK_OPERATION_TYPE)) val operationSource = tlvReader.getUByte(ContextSpecificTag(TAG_OPERATION_SOURCE)) - val userIndex = if (!tlvReader.isNull()) { - tlvReader.getUShort(ContextSpecificTag(TAG_USER_INDEX)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_USER_INDEX)) - null - } - val fabricIndex = if (!tlvReader.isNull()) { - tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_FABRIC_INDEX)) - null - } - val sourceNode = if (!tlvReader.isNull()) { - tlvReader.getULong(ContextSpecificTag(TAG_SOURCE_NODE)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_SOURCE_NODE)) - null - } - val credentials = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_CREDENTIALS))) { - Optional.of(buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_CREDENTIALS)) - while(!tlvReader.isEndOfContainer()) { - this.add(matter.controller.cluster.structs.DoorLockClusterCredentialStruct.fromTlv(AnonymousTag, tlvReader)) + val userIndex = + if (!tlvReader.isNull()) { + tlvReader.getUShort(ContextSpecificTag(TAG_USER_INDEX)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_USER_INDEX)) + null } - tlvReader.exitContainer() - }) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_CREDENTIALS)) - null - } - + val fabricIndex = + if (!tlvReader.isNull()) { + tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_FABRIC_INDEX)) + null + } + val sourceNode = + if (!tlvReader.isNull()) { + tlvReader.getULong(ContextSpecificTag(TAG_SOURCE_NODE)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_SOURCE_NODE)) + null + } + val credentials = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_CREDENTIALS))) { + Optional.of( + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_CREDENTIALS)) + while (!tlvReader.isEndOfContainer()) { + this.add( + matter.controller.cluster.structs.DoorLockClusterCredentialStruct.fromTlv( + AnonymousTag, + tlvReader, + ) + ) + } + tlvReader.exitContainer() + } + ) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_CREDENTIALS)) + null + } + tlvReader.exitContainer() - return DoorLockClusterLockOperationEvent(lockOperationType, operationSource, userIndex, fabricIndex, sourceNode, credentials) + return DoorLockClusterLockOperationEvent( + lockOperationType, + operationSource, + userIndex, + fabricIndex, + sourceNode, + credentials, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DoorLockClusterLockUserChangeEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DoorLockClusterLockUserChangeEvent.kt index bb39257e80cd71..cd0ab80f8a2b92 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DoorLockClusterLockUserChangeEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/DoorLockClusterLockUserChangeEvent.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -31,7 +29,7 @@ class DoorLockClusterLockUserChangeEvent( val userIndex: UShort?, val fabricIndex: UByte?, val sourceNode: ULong?, - val dataIndex: UShort? + val dataIndex: UShort?, ) { override fun toString(): String = buildString { append("DoorLockClusterLockUserChangeEvent {\n") @@ -84,39 +82,51 @@ class DoorLockClusterLockUserChangeEvent( private const val TAG_SOURCE_NODE = 5 private const val TAG_DATA_INDEX = 6 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : DoorLockClusterLockUserChangeEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): DoorLockClusterLockUserChangeEvent { tlvReader.enterStructure(tlvTag) val lockDataType = tlvReader.getUByte(ContextSpecificTag(TAG_LOCK_DATA_TYPE)) val dataOperationType = tlvReader.getUByte(ContextSpecificTag(TAG_DATA_OPERATION_TYPE)) val operationSource = tlvReader.getUByte(ContextSpecificTag(TAG_OPERATION_SOURCE)) - val userIndex = if (!tlvReader.isNull()) { - tlvReader.getUShort(ContextSpecificTag(TAG_USER_INDEX)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_USER_INDEX)) - null - } - val fabricIndex = if (!tlvReader.isNull()) { - tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_FABRIC_INDEX)) - null - } - val sourceNode = if (!tlvReader.isNull()) { - tlvReader.getULong(ContextSpecificTag(TAG_SOURCE_NODE)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_SOURCE_NODE)) - null - } - val dataIndex = if (!tlvReader.isNull()) { - tlvReader.getUShort(ContextSpecificTag(TAG_DATA_INDEX)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_DATA_INDEX)) - null - } - + val userIndex = + if (!tlvReader.isNull()) { + tlvReader.getUShort(ContextSpecificTag(TAG_USER_INDEX)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_USER_INDEX)) + null + } + val fabricIndex = + if (!tlvReader.isNull()) { + tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_FABRIC_INDEX)) + null + } + val sourceNode = + if (!tlvReader.isNull()) { + tlvReader.getULong(ContextSpecificTag(TAG_SOURCE_NODE)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_SOURCE_NODE)) + null + } + val dataIndex = + if (!tlvReader.isNull()) { + tlvReader.getUShort(ContextSpecificTag(TAG_DATA_INDEX)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_DATA_INDEX)) + null + } + tlvReader.exitContainer() - return DoorLockClusterLockUserChangeEvent(lockDataType, dataOperationType, operationSource, userIndex, fabricIndex, sourceNode, dataIndex) + return DoorLockClusterLockUserChangeEvent( + lockDataType, + dataOperationType, + operationSource, + userIndex, + fabricIndex, + sourceNode, + dataIndex, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ElectricalEnergyMeasurementClusterCumulativeEnergyMeasuredEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ElectricalEnergyMeasurementClusterCumulativeEnergyMeasuredEvent.kt index 8fecbdd04a6da1..bf30d118921aa6 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ElectricalEnergyMeasurementClusterCumulativeEnergyMeasuredEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ElectricalEnergyMeasurementClusterCumulativeEnergyMeasuredEvent.kt @@ -18,15 +18,20 @@ package matter.controller.cluster.eventstructs import java.util.Optional 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 ElectricalEnergyMeasurementClusterCumulativeEnergyMeasuredEvent( - val energyImported: Optional, - val energyExported: Optional + val energyImported: + Optional< + matter.controller.cluster.structs.ElectricalEnergyMeasurementClusterEnergyMeasurementStruct + >, + val energyExported: + Optional< + matter.controller.cluster.structs.ElectricalEnergyMeasurementClusterEnergyMeasurementStruct + >, ) { override fun toString(): String = buildString { append("ElectricalEnergyMeasurementClusterCumulativeEnergyMeasuredEvent {\n") @@ -54,22 +59,38 @@ class ElectricalEnergyMeasurementClusterCumulativeEnergyMeasuredEvent( private const val TAG_ENERGY_IMPORTED = 0 private const val TAG_ENERGY_EXPORTED = 1 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : ElectricalEnergyMeasurementClusterCumulativeEnergyMeasuredEvent { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): ElectricalEnergyMeasurementClusterCumulativeEnergyMeasuredEvent { tlvReader.enterStructure(tlvTag) - val energyImported = if (tlvReader.isNextTag(ContextSpecificTag(TAG_ENERGY_IMPORTED))) { - Optional.of(matter.controller.cluster.structs.ElectricalEnergyMeasurementClusterEnergyMeasurementStruct.fromTlv(ContextSpecificTag(TAG_ENERGY_IMPORTED), tlvReader)) - } else { - Optional.empty() - } - val energyExported = if (tlvReader.isNextTag(ContextSpecificTag(TAG_ENERGY_EXPORTED))) { - Optional.of(matter.controller.cluster.structs.ElectricalEnergyMeasurementClusterEnergyMeasurementStruct.fromTlv(ContextSpecificTag(TAG_ENERGY_EXPORTED), tlvReader)) - } else { - Optional.empty() - } - + val energyImported = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_ENERGY_IMPORTED))) { + Optional.of( + matter.controller.cluster.structs + .ElectricalEnergyMeasurementClusterEnergyMeasurementStruct + .fromTlv(ContextSpecificTag(TAG_ENERGY_IMPORTED), tlvReader) + ) + } else { + Optional.empty() + } + val energyExported = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_ENERGY_EXPORTED))) { + Optional.of( + matter.controller.cluster.structs + .ElectricalEnergyMeasurementClusterEnergyMeasurementStruct + .fromTlv(ContextSpecificTag(TAG_ENERGY_EXPORTED), tlvReader) + ) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return ElectricalEnergyMeasurementClusterCumulativeEnergyMeasuredEvent(energyImported, energyExported) + return ElectricalEnergyMeasurementClusterCumulativeEnergyMeasuredEvent( + energyImported, + energyExported, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ElectricalEnergyMeasurementClusterPeriodicEnergyMeasuredEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ElectricalEnergyMeasurementClusterPeriodicEnergyMeasuredEvent.kt index 65f3e9e1dc1ba1..0654435bfd6fb9 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ElectricalEnergyMeasurementClusterPeriodicEnergyMeasuredEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ElectricalEnergyMeasurementClusterPeriodicEnergyMeasuredEvent.kt @@ -18,15 +18,20 @@ package matter.controller.cluster.eventstructs import java.util.Optional 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 ElectricalEnergyMeasurementClusterPeriodicEnergyMeasuredEvent( - val energyImported: Optional, - val energyExported: Optional + val energyImported: + Optional< + matter.controller.cluster.structs.ElectricalEnergyMeasurementClusterEnergyMeasurementStruct + >, + val energyExported: + Optional< + matter.controller.cluster.structs.ElectricalEnergyMeasurementClusterEnergyMeasurementStruct + >, ) { override fun toString(): String = buildString { append("ElectricalEnergyMeasurementClusterPeriodicEnergyMeasuredEvent {\n") @@ -54,22 +59,38 @@ class ElectricalEnergyMeasurementClusterPeriodicEnergyMeasuredEvent( private const val TAG_ENERGY_IMPORTED = 0 private const val TAG_ENERGY_EXPORTED = 1 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : ElectricalEnergyMeasurementClusterPeriodicEnergyMeasuredEvent { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): ElectricalEnergyMeasurementClusterPeriodicEnergyMeasuredEvent { tlvReader.enterStructure(tlvTag) - val energyImported = if (tlvReader.isNextTag(ContextSpecificTag(TAG_ENERGY_IMPORTED))) { - Optional.of(matter.controller.cluster.structs.ElectricalEnergyMeasurementClusterEnergyMeasurementStruct.fromTlv(ContextSpecificTag(TAG_ENERGY_IMPORTED), tlvReader)) - } else { - Optional.empty() - } - val energyExported = if (tlvReader.isNextTag(ContextSpecificTag(TAG_ENERGY_EXPORTED))) { - Optional.of(matter.controller.cluster.structs.ElectricalEnergyMeasurementClusterEnergyMeasurementStruct.fromTlv(ContextSpecificTag(TAG_ENERGY_EXPORTED), tlvReader)) - } else { - Optional.empty() - } - + val energyImported = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_ENERGY_IMPORTED))) { + Optional.of( + matter.controller.cluster.structs + .ElectricalEnergyMeasurementClusterEnergyMeasurementStruct + .fromTlv(ContextSpecificTag(TAG_ENERGY_IMPORTED), tlvReader) + ) + } else { + Optional.empty() + } + val energyExported = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_ENERGY_EXPORTED))) { + Optional.of( + matter.controller.cluster.structs + .ElectricalEnergyMeasurementClusterEnergyMeasurementStruct + .fromTlv(ContextSpecificTag(TAG_ENERGY_EXPORTED), tlvReader) + ) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return ElectricalEnergyMeasurementClusterPeriodicEnergyMeasuredEvent(energyImported, energyExported) + return ElectricalEnergyMeasurementClusterPeriodicEnergyMeasuredEvent( + energyImported, + energyExported, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ElectricalPowerMeasurementClusterMeasurementPeriodRangesEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ElectricalPowerMeasurementClusterMeasurementPeriodRangesEvent.kt index 78baf664f250c1..6688cc9a769ef5 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ElectricalPowerMeasurementClusterMeasurementPeriodRangesEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ElectricalPowerMeasurementClusterMeasurementPeriodRangesEvent.kt @@ -16,7 +16,6 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -25,7 +24,8 @@ import matter.tlv.TlvReader import matter.tlv.TlvWriter class ElectricalPowerMeasurementClusterMeasurementPeriodRangesEvent( - val ranges: List + val ranges: + List ) { override fun toString(): String = buildString { append("ElectricalPowerMeasurementClusterMeasurementPeriodRangesEvent {\n") @@ -48,16 +48,26 @@ class ElectricalPowerMeasurementClusterMeasurementPeriodRangesEvent( companion object { private const val TAG_RANGES = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : ElectricalPowerMeasurementClusterMeasurementPeriodRangesEvent { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): ElectricalPowerMeasurementClusterMeasurementPeriodRangesEvent { tlvReader.enterStructure(tlvTag) - val ranges = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_RANGES)) - while(!tlvReader.isEndOfContainer()) { - this.add(matter.controller.cluster.structs.ElectricalPowerMeasurementClusterMeasurementRangeStruct.fromTlv(AnonymousTag, tlvReader)) + val ranges = + buildList< + matter.controller.cluster.structs.ElectricalPowerMeasurementClusterMeasurementRangeStruct + > { + tlvReader.enterArray(ContextSpecificTag(TAG_RANGES)) + while (!tlvReader.isEndOfContainer()) { + this.add( + matter.controller.cluster.structs + .ElectricalPowerMeasurementClusterMeasurementRangeStruct + .fromTlv(AnonymousTag, tlvReader) + ) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - + tlvReader.exitContainer() return ElectricalPowerMeasurementClusterMeasurementPeriodRangesEvent(ranges) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/EnergyEvseClusterEVConnectedEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/EnergyEvseClusterEVConnectedEvent.kt index 28180727bc065e..672690fcdac70f 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/EnergyEvseClusterEVConnectedEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/EnergyEvseClusterEVConnectedEvent.kt @@ -16,17 +16,13 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional 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 EnergyEvseClusterEVConnectedEvent( - val sessionID: UInt -) { +class EnergyEvseClusterEVConnectedEvent(val sessionID: UInt) { override fun toString(): String = buildString { append("EnergyEvseClusterEVConnectedEvent {\n") append("\tsessionID : $sessionID\n") @@ -44,10 +40,10 @@ class EnergyEvseClusterEVConnectedEvent( companion object { private const val TAG_SESSION_ID = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : EnergyEvseClusterEVConnectedEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): EnergyEvseClusterEVConnectedEvent { tlvReader.enterStructure(tlvTag) val sessionID = tlvReader.getUInt(ContextSpecificTag(TAG_SESSION_ID)) - + tlvReader.exitContainer() return EnergyEvseClusterEVConnectedEvent(sessionID) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/EnergyEvseClusterEVNotDetectedEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/EnergyEvseClusterEVNotDetectedEvent.kt index 17358072f4cf41..7f033f40a6c888 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/EnergyEvseClusterEVNotDetectedEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/EnergyEvseClusterEVNotDetectedEvent.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.eventstructs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -29,7 +28,7 @@ class EnergyEvseClusterEVNotDetectedEvent( val state: UByte, val sessionDuration: UInt, val sessionEnergyCharged: Long, - val sessionEnergyDischarged: Optional + val sessionEnergyDischarged: Optional, ) { override fun toString(): String = buildString { append("EnergyEvseClusterEVNotDetectedEvent {\n") @@ -63,21 +62,28 @@ class EnergyEvseClusterEVNotDetectedEvent( private const val TAG_SESSION_ENERGY_CHARGED = 3 private const val TAG_SESSION_ENERGY_DISCHARGED = 4 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : EnergyEvseClusterEVNotDetectedEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): EnergyEvseClusterEVNotDetectedEvent { tlvReader.enterStructure(tlvTag) val sessionID = tlvReader.getUInt(ContextSpecificTag(TAG_SESSION_ID)) val state = tlvReader.getUByte(ContextSpecificTag(TAG_STATE)) val sessionDuration = tlvReader.getUInt(ContextSpecificTag(TAG_SESSION_DURATION)) val sessionEnergyCharged = tlvReader.getLong(ContextSpecificTag(TAG_SESSION_ENERGY_CHARGED)) - val sessionEnergyDischarged = if (tlvReader.isNextTag(ContextSpecificTag(TAG_SESSION_ENERGY_DISCHARGED))) { - Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_SESSION_ENERGY_DISCHARGED))) - } else { - Optional.empty() - } - + val sessionEnergyDischarged = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_SESSION_ENERGY_DISCHARGED))) { + Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_SESSION_ENERGY_DISCHARGED))) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return EnergyEvseClusterEVNotDetectedEvent(sessionID, state, sessionDuration, sessionEnergyCharged, sessionEnergyDischarged) + return EnergyEvseClusterEVNotDetectedEvent( + sessionID, + state, + sessionDuration, + sessionEnergyCharged, + sessionEnergyDischarged, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/EnergyEvseClusterEnergyTransferStartedEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/EnergyEvseClusterEnergyTransferStartedEvent.kt index f6131547f3fdf8..d6ca275c22f47a 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/EnergyEvseClusterEnergyTransferStartedEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/EnergyEvseClusterEnergyTransferStartedEvent.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.eventstructs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -28,7 +27,7 @@ class EnergyEvseClusterEnergyTransferStartedEvent( val sessionID: UInt, val state: UByte, val maximumCurrent: Long, - val maximumDischargeCurrent: Optional + val maximumDischargeCurrent: Optional, ) { override fun toString(): String = buildString { append("EnergyEvseClusterEnergyTransferStartedEvent {\n") @@ -59,20 +58,26 @@ class EnergyEvseClusterEnergyTransferStartedEvent( private const val TAG_MAXIMUM_CURRENT = 2 private const val TAG_MAXIMUM_DISCHARGE_CURRENT = 3 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : EnergyEvseClusterEnergyTransferStartedEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): EnergyEvseClusterEnergyTransferStartedEvent { tlvReader.enterStructure(tlvTag) val sessionID = tlvReader.getUInt(ContextSpecificTag(TAG_SESSION_ID)) val state = tlvReader.getUByte(ContextSpecificTag(TAG_STATE)) val maximumCurrent = tlvReader.getLong(ContextSpecificTag(TAG_MAXIMUM_CURRENT)) - val maximumDischargeCurrent = if (tlvReader.isNextTag(ContextSpecificTag(TAG_MAXIMUM_DISCHARGE_CURRENT))) { - Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_MAXIMUM_DISCHARGE_CURRENT))) - } else { - Optional.empty() - } - + val maximumDischargeCurrent = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_MAXIMUM_DISCHARGE_CURRENT))) { + Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_MAXIMUM_DISCHARGE_CURRENT))) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return EnergyEvseClusterEnergyTransferStartedEvent(sessionID, state, maximumCurrent, maximumDischargeCurrent) + return EnergyEvseClusterEnergyTransferStartedEvent( + sessionID, + state, + maximumCurrent, + maximumDischargeCurrent, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/EnergyEvseClusterEnergyTransferStoppedEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/EnergyEvseClusterEnergyTransferStoppedEvent.kt index 1eec2bb9109e86..1dea5f56e6e64d 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/EnergyEvseClusterEnergyTransferStoppedEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/EnergyEvseClusterEnergyTransferStoppedEvent.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.eventstructs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -29,7 +28,7 @@ class EnergyEvseClusterEnergyTransferStoppedEvent( val state: UByte, val reason: UByte, val energyTransferred: Long, - val energyDischarged: Optional + val energyDischarged: Optional, ) { override fun toString(): String = buildString { append("EnergyEvseClusterEnergyTransferStoppedEvent {\n") @@ -63,21 +62,28 @@ class EnergyEvseClusterEnergyTransferStoppedEvent( private const val TAG_ENERGY_TRANSFERRED = 4 private const val TAG_ENERGY_DISCHARGED = 5 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : EnergyEvseClusterEnergyTransferStoppedEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): EnergyEvseClusterEnergyTransferStoppedEvent { tlvReader.enterStructure(tlvTag) val sessionID = tlvReader.getUInt(ContextSpecificTag(TAG_SESSION_ID)) val state = tlvReader.getUByte(ContextSpecificTag(TAG_STATE)) val reason = tlvReader.getUByte(ContextSpecificTag(TAG_REASON)) val energyTransferred = tlvReader.getLong(ContextSpecificTag(TAG_ENERGY_TRANSFERRED)) - val energyDischarged = if (tlvReader.isNextTag(ContextSpecificTag(TAG_ENERGY_DISCHARGED))) { - Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_ENERGY_DISCHARGED))) - } else { - Optional.empty() - } - + val energyDischarged = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_ENERGY_DISCHARGED))) { + Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_ENERGY_DISCHARGED))) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return EnergyEvseClusterEnergyTransferStoppedEvent(sessionID, state, reason, energyTransferred, energyDischarged) + return EnergyEvseClusterEnergyTransferStoppedEvent( + sessionID, + state, + reason, + energyTransferred, + energyDischarged, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/EnergyEvseClusterFaultEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/EnergyEvseClusterFaultEvent.kt index 08842a5b4616a3..02800fa6ed6733 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/EnergyEvseClusterFaultEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/EnergyEvseClusterFaultEvent.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -28,7 +26,7 @@ class EnergyEvseClusterFaultEvent( val sessionID: UInt?, val state: UByte, val faultStatePreviousState: UByte, - val faultStateCurrentState: UByte + val faultStateCurrentState: UByte, ) { override fun toString(): String = buildString { append("EnergyEvseClusterFaultEvent {\n") @@ -60,21 +58,29 @@ class EnergyEvseClusterFaultEvent( private const val TAG_FAULT_STATE_PREVIOUS_STATE = 2 private const val TAG_FAULT_STATE_CURRENT_STATE = 4 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : EnergyEvseClusterFaultEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): EnergyEvseClusterFaultEvent { tlvReader.enterStructure(tlvTag) - val sessionID = if (!tlvReader.isNull()) { - tlvReader.getUInt(ContextSpecificTag(TAG_SESSION_ID)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_SESSION_ID)) - null - } + val sessionID = + if (!tlvReader.isNull()) { + tlvReader.getUInt(ContextSpecificTag(TAG_SESSION_ID)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_SESSION_ID)) + null + } val state = tlvReader.getUByte(ContextSpecificTag(TAG_STATE)) - val faultStatePreviousState = tlvReader.getUByte(ContextSpecificTag(TAG_FAULT_STATE_PREVIOUS_STATE)) - val faultStateCurrentState = tlvReader.getUByte(ContextSpecificTag(TAG_FAULT_STATE_CURRENT_STATE)) - + val faultStatePreviousState = + tlvReader.getUByte(ContextSpecificTag(TAG_FAULT_STATE_PREVIOUS_STATE)) + val faultStateCurrentState = + tlvReader.getUByte(ContextSpecificTag(TAG_FAULT_STATE_CURRENT_STATE)) + tlvReader.exitContainer() - return EnergyEvseClusterFaultEvent(sessionID, state, faultStatePreviousState, faultStateCurrentState) + return EnergyEvseClusterFaultEvent( + sessionID, + state, + faultStatePreviousState, + faultStateCurrentState, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/EnergyEvseClusterRFIDEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/EnergyEvseClusterRFIDEvent.kt index 6db4c1a10ed59f..cf0fe503e13bd8 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/EnergyEvseClusterRFIDEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/EnergyEvseClusterRFIDEvent.kt @@ -16,17 +16,13 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional 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 EnergyEvseClusterRFIDEvent( - val uid: ByteArray -) { +class EnergyEvseClusterRFIDEvent(val uid: ByteArray) { override fun toString(): String = buildString { append("EnergyEvseClusterRFIDEvent {\n") append("\tuid : $uid\n") @@ -44,10 +40,10 @@ class EnergyEvseClusterRFIDEvent( companion object { private const val TAG_UID = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : EnergyEvseClusterRFIDEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): EnergyEvseClusterRFIDEvent { tlvReader.enterStructure(tlvTag) val uid = tlvReader.getByteArray(ContextSpecificTag(TAG_UID)) - + tlvReader.exitContainer() return EnergyEvseClusterRFIDEvent(uid) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/GeneralDiagnosticsClusterBootReasonEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/GeneralDiagnosticsClusterBootReasonEvent.kt index 5d6ee591cdf22d..8d13675dece145 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/GeneralDiagnosticsClusterBootReasonEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/GeneralDiagnosticsClusterBootReasonEvent.kt @@ -16,17 +16,13 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional 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 GeneralDiagnosticsClusterBootReasonEvent( - val bootReason: UByte -) { +class GeneralDiagnosticsClusterBootReasonEvent(val bootReason: UByte) { override fun toString(): String = buildString { append("GeneralDiagnosticsClusterBootReasonEvent {\n") append("\tbootReason : $bootReason\n") @@ -44,10 +40,10 @@ class GeneralDiagnosticsClusterBootReasonEvent( companion object { private const val TAG_BOOT_REASON = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : GeneralDiagnosticsClusterBootReasonEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): GeneralDiagnosticsClusterBootReasonEvent { tlvReader.enterStructure(tlvTag) val bootReason = tlvReader.getUByte(ContextSpecificTag(TAG_BOOT_REASON)) - + tlvReader.exitContainer() return GeneralDiagnosticsClusterBootReasonEvent(bootReason) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/GeneralDiagnosticsClusterHardwareFaultChangeEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/GeneralDiagnosticsClusterHardwareFaultChangeEvent.kt index 415b83a66b74ba..0f97ac10d53617 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/GeneralDiagnosticsClusterHardwareFaultChangeEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/GeneralDiagnosticsClusterHardwareFaultChangeEvent.kt @@ -16,7 +16,6 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -26,7 +25,7 @@ import matter.tlv.TlvWriter class GeneralDiagnosticsClusterHardwareFaultChangeEvent( val current: List, - val previous: List + val previous: List, ) { override fun toString(): String = buildString { append("GeneralDiagnosticsClusterHardwareFaultChangeEvent {\n") @@ -56,23 +55,28 @@ class GeneralDiagnosticsClusterHardwareFaultChangeEvent( private const val TAG_CURRENT = 0 private const val TAG_PREVIOUS = 1 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : GeneralDiagnosticsClusterHardwareFaultChangeEvent { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): GeneralDiagnosticsClusterHardwareFaultChangeEvent { tlvReader.enterStructure(tlvTag) - val current = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_CURRENT)) - while(!tlvReader.isEndOfContainer()) { - this.add(tlvReader.getUByte(AnonymousTag)) + val current = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_CURRENT)) + while (!tlvReader.isEndOfContainer()) { + this.add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - val previous = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_PREVIOUS)) - while(!tlvReader.isEndOfContainer()) { - this.add(tlvReader.getUByte(AnonymousTag)) + val previous = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_PREVIOUS)) + while (!tlvReader.isEndOfContainer()) { + this.add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - + tlvReader.exitContainer() return GeneralDiagnosticsClusterHardwareFaultChangeEvent(current, previous) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/GeneralDiagnosticsClusterNetworkFaultChangeEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/GeneralDiagnosticsClusterNetworkFaultChangeEvent.kt index e5ae628b6edfc1..c20ffadb2b321f 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/GeneralDiagnosticsClusterNetworkFaultChangeEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/GeneralDiagnosticsClusterNetworkFaultChangeEvent.kt @@ -16,7 +16,6 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -26,7 +25,7 @@ import matter.tlv.TlvWriter class GeneralDiagnosticsClusterNetworkFaultChangeEvent( val current: List, - val previous: List + val previous: List, ) { override fun toString(): String = buildString { append("GeneralDiagnosticsClusterNetworkFaultChangeEvent {\n") @@ -56,23 +55,28 @@ class GeneralDiagnosticsClusterNetworkFaultChangeEvent( private const val TAG_CURRENT = 0 private const val TAG_PREVIOUS = 1 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : GeneralDiagnosticsClusterNetworkFaultChangeEvent { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): GeneralDiagnosticsClusterNetworkFaultChangeEvent { tlvReader.enterStructure(tlvTag) - val current = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_CURRENT)) - while(!tlvReader.isEndOfContainer()) { - this.add(tlvReader.getUByte(AnonymousTag)) + val current = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_CURRENT)) + while (!tlvReader.isEndOfContainer()) { + this.add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - val previous = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_PREVIOUS)) - while(!tlvReader.isEndOfContainer()) { - this.add(tlvReader.getUByte(AnonymousTag)) + val previous = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_PREVIOUS)) + while (!tlvReader.isEndOfContainer()) { + this.add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - + tlvReader.exitContainer() return GeneralDiagnosticsClusterNetworkFaultChangeEvent(current, previous) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/GeneralDiagnosticsClusterRadioFaultChangeEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/GeneralDiagnosticsClusterRadioFaultChangeEvent.kt index 9ebbfae718bb68..eaa89f70e7c8c6 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/GeneralDiagnosticsClusterRadioFaultChangeEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/GeneralDiagnosticsClusterRadioFaultChangeEvent.kt @@ -16,7 +16,6 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -26,7 +25,7 @@ import matter.tlv.TlvWriter class GeneralDiagnosticsClusterRadioFaultChangeEvent( val current: List, - val previous: List + val previous: List, ) { override fun toString(): String = buildString { append("GeneralDiagnosticsClusterRadioFaultChangeEvent {\n") @@ -56,23 +55,25 @@ class GeneralDiagnosticsClusterRadioFaultChangeEvent( private const val TAG_CURRENT = 0 private const val TAG_PREVIOUS = 1 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : GeneralDiagnosticsClusterRadioFaultChangeEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): GeneralDiagnosticsClusterRadioFaultChangeEvent { tlvReader.enterStructure(tlvTag) - val current = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_CURRENT)) - while(!tlvReader.isEndOfContainer()) { - this.add(tlvReader.getUByte(AnonymousTag)) + val current = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_CURRENT)) + while (!tlvReader.isEndOfContainer()) { + this.add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - val previous = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_PREVIOUS)) - while(!tlvReader.isEndOfContainer()) { - this.add(tlvReader.getUByte(AnonymousTag)) + val previous = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_PREVIOUS)) + while (!tlvReader.isEndOfContainer()) { + this.add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - + tlvReader.exitContainer() return GeneralDiagnosticsClusterRadioFaultChangeEvent(current, previous) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/MediaPlaybackClusterStateChangedEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/MediaPlaybackClusterStateChangedEvent.kt index d7b7eb6f0d01d5..58b861020c85b3 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/MediaPlaybackClusterStateChangedEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/MediaPlaybackClusterStateChangedEvent.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.eventstructs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -33,7 +32,7 @@ class MediaPlaybackClusterStateChangedEvent( val seekRangeEnd: ULong, val seekRangeStart: ULong, val data: Optional, - val audioAdvanceUnmuted: Boolean + val audioAdvanceUnmuted: Boolean, ) { override fun toString(): String = buildString { append("MediaPlaybackClusterStateChangedEvent {\n") @@ -79,25 +78,40 @@ class MediaPlaybackClusterStateChangedEvent( private const val TAG_DATA = 7 private const val TAG_AUDIO_ADVANCE_UNMUTED = 8 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : MediaPlaybackClusterStateChangedEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): MediaPlaybackClusterStateChangedEvent { tlvReader.enterStructure(tlvTag) val currentState = tlvReader.getUByte(ContextSpecificTag(TAG_CURRENT_STATE)) val startTime = tlvReader.getULong(ContextSpecificTag(TAG_START_TIME)) val duration = tlvReader.getULong(ContextSpecificTag(TAG_DURATION)) - val sampledPosition = matter.controller.cluster.structs.MediaPlaybackClusterPlaybackPositionStruct.fromTlv(ContextSpecificTag(TAG_SAMPLED_POSITION), tlvReader) + val sampledPosition = + matter.controller.cluster.structs.MediaPlaybackClusterPlaybackPositionStruct.fromTlv( + ContextSpecificTag(TAG_SAMPLED_POSITION), + tlvReader, + ) val playbackSpeed = tlvReader.getFloat(ContextSpecificTag(TAG_PLAYBACK_SPEED)) val seekRangeEnd = tlvReader.getULong(ContextSpecificTag(TAG_SEEK_RANGE_END)) val seekRangeStart = tlvReader.getULong(ContextSpecificTag(TAG_SEEK_RANGE_START)) - val data = if (tlvReader.isNextTag(ContextSpecificTag(TAG_DATA))) { - Optional.of(tlvReader.getByteArray(ContextSpecificTag(TAG_DATA))) - } else { - Optional.empty() - } + val data = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_DATA))) { + Optional.of(tlvReader.getByteArray(ContextSpecificTag(TAG_DATA))) + } else { + Optional.empty() + } val audioAdvanceUnmuted = tlvReader.getBoolean(ContextSpecificTag(TAG_AUDIO_ADVANCE_UNMUTED)) - + tlvReader.exitContainer() - return MediaPlaybackClusterStateChangedEvent(currentState, startTime, duration, sampledPosition, playbackSpeed, seekRangeEnd, seekRangeStart, data, audioAdvanceUnmuted) + return MediaPlaybackClusterStateChangedEvent( + currentState, + startTime, + duration, + sampledPosition, + playbackSpeed, + seekRangeEnd, + seekRangeStart, + data, + audioAdvanceUnmuted, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/MessagesClusterMessageCompleteEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/MessagesClusterMessageCompleteEvent.kt index 1349a714e327c3..9255c6a84b3e93 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/MessagesClusterMessageCompleteEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/MessagesClusterMessageCompleteEvent.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.eventstructs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -28,7 +27,7 @@ class MessagesClusterMessageCompleteEvent( val messageID: ByteArray, val responseID: Optional?, val reply: Optional?, - val futureMessagesPreference: UByte? + val futureMessagesPreference: UByte?, ) { override fun toString(): String = buildString { append("MessagesClusterMessageCompleteEvent {\n") @@ -45,17 +44,17 @@ class MessagesClusterMessageCompleteEvent( put(ContextSpecificTag(TAG_MESSAGE_ID), messageID) if (responseID != null) { if (responseID.isPresent) { - val optresponseID = responseID.get() - put(ContextSpecificTag(TAG_RESPONSE_ID), optresponseID) - } + val optresponseID = responseID.get() + put(ContextSpecificTag(TAG_RESPONSE_ID), optresponseID) + } } else { putNull(ContextSpecificTag(TAG_RESPONSE_ID)) } if (reply != null) { if (reply.isPresent) { - val optreply = reply.get() - put(ContextSpecificTag(TAG_REPLY), optreply) - } + val optreply = reply.get() + put(ContextSpecificTag(TAG_REPLY), optreply) + } } else { putNull(ContextSpecificTag(TAG_REPLY)) } @@ -74,39 +73,47 @@ class MessagesClusterMessageCompleteEvent( private const val TAG_REPLY = 2 private const val TAG_FUTURE_MESSAGES_PREFERENCE = 3 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : MessagesClusterMessageCompleteEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): MessagesClusterMessageCompleteEvent { tlvReader.enterStructure(tlvTag) val messageID = tlvReader.getByteArray(ContextSpecificTag(TAG_MESSAGE_ID)) - val responseID = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_RESPONSE_ID))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_RESPONSE_ID))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_RESPONSE_ID)) - null - } - val reply = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_REPLY))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_REPLY))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_REPLY)) - null - } - val futureMessagesPreference = if (!tlvReader.isNull()) { - tlvReader.getUByte(ContextSpecificTag(TAG_FUTURE_MESSAGES_PREFERENCE)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_FUTURE_MESSAGES_PREFERENCE)) - null - } - + val responseID = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_RESPONSE_ID))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_RESPONSE_ID))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_RESPONSE_ID)) + null + } + val reply = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_REPLY))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_REPLY))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_REPLY)) + null + } + val futureMessagesPreference = + if (!tlvReader.isNull()) { + tlvReader.getUByte(ContextSpecificTag(TAG_FUTURE_MESSAGES_PREFERENCE)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_FUTURE_MESSAGES_PREFERENCE)) + null + } + tlvReader.exitContainer() - return MessagesClusterMessageCompleteEvent(messageID, responseID, reply, futureMessagesPreference) + return MessagesClusterMessageCompleteEvent( + messageID, + responseID, + reply, + futureMessagesPreference, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/MessagesClusterMessagePresentedEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/MessagesClusterMessagePresentedEvent.kt index 9526fcd47f5fc4..eb92978ebc2d27 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/MessagesClusterMessagePresentedEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/MessagesClusterMessagePresentedEvent.kt @@ -16,17 +16,13 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional 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 MessagesClusterMessagePresentedEvent( - val messageID: ByteArray -) { +class MessagesClusterMessagePresentedEvent(val messageID: ByteArray) { override fun toString(): String = buildString { append("MessagesClusterMessagePresentedEvent {\n") append("\tmessageID : $messageID\n") @@ -44,10 +40,10 @@ class MessagesClusterMessagePresentedEvent( companion object { private const val TAG_MESSAGE_ID = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : MessagesClusterMessagePresentedEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): MessagesClusterMessagePresentedEvent { tlvReader.enterStructure(tlvTag) val messageID = tlvReader.getByteArray(ContextSpecificTag(TAG_MESSAGE_ID)) - + tlvReader.exitContainer() return MessagesClusterMessagePresentedEvent(messageID) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/MessagesClusterMessageQueuedEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/MessagesClusterMessageQueuedEvent.kt index b7481a30e837c7..5f0e2b0b3c46fe 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/MessagesClusterMessageQueuedEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/MessagesClusterMessageQueuedEvent.kt @@ -16,17 +16,13 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional 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 MessagesClusterMessageQueuedEvent( - val messageID: ByteArray -) { +class MessagesClusterMessageQueuedEvent(val messageID: ByteArray) { override fun toString(): String = buildString { append("MessagesClusterMessageQueuedEvent {\n") append("\tmessageID : $messageID\n") @@ -44,10 +40,10 @@ class MessagesClusterMessageQueuedEvent( companion object { private const val TAG_MESSAGE_ID = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : MessagesClusterMessageQueuedEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): MessagesClusterMessageQueuedEvent { tlvReader.enterStructure(tlvTag) val messageID = tlvReader.getByteArray(ContextSpecificTag(TAG_MESSAGE_ID)) - + tlvReader.exitContainer() return MessagesClusterMessageQueuedEvent(messageID) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OperationalStateClusterOperationCompletionEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OperationalStateClusterOperationCompletionEvent.kt index e5a17a96700fca..b056da59644a7f 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OperationalStateClusterOperationCompletionEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OperationalStateClusterOperationCompletionEvent.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.eventstructs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -27,7 +26,7 @@ import matter.tlv.TlvWriter class OperationalStateClusterOperationCompletionEvent( val completionErrorCode: UByte, val totalOperationalTime: Optional?, - val pausedTime: Optional? + val pausedTime: Optional?, ) { override fun toString(): String = buildString { append("OperationalStateClusterOperationCompletionEvent {\n") @@ -43,17 +42,17 @@ class OperationalStateClusterOperationCompletionEvent( put(ContextSpecificTag(TAG_COMPLETION_ERROR_CODE), completionErrorCode) if (totalOperationalTime != null) { if (totalOperationalTime.isPresent) { - val opttotalOperationalTime = totalOperationalTime.get() - put(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME), opttotalOperationalTime) - } + val opttotalOperationalTime = totalOperationalTime.get() + put(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME), opttotalOperationalTime) + } } else { putNull(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME)) } if (pausedTime != null) { if (pausedTime.isPresent) { - val optpausedTime = pausedTime.get() - put(ContextSpecificTag(TAG_PAUSED_TIME), optpausedTime) - } + val optpausedTime = pausedTime.get() + put(ContextSpecificTag(TAG_PAUSED_TIME), optpausedTime) + } } else { putNull(ContextSpecificTag(TAG_PAUSED_TIME)) } @@ -66,33 +65,42 @@ class OperationalStateClusterOperationCompletionEvent( private const val TAG_TOTAL_OPERATIONAL_TIME = 1 private const val TAG_PAUSED_TIME = 2 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : OperationalStateClusterOperationCompletionEvent { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): OperationalStateClusterOperationCompletionEvent { tlvReader.enterStructure(tlvTag) val completionErrorCode = tlvReader.getUByte(ContextSpecificTag(TAG_COMPLETION_ERROR_CODE)) - val totalOperationalTime = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME)) - null - } - val pausedTime = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_PAUSED_TIME))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_PAUSED_TIME))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_PAUSED_TIME)) - null - } - + val totalOperationalTime = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME)) + null + } + val pausedTime = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_PAUSED_TIME))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_PAUSED_TIME))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_PAUSED_TIME)) + null + } + tlvReader.exitContainer() - return OperationalStateClusterOperationCompletionEvent(completionErrorCode, totalOperationalTime, pausedTime) + return OperationalStateClusterOperationCompletionEvent( + completionErrorCode, + totalOperationalTime, + pausedTime, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OperationalStateClusterOperationalErrorEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OperationalStateClusterOperationalErrorEvent.kt index 10bd2f4144b114..b2101fbfd5c5d9 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OperationalStateClusterOperationalErrorEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OperationalStateClusterOperationalErrorEvent.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -44,10 +42,14 @@ class OperationalStateClusterOperationalErrorEvent( companion object { private const val TAG_ERROR_STATE = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : OperationalStateClusterOperationalErrorEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): OperationalStateClusterOperationalErrorEvent { tlvReader.enterStructure(tlvTag) - val errorState = matter.controller.cluster.structs.OperationalStateClusterErrorStateStruct.fromTlv(ContextSpecificTag(TAG_ERROR_STATE), tlvReader) - + val errorState = + matter.controller.cluster.structs.OperationalStateClusterErrorStateStruct.fromTlv( + ContextSpecificTag(TAG_ERROR_STATE), + tlvReader, + ) + tlvReader.exitContainer() return OperationalStateClusterOperationalErrorEvent(errorState) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OtaSoftwareUpdateRequestorClusterDownloadErrorEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OtaSoftwareUpdateRequestorClusterDownloadErrorEvent.kt index 3cdebe626405a4..a336ae37ddff83 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OtaSoftwareUpdateRequestorClusterDownloadErrorEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OtaSoftwareUpdateRequestorClusterDownloadErrorEvent.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -28,7 +26,7 @@ class OtaSoftwareUpdateRequestorClusterDownloadErrorEvent( val softwareVersion: UInt, val bytesDownloaded: ULong, val progressPercent: UByte?, - val platformCode: Long? + val platformCode: Long?, ) { override fun toString(): String = buildString { append("OtaSoftwareUpdateRequestorClusterDownloadErrorEvent {\n") @@ -64,26 +62,36 @@ class OtaSoftwareUpdateRequestorClusterDownloadErrorEvent( private const val TAG_PROGRESS_PERCENT = 2 private const val TAG_PLATFORM_CODE = 3 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : OtaSoftwareUpdateRequestorClusterDownloadErrorEvent { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): OtaSoftwareUpdateRequestorClusterDownloadErrorEvent { tlvReader.enterStructure(tlvTag) val softwareVersion = tlvReader.getUInt(ContextSpecificTag(TAG_SOFTWARE_VERSION)) val bytesDownloaded = tlvReader.getULong(ContextSpecificTag(TAG_BYTES_DOWNLOADED)) - val progressPercent = if (!tlvReader.isNull()) { - tlvReader.getUByte(ContextSpecificTag(TAG_PROGRESS_PERCENT)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_PROGRESS_PERCENT)) - null - } - val platformCode = if (!tlvReader.isNull()) { - tlvReader.getLong(ContextSpecificTag(TAG_PLATFORM_CODE)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_PLATFORM_CODE)) - null - } - + val progressPercent = + if (!tlvReader.isNull()) { + tlvReader.getUByte(ContextSpecificTag(TAG_PROGRESS_PERCENT)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_PROGRESS_PERCENT)) + null + } + val platformCode = + if (!tlvReader.isNull()) { + tlvReader.getLong(ContextSpecificTag(TAG_PLATFORM_CODE)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_PLATFORM_CODE)) + null + } + tlvReader.exitContainer() - return OtaSoftwareUpdateRequestorClusterDownloadErrorEvent(softwareVersion, bytesDownloaded, progressPercent, platformCode) + return OtaSoftwareUpdateRequestorClusterDownloadErrorEvent( + softwareVersion, + bytesDownloaded, + progressPercent, + platformCode, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OtaSoftwareUpdateRequestorClusterStateTransitionEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OtaSoftwareUpdateRequestorClusterStateTransitionEvent.kt index cacab69022c9c7..5c94d6a9e91ded 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OtaSoftwareUpdateRequestorClusterStateTransitionEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OtaSoftwareUpdateRequestorClusterStateTransitionEvent.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -28,7 +26,7 @@ class OtaSoftwareUpdateRequestorClusterStateTransitionEvent( val previousState: UByte, val newState: UByte, val reason: UByte, - val targetSoftwareVersion: UInt? + val targetSoftwareVersion: UInt?, ) { override fun toString(): String = buildString { append("OtaSoftwareUpdateRequestorClusterStateTransitionEvent {\n") @@ -60,21 +58,30 @@ class OtaSoftwareUpdateRequestorClusterStateTransitionEvent( private const val TAG_REASON = 2 private const val TAG_TARGET_SOFTWARE_VERSION = 3 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : OtaSoftwareUpdateRequestorClusterStateTransitionEvent { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): OtaSoftwareUpdateRequestorClusterStateTransitionEvent { tlvReader.enterStructure(tlvTag) val previousState = tlvReader.getUByte(ContextSpecificTag(TAG_PREVIOUS_STATE)) val newState = tlvReader.getUByte(ContextSpecificTag(TAG_NEW_STATE)) val reason = tlvReader.getUByte(ContextSpecificTag(TAG_REASON)) - val targetSoftwareVersion = if (!tlvReader.isNull()) { - tlvReader.getUInt(ContextSpecificTag(TAG_TARGET_SOFTWARE_VERSION)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_TARGET_SOFTWARE_VERSION)) - null - } - + val targetSoftwareVersion = + if (!tlvReader.isNull()) { + tlvReader.getUInt(ContextSpecificTag(TAG_TARGET_SOFTWARE_VERSION)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_TARGET_SOFTWARE_VERSION)) + null + } + tlvReader.exitContainer() - return OtaSoftwareUpdateRequestorClusterStateTransitionEvent(previousState, newState, reason, targetSoftwareVersion) + return OtaSoftwareUpdateRequestorClusterStateTransitionEvent( + previousState, + newState, + reason, + targetSoftwareVersion, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OtaSoftwareUpdateRequestorClusterVersionAppliedEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OtaSoftwareUpdateRequestorClusterVersionAppliedEvent.kt index b4cca73ec9cca2..bc361f53a5b2a3 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OtaSoftwareUpdateRequestorClusterVersionAppliedEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OtaSoftwareUpdateRequestorClusterVersionAppliedEvent.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +24,7 @@ import matter.tlv.TlvWriter class OtaSoftwareUpdateRequestorClusterVersionAppliedEvent( val softwareVersion: UInt, - val productID: UShort + val productID: UShort, ) { override fun toString(): String = buildString { append("OtaSoftwareUpdateRequestorClusterVersionAppliedEvent {\n") @@ -48,11 +46,14 @@ class OtaSoftwareUpdateRequestorClusterVersionAppliedEvent( private const val TAG_SOFTWARE_VERSION = 0 private const val TAG_PRODUCT_ID = 1 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : OtaSoftwareUpdateRequestorClusterVersionAppliedEvent { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): OtaSoftwareUpdateRequestorClusterVersionAppliedEvent { tlvReader.enterStructure(tlvTag) val softwareVersion = tlvReader.getUInt(ContextSpecificTag(TAG_SOFTWARE_VERSION)) val productID = tlvReader.getUShort(ContextSpecificTag(TAG_PRODUCT_ID)) - + tlvReader.exitContainer() return OtaSoftwareUpdateRequestorClusterVersionAppliedEvent(softwareVersion, productID) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OvenCavityOperationalStateClusterOperationCompletionEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OvenCavityOperationalStateClusterOperationCompletionEvent.kt index c2f767d8be59a5..bceab29e1e313d 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OvenCavityOperationalStateClusterOperationCompletionEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OvenCavityOperationalStateClusterOperationCompletionEvent.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.eventstructs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -27,7 +26,7 @@ import matter.tlv.TlvWriter class OvenCavityOperationalStateClusterOperationCompletionEvent( val completionErrorCode: UByte, val totalOperationalTime: Optional?, - val pausedTime: Optional? + val pausedTime: Optional?, ) { override fun toString(): String = buildString { append("OvenCavityOperationalStateClusterOperationCompletionEvent {\n") @@ -43,17 +42,17 @@ class OvenCavityOperationalStateClusterOperationCompletionEvent( put(ContextSpecificTag(TAG_COMPLETION_ERROR_CODE), completionErrorCode) if (totalOperationalTime != null) { if (totalOperationalTime.isPresent) { - val opttotalOperationalTime = totalOperationalTime.get() - put(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME), opttotalOperationalTime) - } + val opttotalOperationalTime = totalOperationalTime.get() + put(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME), opttotalOperationalTime) + } } else { putNull(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME)) } if (pausedTime != null) { if (pausedTime.isPresent) { - val optpausedTime = pausedTime.get() - put(ContextSpecificTag(TAG_PAUSED_TIME), optpausedTime) - } + val optpausedTime = pausedTime.get() + put(ContextSpecificTag(TAG_PAUSED_TIME), optpausedTime) + } } else { putNull(ContextSpecificTag(TAG_PAUSED_TIME)) } @@ -66,33 +65,42 @@ class OvenCavityOperationalStateClusterOperationCompletionEvent( private const val TAG_TOTAL_OPERATIONAL_TIME = 1 private const val TAG_PAUSED_TIME = 2 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : OvenCavityOperationalStateClusterOperationCompletionEvent { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): OvenCavityOperationalStateClusterOperationCompletionEvent { tlvReader.enterStructure(tlvTag) val completionErrorCode = tlvReader.getUByte(ContextSpecificTag(TAG_COMPLETION_ERROR_CODE)) - val totalOperationalTime = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME)) - null - } - val pausedTime = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_PAUSED_TIME))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_PAUSED_TIME))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_PAUSED_TIME)) - null - } - + val totalOperationalTime = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME)) + null + } + val pausedTime = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_PAUSED_TIME))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_PAUSED_TIME))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_PAUSED_TIME)) + null + } + tlvReader.exitContainer() - return OvenCavityOperationalStateClusterOperationCompletionEvent(completionErrorCode, totalOperationalTime, pausedTime) + return OvenCavityOperationalStateClusterOperationCompletionEvent( + completionErrorCode, + totalOperationalTime, + pausedTime, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OvenCavityOperationalStateClusterOperationalErrorEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OvenCavityOperationalStateClusterOperationalErrorEvent.kt index ee5fe0b442932f..32cbc2f431b862 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OvenCavityOperationalStateClusterOperationalErrorEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OvenCavityOperationalStateClusterOperationalErrorEvent.kt @@ -16,16 +16,15 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional 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 OvenCavityOperationalStateClusterOperationalErrorEvent( - val errorState: matter.controller.cluster.structs.OvenCavityOperationalStateClusterErrorStateStruct + val errorState: + matter.controller.cluster.structs.OvenCavityOperationalStateClusterErrorStateStruct ) { override fun toString(): String = buildString { append("OvenCavityOperationalStateClusterOperationalErrorEvent {\n") @@ -44,10 +43,17 @@ class OvenCavityOperationalStateClusterOperationalErrorEvent( companion object { private const val TAG_ERROR_STATE = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : OvenCavityOperationalStateClusterOperationalErrorEvent { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): OvenCavityOperationalStateClusterOperationalErrorEvent { tlvReader.enterStructure(tlvTag) - val errorState = matter.controller.cluster.structs.OvenCavityOperationalStateClusterErrorStateStruct.fromTlv(ContextSpecificTag(TAG_ERROR_STATE), tlvReader) - + val errorState = + matter.controller.cluster.structs.OvenCavityOperationalStateClusterErrorStateStruct.fromTlv( + ContextSpecificTag(TAG_ERROR_STATE), + tlvReader, + ) + tlvReader.exitContainer() return OvenCavityOperationalStateClusterOperationalErrorEvent(errorState) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/PowerSourceClusterBatChargeFaultChangeEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/PowerSourceClusterBatChargeFaultChangeEvent.kt index 6669a84bd6ec2e..2290f97774eb1b 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/PowerSourceClusterBatChargeFaultChangeEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/PowerSourceClusterBatChargeFaultChangeEvent.kt @@ -16,7 +16,6 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -26,7 +25,7 @@ import matter.tlv.TlvWriter class PowerSourceClusterBatChargeFaultChangeEvent( val current: List, - val previous: List + val previous: List, ) { override fun toString(): String = buildString { append("PowerSourceClusterBatChargeFaultChangeEvent {\n") @@ -56,23 +55,25 @@ class PowerSourceClusterBatChargeFaultChangeEvent( private const val TAG_CURRENT = 0 private const val TAG_PREVIOUS = 1 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : PowerSourceClusterBatChargeFaultChangeEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): PowerSourceClusterBatChargeFaultChangeEvent { tlvReader.enterStructure(tlvTag) - val current = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_CURRENT)) - while(!tlvReader.isEndOfContainer()) { - this.add(tlvReader.getUByte(AnonymousTag)) + val current = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_CURRENT)) + while (!tlvReader.isEndOfContainer()) { + this.add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - val previous = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_PREVIOUS)) - while(!tlvReader.isEndOfContainer()) { - this.add(tlvReader.getUByte(AnonymousTag)) + val previous = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_PREVIOUS)) + while (!tlvReader.isEndOfContainer()) { + this.add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - + tlvReader.exitContainer() return PowerSourceClusterBatChargeFaultChangeEvent(current, previous) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/PowerSourceClusterBatFaultChangeEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/PowerSourceClusterBatFaultChangeEvent.kt index 50752bc8ce3d78..7aa1a81b862fd5 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/PowerSourceClusterBatFaultChangeEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/PowerSourceClusterBatFaultChangeEvent.kt @@ -16,7 +16,6 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -24,10 +23,7 @@ import matter.tlv.Tag import matter.tlv.TlvReader import matter.tlv.TlvWriter -class PowerSourceClusterBatFaultChangeEvent( - val current: List, - val previous: List -) { +class PowerSourceClusterBatFaultChangeEvent(val current: List, val previous: List) { override fun toString(): String = buildString { append("PowerSourceClusterBatFaultChangeEvent {\n") append("\tcurrent : $current\n") @@ -56,23 +52,25 @@ class PowerSourceClusterBatFaultChangeEvent( private const val TAG_CURRENT = 0 private const val TAG_PREVIOUS = 1 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : PowerSourceClusterBatFaultChangeEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): PowerSourceClusterBatFaultChangeEvent { tlvReader.enterStructure(tlvTag) - val current = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_CURRENT)) - while(!tlvReader.isEndOfContainer()) { - this.add(tlvReader.getUByte(AnonymousTag)) + val current = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_CURRENT)) + while (!tlvReader.isEndOfContainer()) { + this.add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - val previous = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_PREVIOUS)) - while(!tlvReader.isEndOfContainer()) { - this.add(tlvReader.getUByte(AnonymousTag)) + val previous = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_PREVIOUS)) + while (!tlvReader.isEndOfContainer()) { + this.add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - + tlvReader.exitContainer() return PowerSourceClusterBatFaultChangeEvent(current, previous) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/PowerSourceClusterWiredFaultChangeEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/PowerSourceClusterWiredFaultChangeEvent.kt index 9f125a71de6a58..5dc6444f06cd51 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/PowerSourceClusterWiredFaultChangeEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/PowerSourceClusterWiredFaultChangeEvent.kt @@ -16,7 +16,6 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -24,10 +23,7 @@ import matter.tlv.Tag import matter.tlv.TlvReader import matter.tlv.TlvWriter -class PowerSourceClusterWiredFaultChangeEvent( - val current: List, - val previous: List -) { +class PowerSourceClusterWiredFaultChangeEvent(val current: List, val previous: List) { override fun toString(): String = buildString { append("PowerSourceClusterWiredFaultChangeEvent {\n") append("\tcurrent : $current\n") @@ -56,23 +52,25 @@ class PowerSourceClusterWiredFaultChangeEvent( private const val TAG_CURRENT = 0 private const val TAG_PREVIOUS = 1 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : PowerSourceClusterWiredFaultChangeEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): PowerSourceClusterWiredFaultChangeEvent { tlvReader.enterStructure(tlvTag) - val current = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_CURRENT)) - while(!tlvReader.isEndOfContainer()) { - this.add(tlvReader.getUByte(AnonymousTag)) + val current = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_CURRENT)) + while (!tlvReader.isEndOfContainer()) { + this.add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - val previous = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_PREVIOUS)) - while(!tlvReader.isEndOfContainer()) { - this.add(tlvReader.getUByte(AnonymousTag)) + val previous = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_PREVIOUS)) + while (!tlvReader.isEndOfContainer()) { + this.add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - + tlvReader.exitContainer() return PowerSourceClusterWiredFaultChangeEvent(current, previous) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/RefrigeratorAlarmClusterNotifyEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/RefrigeratorAlarmClusterNotifyEvent.kt index 75df72186f31ce..7d32c11c70554e 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/RefrigeratorAlarmClusterNotifyEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/RefrigeratorAlarmClusterNotifyEvent.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -28,7 +26,7 @@ class RefrigeratorAlarmClusterNotifyEvent( val active: UInt, val inactive: UInt, val state: UInt, - val mask: UInt + val mask: UInt, ) { override fun toString(): String = buildString { append("RefrigeratorAlarmClusterNotifyEvent {\n") @@ -56,13 +54,13 @@ class RefrigeratorAlarmClusterNotifyEvent( private const val TAG_STATE = 2 private const val TAG_MASK = 3 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : RefrigeratorAlarmClusterNotifyEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): RefrigeratorAlarmClusterNotifyEvent { tlvReader.enterStructure(tlvTag) val active = tlvReader.getUInt(ContextSpecificTag(TAG_ACTIVE)) val inactive = tlvReader.getUInt(ContextSpecificTag(TAG_INACTIVE)) val state = tlvReader.getUInt(ContextSpecificTag(TAG_STATE)) val mask = tlvReader.getUInt(ContextSpecificTag(TAG_MASK)) - + tlvReader.exitContainer() return RefrigeratorAlarmClusterNotifyEvent(active, inactive, state, mask) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/RvcOperationalStateClusterOperationCompletionEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/RvcOperationalStateClusterOperationCompletionEvent.kt index 82db20e092df34..4ecfe3b4266ee3 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/RvcOperationalStateClusterOperationCompletionEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/RvcOperationalStateClusterOperationCompletionEvent.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.eventstructs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -27,7 +26,7 @@ import matter.tlv.TlvWriter class RvcOperationalStateClusterOperationCompletionEvent( val completionErrorCode: UByte, val totalOperationalTime: Optional?, - val pausedTime: Optional? + val pausedTime: Optional?, ) { override fun toString(): String = buildString { append("RvcOperationalStateClusterOperationCompletionEvent {\n") @@ -43,17 +42,17 @@ class RvcOperationalStateClusterOperationCompletionEvent( put(ContextSpecificTag(TAG_COMPLETION_ERROR_CODE), completionErrorCode) if (totalOperationalTime != null) { if (totalOperationalTime.isPresent) { - val opttotalOperationalTime = totalOperationalTime.get() - put(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME), opttotalOperationalTime) - } + val opttotalOperationalTime = totalOperationalTime.get() + put(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME), opttotalOperationalTime) + } } else { putNull(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME)) } if (pausedTime != null) { if (pausedTime.isPresent) { - val optpausedTime = pausedTime.get() - put(ContextSpecificTag(TAG_PAUSED_TIME), optpausedTime) - } + val optpausedTime = pausedTime.get() + put(ContextSpecificTag(TAG_PAUSED_TIME), optpausedTime) + } } else { putNull(ContextSpecificTag(TAG_PAUSED_TIME)) } @@ -66,33 +65,42 @@ class RvcOperationalStateClusterOperationCompletionEvent( private const val TAG_TOTAL_OPERATIONAL_TIME = 1 private const val TAG_PAUSED_TIME = 2 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : RvcOperationalStateClusterOperationCompletionEvent { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): RvcOperationalStateClusterOperationCompletionEvent { tlvReader.enterStructure(tlvTag) val completionErrorCode = tlvReader.getUByte(ContextSpecificTag(TAG_COMPLETION_ERROR_CODE)) - val totalOperationalTime = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME)) - null - } - val pausedTime = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_PAUSED_TIME))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_PAUSED_TIME))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_PAUSED_TIME)) - null - } - + val totalOperationalTime = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME)) + null + } + val pausedTime = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_PAUSED_TIME))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_PAUSED_TIME))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_PAUSED_TIME)) + null + } + tlvReader.exitContainer() - return RvcOperationalStateClusterOperationCompletionEvent(completionErrorCode, totalOperationalTime, pausedTime) + return RvcOperationalStateClusterOperationCompletionEvent( + completionErrorCode, + totalOperationalTime, + pausedTime, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/RvcOperationalStateClusterOperationalErrorEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/RvcOperationalStateClusterOperationalErrorEvent.kt index 092b9234e3b44d..ad1c620ea96f4b 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/RvcOperationalStateClusterOperationalErrorEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/RvcOperationalStateClusterOperationalErrorEvent.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -44,10 +42,17 @@ class RvcOperationalStateClusterOperationalErrorEvent( companion object { private const val TAG_ERROR_STATE = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : RvcOperationalStateClusterOperationalErrorEvent { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): RvcOperationalStateClusterOperationalErrorEvent { tlvReader.enterStructure(tlvTag) - val errorState = matter.controller.cluster.structs.RvcOperationalStateClusterErrorStateStruct.fromTlv(ContextSpecificTag(TAG_ERROR_STATE), tlvReader) - + val errorState = + matter.controller.cluster.structs.RvcOperationalStateClusterErrorStateStruct.fromTlv( + ContextSpecificTag(TAG_ERROR_STATE), + tlvReader, + ) + tlvReader.exitContainer() return RvcOperationalStateClusterOperationalErrorEvent(errorState) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SampleMeiClusterPingCountEventEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SampleMeiClusterPingCountEventEvent.kt index e6853817f212a1..5570ba7a3af4a3 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SampleMeiClusterPingCountEventEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SampleMeiClusterPingCountEventEvent.kt @@ -16,18 +16,13 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional 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 SampleMeiClusterPingCountEventEvent( - val count: UInt, - val fabricIndex: UByte -) { +class SampleMeiClusterPingCountEventEvent(val count: UInt, val fabricIndex: UByte) { override fun toString(): String = buildString { append("SampleMeiClusterPingCountEventEvent {\n") append("\tcount : $count\n") @@ -48,11 +43,11 @@ class SampleMeiClusterPingCountEventEvent( private const val TAG_COUNT = 1 private const val TAG_FABRIC_INDEX = 254 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : SampleMeiClusterPingCountEventEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): SampleMeiClusterPingCountEventEvent { tlvReader.enterStructure(tlvTag) val count = tlvReader.getUInt(ContextSpecificTag(TAG_COUNT)) val fabricIndex = tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) - + tlvReader.exitContainer() return SampleMeiClusterPingCountEventEvent(count, fabricIndex) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SmokeCoAlarmClusterCOAlarmEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SmokeCoAlarmClusterCOAlarmEvent.kt index ab23f8de4499fc..52c7a19053aacb 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SmokeCoAlarmClusterCOAlarmEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SmokeCoAlarmClusterCOAlarmEvent.kt @@ -16,17 +16,13 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional 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 SmokeCoAlarmClusterCOAlarmEvent( - val alarmSeverityLevel: UByte -) { +class SmokeCoAlarmClusterCOAlarmEvent(val alarmSeverityLevel: UByte) { override fun toString(): String = buildString { append("SmokeCoAlarmClusterCOAlarmEvent {\n") append("\talarmSeverityLevel : $alarmSeverityLevel\n") @@ -44,10 +40,10 @@ class SmokeCoAlarmClusterCOAlarmEvent( companion object { private const val TAG_ALARM_SEVERITY_LEVEL = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : SmokeCoAlarmClusterCOAlarmEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): SmokeCoAlarmClusterCOAlarmEvent { tlvReader.enterStructure(tlvTag) val alarmSeverityLevel = tlvReader.getUByte(ContextSpecificTag(TAG_ALARM_SEVERITY_LEVEL)) - + tlvReader.exitContainer() return SmokeCoAlarmClusterCOAlarmEvent(alarmSeverityLevel) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SmokeCoAlarmClusterInterconnectCOAlarmEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SmokeCoAlarmClusterInterconnectCOAlarmEvent.kt index 3ccd697a30d045..80c6a860b1ccc0 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SmokeCoAlarmClusterInterconnectCOAlarmEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SmokeCoAlarmClusterInterconnectCOAlarmEvent.kt @@ -16,17 +16,13 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional 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 SmokeCoAlarmClusterInterconnectCOAlarmEvent( - val alarmSeverityLevel: UByte -) { +class SmokeCoAlarmClusterInterconnectCOAlarmEvent(val alarmSeverityLevel: UByte) { override fun toString(): String = buildString { append("SmokeCoAlarmClusterInterconnectCOAlarmEvent {\n") append("\talarmSeverityLevel : $alarmSeverityLevel\n") @@ -44,10 +40,10 @@ class SmokeCoAlarmClusterInterconnectCOAlarmEvent( companion object { private const val TAG_ALARM_SEVERITY_LEVEL = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : SmokeCoAlarmClusterInterconnectCOAlarmEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): SmokeCoAlarmClusterInterconnectCOAlarmEvent { tlvReader.enterStructure(tlvTag) val alarmSeverityLevel = tlvReader.getUByte(ContextSpecificTag(TAG_ALARM_SEVERITY_LEVEL)) - + tlvReader.exitContainer() return SmokeCoAlarmClusterInterconnectCOAlarmEvent(alarmSeverityLevel) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SmokeCoAlarmClusterInterconnectSmokeAlarmEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SmokeCoAlarmClusterInterconnectSmokeAlarmEvent.kt index 3edfa2543f5b3f..2a3f3f2d05c730 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SmokeCoAlarmClusterInterconnectSmokeAlarmEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SmokeCoAlarmClusterInterconnectSmokeAlarmEvent.kt @@ -16,17 +16,13 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional 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 SmokeCoAlarmClusterInterconnectSmokeAlarmEvent( - val alarmSeverityLevel: UByte -) { +class SmokeCoAlarmClusterInterconnectSmokeAlarmEvent(val alarmSeverityLevel: UByte) { override fun toString(): String = buildString { append("SmokeCoAlarmClusterInterconnectSmokeAlarmEvent {\n") append("\talarmSeverityLevel : $alarmSeverityLevel\n") @@ -44,10 +40,10 @@ class SmokeCoAlarmClusterInterconnectSmokeAlarmEvent( companion object { private const val TAG_ALARM_SEVERITY_LEVEL = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : SmokeCoAlarmClusterInterconnectSmokeAlarmEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): SmokeCoAlarmClusterInterconnectSmokeAlarmEvent { tlvReader.enterStructure(tlvTag) val alarmSeverityLevel = tlvReader.getUByte(ContextSpecificTag(TAG_ALARM_SEVERITY_LEVEL)) - + tlvReader.exitContainer() return SmokeCoAlarmClusterInterconnectSmokeAlarmEvent(alarmSeverityLevel) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SmokeCoAlarmClusterLowBatteryEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SmokeCoAlarmClusterLowBatteryEvent.kt index 42579fecbdda42..3930c40935d0ef 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SmokeCoAlarmClusterLowBatteryEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SmokeCoAlarmClusterLowBatteryEvent.kt @@ -16,17 +16,13 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional 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 SmokeCoAlarmClusterLowBatteryEvent( - val alarmSeverityLevel: UByte -) { +class SmokeCoAlarmClusterLowBatteryEvent(val alarmSeverityLevel: UByte) { override fun toString(): String = buildString { append("SmokeCoAlarmClusterLowBatteryEvent {\n") append("\talarmSeverityLevel : $alarmSeverityLevel\n") @@ -44,10 +40,10 @@ class SmokeCoAlarmClusterLowBatteryEvent( companion object { private const val TAG_ALARM_SEVERITY_LEVEL = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : SmokeCoAlarmClusterLowBatteryEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): SmokeCoAlarmClusterLowBatteryEvent { tlvReader.enterStructure(tlvTag) val alarmSeverityLevel = tlvReader.getUByte(ContextSpecificTag(TAG_ALARM_SEVERITY_LEVEL)) - + tlvReader.exitContainer() return SmokeCoAlarmClusterLowBatteryEvent(alarmSeverityLevel) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SmokeCoAlarmClusterSmokeAlarmEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SmokeCoAlarmClusterSmokeAlarmEvent.kt index 25a54c367090c2..934c42da5479a2 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SmokeCoAlarmClusterSmokeAlarmEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SmokeCoAlarmClusterSmokeAlarmEvent.kt @@ -16,17 +16,13 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional 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 SmokeCoAlarmClusterSmokeAlarmEvent( - val alarmSeverityLevel: UByte -) { +class SmokeCoAlarmClusterSmokeAlarmEvent(val alarmSeverityLevel: UByte) { override fun toString(): String = buildString { append("SmokeCoAlarmClusterSmokeAlarmEvent {\n") append("\talarmSeverityLevel : $alarmSeverityLevel\n") @@ -44,10 +40,10 @@ class SmokeCoAlarmClusterSmokeAlarmEvent( companion object { private const val TAG_ALARM_SEVERITY_LEVEL = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : SmokeCoAlarmClusterSmokeAlarmEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): SmokeCoAlarmClusterSmokeAlarmEvent { tlvReader.enterStructure(tlvTag) val alarmSeverityLevel = tlvReader.getUByte(ContextSpecificTag(TAG_ALARM_SEVERITY_LEVEL)) - + tlvReader.exitContainer() return SmokeCoAlarmClusterSmokeAlarmEvent(alarmSeverityLevel) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SoftwareDiagnosticsClusterSoftwareFaultEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SoftwareDiagnosticsClusterSoftwareFaultEvent.kt index 5d78915d64828a..13a984acfd4da5 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SoftwareDiagnosticsClusterSoftwareFaultEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SoftwareDiagnosticsClusterSoftwareFaultEvent.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.eventstructs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -27,7 +26,7 @@ import matter.tlv.TlvWriter class SoftwareDiagnosticsClusterSoftwareFaultEvent( val id: ULong, val name: Optional, - val faultRecording: Optional + val faultRecording: Optional, ) { override fun toString(): String = buildString { append("SoftwareDiagnosticsClusterSoftwareFaultEvent {\n") @@ -58,20 +57,22 @@ class SoftwareDiagnosticsClusterSoftwareFaultEvent( private const val TAG_NAME = 1 private const val TAG_FAULT_RECORDING = 2 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : SoftwareDiagnosticsClusterSoftwareFaultEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): SoftwareDiagnosticsClusterSoftwareFaultEvent { tlvReader.enterStructure(tlvTag) val id = tlvReader.getULong(ContextSpecificTag(TAG_ID)) - val name = if (tlvReader.isNextTag(ContextSpecificTag(TAG_NAME))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_NAME))) - } else { - Optional.empty() - } - val faultRecording = if (tlvReader.isNextTag(ContextSpecificTag(TAG_FAULT_RECORDING))) { - Optional.of(tlvReader.getByteArray(ContextSpecificTag(TAG_FAULT_RECORDING))) - } else { - Optional.empty() - } - + val name = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_NAME))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_NAME))) + } else { + Optional.empty() + } + val faultRecording = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_FAULT_RECORDING))) { + Optional.of(tlvReader.getByteArray(ContextSpecificTag(TAG_FAULT_RECORDING))) + } else { + Optional.empty() + } + tlvReader.exitContainer() return SoftwareDiagnosticsClusterSoftwareFaultEvent(id, name, faultRecording) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterInitialPressEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterInitialPressEvent.kt index eef9c3864807ea..f7a74f79826494 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterInitialPressEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterInitialPressEvent.kt @@ -16,17 +16,13 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional 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 SwitchClusterInitialPressEvent( - val newPosition: UByte -) { +class SwitchClusterInitialPressEvent(val newPosition: UByte) { override fun toString(): String = buildString { append("SwitchClusterInitialPressEvent {\n") append("\tnewPosition : $newPosition\n") @@ -44,10 +40,10 @@ class SwitchClusterInitialPressEvent( companion object { private const val TAG_NEW_POSITION = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : SwitchClusterInitialPressEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): SwitchClusterInitialPressEvent { tlvReader.enterStructure(tlvTag) val newPosition = tlvReader.getUByte(ContextSpecificTag(TAG_NEW_POSITION)) - + tlvReader.exitContainer() return SwitchClusterInitialPressEvent(newPosition) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterLongPressEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterLongPressEvent.kt index 42cd9c501135bc..bacc49c76bbc53 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterLongPressEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterLongPressEvent.kt @@ -16,17 +16,13 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional 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 SwitchClusterLongPressEvent( - val newPosition: UByte -) { +class SwitchClusterLongPressEvent(val newPosition: UByte) { override fun toString(): String = buildString { append("SwitchClusterLongPressEvent {\n") append("\tnewPosition : $newPosition\n") @@ -44,10 +40,10 @@ class SwitchClusterLongPressEvent( companion object { private const val TAG_NEW_POSITION = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : SwitchClusterLongPressEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): SwitchClusterLongPressEvent { tlvReader.enterStructure(tlvTag) val newPosition = tlvReader.getUByte(ContextSpecificTag(TAG_NEW_POSITION)) - + tlvReader.exitContainer() return SwitchClusterLongPressEvent(newPosition) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterLongReleaseEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterLongReleaseEvent.kt index 8de4860fe1f299..cbd0166269542b 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterLongReleaseEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterLongReleaseEvent.kt @@ -16,17 +16,13 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional 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 SwitchClusterLongReleaseEvent( - val previousPosition: UByte -) { +class SwitchClusterLongReleaseEvent(val previousPosition: UByte) { override fun toString(): String = buildString { append("SwitchClusterLongReleaseEvent {\n") append("\tpreviousPosition : $previousPosition\n") @@ -44,10 +40,10 @@ class SwitchClusterLongReleaseEvent( companion object { private const val TAG_PREVIOUS_POSITION = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : SwitchClusterLongReleaseEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): SwitchClusterLongReleaseEvent { tlvReader.enterStructure(tlvTag) val previousPosition = tlvReader.getUByte(ContextSpecificTag(TAG_PREVIOUS_POSITION)) - + tlvReader.exitContainer() return SwitchClusterLongReleaseEvent(previousPosition) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterMultiPressCompleteEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterMultiPressCompleteEvent.kt index 49d9b22f9b45ff..584fa5bf06323b 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterMultiPressCompleteEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterMultiPressCompleteEvent.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +24,7 @@ import matter.tlv.TlvWriter class SwitchClusterMultiPressCompleteEvent( val previousPosition: UByte, - val totalNumberOfPressesCounted: UByte + val totalNumberOfPressesCounted: UByte, ) { override fun toString(): String = buildString { append("SwitchClusterMultiPressCompleteEvent {\n") @@ -48,11 +46,12 @@ class SwitchClusterMultiPressCompleteEvent( private const val TAG_PREVIOUS_POSITION = 0 private const val TAG_TOTAL_NUMBER_OF_PRESSES_COUNTED = 1 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : SwitchClusterMultiPressCompleteEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): SwitchClusterMultiPressCompleteEvent { tlvReader.enterStructure(tlvTag) val previousPosition = tlvReader.getUByte(ContextSpecificTag(TAG_PREVIOUS_POSITION)) - val totalNumberOfPressesCounted = tlvReader.getUByte(ContextSpecificTag(TAG_TOTAL_NUMBER_OF_PRESSES_COUNTED)) - + val totalNumberOfPressesCounted = + tlvReader.getUByte(ContextSpecificTag(TAG_TOTAL_NUMBER_OF_PRESSES_COUNTED)) + tlvReader.exitContainer() return SwitchClusterMultiPressCompleteEvent(previousPosition, totalNumberOfPressesCounted) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterMultiPressOngoingEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterMultiPressOngoingEvent.kt index 104be8f4fb63ee..5b621da3f813a0 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterMultiPressOngoingEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterMultiPressOngoingEvent.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +24,7 @@ import matter.tlv.TlvWriter class SwitchClusterMultiPressOngoingEvent( val newPosition: UByte, - val currentNumberOfPressesCounted: UByte + val currentNumberOfPressesCounted: UByte, ) { override fun toString(): String = buildString { append("SwitchClusterMultiPressOngoingEvent {\n") @@ -48,11 +46,12 @@ class SwitchClusterMultiPressOngoingEvent( private const val TAG_NEW_POSITION = 0 private const val TAG_CURRENT_NUMBER_OF_PRESSES_COUNTED = 1 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : SwitchClusterMultiPressOngoingEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): SwitchClusterMultiPressOngoingEvent { tlvReader.enterStructure(tlvTag) val newPosition = tlvReader.getUByte(ContextSpecificTag(TAG_NEW_POSITION)) - val currentNumberOfPressesCounted = tlvReader.getUByte(ContextSpecificTag(TAG_CURRENT_NUMBER_OF_PRESSES_COUNTED)) - + val currentNumberOfPressesCounted = + tlvReader.getUByte(ContextSpecificTag(TAG_CURRENT_NUMBER_OF_PRESSES_COUNTED)) + tlvReader.exitContainer() return SwitchClusterMultiPressOngoingEvent(newPosition, currentNumberOfPressesCounted) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterShortReleaseEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterShortReleaseEvent.kt index 156c253a485af1..c08c0e63f8b5e1 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterShortReleaseEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterShortReleaseEvent.kt @@ -16,17 +16,13 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional 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 SwitchClusterShortReleaseEvent( - val previousPosition: UByte -) { +class SwitchClusterShortReleaseEvent(val previousPosition: UByte) { override fun toString(): String = buildString { append("SwitchClusterShortReleaseEvent {\n") append("\tpreviousPosition : $previousPosition\n") @@ -44,10 +40,10 @@ class SwitchClusterShortReleaseEvent( companion object { private const val TAG_PREVIOUS_POSITION = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : SwitchClusterShortReleaseEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): SwitchClusterShortReleaseEvent { tlvReader.enterStructure(tlvTag) val previousPosition = tlvReader.getUByte(ContextSpecificTag(TAG_PREVIOUS_POSITION)) - + tlvReader.exitContainer() return SwitchClusterShortReleaseEvent(previousPosition) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterSwitchLatchedEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterSwitchLatchedEvent.kt index f08eaeee96a617..4aae22fb446979 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterSwitchLatchedEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SwitchClusterSwitchLatchedEvent.kt @@ -16,17 +16,13 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional 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 SwitchClusterSwitchLatchedEvent( - val newPosition: UByte -) { +class SwitchClusterSwitchLatchedEvent(val newPosition: UByte) { override fun toString(): String = buildString { append("SwitchClusterSwitchLatchedEvent {\n") append("\tnewPosition : $newPosition\n") @@ -44,10 +40,10 @@ class SwitchClusterSwitchLatchedEvent( companion object { private const val TAG_NEW_POSITION = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : SwitchClusterSwitchLatchedEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): SwitchClusterSwitchLatchedEvent { tlvReader.enterStructure(tlvTag) val newPosition = tlvReader.getUByte(ContextSpecificTag(TAG_NEW_POSITION)) - + tlvReader.exitContainer() return SwitchClusterSwitchLatchedEvent(newPosition) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/TargetNavigatorClusterTargetUpdatedEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/TargetNavigatorClusterTargetUpdatedEvent.kt index 86a03eb5080eba..7e585378937cee 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/TargetNavigatorClusterTargetUpdatedEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/TargetNavigatorClusterTargetUpdatedEvent.kt @@ -16,7 +16,6 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -27,7 +26,7 @@ import matter.tlv.TlvWriter class TargetNavigatorClusterTargetUpdatedEvent( val targetList: List, val currentTarget: UByte, - val data: ByteArray + val data: ByteArray, ) { override fun toString(): String = buildString { append("TargetNavigatorClusterTargetUpdatedEvent {\n") @@ -56,18 +55,24 @@ class TargetNavigatorClusterTargetUpdatedEvent( private const val TAG_CURRENT_TARGET = 1 private const val TAG_DATA = 2 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : TargetNavigatorClusterTargetUpdatedEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): TargetNavigatorClusterTargetUpdatedEvent { tlvReader.enterStructure(tlvTag) - val targetList = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_TARGET_LIST)) - while(!tlvReader.isEndOfContainer()) { - this.add(matter.controller.cluster.structs.TargetNavigatorClusterTargetInfoStruct.fromTlv(AnonymousTag, tlvReader)) + val targetList = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_TARGET_LIST)) + while (!tlvReader.isEndOfContainer()) { + this.add( + matter.controller.cluster.structs.TargetNavigatorClusterTargetInfoStruct.fromTlv( + AnonymousTag, + tlvReader, + ) + ) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } val currentTarget = tlvReader.getUByte(ContextSpecificTag(TAG_CURRENT_TARGET)) val data = tlvReader.getByteArray(ContextSpecificTag(TAG_DATA)) - + tlvReader.exitContainer() return TargetNavigatorClusterTargetUpdatedEvent(targetList, currentTarget, data) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ThreadNetworkDiagnosticsClusterConnectionStatusEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ThreadNetworkDiagnosticsClusterConnectionStatusEvent.kt index 823b3eb003da4a..cc872ec9049acc 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ThreadNetworkDiagnosticsClusterConnectionStatusEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ThreadNetworkDiagnosticsClusterConnectionStatusEvent.kt @@ -16,17 +16,13 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional 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 ThreadNetworkDiagnosticsClusterConnectionStatusEvent( - val connectionStatus: UByte -) { +class ThreadNetworkDiagnosticsClusterConnectionStatusEvent(val connectionStatus: UByte) { override fun toString(): String = buildString { append("ThreadNetworkDiagnosticsClusterConnectionStatusEvent {\n") append("\tconnectionStatus : $connectionStatus\n") @@ -44,10 +40,13 @@ class ThreadNetworkDiagnosticsClusterConnectionStatusEvent( companion object { private const val TAG_CONNECTION_STATUS = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : ThreadNetworkDiagnosticsClusterConnectionStatusEvent { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): ThreadNetworkDiagnosticsClusterConnectionStatusEvent { tlvReader.enterStructure(tlvTag) val connectionStatus = tlvReader.getUByte(ContextSpecificTag(TAG_CONNECTION_STATUS)) - + tlvReader.exitContainer() return ThreadNetworkDiagnosticsClusterConnectionStatusEvent(connectionStatus) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ThreadNetworkDiagnosticsClusterNetworkFaultChangeEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ThreadNetworkDiagnosticsClusterNetworkFaultChangeEvent.kt index 01a5989a931f38..e81f3bedbfc279 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ThreadNetworkDiagnosticsClusterNetworkFaultChangeEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ThreadNetworkDiagnosticsClusterNetworkFaultChangeEvent.kt @@ -16,7 +16,6 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -26,7 +25,7 @@ import matter.tlv.TlvWriter class ThreadNetworkDiagnosticsClusterNetworkFaultChangeEvent( val current: List, - val previous: List + val previous: List, ) { override fun toString(): String = buildString { append("ThreadNetworkDiagnosticsClusterNetworkFaultChangeEvent {\n") @@ -56,23 +55,28 @@ class ThreadNetworkDiagnosticsClusterNetworkFaultChangeEvent( private const val TAG_CURRENT = 0 private const val TAG_PREVIOUS = 1 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : ThreadNetworkDiagnosticsClusterNetworkFaultChangeEvent { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): ThreadNetworkDiagnosticsClusterNetworkFaultChangeEvent { tlvReader.enterStructure(tlvTag) - val current = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_CURRENT)) - while(!tlvReader.isEndOfContainer()) { - this.add(tlvReader.getUByte(AnonymousTag)) + val current = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_CURRENT)) + while (!tlvReader.isEndOfContainer()) { + this.add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - val previous = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_PREVIOUS)) - while(!tlvReader.isEndOfContainer()) { - this.add(tlvReader.getUByte(AnonymousTag)) + val previous = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_PREVIOUS)) + while (!tlvReader.isEndOfContainer()) { + this.add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - + tlvReader.exitContainer() return ThreadNetworkDiagnosticsClusterNetworkFaultChangeEvent(current, previous) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/TimeSynchronizationClusterDSTStatusEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/TimeSynchronizationClusterDSTStatusEvent.kt index 7178725bc96112..53a976552ca1a1 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/TimeSynchronizationClusterDSTStatusEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/TimeSynchronizationClusterDSTStatusEvent.kt @@ -16,17 +16,13 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional 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 TimeSynchronizationClusterDSTStatusEvent( - val DSTOffsetActive: Boolean -) { +class TimeSynchronizationClusterDSTStatusEvent(val DSTOffsetActive: Boolean) { override fun toString(): String = buildString { append("TimeSynchronizationClusterDSTStatusEvent {\n") append("\tDSTOffsetActive : $DSTOffsetActive\n") @@ -44,10 +40,10 @@ class TimeSynchronizationClusterDSTStatusEvent( companion object { private const val TAG_DST_OFFSET_ACTIVE = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : TimeSynchronizationClusterDSTStatusEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): TimeSynchronizationClusterDSTStatusEvent { tlvReader.enterStructure(tlvTag) val DSTOffsetActive = tlvReader.getBoolean(ContextSpecificTag(TAG_DST_OFFSET_ACTIVE)) - + tlvReader.exitContainer() return TimeSynchronizationClusterDSTStatusEvent(DSTOffsetActive) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/TimeSynchronizationClusterTimeZoneStatusEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/TimeSynchronizationClusterTimeZoneStatusEvent.kt index 0a12d142db0443..0ef92440535c0a 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/TimeSynchronizationClusterTimeZoneStatusEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/TimeSynchronizationClusterTimeZoneStatusEvent.kt @@ -18,16 +18,12 @@ package matter.controller.cluster.eventstructs import java.util.Optional 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 TimeSynchronizationClusterTimeZoneStatusEvent( - val offset: Int, - val name: Optional -) { +class TimeSynchronizationClusterTimeZoneStatusEvent(val offset: Int, val name: Optional) { override fun toString(): String = buildString { append("TimeSynchronizationClusterTimeZoneStatusEvent {\n") append("\toffset : $offset\n") @@ -51,15 +47,16 @@ class TimeSynchronizationClusterTimeZoneStatusEvent( private const val TAG_OFFSET = 0 private const val TAG_NAME = 1 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : TimeSynchronizationClusterTimeZoneStatusEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): TimeSynchronizationClusterTimeZoneStatusEvent { tlvReader.enterStructure(tlvTag) val offset = tlvReader.getInt(ContextSpecificTag(TAG_OFFSET)) - val name = if (tlvReader.isNextTag(ContextSpecificTag(TAG_NAME))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_NAME))) - } else { - Optional.empty() - } - + val name = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_NAME))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_NAME))) + } else { + Optional.empty() + } + tlvReader.exitContainer() return TimeSynchronizationClusterTimeZoneStatusEvent(offset, name) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/UnitTestingClusterTestDifferentVendorMeiEventEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/UnitTestingClusterTestDifferentVendorMeiEventEvent.kt index add97526607d6d..f5119e3ee0b406 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/UnitTestingClusterTestDifferentVendorMeiEventEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/UnitTestingClusterTestDifferentVendorMeiEventEvent.kt @@ -16,17 +16,13 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional 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 UnitTestingClusterTestDifferentVendorMeiEventEvent( - val arg1: UByte -) { +class UnitTestingClusterTestDifferentVendorMeiEventEvent(val arg1: UByte) { override fun toString(): String = buildString { append("UnitTestingClusterTestDifferentVendorMeiEventEvent {\n") append("\targ1 : $arg1\n") @@ -44,10 +40,13 @@ class UnitTestingClusterTestDifferentVendorMeiEventEvent( companion object { private const val TAG_ARG1 = 1 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : UnitTestingClusterTestDifferentVendorMeiEventEvent { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): UnitTestingClusterTestDifferentVendorMeiEventEvent { tlvReader.enterStructure(tlvTag) val arg1 = tlvReader.getUByte(ContextSpecificTag(TAG_ARG1)) - + tlvReader.exitContainer() return UnitTestingClusterTestDifferentVendorMeiEventEvent(arg1) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/UnitTestingClusterTestEventEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/UnitTestingClusterTestEventEvent.kt index 2294e08b8377db..3d3fb3827695dc 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/UnitTestingClusterTestEventEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/UnitTestingClusterTestEventEvent.kt @@ -16,7 +16,6 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -30,7 +29,7 @@ class UnitTestingClusterTestEventEvent( val arg3: Boolean, val arg4: matter.controller.cluster.structs.UnitTestingClusterSimpleStruct, val arg5: List, - val arg6: List + val arg6: List, ) { override fun toString(): String = buildString { append("UnitTestingClusterTestEventEvent {\n") @@ -72,27 +71,38 @@ class UnitTestingClusterTestEventEvent( private const val TAG_ARG5 = 5 private const val TAG_ARG6 = 6 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : UnitTestingClusterTestEventEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): UnitTestingClusterTestEventEvent { tlvReader.enterStructure(tlvTag) val arg1 = tlvReader.getUByte(ContextSpecificTag(TAG_ARG1)) val arg2 = tlvReader.getUByte(ContextSpecificTag(TAG_ARG2)) val arg3 = tlvReader.getBoolean(ContextSpecificTag(TAG_ARG3)) - val arg4 = matter.controller.cluster.structs.UnitTestingClusterSimpleStruct.fromTlv(ContextSpecificTag(TAG_ARG4), tlvReader) - val arg5 = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_ARG5)) - while(!tlvReader.isEndOfContainer()) { - this.add(matter.controller.cluster.structs.UnitTestingClusterSimpleStruct.fromTlv(AnonymousTag, tlvReader)) + val arg4 = + matter.controller.cluster.structs.UnitTestingClusterSimpleStruct.fromTlv( + ContextSpecificTag(TAG_ARG4), + tlvReader, + ) + val arg5 = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_ARG5)) + while (!tlvReader.isEndOfContainer()) { + this.add( + matter.controller.cluster.structs.UnitTestingClusterSimpleStruct.fromTlv( + AnonymousTag, + tlvReader, + ) + ) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - val arg6 = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_ARG6)) - while(!tlvReader.isEndOfContainer()) { - this.add(tlvReader.getUByte(AnonymousTag)) + val arg6 = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_ARG6)) + while (!tlvReader.isEndOfContainer()) { + this.add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() } - tlvReader.exitContainer() - } - + tlvReader.exitContainer() return UnitTestingClusterTestEventEvent(arg1, arg2, arg3, arg4, arg5, arg6) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/UnitTestingClusterTestFabricScopedEventEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/UnitTestingClusterTestFabricScopedEventEvent.kt index a52b06cd5cbd96..b0ac8683c99209 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/UnitTestingClusterTestFabricScopedEventEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/UnitTestingClusterTestFabricScopedEventEvent.kt @@ -16,17 +16,13 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional 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 UnitTestingClusterTestFabricScopedEventEvent( - val fabricIndex: UByte -) { +class UnitTestingClusterTestFabricScopedEventEvent(val fabricIndex: UByte) { override fun toString(): String = buildString { append("UnitTestingClusterTestFabricScopedEventEvent {\n") append("\tfabricIndex : $fabricIndex\n") @@ -44,10 +40,10 @@ class UnitTestingClusterTestFabricScopedEventEvent( companion object { private const val TAG_FABRIC_INDEX = 254 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : UnitTestingClusterTestFabricScopedEventEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): UnitTestingClusterTestFabricScopedEventEvent { tlvReader.enterStructure(tlvTag) val fabricIndex = tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) - + tlvReader.exitContainer() return UnitTestingClusterTestFabricScopedEventEvent(fabricIndex) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ValveConfigurationAndControlClusterValveFaultEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ValveConfigurationAndControlClusterValveFaultEvent.kt index a740d0e35331fe..a19524d74e9c9e 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ValveConfigurationAndControlClusterValveFaultEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ValveConfigurationAndControlClusterValveFaultEvent.kt @@ -16,17 +16,13 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional 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 ValveConfigurationAndControlClusterValveFaultEvent( - val valveFault: UShort -) { +class ValveConfigurationAndControlClusterValveFaultEvent(val valveFault: UShort) { override fun toString(): String = buildString { append("ValveConfigurationAndControlClusterValveFaultEvent {\n") append("\tvalveFault : $valveFault\n") @@ -44,10 +40,13 @@ class ValveConfigurationAndControlClusterValveFaultEvent( companion object { private const val TAG_VALVE_FAULT = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : ValveConfigurationAndControlClusterValveFaultEvent { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): ValveConfigurationAndControlClusterValveFaultEvent { tlvReader.enterStructure(tlvTag) val valveFault = tlvReader.getUShort(ContextSpecificTag(TAG_VALVE_FAULT)) - + tlvReader.exitContainer() return ValveConfigurationAndControlClusterValveFaultEvent(valveFault) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ValveConfigurationAndControlClusterValveStateChangedEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ValveConfigurationAndControlClusterValveStateChangedEvent.kt index 2331135586801c..332e4e19342ebf 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ValveConfigurationAndControlClusterValveStateChangedEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/ValveConfigurationAndControlClusterValveStateChangedEvent.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.eventstructs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +25,7 @@ import matter.tlv.TlvWriter class ValveConfigurationAndControlClusterValveStateChangedEvent( val valveState: UByte, - val valveLevel: Optional + val valveLevel: Optional, ) { override fun toString(): String = buildString { append("ValveConfigurationAndControlClusterValveStateChangedEvent {\n") @@ -51,15 +50,19 @@ class ValveConfigurationAndControlClusterValveStateChangedEvent( private const val TAG_VALVE_STATE = 0 private const val TAG_VALVE_LEVEL = 1 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : ValveConfigurationAndControlClusterValveStateChangedEvent { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): ValveConfigurationAndControlClusterValveStateChangedEvent { tlvReader.enterStructure(tlvTag) val valveState = tlvReader.getUByte(ContextSpecificTag(TAG_VALVE_STATE)) - val valveLevel = if (tlvReader.isNextTag(ContextSpecificTag(TAG_VALVE_LEVEL))) { - Optional.of(tlvReader.getUByte(ContextSpecificTag(TAG_VALVE_LEVEL))) - } else { - Optional.empty() - } - + val valveLevel = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_VALVE_LEVEL))) { + Optional.of(tlvReader.getUByte(ContextSpecificTag(TAG_VALVE_LEVEL))) + } else { + Optional.empty() + } + tlvReader.exitContainer() return ValveConfigurationAndControlClusterValveStateChangedEvent(valveState, valveLevel) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/WaterHeaterManagementClusterBoostStartedEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/WaterHeaterManagementClusterBoostStartedEvent.kt index 192b9e9c6421c9..44e51796c1fa50 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/WaterHeaterManagementClusterBoostStartedEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/WaterHeaterManagementClusterBoostStartedEvent.kt @@ -16,16 +16,15 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional 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 WaterHeaterManagementClusterBoostStartedEvent( - val boostInfo: matter.controller.cluster.structs.WaterHeaterManagementClusterWaterHeaterBoostInfoStruct + val boostInfo: + matter.controller.cluster.structs.WaterHeaterManagementClusterWaterHeaterBoostInfoStruct ) { override fun toString(): String = buildString { append("WaterHeaterManagementClusterBoostStartedEvent {\n") @@ -44,10 +43,12 @@ class WaterHeaterManagementClusterBoostStartedEvent( companion object { private const val TAG_BOOST_INFO = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : WaterHeaterManagementClusterBoostStartedEvent { + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): WaterHeaterManagementClusterBoostStartedEvent { tlvReader.enterStructure(tlvTag) - val boostInfo = matter.controller.cluster.structs.WaterHeaterManagementClusterWaterHeaterBoostInfoStruct.fromTlv(ContextSpecificTag(TAG_BOOST_INFO), tlvReader) - + val boostInfo = + matter.controller.cluster.structs.WaterHeaterManagementClusterWaterHeaterBoostInfoStruct + .fromTlv(ContextSpecificTag(TAG_BOOST_INFO), tlvReader) + tlvReader.exitContainer() return WaterHeaterManagementClusterBoostStartedEvent(boostInfo) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/WiFiNetworkDiagnosticsClusterAssociationFailureEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/WiFiNetworkDiagnosticsClusterAssociationFailureEvent.kt index fddf6cdad7a8a6..64f5392aa4fb50 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/WiFiNetworkDiagnosticsClusterAssociationFailureEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/WiFiNetworkDiagnosticsClusterAssociationFailureEvent.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +24,7 @@ import matter.tlv.TlvWriter class WiFiNetworkDiagnosticsClusterAssociationFailureEvent( val associationFailureCause: UByte, - val status: UShort + val status: UShort, ) { override fun toString(): String = buildString { append("WiFiNetworkDiagnosticsClusterAssociationFailureEvent {\n") @@ -48,11 +46,15 @@ class WiFiNetworkDiagnosticsClusterAssociationFailureEvent( private const val TAG_ASSOCIATION_FAILURE_CAUSE = 0 private const val TAG_STATUS = 1 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : WiFiNetworkDiagnosticsClusterAssociationFailureEvent { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): WiFiNetworkDiagnosticsClusterAssociationFailureEvent { tlvReader.enterStructure(tlvTag) - val associationFailureCause = tlvReader.getUByte(ContextSpecificTag(TAG_ASSOCIATION_FAILURE_CAUSE)) + val associationFailureCause = + tlvReader.getUByte(ContextSpecificTag(TAG_ASSOCIATION_FAILURE_CAUSE)) val status = tlvReader.getUShort(ContextSpecificTag(TAG_STATUS)) - + tlvReader.exitContainer() return WiFiNetworkDiagnosticsClusterAssociationFailureEvent(associationFailureCause, status) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/WiFiNetworkDiagnosticsClusterConnectionStatusEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/WiFiNetworkDiagnosticsClusterConnectionStatusEvent.kt index 0e668adcf859dd..122e44de1dc246 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/WiFiNetworkDiagnosticsClusterConnectionStatusEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/WiFiNetworkDiagnosticsClusterConnectionStatusEvent.kt @@ -16,17 +16,13 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional 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 WiFiNetworkDiagnosticsClusterConnectionStatusEvent( - val connectionStatus: UByte -) { +class WiFiNetworkDiagnosticsClusterConnectionStatusEvent(val connectionStatus: UByte) { override fun toString(): String = buildString { append("WiFiNetworkDiagnosticsClusterConnectionStatusEvent {\n") append("\tconnectionStatus : $connectionStatus\n") @@ -44,10 +40,13 @@ class WiFiNetworkDiagnosticsClusterConnectionStatusEvent( companion object { private const val TAG_CONNECTION_STATUS = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : WiFiNetworkDiagnosticsClusterConnectionStatusEvent { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): WiFiNetworkDiagnosticsClusterConnectionStatusEvent { tlvReader.enterStructure(tlvTag) val connectionStatus = tlvReader.getUByte(ContextSpecificTag(TAG_CONNECTION_STATUS)) - + tlvReader.exitContainer() return WiFiNetworkDiagnosticsClusterConnectionStatusEvent(connectionStatus) diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/WiFiNetworkDiagnosticsClusterDisconnectionEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/WiFiNetworkDiagnosticsClusterDisconnectionEvent.kt index 40a4bf1d3cc947..baff7be3fea8cb 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/WiFiNetworkDiagnosticsClusterDisconnectionEvent.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/WiFiNetworkDiagnosticsClusterDisconnectionEvent.kt @@ -16,17 +16,13 @@ */ package matter.controller.cluster.eventstructs -import java.util.Optional 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 WiFiNetworkDiagnosticsClusterDisconnectionEvent( - val reasonCode: UShort -) { +class WiFiNetworkDiagnosticsClusterDisconnectionEvent(val reasonCode: UShort) { override fun toString(): String = buildString { append("WiFiNetworkDiagnosticsClusterDisconnectionEvent {\n") append("\treasonCode : $reasonCode\n") @@ -44,10 +40,13 @@ class WiFiNetworkDiagnosticsClusterDisconnectionEvent( companion object { private const val TAG_REASON_CODE = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : WiFiNetworkDiagnosticsClusterDisconnectionEvent { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): WiFiNetworkDiagnosticsClusterDisconnectionEvent { tlvReader.enterStructure(tlvTag) val reasonCode = tlvReader.getUShort(ContextSpecificTag(TAG_REASON_CODE)) - + tlvReader.exitContainer() return WiFiNetworkDiagnosticsClusterDisconnectionEvent(reasonCode) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/AccessControlClusterAccessControlEntryStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/AccessControlClusterAccessControlEntryStruct.kt index bd703215de0a5b..e452c201c3c824 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/AccessControlClusterAccessControlEntryStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/AccessControlClusterAccessControlEntryStruct.kt @@ -16,7 +16,6 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -29,7 +28,7 @@ class AccessControlClusterAccessControlEntryStruct( val authMode: UByte, val subjects: List?, val targets: List?, - val fabricIndex: UByte + val fabricIndex: UByte, ) { override fun toString(): String = buildString { append("AccessControlClusterAccessControlEntryStruct {\n") @@ -48,19 +47,19 @@ class AccessControlClusterAccessControlEntryStruct( put(ContextSpecificTag(TAG_AUTH_MODE), authMode) if (subjects != null) { startArray(ContextSpecificTag(TAG_SUBJECTS)) - for (item in subjects.iterator()) { - put(AnonymousTag, item) - } - endArray() + for (item in subjects.iterator()) { + put(AnonymousTag, item) + } + endArray() } else { putNull(ContextSpecificTag(TAG_SUBJECTS)) } if (targets != null) { startArray(ContextSpecificTag(TAG_TARGETS)) - for (item in targets.iterator()) { - item.toTlv(AnonymousTag, this) - } - endArray() + for (item in targets.iterator()) { + item.toTlv(AnonymousTag, this) + } + endArray() } else { putNull(ContextSpecificTag(TAG_TARGETS)) } @@ -80,35 +79,43 @@ class AccessControlClusterAccessControlEntryStruct( tlvReader.enterStructure(tlvTag) val privilege = tlvReader.getUByte(ContextSpecificTag(TAG_PRIVILEGE)) val authMode = tlvReader.getUByte(ContextSpecificTag(TAG_AUTH_MODE)) - val subjects = if (!tlvReader.isNull()) { - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_SUBJECTS)) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getULong(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_SUBJECTS)) - null - } - val targets = if (!tlvReader.isNull()) { - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_TARGETS)) - while(!tlvReader.isEndOfContainer()) { - add(AccessControlClusterAccessControlTargetStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_TARGETS)) - null - } + val subjects = + if (!tlvReader.isNull()) { + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_SUBJECTS)) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getULong(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_SUBJECTS)) + null + } + val targets = + if (!tlvReader.isNull()) { + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_TARGETS)) + while (!tlvReader.isEndOfContainer()) { + add(AccessControlClusterAccessControlTargetStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_TARGETS)) + null + } val fabricIndex = tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) - + tlvReader.exitContainer() - return AccessControlClusterAccessControlEntryStruct(privilege, authMode, subjects, targets, fabricIndex) + return AccessControlClusterAccessControlEntryStruct( + privilege, + authMode, + subjects, + targets, + fabricIndex, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/AccessControlClusterAccessControlExtensionStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/AccessControlClusterAccessControlExtensionStruct.kt index 8ffb7a94a61ed1..34abd2cb66e907 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/AccessControlClusterAccessControlExtensionStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/AccessControlClusterAccessControlExtensionStruct.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +24,7 @@ import matter.tlv.TlvWriter class AccessControlClusterAccessControlExtensionStruct( val data: ByteArray, - val fabricIndex: UByte + val fabricIndex: UByte, ) { override fun toString(): String = buildString { append("AccessControlClusterAccessControlExtensionStruct {\n") @@ -48,11 +46,14 @@ class AccessControlClusterAccessControlExtensionStruct( private const val TAG_DATA = 1 private const val TAG_FABRIC_INDEX = 254 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): AccessControlClusterAccessControlExtensionStruct { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): AccessControlClusterAccessControlExtensionStruct { tlvReader.enterStructure(tlvTag) val data = tlvReader.getByteArray(ContextSpecificTag(TAG_DATA)) val fabricIndex = tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) - + tlvReader.exitContainer() return AccessControlClusterAccessControlExtensionStruct(data, fabricIndex) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/AccessControlClusterAccessControlTargetStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/AccessControlClusterAccessControlTargetStruct.kt index dc275d27e5f803..518b2ec671cb28 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/AccessControlClusterAccessControlTargetStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/AccessControlClusterAccessControlTargetStruct.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -27,7 +25,7 @@ import matter.tlv.TlvWriter class AccessControlClusterAccessControlTargetStruct( val cluster: UInt?, val endpoint: UShort?, - val deviceType: UInt? + val deviceType: UInt?, ) { override fun toString(): String = buildString { append("AccessControlClusterAccessControlTargetStruct {\n") @@ -66,25 +64,28 @@ class AccessControlClusterAccessControlTargetStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): AccessControlClusterAccessControlTargetStruct { tlvReader.enterStructure(tlvTag) - val cluster = if (!tlvReader.isNull()) { - tlvReader.getUInt(ContextSpecificTag(TAG_CLUSTER)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_CLUSTER)) - null - } - val endpoint = if (!tlvReader.isNull()) { - tlvReader.getUShort(ContextSpecificTag(TAG_ENDPOINT)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_ENDPOINT)) - null - } - val deviceType = if (!tlvReader.isNull()) { - tlvReader.getUInt(ContextSpecificTag(TAG_DEVICE_TYPE)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_DEVICE_TYPE)) - null - } - + val cluster = + if (!tlvReader.isNull()) { + tlvReader.getUInt(ContextSpecificTag(TAG_CLUSTER)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_CLUSTER)) + null + } + val endpoint = + if (!tlvReader.isNull()) { + tlvReader.getUShort(ContextSpecificTag(TAG_ENDPOINT)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_ENDPOINT)) + null + } + val deviceType = + if (!tlvReader.isNull()) { + tlvReader.getUInt(ContextSpecificTag(TAG_DEVICE_TYPE)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_DEVICE_TYPE)) + null + } + tlvReader.exitContainer() return AccessControlClusterAccessControlTargetStruct(cluster, endpoint, deviceType) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/AccessControlClusterAccessRestrictionEntryStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/AccessControlClusterAccessRestrictionEntryStruct.kt index c2cd26aba3ca98..6750b4fc80c401 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/AccessControlClusterAccessRestrictionEntryStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/AccessControlClusterAccessRestrictionEntryStruct.kt @@ -16,7 +16,6 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -28,7 +27,7 @@ class AccessControlClusterAccessRestrictionEntryStruct( val endpoint: UShort, val cluster: UInt, val restrictions: List, - val fabricIndex: UByte + val fabricIndex: UByte, ) { override fun toString(): String = buildString { append("AccessControlClusterAccessRestrictionEntryStruct {\n") @@ -60,22 +59,31 @@ class AccessControlClusterAccessRestrictionEntryStruct( private const val TAG_RESTRICTIONS = 2 private const val TAG_FABRIC_INDEX = 254 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): AccessControlClusterAccessRestrictionEntryStruct { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): AccessControlClusterAccessRestrictionEntryStruct { tlvReader.enterStructure(tlvTag) val endpoint = tlvReader.getUShort(ContextSpecificTag(TAG_ENDPOINT)) val cluster = tlvReader.getUInt(ContextSpecificTag(TAG_CLUSTER)) - val restrictions = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_RESTRICTIONS)) - while(!tlvReader.isEndOfContainer()) { - add(AccessControlClusterAccessRestrictionStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val restrictions = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_RESTRICTIONS)) + while (!tlvReader.isEndOfContainer()) { + add(AccessControlClusterAccessRestrictionStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } val fabricIndex = tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) - + tlvReader.exitContainer() - return AccessControlClusterAccessRestrictionEntryStruct(endpoint, cluster, restrictions, fabricIndex) + return AccessControlClusterAccessRestrictionEntryStruct( + endpoint, + cluster, + restrictions, + fabricIndex, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/AccessControlClusterAccessRestrictionStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/AccessControlClusterAccessRestrictionStruct.kt index dae6259cbc6217..16452c2baa2919 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/AccessControlClusterAccessRestrictionStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/AccessControlClusterAccessRestrictionStruct.kt @@ -16,18 +16,13 @@ */ package matter.controller.cluster.structs -import java.util.Optional 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 AccessControlClusterAccessRestrictionStruct( - val type: UByte, - val id: UInt? -) { +class AccessControlClusterAccessRestrictionStruct(val type: UByte, val id: UInt?) { override fun toString(): String = buildString { append("AccessControlClusterAccessRestrictionStruct {\n") append("\ttype : $type\n") @@ -55,13 +50,14 @@ class AccessControlClusterAccessRestrictionStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): AccessControlClusterAccessRestrictionStruct { tlvReader.enterStructure(tlvTag) val type = tlvReader.getUByte(ContextSpecificTag(TAG_TYPE)) - val id = if (!tlvReader.isNull()) { - tlvReader.getUInt(ContextSpecificTag(TAG_ID)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_ID)) - null - } - + val id = + if (!tlvReader.isNull()) { + tlvReader.getUInt(ContextSpecificTag(TAG_ID)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_ID)) + null + } + tlvReader.exitContainer() return AccessControlClusterAccessRestrictionStruct(type, id) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/AccessControlClusterCommissioningAccessRestrictionEntryStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/AccessControlClusterCommissioningAccessRestrictionEntryStruct.kt index c24ffa1c6cdbe8..c2c9582400272a 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/AccessControlClusterCommissioningAccessRestrictionEntryStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/AccessControlClusterCommissioningAccessRestrictionEntryStruct.kt @@ -16,7 +16,6 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -27,7 +26,7 @@ import matter.tlv.TlvWriter class AccessControlClusterCommissioningAccessRestrictionEntryStruct( val endpoint: UShort, val cluster: UInt, - val restrictions: List + val restrictions: List, ) { override fun toString(): String = buildString { append("AccessControlClusterCommissioningAccessRestrictionEntryStruct {\n") @@ -56,21 +55,29 @@ class AccessControlClusterCommissioningAccessRestrictionEntryStruct( private const val TAG_CLUSTER = 1 private const val TAG_RESTRICTIONS = 2 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): AccessControlClusterCommissioningAccessRestrictionEntryStruct { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): AccessControlClusterCommissioningAccessRestrictionEntryStruct { tlvReader.enterStructure(tlvTag) val endpoint = tlvReader.getUShort(ContextSpecificTag(TAG_ENDPOINT)) val cluster = tlvReader.getUInt(ContextSpecificTag(TAG_CLUSTER)) - val restrictions = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_RESTRICTIONS)) - while(!tlvReader.isEndOfContainer()) { - add(AccessControlClusterAccessRestrictionStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - + val restrictions = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_RESTRICTIONS)) + while (!tlvReader.isEndOfContainer()) { + add(AccessControlClusterAccessRestrictionStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + tlvReader.exitContainer() - return AccessControlClusterCommissioningAccessRestrictionEntryStruct(endpoint, cluster, restrictions) + return AccessControlClusterCommissioningAccessRestrictionEntryStruct( + endpoint, + cluster, + restrictions, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ActionsClusterActionStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ActionsClusterActionStruct.kt index 965cedd6ace042..080da76540c4a6 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ActionsClusterActionStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ActionsClusterActionStruct.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -30,7 +28,7 @@ class ActionsClusterActionStruct( val type: UByte, val endpointListID: UShort, val supportedCommands: UShort, - val state: UByte + val state: UByte, ) { override fun toString(): String = buildString { append("ActionsClusterActionStruct {\n") @@ -72,10 +70,17 @@ class ActionsClusterActionStruct( val endpointListID = tlvReader.getUShort(ContextSpecificTag(TAG_ENDPOINT_LIST_ID)) val supportedCommands = tlvReader.getUShort(ContextSpecificTag(TAG_SUPPORTED_COMMANDS)) val state = tlvReader.getUByte(ContextSpecificTag(TAG_STATE)) - + tlvReader.exitContainer() - return ActionsClusterActionStruct(actionID, name, type, endpointListID, supportedCommands, state) + return ActionsClusterActionStruct( + actionID, + name, + type, + endpointListID, + supportedCommands, + state, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ActionsClusterEndpointListStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ActionsClusterEndpointListStruct.kt index df60e68d39bae8..3c4603e164076d 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ActionsClusterEndpointListStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ActionsClusterEndpointListStruct.kt @@ -16,7 +16,6 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -28,7 +27,7 @@ class ActionsClusterEndpointListStruct( val endpointListID: UShort, val name: String, val type: UByte, - val endpoints: List + val endpoints: List, ) { override fun toString(): String = buildString { append("ActionsClusterEndpointListStruct {\n") @@ -65,14 +64,15 @@ class ActionsClusterEndpointListStruct( val endpointListID = tlvReader.getUShort(ContextSpecificTag(TAG_ENDPOINT_LIST_ID)) val name = tlvReader.getString(ContextSpecificTag(TAG_NAME)) val type = tlvReader.getUByte(ContextSpecificTag(TAG_TYPE)) - val endpoints = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_ENDPOINTS)) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getUShort(AnonymousTag)) - } - tlvReader.exitContainer() - } - + val endpoints = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_ENDPOINTS)) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUShort(AnonymousTag)) + } + tlvReader.exitContainer() + } + tlvReader.exitContainer() return ActionsClusterEndpointListStruct(endpointListID, name, type, endpoints) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ActivatedCarbonFilterMonitoringClusterReplacementProductStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ActivatedCarbonFilterMonitoringClusterReplacementProductStruct.kt index c43c172f39ad4a..20c989ddc5a368 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ActivatedCarbonFilterMonitoringClusterReplacementProductStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ActivatedCarbonFilterMonitoringClusterReplacementProductStruct.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +24,7 @@ import matter.tlv.TlvWriter class ActivatedCarbonFilterMonitoringClusterReplacementProductStruct( val productIdentifierType: UByte, - val productIdentifierValue: String + val productIdentifierValue: String, ) { override fun toString(): String = buildString { append("ActivatedCarbonFilterMonitoringClusterReplacementProductStruct {\n") @@ -48,14 +46,22 @@ class ActivatedCarbonFilterMonitoringClusterReplacementProductStruct( private const val TAG_PRODUCT_IDENTIFIER_TYPE = 0 private const val TAG_PRODUCT_IDENTIFIER_VALUE = 1 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ActivatedCarbonFilterMonitoringClusterReplacementProductStruct { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): ActivatedCarbonFilterMonitoringClusterReplacementProductStruct { tlvReader.enterStructure(tlvTag) - val productIdentifierType = tlvReader.getUByte(ContextSpecificTag(TAG_PRODUCT_IDENTIFIER_TYPE)) - val productIdentifierValue = tlvReader.getString(ContextSpecificTag(TAG_PRODUCT_IDENTIFIER_VALUE)) - + val productIdentifierType = + tlvReader.getUByte(ContextSpecificTag(TAG_PRODUCT_IDENTIFIER_TYPE)) + val productIdentifierValue = + tlvReader.getString(ContextSpecificTag(TAG_PRODUCT_IDENTIFIER_VALUE)) + tlvReader.exitContainer() - return ActivatedCarbonFilterMonitoringClusterReplacementProductStruct(productIdentifierType, productIdentifierValue) + return ActivatedCarbonFilterMonitoringClusterReplacementProductStruct( + productIdentifierType, + productIdentifierValue, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ApplicationBasicClusterApplicationStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ApplicationBasicClusterApplicationStruct.kt index 32845e1a63817a..be4a1e7984e307 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ApplicationBasicClusterApplicationStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ApplicationBasicClusterApplicationStruct.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +24,7 @@ import matter.tlv.TlvWriter class ApplicationBasicClusterApplicationStruct( val catalogVendorID: UShort, - val applicationID: String + val applicationID: String, ) { override fun toString(): String = buildString { append("ApplicationBasicClusterApplicationStruct {\n") @@ -52,7 +50,7 @@ class ApplicationBasicClusterApplicationStruct( tlvReader.enterStructure(tlvTag) val catalogVendorID = tlvReader.getUShort(ContextSpecificTag(TAG_CATALOG_VENDOR_ID)) val applicationID = tlvReader.getString(ContextSpecificTag(TAG_APPLICATION_ID)) - + tlvReader.exitContainer() return ApplicationBasicClusterApplicationStruct(catalogVendorID, applicationID) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ApplicationLauncherClusterApplicationEPStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ApplicationLauncherClusterApplicationEPStruct.kt index eeca3b79254426..8e6b905d8aa91c 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ApplicationLauncherClusterApplicationEPStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ApplicationLauncherClusterApplicationEPStruct.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +25,7 @@ import matter.tlv.TlvWriter class ApplicationLauncherClusterApplicationEPStruct( val application: ApplicationLauncherClusterApplicationStruct, - val endpoint: Optional + val endpoint: Optional, ) { override fun toString(): String = buildString { append("ApplicationLauncherClusterApplicationEPStruct {\n") @@ -53,13 +52,18 @@ class ApplicationLauncherClusterApplicationEPStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ApplicationLauncherClusterApplicationEPStruct { tlvReader.enterStructure(tlvTag) - val application = ApplicationLauncherClusterApplicationStruct.fromTlv(ContextSpecificTag(TAG_APPLICATION), tlvReader) - val endpoint = if (tlvReader.isNextTag(ContextSpecificTag(TAG_ENDPOINT))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_ENDPOINT))) - } else { - Optional.empty() - } - + val application = + ApplicationLauncherClusterApplicationStruct.fromTlv( + ContextSpecificTag(TAG_APPLICATION), + tlvReader, + ) + val endpoint = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_ENDPOINT))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_ENDPOINT))) + } else { + Optional.empty() + } + tlvReader.exitContainer() return ApplicationLauncherClusterApplicationEPStruct(application, endpoint) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ApplicationLauncherClusterApplicationStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ApplicationLauncherClusterApplicationStruct.kt index 0427e6d5bd22b8..ea921ee690d16c 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ApplicationLauncherClusterApplicationStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ApplicationLauncherClusterApplicationStruct.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +24,7 @@ import matter.tlv.TlvWriter class ApplicationLauncherClusterApplicationStruct( val catalogVendorID: UShort, - val applicationID: String + val applicationID: String, ) { override fun toString(): String = buildString { append("ApplicationLauncherClusterApplicationStruct {\n") @@ -52,7 +50,7 @@ class ApplicationLauncherClusterApplicationStruct( tlvReader.enterStructure(tlvTag) val catalogVendorID = tlvReader.getUShort(ContextSpecificTag(TAG_CATALOG_VENDOR_ID)) val applicationID = tlvReader.getString(ContextSpecificTag(TAG_APPLICATION_ID)) - + tlvReader.exitContainer() return ApplicationLauncherClusterApplicationStruct(catalogVendorID, applicationID) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/AudioOutputClusterOutputInfoStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/AudioOutputClusterOutputInfoStruct.kt index 2a48b0b450bf4a..e37c78ff74d38c 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/AudioOutputClusterOutputInfoStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/AudioOutputClusterOutputInfoStruct.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -27,7 +25,7 @@ import matter.tlv.TlvWriter class AudioOutputClusterOutputInfoStruct( val index: UByte, val outputType: UByte, - val name: String + val name: String, ) { override fun toString(): String = buildString { append("AudioOutputClusterOutputInfoStruct {\n") @@ -57,7 +55,7 @@ class AudioOutputClusterOutputInfoStruct( val index = tlvReader.getUByte(ContextSpecificTag(TAG_INDEX)) val outputType = tlvReader.getUByte(ContextSpecificTag(TAG_OUTPUT_TYPE)) val name = tlvReader.getString(ContextSpecificTag(TAG_NAME)) - + tlvReader.exitContainer() return AudioOutputClusterOutputInfoStruct(index, outputType, name) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/BasicInformationClusterCapabilityMinimaStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/BasicInformationClusterCapabilityMinimaStruct.kt index aa977b5fdb8578..74a5a0bb98be93 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/BasicInformationClusterCapabilityMinimaStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/BasicInformationClusterCapabilityMinimaStruct.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +24,7 @@ import matter.tlv.TlvWriter class BasicInformationClusterCapabilityMinimaStruct( val caseSessionsPerFabric: UShort, - val subscriptionsPerFabric: UShort + val subscriptionsPerFabric: UShort, ) { override fun toString(): String = buildString { append("BasicInformationClusterCapabilityMinimaStruct {\n") @@ -50,12 +48,17 @@ class BasicInformationClusterCapabilityMinimaStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): BasicInformationClusterCapabilityMinimaStruct { tlvReader.enterStructure(tlvTag) - val caseSessionsPerFabric = tlvReader.getUShort(ContextSpecificTag(TAG_CASE_SESSIONS_PER_FABRIC)) - val subscriptionsPerFabric = tlvReader.getUShort(ContextSpecificTag(TAG_SUBSCRIPTIONS_PER_FABRIC)) - + val caseSessionsPerFabric = + tlvReader.getUShort(ContextSpecificTag(TAG_CASE_SESSIONS_PER_FABRIC)) + val subscriptionsPerFabric = + tlvReader.getUShort(ContextSpecificTag(TAG_SUBSCRIPTIONS_PER_FABRIC)) + tlvReader.exitContainer() - return BasicInformationClusterCapabilityMinimaStruct(caseSessionsPerFabric, subscriptionsPerFabric) + return BasicInformationClusterCapabilityMinimaStruct( + caseSessionsPerFabric, + subscriptionsPerFabric, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/BasicInformationClusterProductAppearanceStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/BasicInformationClusterProductAppearanceStruct.kt index d5cc1315e520cd..56583564b0c687 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/BasicInformationClusterProductAppearanceStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/BasicInformationClusterProductAppearanceStruct.kt @@ -16,18 +16,13 @@ */ package matter.controller.cluster.structs -import java.util.Optional 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 BasicInformationClusterProductAppearanceStruct( - val finish: UByte, - val primaryColor: UByte? -) { +class BasicInformationClusterProductAppearanceStruct(val finish: UByte, val primaryColor: UByte?) { override fun toString(): String = buildString { append("BasicInformationClusterProductAppearanceStruct {\n") append("\tfinish : $finish\n") @@ -55,13 +50,14 @@ class BasicInformationClusterProductAppearanceStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): BasicInformationClusterProductAppearanceStruct { tlvReader.enterStructure(tlvTag) val finish = tlvReader.getUByte(ContextSpecificTag(TAG_FINISH)) - val primaryColor = if (!tlvReader.isNull()) { - tlvReader.getUByte(ContextSpecificTag(TAG_PRIMARY_COLOR)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_PRIMARY_COLOR)) - null - } - + val primaryColor = + if (!tlvReader.isNull()) { + tlvReader.getUByte(ContextSpecificTag(TAG_PRIMARY_COLOR)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_PRIMARY_COLOR)) + null + } + tlvReader.exitContainer() return BasicInformationClusterProductAppearanceStruct(finish, primaryColor) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/BindingClusterTargetStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/BindingClusterTargetStruct.kt index 1a382bd10ab5a0..e4e3d8027767ca 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/BindingClusterTargetStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/BindingClusterTargetStruct.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -29,7 +28,7 @@ class BindingClusterTargetStruct( val group: Optional, val endpoint: Optional, val cluster: Optional, - val fabricIndex: UByte + val fabricIndex: UByte, ) { override fun toString(): String = buildString { append("BindingClusterTargetStruct {\n") @@ -74,28 +73,32 @@ class BindingClusterTargetStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): BindingClusterTargetStruct { tlvReader.enterStructure(tlvTag) - val node = if (tlvReader.isNextTag(ContextSpecificTag(TAG_NODE))) { - Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_NODE))) - } else { - Optional.empty() - } - val group = if (tlvReader.isNextTag(ContextSpecificTag(TAG_GROUP))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_GROUP))) - } else { - Optional.empty() - } - val endpoint = if (tlvReader.isNextTag(ContextSpecificTag(TAG_ENDPOINT))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_ENDPOINT))) - } else { - Optional.empty() - } - val cluster = if (tlvReader.isNextTag(ContextSpecificTag(TAG_CLUSTER))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_CLUSTER))) - } else { - Optional.empty() - } + val node = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_NODE))) { + Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_NODE))) + } else { + Optional.empty() + } + val group = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_GROUP))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_GROUP))) + } else { + Optional.empty() + } + val endpoint = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_ENDPOINT))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_ENDPOINT))) + } else { + Optional.empty() + } + val cluster = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_CLUSTER))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_CLUSTER))) + } else { + Optional.empty() + } val fabricIndex = tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) - + tlvReader.exitContainer() return BindingClusterTargetStruct(node, group, endpoint, cluster, fabricIndex) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/BridgedDeviceBasicInformationClusterProductAppearanceStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/BridgedDeviceBasicInformationClusterProductAppearanceStruct.kt index 9e9eabc793ef94..d1b8b79bc3f553 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/BridgedDeviceBasicInformationClusterProductAppearanceStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/BridgedDeviceBasicInformationClusterProductAppearanceStruct.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +24,7 @@ import matter.tlv.TlvWriter class BridgedDeviceBasicInformationClusterProductAppearanceStruct( val finish: UByte, - val primaryColor: UByte? + val primaryColor: UByte?, ) { override fun toString(): String = buildString { append("BridgedDeviceBasicInformationClusterProductAppearanceStruct {\n") @@ -52,16 +50,20 @@ class BridgedDeviceBasicInformationClusterProductAppearanceStruct( private const val TAG_FINISH = 0 private const val TAG_PRIMARY_COLOR = 1 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): BridgedDeviceBasicInformationClusterProductAppearanceStruct { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): BridgedDeviceBasicInformationClusterProductAppearanceStruct { tlvReader.enterStructure(tlvTag) val finish = tlvReader.getUByte(ContextSpecificTag(TAG_FINISH)) - val primaryColor = if (!tlvReader.isNull()) { - tlvReader.getUByte(ContextSpecificTag(TAG_PRIMARY_COLOR)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_PRIMARY_COLOR)) - null - } - + val primaryColor = + if (!tlvReader.isNull()) { + tlvReader.getUByte(ContextSpecificTag(TAG_PRIMARY_COLOR)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_PRIMARY_COLOR)) + null + } + tlvReader.exitContainer() return BridgedDeviceBasicInformationClusterProductAppearanceStruct(finish, primaryColor) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterAdditionalInfoStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterAdditionalInfoStruct.kt index 9c504e9f434b18..cd2eacc749cb0d 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterAdditionalInfoStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterAdditionalInfoStruct.kt @@ -16,18 +16,13 @@ */ package matter.controller.cluster.structs -import java.util.Optional 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 ChannelClusterAdditionalInfoStruct( - val name: String, - val value: String -) { +class ChannelClusterAdditionalInfoStruct(val name: String, val value: String) { override fun toString(): String = buildString { append("ChannelClusterAdditionalInfoStruct {\n") append("\tname : $name\n") @@ -52,7 +47,7 @@ class ChannelClusterAdditionalInfoStruct( tlvReader.enterStructure(tlvTag) val name = tlvReader.getString(ContextSpecificTag(TAG_NAME)) val value = tlvReader.getString(ContextSpecificTag(TAG_VALUE)) - + tlvReader.exitContainer() return ChannelClusterAdditionalInfoStruct(name, value) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterChannelInfoStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterChannelInfoStruct.kt index 914bcad0e6cc7f..13b805080c391b 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterChannelInfoStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterChannelInfoStruct.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -31,7 +30,7 @@ class ChannelClusterChannelInfoStruct( val callSign: Optional, val affiliateCallSign: Optional, val identifier: Optional, - val type: Optional + val type: Optional, ) { override fun toString(): String = buildString { append("ChannelClusterChannelInfoStruct {\n") @@ -87,35 +86,48 @@ class ChannelClusterChannelInfoStruct( tlvReader.enterStructure(tlvTag) val majorNumber = tlvReader.getUShort(ContextSpecificTag(TAG_MAJOR_NUMBER)) val minorNumber = tlvReader.getUShort(ContextSpecificTag(TAG_MINOR_NUMBER)) - val name = if (tlvReader.isNextTag(ContextSpecificTag(TAG_NAME))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_NAME))) - } else { - Optional.empty() - } - val callSign = if (tlvReader.isNextTag(ContextSpecificTag(TAG_CALL_SIGN))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_CALL_SIGN))) - } else { - Optional.empty() - } - val affiliateCallSign = if (tlvReader.isNextTag(ContextSpecificTag(TAG_AFFILIATE_CALL_SIGN))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_AFFILIATE_CALL_SIGN))) - } else { - Optional.empty() - } - val identifier = if (tlvReader.isNextTag(ContextSpecificTag(TAG_IDENTIFIER))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_IDENTIFIER))) - } else { - Optional.empty() - } - val type = if (tlvReader.isNextTag(ContextSpecificTag(TAG_TYPE))) { - Optional.of(tlvReader.getUByte(ContextSpecificTag(TAG_TYPE))) - } else { - Optional.empty() - } - + val name = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_NAME))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_NAME))) + } else { + Optional.empty() + } + val callSign = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_CALL_SIGN))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_CALL_SIGN))) + } else { + Optional.empty() + } + val affiliateCallSign = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_AFFILIATE_CALL_SIGN))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_AFFILIATE_CALL_SIGN))) + } else { + Optional.empty() + } + val identifier = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_IDENTIFIER))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_IDENTIFIER))) + } else { + Optional.empty() + } + val type = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_TYPE))) { + Optional.of(tlvReader.getUByte(ContextSpecificTag(TAG_TYPE))) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return ChannelClusterChannelInfoStruct(majorNumber, minorNumber, name, callSign, affiliateCallSign, identifier, type) + return ChannelClusterChannelInfoStruct( + majorNumber, + minorNumber, + name, + callSign, + affiliateCallSign, + identifier, + type, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterChannelPagingStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterChannelPagingStruct.kt index f3b7c7d5f51755..e84410d09dd64d 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterChannelPagingStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterChannelPagingStruct.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +25,7 @@ import matter.tlv.TlvWriter class ChannelClusterChannelPagingStruct( val previousToken: Optional?, - val nextToken: Optional? + val nextToken: Optional?, ) { override fun toString(): String = buildString { append("ChannelClusterChannelPagingStruct {\n") @@ -40,17 +39,17 @@ class ChannelClusterChannelPagingStruct( startStructure(tlvTag) if (previousToken != null) { if (previousToken.isPresent) { - val optpreviousToken = previousToken.get() - optpreviousToken.toTlv(ContextSpecificTag(TAG_PREVIOUS_TOKEN), this) - } + val optpreviousToken = previousToken.get() + optpreviousToken.toTlv(ContextSpecificTag(TAG_PREVIOUS_TOKEN), this) + } } else { putNull(ContextSpecificTag(TAG_PREVIOUS_TOKEN)) } if (nextToken != null) { if (nextToken.isPresent) { - val optnextToken = nextToken.get() - optnextToken.toTlv(ContextSpecificTag(TAG_NEXT_TOKEN), this) - } + val optnextToken = nextToken.get() + optnextToken.toTlv(ContextSpecificTag(TAG_NEXT_TOKEN), this) + } } else { putNull(ContextSpecificTag(TAG_NEXT_TOKEN)) } @@ -64,27 +63,36 @@ class ChannelClusterChannelPagingStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ChannelClusterChannelPagingStruct { tlvReader.enterStructure(tlvTag) - val previousToken = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_PREVIOUS_TOKEN))) { - Optional.of(ChannelClusterPageTokenStruct.fromTlv(ContextSpecificTag(TAG_PREVIOUS_TOKEN), tlvReader)) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_PREVIOUS_TOKEN)) - null - } - val nextToken = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_NEXT_TOKEN))) { - Optional.of(ChannelClusterPageTokenStruct.fromTlv(ContextSpecificTag(TAG_NEXT_TOKEN), tlvReader)) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_NEXT_TOKEN)) - null - } - + val previousToken = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_PREVIOUS_TOKEN))) { + Optional.of( + ChannelClusterPageTokenStruct.fromTlv( + ContextSpecificTag(TAG_PREVIOUS_TOKEN), + tlvReader, + ) + ) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_PREVIOUS_TOKEN)) + null + } + val nextToken = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_NEXT_TOKEN))) { + Optional.of( + ChannelClusterPageTokenStruct.fromTlv(ContextSpecificTag(TAG_NEXT_TOKEN), tlvReader) + ) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_NEXT_TOKEN)) + null + } + tlvReader.exitContainer() return ChannelClusterChannelPagingStruct(previousToken, nextToken) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterLineupInfoStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterLineupInfoStruct.kt index 21eb682b010a20..9863a0515c0070 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterLineupInfoStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterLineupInfoStruct.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -28,7 +27,7 @@ class ChannelClusterLineupInfoStruct( val operatorName: String, val lineupName: Optional, val postalCode: Optional, - val lineupInfoType: UByte + val lineupInfoType: UByte, ) { override fun toString(): String = buildString { append("ChannelClusterLineupInfoStruct {\n") @@ -65,18 +64,20 @@ class ChannelClusterLineupInfoStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ChannelClusterLineupInfoStruct { tlvReader.enterStructure(tlvTag) val operatorName = tlvReader.getString(ContextSpecificTag(TAG_OPERATOR_NAME)) - val lineupName = if (tlvReader.isNextTag(ContextSpecificTag(TAG_LINEUP_NAME))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_LINEUP_NAME))) - } else { - Optional.empty() - } - val postalCode = if (tlvReader.isNextTag(ContextSpecificTag(TAG_POSTAL_CODE))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_POSTAL_CODE))) - } else { - Optional.empty() - } + val lineupName = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_LINEUP_NAME))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_LINEUP_NAME))) + } else { + Optional.empty() + } + val postalCode = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_POSTAL_CODE))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_POSTAL_CODE))) + } else { + Optional.empty() + } val lineupInfoType = tlvReader.getUByte(ContextSpecificTag(TAG_LINEUP_INFO_TYPE)) - + tlvReader.exitContainer() return ChannelClusterLineupInfoStruct(operatorName, lineupName, postalCode, lineupInfoType) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterPageTokenStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterPageTokenStruct.kt index 963a7c2beb5ffa..f42ecb1d1219f3 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterPageTokenStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterPageTokenStruct.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -27,7 +26,7 @@ import matter.tlv.TlvWriter class ChannelClusterPageTokenStruct( val limit: Optional, val after: Optional, - val before: Optional + val before: Optional, ) { override fun toString(): String = buildString { append("ChannelClusterPageTokenStruct {\n") @@ -63,22 +62,25 @@ class ChannelClusterPageTokenStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ChannelClusterPageTokenStruct { tlvReader.enterStructure(tlvTag) - val limit = if (tlvReader.isNextTag(ContextSpecificTag(TAG_LIMIT))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_LIMIT))) - } else { - Optional.empty() - } - val after = if (tlvReader.isNextTag(ContextSpecificTag(TAG_AFTER))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_AFTER))) - } else { - Optional.empty() - } - val before = if (tlvReader.isNextTag(ContextSpecificTag(TAG_BEFORE))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_BEFORE))) - } else { - Optional.empty() - } - + val limit = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_LIMIT))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_LIMIT))) + } else { + Optional.empty() + } + val after = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_AFTER))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_AFTER))) + } else { + Optional.empty() + } + val before = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_BEFORE))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_BEFORE))) + } else { + Optional.empty() + } + tlvReader.exitContainer() return ChannelClusterPageTokenStruct(limit, after, before) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterProgramCastStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterProgramCastStruct.kt index 54568f0b775970..45b0a22100ef25 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterProgramCastStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterProgramCastStruct.kt @@ -16,18 +16,13 @@ */ package matter.controller.cluster.structs -import java.util.Optional 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 ChannelClusterProgramCastStruct( - val name: String, - val role: String -) { +class ChannelClusterProgramCastStruct(val name: String, val role: String) { override fun toString(): String = buildString { append("ChannelClusterProgramCastStruct {\n") append("\tname : $name\n") @@ -52,7 +47,7 @@ class ChannelClusterProgramCastStruct( tlvReader.enterStructure(tlvTag) val name = tlvReader.getString(ContextSpecificTag(TAG_NAME)) val role = tlvReader.getString(ContextSpecificTag(TAG_ROLE)) - + tlvReader.exitContainer() return ChannelClusterProgramCastStruct(name, role) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterProgramCategoryStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterProgramCategoryStruct.kt index 3ffaea537244dc..6e89f24cd39e25 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterProgramCategoryStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterProgramCategoryStruct.kt @@ -18,16 +18,12 @@ package matter.controller.cluster.structs import java.util.Optional 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 ChannelClusterProgramCategoryStruct( - val category: String, - val subCategory: Optional -) { +class ChannelClusterProgramCategoryStruct(val category: String, val subCategory: Optional) { override fun toString(): String = buildString { append("ChannelClusterProgramCategoryStruct {\n") append("\tcategory : $category\n") @@ -54,12 +50,13 @@ class ChannelClusterProgramCategoryStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ChannelClusterProgramCategoryStruct { tlvReader.enterStructure(tlvTag) val category = tlvReader.getString(ContextSpecificTag(TAG_CATEGORY)) - val subCategory = if (tlvReader.isNextTag(ContextSpecificTag(TAG_SUB_CATEGORY))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_SUB_CATEGORY))) - } else { - Optional.empty() - } - + val subCategory = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_SUB_CATEGORY))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_SUB_CATEGORY))) + } else { + Optional.empty() + } + tlvReader.exitContainer() return ChannelClusterProgramCategoryStruct(category, subCategory) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterProgramStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterProgramStruct.kt index 6b0bf99a15529b..c8dfd42de67a1c 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterProgramStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterProgramStruct.kt @@ -43,7 +43,7 @@ class ChannelClusterProgramStruct( val seriesInfo: Optional?, val categoryList: Optional>, val castList: Optional>, - val externalIDList: Optional> + val externalIDList: Optional>, ) { override fun toString(): String = buildString { append("ChannelClusterProgramStruct {\n") @@ -88,18 +88,18 @@ class ChannelClusterProgramStruct( if (audioLanguages.isPresent) { val optaudioLanguages = audioLanguages.get() startArray(ContextSpecificTag(TAG_AUDIO_LANGUAGES)) - for (item in optaudioLanguages.iterator()) { - put(AnonymousTag, item) - } - endArray() + for (item in optaudioLanguages.iterator()) { + put(AnonymousTag, item) + } + endArray() } if (ratings.isPresent) { val optratings = ratings.get() startArray(ContextSpecificTag(TAG_RATINGS)) - for (item in optratings.iterator()) { - put(AnonymousTag, item) - } - endArray() + for (item in optratings.iterator()) { + put(AnonymousTag, item) + } + endArray() } if (thumbnailUrl.isPresent) { val optthumbnailUrl = thumbnailUrl.get() @@ -127,35 +127,35 @@ class ChannelClusterProgramStruct( } if (seriesInfo != null) { if (seriesInfo.isPresent) { - val optseriesInfo = seriesInfo.get() - optseriesInfo.toTlv(ContextSpecificTag(TAG_SERIES_INFO), this) - } + val optseriesInfo = seriesInfo.get() + optseriesInfo.toTlv(ContextSpecificTag(TAG_SERIES_INFO), this) + } } else { putNull(ContextSpecificTag(TAG_SERIES_INFO)) } if (categoryList.isPresent) { val optcategoryList = categoryList.get() startArray(ContextSpecificTag(TAG_CATEGORY_LIST)) - for (item in optcategoryList.iterator()) { - item.toTlv(AnonymousTag, this) - } - endArray() + for (item in optcategoryList.iterator()) { + item.toTlv(AnonymousTag, this) + } + endArray() } if (castList.isPresent) { val optcastList = castList.get() startArray(ContextSpecificTag(TAG_CAST_LIST)) - for (item in optcastList.iterator()) { - item.toTlv(AnonymousTag, this) - } - endArray() + for (item in optcastList.iterator()) { + item.toTlv(AnonymousTag, this) + } + endArray() } if (externalIDList.isPresent) { val optexternalIDList = externalIDList.get() startArray(ContextSpecificTag(TAG_EXTERNAL_ID_LIST)) - for (item in optexternalIDList.iterator()) { - item.toTlv(AnonymousTag, this) - } - endArray() + for (item in optexternalIDList.iterator()) { + item.toTlv(AnonymousTag, this) + } + endArray() } endStructure() } @@ -185,119 +185,166 @@ class ChannelClusterProgramStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ChannelClusterProgramStruct { tlvReader.enterStructure(tlvTag) val identifier = tlvReader.getString(ContextSpecificTag(TAG_IDENTIFIER)) - val channel = ChannelClusterChannelInfoStruct.fromTlv(ContextSpecificTag(TAG_CHANNEL), tlvReader) + val channel = + ChannelClusterChannelInfoStruct.fromTlv(ContextSpecificTag(TAG_CHANNEL), tlvReader) val startTime = tlvReader.getUInt(ContextSpecificTag(TAG_START_TIME)) val endTime = tlvReader.getUInt(ContextSpecificTag(TAG_END_TIME)) val title = tlvReader.getString(ContextSpecificTag(TAG_TITLE)) - val subtitle = if (tlvReader.isNextTag(ContextSpecificTag(TAG_SUBTITLE))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_SUBTITLE))) - } else { - Optional.empty() - } - val description = if (tlvReader.isNextTag(ContextSpecificTag(TAG_DESCRIPTION))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_DESCRIPTION))) - } else { - Optional.empty() - } - val audioLanguages = if (tlvReader.isNextTag(ContextSpecificTag(TAG_AUDIO_LANGUAGES))) { - Optional.of(buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_AUDIO_LANGUAGES)) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getString(AnonymousTag)) - } - tlvReader.exitContainer() - }) - } else { - Optional.empty() - } - val ratings = if (tlvReader.isNextTag(ContextSpecificTag(TAG_RATINGS))) { - Optional.of(buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_RATINGS)) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getString(AnonymousTag)) - } - tlvReader.exitContainer() - }) - } else { - Optional.empty() - } - val thumbnailUrl = if (tlvReader.isNextTag(ContextSpecificTag(TAG_THUMBNAIL_URL))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_THUMBNAIL_URL))) - } else { - Optional.empty() - } - val posterArtUrl = if (tlvReader.isNextTag(ContextSpecificTag(TAG_POSTER_ART_URL))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_POSTER_ART_URL))) - } else { - Optional.empty() - } - val dvbiUrl = if (tlvReader.isNextTag(ContextSpecificTag(TAG_DVBI_URL))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_DVBI_URL))) - } else { - Optional.empty() - } - val releaseDate = if (tlvReader.isNextTag(ContextSpecificTag(TAG_RELEASE_DATE))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_RELEASE_DATE))) - } else { - Optional.empty() - } - val parentalGuidanceText = if (tlvReader.isNextTag(ContextSpecificTag(TAG_PARENTAL_GUIDANCE_TEXT))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_PARENTAL_GUIDANCE_TEXT))) - } else { - Optional.empty() - } - val recordingFlag = if (tlvReader.isNextTag(ContextSpecificTag(TAG_RECORDING_FLAG))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_RECORDING_FLAG))) - } else { - Optional.empty() - } - val seriesInfo = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_SERIES_INFO))) { - Optional.of(ChannelClusterSeriesInfoStruct.fromTlv(ContextSpecificTag(TAG_SERIES_INFO), tlvReader)) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_SERIES_INFO)) - null - } - val categoryList = if (tlvReader.isNextTag(ContextSpecificTag(TAG_CATEGORY_LIST))) { - Optional.of(buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_CATEGORY_LIST)) - while(!tlvReader.isEndOfContainer()) { - add(ChannelClusterProgramCategoryStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - }) - } else { - Optional.empty() - } - val castList = if (tlvReader.isNextTag(ContextSpecificTag(TAG_CAST_LIST))) { - Optional.of(buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_CAST_LIST)) - while(!tlvReader.isEndOfContainer()) { - add(ChannelClusterProgramCastStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - }) - } else { - Optional.empty() - } - val externalIDList = if (tlvReader.isNextTag(ContextSpecificTag(TAG_EXTERNAL_ID_LIST))) { - Optional.of(buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_EXTERNAL_ID_LIST)) - while(!tlvReader.isEndOfContainer()) { - add(ChannelClusterProgramCastStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - }) - } else { - Optional.empty() - } - + val subtitle = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_SUBTITLE))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_SUBTITLE))) + } else { + Optional.empty() + } + val description = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_DESCRIPTION))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_DESCRIPTION))) + } else { + Optional.empty() + } + val audioLanguages = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_AUDIO_LANGUAGES))) { + Optional.of( + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_AUDIO_LANGUAGES)) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getString(AnonymousTag)) + } + tlvReader.exitContainer() + } + ) + } else { + Optional.empty() + } + val ratings = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_RATINGS))) { + Optional.of( + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_RATINGS)) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getString(AnonymousTag)) + } + tlvReader.exitContainer() + } + ) + } else { + Optional.empty() + } + val thumbnailUrl = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_THUMBNAIL_URL))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_THUMBNAIL_URL))) + } else { + Optional.empty() + } + val posterArtUrl = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_POSTER_ART_URL))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_POSTER_ART_URL))) + } else { + Optional.empty() + } + val dvbiUrl = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_DVBI_URL))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_DVBI_URL))) + } else { + Optional.empty() + } + val releaseDate = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_RELEASE_DATE))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_RELEASE_DATE))) + } else { + Optional.empty() + } + val parentalGuidanceText = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_PARENTAL_GUIDANCE_TEXT))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_PARENTAL_GUIDANCE_TEXT))) + } else { + Optional.empty() + } + val recordingFlag = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_RECORDING_FLAG))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_RECORDING_FLAG))) + } else { + Optional.empty() + } + val seriesInfo = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_SERIES_INFO))) { + Optional.of( + ChannelClusterSeriesInfoStruct.fromTlv(ContextSpecificTag(TAG_SERIES_INFO), tlvReader) + ) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_SERIES_INFO)) + null + } + val categoryList = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_CATEGORY_LIST))) { + Optional.of( + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_CATEGORY_LIST)) + while (!tlvReader.isEndOfContainer()) { + add(ChannelClusterProgramCategoryStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + ) + } else { + Optional.empty() + } + val castList = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_CAST_LIST))) { + Optional.of( + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_CAST_LIST)) + while (!tlvReader.isEndOfContainer()) { + add(ChannelClusterProgramCastStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + ) + } else { + Optional.empty() + } + val externalIDList = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_EXTERNAL_ID_LIST))) { + Optional.of( + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_EXTERNAL_ID_LIST)) + while (!tlvReader.isEndOfContainer()) { + add(ChannelClusterProgramCastStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + ) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return ChannelClusterProgramStruct(identifier, channel, startTime, endTime, title, subtitle, description, audioLanguages, ratings, thumbnailUrl, posterArtUrl, dvbiUrl, releaseDate, parentalGuidanceText, recordingFlag, seriesInfo, categoryList, castList, externalIDList) + return ChannelClusterProgramStruct( + identifier, + channel, + startTime, + endTime, + title, + subtitle, + description, + audioLanguages, + ratings, + thumbnailUrl, + posterArtUrl, + dvbiUrl, + releaseDate, + parentalGuidanceText, + recordingFlag, + seriesInfo, + categoryList, + castList, + externalIDList, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterSeriesInfoStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterSeriesInfoStruct.kt index c0445d55460703..9e3928a48de8a5 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterSeriesInfoStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ChannelClusterSeriesInfoStruct.kt @@ -16,18 +16,13 @@ */ package matter.controller.cluster.structs -import java.util.Optional 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 ChannelClusterSeriesInfoStruct( - val season: String, - val episode: String -) { +class ChannelClusterSeriesInfoStruct(val season: String, val episode: String) { override fun toString(): String = buildString { append("ChannelClusterSeriesInfoStruct {\n") append("\tseason : $season\n") @@ -52,7 +47,7 @@ class ChannelClusterSeriesInfoStruct( tlvReader.enterStructure(tlvTag) val season = tlvReader.getString(ContextSpecificTag(TAG_SEASON)) val episode = tlvReader.getString(ContextSpecificTag(TAG_EPISODE)) - + tlvReader.exitContainer() return ChannelClusterSeriesInfoStruct(season, episode) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ContentControlClusterRatingNameStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ContentControlClusterRatingNameStruct.kt index fe5058eb533a87..fd405633efdf9f 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ContentControlClusterRatingNameStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ContentControlClusterRatingNameStruct.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +25,7 @@ import matter.tlv.TlvWriter class ContentControlClusterRatingNameStruct( val ratingName: String, - val ratingNameDesc: Optional + val ratingNameDesc: Optional, ) { override fun toString(): String = buildString { append("ContentControlClusterRatingNameStruct {\n") @@ -54,12 +53,13 @@ class ContentControlClusterRatingNameStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ContentControlClusterRatingNameStruct { tlvReader.enterStructure(tlvTag) val ratingName = tlvReader.getString(ContextSpecificTag(TAG_RATING_NAME)) - val ratingNameDesc = if (tlvReader.isNextTag(ContextSpecificTag(TAG_RATING_NAME_DESC))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_RATING_NAME_DESC))) - } else { - Optional.empty() - } - + val ratingNameDesc = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_RATING_NAME_DESC))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_RATING_NAME_DESC))) + } else { + Optional.empty() + } + tlvReader.exitContainer() return ContentControlClusterRatingNameStruct(ratingName, ratingNameDesc) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterAdditionalInfoStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterAdditionalInfoStruct.kt index 504997933652c9..af51becfe86381 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterAdditionalInfoStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterAdditionalInfoStruct.kt @@ -16,18 +16,13 @@ */ package matter.controller.cluster.structs -import java.util.Optional 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 ContentLauncherClusterAdditionalInfoStruct( - val name: String, - val value: String -) { +class ContentLauncherClusterAdditionalInfoStruct(val name: String, val value: String) { override fun toString(): String = buildString { append("ContentLauncherClusterAdditionalInfoStruct {\n") append("\tname : $name\n") @@ -52,7 +47,7 @@ class ContentLauncherClusterAdditionalInfoStruct( tlvReader.enterStructure(tlvTag) val name = tlvReader.getString(ContextSpecificTag(TAG_NAME)) val value = tlvReader.getString(ContextSpecificTag(TAG_VALUE)) - + tlvReader.exitContainer() return ContentLauncherClusterAdditionalInfoStruct(name, value) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterBrandingInformationStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterBrandingInformationStruct.kt index e94826e1eb40d8..fa9e391b5af70e 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterBrandingInformationStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterBrandingInformationStruct.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -30,7 +29,7 @@ class ContentLauncherClusterBrandingInformationStruct( val logo: Optional, val progressBar: Optional, val splash: Optional, - val waterMark: Optional + val waterMark: Optional, ) { override fun toString(): String = buildString { append("ContentLauncherClusterBrandingInformationStruct {\n") @@ -79,38 +78,78 @@ class ContentLauncherClusterBrandingInformationStruct( private const val TAG_SPLASH = 4 private const val TAG_WATER_MARK = 5 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ContentLauncherClusterBrandingInformationStruct { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): ContentLauncherClusterBrandingInformationStruct { tlvReader.enterStructure(tlvTag) val providerName = tlvReader.getString(ContextSpecificTag(TAG_PROVIDER_NAME)) - val background = if (tlvReader.isNextTag(ContextSpecificTag(TAG_BACKGROUND))) { - Optional.of(ContentLauncherClusterStyleInformationStruct.fromTlv(ContextSpecificTag(TAG_BACKGROUND), tlvReader)) - } else { - Optional.empty() - } - val logo = if (tlvReader.isNextTag(ContextSpecificTag(TAG_LOGO))) { - Optional.of(ContentLauncherClusterStyleInformationStruct.fromTlv(ContextSpecificTag(TAG_LOGO), tlvReader)) - } else { - Optional.empty() - } - val progressBar = if (tlvReader.isNextTag(ContextSpecificTag(TAG_PROGRESS_BAR))) { - Optional.of(ContentLauncherClusterStyleInformationStruct.fromTlv(ContextSpecificTag(TAG_PROGRESS_BAR), tlvReader)) - } else { - Optional.empty() - } - val splash = if (tlvReader.isNextTag(ContextSpecificTag(TAG_SPLASH))) { - Optional.of(ContentLauncherClusterStyleInformationStruct.fromTlv(ContextSpecificTag(TAG_SPLASH), tlvReader)) - } else { - Optional.empty() - } - val waterMark = if (tlvReader.isNextTag(ContextSpecificTag(TAG_WATER_MARK))) { - Optional.of(ContentLauncherClusterStyleInformationStruct.fromTlv(ContextSpecificTag(TAG_WATER_MARK), tlvReader)) - } else { - Optional.empty() - } - + val background = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_BACKGROUND))) { + Optional.of( + ContentLauncherClusterStyleInformationStruct.fromTlv( + ContextSpecificTag(TAG_BACKGROUND), + tlvReader, + ) + ) + } else { + Optional.empty() + } + val logo = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_LOGO))) { + Optional.of( + ContentLauncherClusterStyleInformationStruct.fromTlv( + ContextSpecificTag(TAG_LOGO), + tlvReader, + ) + ) + } else { + Optional.empty() + } + val progressBar = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_PROGRESS_BAR))) { + Optional.of( + ContentLauncherClusterStyleInformationStruct.fromTlv( + ContextSpecificTag(TAG_PROGRESS_BAR), + tlvReader, + ) + ) + } else { + Optional.empty() + } + val splash = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_SPLASH))) { + Optional.of( + ContentLauncherClusterStyleInformationStruct.fromTlv( + ContextSpecificTag(TAG_SPLASH), + tlvReader, + ) + ) + } else { + Optional.empty() + } + val waterMark = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_WATER_MARK))) { + Optional.of( + ContentLauncherClusterStyleInformationStruct.fromTlv( + ContextSpecificTag(TAG_WATER_MARK), + tlvReader, + ) + ) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return ContentLauncherClusterBrandingInformationStruct(providerName, background, logo, progressBar, splash, waterMark) + return ContentLauncherClusterBrandingInformationStruct( + providerName, + background, + logo, + progressBar, + splash, + waterMark, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterContentSearchStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterContentSearchStruct.kt index 052e4f66723755..1fe0fc71463ee6 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterContentSearchStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterContentSearchStruct.kt @@ -16,7 +16,6 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -50,14 +49,15 @@ class ContentLauncherClusterContentSearchStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ContentLauncherClusterContentSearchStruct { tlvReader.enterStructure(tlvTag) - val parameterList = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_PARAMETER_LIST)) - while(!tlvReader.isEndOfContainer()) { - add(ContentLauncherClusterParameterStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - + val parameterList = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_PARAMETER_LIST)) + while (!tlvReader.isEndOfContainer()) { + add(ContentLauncherClusterParameterStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + tlvReader.exitContainer() return ContentLauncherClusterContentSearchStruct(parameterList) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterDimensionStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterDimensionStruct.kt index 5870e4079531e8..d9d100400566e8 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterDimensionStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterDimensionStruct.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -27,7 +25,7 @@ import matter.tlv.TlvWriter class ContentLauncherClusterDimensionStruct( val width: Double, val height: Double, - val metric: UByte + val metric: UByte, ) { override fun toString(): String = buildString { append("ContentLauncherClusterDimensionStruct {\n") @@ -57,7 +55,7 @@ class ContentLauncherClusterDimensionStruct( val width = tlvReader.getDouble(ContextSpecificTag(TAG_WIDTH)) val height = tlvReader.getDouble(ContextSpecificTag(TAG_HEIGHT)) val metric = tlvReader.getUByte(ContextSpecificTag(TAG_METRIC)) - + tlvReader.exitContainer() return ContentLauncherClusterDimensionStruct(width, height, metric) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterParameterStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterParameterStruct.kt index 03f542ae56835a..1785ef89c54840 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterParameterStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterParameterStruct.kt @@ -27,7 +27,7 @@ import matter.tlv.TlvWriter class ContentLauncherClusterParameterStruct( val type: UByte, val value: String, - val externalIDList: Optional> + val externalIDList: Optional>, ) { override fun toString(): String = buildString { append("ContentLauncherClusterParameterStruct {\n") @@ -45,10 +45,10 @@ class ContentLauncherClusterParameterStruct( if (externalIDList.isPresent) { val optexternalIDList = externalIDList.get() startArray(ContextSpecificTag(TAG_EXTERNAL_ID_LIST)) - for (item in optexternalIDList.iterator()) { - item.toTlv(AnonymousTag, this) - } - endArray() + for (item in optexternalIDList.iterator()) { + item.toTlv(AnonymousTag, this) + } + endArray() } endStructure() } @@ -63,18 +63,21 @@ class ContentLauncherClusterParameterStruct( tlvReader.enterStructure(tlvTag) val type = tlvReader.getUByte(ContextSpecificTag(TAG_TYPE)) val value = tlvReader.getString(ContextSpecificTag(TAG_VALUE)) - val externalIDList = if (tlvReader.isNextTag(ContextSpecificTag(TAG_EXTERNAL_ID_LIST))) { - Optional.of(buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_EXTERNAL_ID_LIST)) - while(!tlvReader.isEndOfContainer()) { - add(ContentLauncherClusterAdditionalInfoStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - }) - } else { - Optional.empty() - } - + val externalIDList = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_EXTERNAL_ID_LIST))) { + Optional.of( + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_EXTERNAL_ID_LIST)) + while (!tlvReader.isEndOfContainer()) { + add(ContentLauncherClusterAdditionalInfoStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + ) + } else { + Optional.empty() + } + tlvReader.exitContainer() return ContentLauncherClusterParameterStruct(type, value, externalIDList) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterPlaybackPreferencesStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterPlaybackPreferencesStruct.kt index adba8615ee2d73..aa71bc1d9895a6 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterPlaybackPreferencesStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterPlaybackPreferencesStruct.kt @@ -27,7 +27,7 @@ import matter.tlv.TlvWriter class ContentLauncherClusterPlaybackPreferencesStruct( val playbackPosition: ULong, val textTrack: ContentLauncherClusterTrackPreferenceStruct, - val audioTracks: Optional> + val audioTracks: Optional>, ) { override fun toString(): String = buildString { append("ContentLauncherClusterPlaybackPreferencesStruct {\n") @@ -45,10 +45,10 @@ class ContentLauncherClusterPlaybackPreferencesStruct( if (audioTracks.isPresent) { val optaudioTracks = audioTracks.get() startArray(ContextSpecificTag(TAG_AUDIO_TRACKS)) - for (item in optaudioTracks.iterator()) { - item.toTlv(AnonymousTag, this) - } - endArray() + for (item in optaudioTracks.iterator()) { + item.toTlv(AnonymousTag, this) + } + endArray() } endStructure() } @@ -59,25 +59,39 @@ class ContentLauncherClusterPlaybackPreferencesStruct( private const val TAG_TEXT_TRACK = 1 private const val TAG_AUDIO_TRACKS = 2 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ContentLauncherClusterPlaybackPreferencesStruct { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): ContentLauncherClusterPlaybackPreferencesStruct { tlvReader.enterStructure(tlvTag) val playbackPosition = tlvReader.getULong(ContextSpecificTag(TAG_PLAYBACK_POSITION)) - val textTrack = ContentLauncherClusterTrackPreferenceStruct.fromTlv(ContextSpecificTag(TAG_TEXT_TRACK), tlvReader) - val audioTracks = if (tlvReader.isNextTag(ContextSpecificTag(TAG_AUDIO_TRACKS))) { - Optional.of(buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_AUDIO_TRACKS)) - while(!tlvReader.isEndOfContainer()) { - add(ContentLauncherClusterTrackPreferenceStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - }) - } else { - Optional.empty() - } - + val textTrack = + ContentLauncherClusterTrackPreferenceStruct.fromTlv( + ContextSpecificTag(TAG_TEXT_TRACK), + tlvReader, + ) + val audioTracks = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_AUDIO_TRACKS))) { + Optional.of( + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_AUDIO_TRACKS)) + while (!tlvReader.isEndOfContainer()) { + add(ContentLauncherClusterTrackPreferenceStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + ) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return ContentLauncherClusterPlaybackPreferencesStruct(playbackPosition, textTrack, audioTracks) + return ContentLauncherClusterPlaybackPreferencesStruct( + playbackPosition, + textTrack, + audioTracks, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterStyleInformationStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterStyleInformationStruct.kt index 192719b95e2400..b1a5ea8bfe0a70 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterStyleInformationStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterStyleInformationStruct.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -27,7 +26,7 @@ import matter.tlv.TlvWriter class ContentLauncherClusterStyleInformationStruct( val imageURL: Optional, val color: Optional, - val size: Optional + val size: Optional, ) { override fun toString(): String = buildString { append("ContentLauncherClusterStyleInformationStruct {\n") @@ -63,22 +62,27 @@ class ContentLauncherClusterStyleInformationStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ContentLauncherClusterStyleInformationStruct { tlvReader.enterStructure(tlvTag) - val imageURL = if (tlvReader.isNextTag(ContextSpecificTag(TAG_IMAGE_URL))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_IMAGE_URL))) - } else { - Optional.empty() - } - val color = if (tlvReader.isNextTag(ContextSpecificTag(TAG_COLOR))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_COLOR))) - } else { - Optional.empty() - } - val size = if (tlvReader.isNextTag(ContextSpecificTag(TAG_SIZE))) { - Optional.of(ContentLauncherClusterDimensionStruct.fromTlv(ContextSpecificTag(TAG_SIZE), tlvReader)) - } else { - Optional.empty() - } - + val imageURL = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_IMAGE_URL))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_IMAGE_URL))) + } else { + Optional.empty() + } + val color = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_COLOR))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_COLOR))) + } else { + Optional.empty() + } + val size = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_SIZE))) { + Optional.of( + ContentLauncherClusterDimensionStruct.fromTlv(ContextSpecificTag(TAG_SIZE), tlvReader) + ) + } else { + Optional.empty() + } + tlvReader.exitContainer() return ContentLauncherClusterStyleInformationStruct(imageURL, color, size) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterTrackPreferenceStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterTrackPreferenceStruct.kt index 47dadc45c6f0b3..1e0b96a553e125 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterTrackPreferenceStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ContentLauncherClusterTrackPreferenceStruct.kt @@ -27,7 +27,7 @@ import matter.tlv.TlvWriter class ContentLauncherClusterTrackPreferenceStruct( val languageCode: String, val characteristics: Optional>, - val audioOutputIndex: UByte + val audioOutputIndex: UByte, ) { override fun toString(): String = buildString { append("ContentLauncherClusterTrackPreferenceStruct {\n") @@ -44,10 +44,10 @@ class ContentLauncherClusterTrackPreferenceStruct( if (characteristics.isPresent) { val optcharacteristics = characteristics.get() startArray(ContextSpecificTag(TAG_CHARACTERISTICS)) - for (item in optcharacteristics.iterator()) { - put(AnonymousTag, item) - } - endArray() + for (item in optcharacteristics.iterator()) { + put(AnonymousTag, item) + } + endArray() } put(ContextSpecificTag(TAG_AUDIO_OUTPUT_INDEX), audioOutputIndex) endStructure() @@ -62,22 +62,29 @@ class ContentLauncherClusterTrackPreferenceStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ContentLauncherClusterTrackPreferenceStruct { tlvReader.enterStructure(tlvTag) val languageCode = tlvReader.getString(ContextSpecificTag(TAG_LANGUAGE_CODE)) - val characteristics = if (tlvReader.isNextTag(ContextSpecificTag(TAG_CHARACTERISTICS))) { - Optional.of(buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_CHARACTERISTICS)) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - }) - } else { - Optional.empty() - } + val characteristics = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_CHARACTERISTICS))) { + Optional.of( + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_CHARACTERISTICS)) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + ) + } else { + Optional.empty() + } val audioOutputIndex = tlvReader.getUByte(ContextSpecificTag(TAG_AUDIO_OUTPUT_INDEX)) - + tlvReader.exitContainer() - return ContentLauncherClusterTrackPreferenceStruct(languageCode, characteristics, audioOutputIndex) + return ContentLauncherClusterTrackPreferenceStruct( + languageCode, + characteristics, + audioOutputIndex, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterAverageLoadControlStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterAverageLoadControlStruct.kt index 5a055dd4270923..c59c3b96d2a63b 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterAverageLoadControlStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterAverageLoadControlStruct.kt @@ -16,17 +16,13 @@ */ package matter.controller.cluster.structs -import java.util.Optional 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 DemandResponseLoadControlClusterAverageLoadControlStruct( - val loadAdjustment: Byte -) { +class DemandResponseLoadControlClusterAverageLoadControlStruct(val loadAdjustment: Byte) { override fun toString(): String = buildString { append("DemandResponseLoadControlClusterAverageLoadControlStruct {\n") append("\tloadAdjustment : $loadAdjustment\n") @@ -44,10 +40,13 @@ class DemandResponseLoadControlClusterAverageLoadControlStruct( companion object { private const val TAG_LOAD_ADJUSTMENT = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): DemandResponseLoadControlClusterAverageLoadControlStruct { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): DemandResponseLoadControlClusterAverageLoadControlStruct { tlvReader.enterStructure(tlvTag) val loadAdjustment = tlvReader.getByte(ContextSpecificTag(TAG_LOAD_ADJUSTMENT)) - + tlvReader.exitContainer() return DemandResponseLoadControlClusterAverageLoadControlStruct(loadAdjustment) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterDutyCycleControlStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterDutyCycleControlStruct.kt index 9573a4e3ff11fa..db86b004c9ae35 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterDutyCycleControlStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterDutyCycleControlStruct.kt @@ -16,17 +16,13 @@ */ package matter.controller.cluster.structs -import java.util.Optional 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 DemandResponseLoadControlClusterDutyCycleControlStruct( - val dutyCycle: UByte -) { +class DemandResponseLoadControlClusterDutyCycleControlStruct(val dutyCycle: UByte) { override fun toString(): String = buildString { append("DemandResponseLoadControlClusterDutyCycleControlStruct {\n") append("\tdutyCycle : $dutyCycle\n") @@ -44,10 +40,13 @@ class DemandResponseLoadControlClusterDutyCycleControlStruct( companion object { private const val TAG_DUTY_CYCLE = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): DemandResponseLoadControlClusterDutyCycleControlStruct { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): DemandResponseLoadControlClusterDutyCycleControlStruct { tlvReader.enterStructure(tlvTag) val dutyCycle = tlvReader.getUByte(ContextSpecificTag(TAG_DUTY_CYCLE)) - + tlvReader.exitContainer() return DemandResponseLoadControlClusterDutyCycleControlStruct(dutyCycle) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterHeatingSourceControlStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterHeatingSourceControlStruct.kt index ed90e36f3a637e..0624700d6ddd5a 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterHeatingSourceControlStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterHeatingSourceControlStruct.kt @@ -16,17 +16,13 @@ */ package matter.controller.cluster.structs -import java.util.Optional 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 DemandResponseLoadControlClusterHeatingSourceControlStruct( - val heatingSource: UByte -) { +class DemandResponseLoadControlClusterHeatingSourceControlStruct(val heatingSource: UByte) { override fun toString(): String = buildString { append("DemandResponseLoadControlClusterHeatingSourceControlStruct {\n") append("\theatingSource : $heatingSource\n") @@ -44,10 +40,13 @@ class DemandResponseLoadControlClusterHeatingSourceControlStruct( companion object { private const val TAG_HEATING_SOURCE = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): DemandResponseLoadControlClusterHeatingSourceControlStruct { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): DemandResponseLoadControlClusterHeatingSourceControlStruct { tlvReader.enterStructure(tlvTag) val heatingSource = tlvReader.getUByte(ContextSpecificTag(TAG_HEATING_SOURCE)) - + tlvReader.exitContainer() return DemandResponseLoadControlClusterHeatingSourceControlStruct(heatingSource) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterLoadControlEventStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterLoadControlEventStruct.kt index b0c75402f1f006..e17da92ffddf7e 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterLoadControlEventStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterLoadControlEventStruct.kt @@ -32,7 +32,7 @@ class DemandResponseLoadControlClusterLoadControlEventStruct( val enrollmentGroup: Optional, val criticality: UByte, val startTime: UInt?, - val transitions: List + val transitions: List, ) { override fun toString(): String = buildString { append("DemandResponseLoadControlClusterLoadControlEventStruct {\n") @@ -87,40 +87,61 @@ class DemandResponseLoadControlClusterLoadControlEventStruct( private const val TAG_START_TIME = 6 private const val TAG_TRANSITIONS = 7 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): DemandResponseLoadControlClusterLoadControlEventStruct { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): DemandResponseLoadControlClusterLoadControlEventStruct { tlvReader.enterStructure(tlvTag) val eventID = tlvReader.getByteArray(ContextSpecificTag(TAG_EVENT_ID)) - val programID = if (!tlvReader.isNull()) { - tlvReader.getByteArray(ContextSpecificTag(TAG_PROGRAM_ID)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_PROGRAM_ID)) - null - } + val programID = + if (!tlvReader.isNull()) { + tlvReader.getByteArray(ContextSpecificTag(TAG_PROGRAM_ID)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_PROGRAM_ID)) + null + } val control = tlvReader.getUShort(ContextSpecificTag(TAG_CONTROL)) val deviceClass = tlvReader.getUInt(ContextSpecificTag(TAG_DEVICE_CLASS)) - val enrollmentGroup = if (tlvReader.isNextTag(ContextSpecificTag(TAG_ENROLLMENT_GROUP))) { - Optional.of(tlvReader.getUByte(ContextSpecificTag(TAG_ENROLLMENT_GROUP))) - } else { - Optional.empty() - } + val enrollmentGroup = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_ENROLLMENT_GROUP))) { + Optional.of(tlvReader.getUByte(ContextSpecificTag(TAG_ENROLLMENT_GROUP))) + } else { + Optional.empty() + } val criticality = tlvReader.getUByte(ContextSpecificTag(TAG_CRITICALITY)) - val startTime = if (!tlvReader.isNull()) { - tlvReader.getUInt(ContextSpecificTag(TAG_START_TIME)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_START_TIME)) - null - } - val transitions = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_TRANSITIONS)) - while(!tlvReader.isEndOfContainer()) { - add(DemandResponseLoadControlClusterLoadControlEventTransitionStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - + val startTime = + if (!tlvReader.isNull()) { + tlvReader.getUInt(ContextSpecificTag(TAG_START_TIME)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_START_TIME)) + null + } + val transitions = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_TRANSITIONS)) + while (!tlvReader.isEndOfContainer()) { + add( + DemandResponseLoadControlClusterLoadControlEventTransitionStruct.fromTlv( + AnonymousTag, + tlvReader, + ) + ) + } + tlvReader.exitContainer() + } + tlvReader.exitContainer() - return DemandResponseLoadControlClusterLoadControlEventStruct(eventID, programID, control, deviceClass, enrollmentGroup, criticality, startTime, transitions) + return DemandResponseLoadControlClusterLoadControlEventStruct( + eventID, + programID, + control, + deviceClass, + enrollmentGroup, + criticality, + startTime, + transitions, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterLoadControlEventTransitionStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterLoadControlEventTransitionStruct.kt index 8b11bb21f1b0a0..cf7f5f337061db 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterLoadControlEventTransitionStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterLoadControlEventTransitionStruct.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -31,7 +30,7 @@ class DemandResponseLoadControlClusterLoadControlEventTransitionStruct( val averageLoadControl: Optional, val dutyCycleControl: Optional, val powerSavingsControl: Optional, - val heatingSourceControl: Optional + val heatingSourceControl: Optional, ) { override fun toString(): String = buildString { append("DemandResponseLoadControlClusterLoadControlEventTransitionStruct {\n") @@ -83,39 +82,80 @@ class DemandResponseLoadControlClusterLoadControlEventTransitionStruct( private const val TAG_POWER_SAVINGS_CONTROL = 5 private const val TAG_HEATING_SOURCE_CONTROL = 6 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): DemandResponseLoadControlClusterLoadControlEventTransitionStruct { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): DemandResponseLoadControlClusterLoadControlEventTransitionStruct { tlvReader.enterStructure(tlvTag) val duration = tlvReader.getUShort(ContextSpecificTag(TAG_DURATION)) val control = tlvReader.getUShort(ContextSpecificTag(TAG_CONTROL)) - val temperatureControl = if (tlvReader.isNextTag(ContextSpecificTag(TAG_TEMPERATURE_CONTROL))) { - Optional.of(DemandResponseLoadControlClusterTemperatureControlStruct.fromTlv(ContextSpecificTag(TAG_TEMPERATURE_CONTROL), tlvReader)) - } else { - Optional.empty() - } - val averageLoadControl = if (tlvReader.isNextTag(ContextSpecificTag(TAG_AVERAGE_LOAD_CONTROL))) { - Optional.of(DemandResponseLoadControlClusterAverageLoadControlStruct.fromTlv(ContextSpecificTag(TAG_AVERAGE_LOAD_CONTROL), tlvReader)) - } else { - Optional.empty() - } - val dutyCycleControl = if (tlvReader.isNextTag(ContextSpecificTag(TAG_DUTY_CYCLE_CONTROL))) { - Optional.of(DemandResponseLoadControlClusterDutyCycleControlStruct.fromTlv(ContextSpecificTag(TAG_DUTY_CYCLE_CONTROL), tlvReader)) - } else { - Optional.empty() - } - val powerSavingsControl = if (tlvReader.isNextTag(ContextSpecificTag(TAG_POWER_SAVINGS_CONTROL))) { - Optional.of(DemandResponseLoadControlClusterPowerSavingsControlStruct.fromTlv(ContextSpecificTag(TAG_POWER_SAVINGS_CONTROL), tlvReader)) - } else { - Optional.empty() - } - val heatingSourceControl = if (tlvReader.isNextTag(ContextSpecificTag(TAG_HEATING_SOURCE_CONTROL))) { - Optional.of(DemandResponseLoadControlClusterHeatingSourceControlStruct.fromTlv(ContextSpecificTag(TAG_HEATING_SOURCE_CONTROL), tlvReader)) - } else { - Optional.empty() - } - + val temperatureControl = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_TEMPERATURE_CONTROL))) { + Optional.of( + DemandResponseLoadControlClusterTemperatureControlStruct.fromTlv( + ContextSpecificTag(TAG_TEMPERATURE_CONTROL), + tlvReader, + ) + ) + } else { + Optional.empty() + } + val averageLoadControl = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_AVERAGE_LOAD_CONTROL))) { + Optional.of( + DemandResponseLoadControlClusterAverageLoadControlStruct.fromTlv( + ContextSpecificTag(TAG_AVERAGE_LOAD_CONTROL), + tlvReader, + ) + ) + } else { + Optional.empty() + } + val dutyCycleControl = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_DUTY_CYCLE_CONTROL))) { + Optional.of( + DemandResponseLoadControlClusterDutyCycleControlStruct.fromTlv( + ContextSpecificTag(TAG_DUTY_CYCLE_CONTROL), + tlvReader, + ) + ) + } else { + Optional.empty() + } + val powerSavingsControl = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_POWER_SAVINGS_CONTROL))) { + Optional.of( + DemandResponseLoadControlClusterPowerSavingsControlStruct.fromTlv( + ContextSpecificTag(TAG_POWER_SAVINGS_CONTROL), + tlvReader, + ) + ) + } else { + Optional.empty() + } + val heatingSourceControl = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_HEATING_SOURCE_CONTROL))) { + Optional.of( + DemandResponseLoadControlClusterHeatingSourceControlStruct.fromTlv( + ContextSpecificTag(TAG_HEATING_SOURCE_CONTROL), + tlvReader, + ) + ) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return DemandResponseLoadControlClusterLoadControlEventTransitionStruct(duration, control, temperatureControl, averageLoadControl, dutyCycleControl, powerSavingsControl, heatingSourceControl) + return DemandResponseLoadControlClusterLoadControlEventTransitionStruct( + duration, + control, + temperatureControl, + averageLoadControl, + dutyCycleControl, + powerSavingsControl, + heatingSourceControl, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterLoadControlProgramStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterLoadControlProgramStruct.kt index 32b997de3d68cc..e22ed84158307e 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterLoadControlProgramStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterLoadControlProgramStruct.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -29,7 +27,7 @@ class DemandResponseLoadControlClusterLoadControlProgramStruct( val name: String, val enrollmentGroup: UByte?, val randomStartMinutes: UByte?, - val randomDurationMinutes: UByte? + val randomDurationMinutes: UByte?, ) { override fun toString(): String = buildString { append("DemandResponseLoadControlClusterLoadControlProgramStruct {\n") @@ -72,32 +70,44 @@ class DemandResponseLoadControlClusterLoadControlProgramStruct( private const val TAG_RANDOM_START_MINUTES = 3 private const val TAG_RANDOM_DURATION_MINUTES = 4 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): DemandResponseLoadControlClusterLoadControlProgramStruct { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): DemandResponseLoadControlClusterLoadControlProgramStruct { tlvReader.enterStructure(tlvTag) val programID = tlvReader.getByteArray(ContextSpecificTag(TAG_PROGRAM_ID)) val name = tlvReader.getString(ContextSpecificTag(TAG_NAME)) - val enrollmentGroup = if (!tlvReader.isNull()) { - tlvReader.getUByte(ContextSpecificTag(TAG_ENROLLMENT_GROUP)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_ENROLLMENT_GROUP)) - null - } - val randomStartMinutes = if (!tlvReader.isNull()) { - tlvReader.getUByte(ContextSpecificTag(TAG_RANDOM_START_MINUTES)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_RANDOM_START_MINUTES)) - null - } - val randomDurationMinutes = if (!tlvReader.isNull()) { - tlvReader.getUByte(ContextSpecificTag(TAG_RANDOM_DURATION_MINUTES)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_RANDOM_DURATION_MINUTES)) - null - } - + val enrollmentGroup = + if (!tlvReader.isNull()) { + tlvReader.getUByte(ContextSpecificTag(TAG_ENROLLMENT_GROUP)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_ENROLLMENT_GROUP)) + null + } + val randomStartMinutes = + if (!tlvReader.isNull()) { + tlvReader.getUByte(ContextSpecificTag(TAG_RANDOM_START_MINUTES)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_RANDOM_START_MINUTES)) + null + } + val randomDurationMinutes = + if (!tlvReader.isNull()) { + tlvReader.getUByte(ContextSpecificTag(TAG_RANDOM_DURATION_MINUTES)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_RANDOM_DURATION_MINUTES)) + null + } + tlvReader.exitContainer() - return DemandResponseLoadControlClusterLoadControlProgramStruct(programID, name, enrollmentGroup, randomStartMinutes, randomDurationMinutes) + return DemandResponseLoadControlClusterLoadControlProgramStruct( + programID, + name, + enrollmentGroup, + randomStartMinutes, + randomDurationMinutes, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterPowerSavingsControlStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterPowerSavingsControlStruct.kt index 08d7bc21262e2e..86fa69fc99fb1b 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterPowerSavingsControlStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterPowerSavingsControlStruct.kt @@ -16,17 +16,13 @@ */ package matter.controller.cluster.structs -import java.util.Optional 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 DemandResponseLoadControlClusterPowerSavingsControlStruct( - val powerSavings: UByte -) { +class DemandResponseLoadControlClusterPowerSavingsControlStruct(val powerSavings: UByte) { override fun toString(): String = buildString { append("DemandResponseLoadControlClusterPowerSavingsControlStruct {\n") append("\tpowerSavings : $powerSavings\n") @@ -44,10 +40,13 @@ class DemandResponseLoadControlClusterPowerSavingsControlStruct( companion object { private const val TAG_POWER_SAVINGS = 0 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): DemandResponseLoadControlClusterPowerSavingsControlStruct { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): DemandResponseLoadControlClusterPowerSavingsControlStruct { tlvReader.enterStructure(tlvTag) val powerSavings = tlvReader.getUByte(ContextSpecificTag(TAG_POWER_SAVINGS)) - + tlvReader.exitContainer() return DemandResponseLoadControlClusterPowerSavingsControlStruct(powerSavings) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterTemperatureControlStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterTemperatureControlStruct.kt index d6bd0cd2524906..099dfb3628e747 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterTemperatureControlStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/DemandResponseLoadControlClusterTemperatureControlStruct.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -28,7 +27,7 @@ class DemandResponseLoadControlClusterTemperatureControlStruct( val coolingTempOffset: Optional?, val heatingtTempOffset: Optional?, val coolingTempSetpoint: Optional?, - val heatingTempSetpoint: Optional? + val heatingTempSetpoint: Optional?, ) { override fun toString(): String = buildString { append("DemandResponseLoadControlClusterTemperatureControlStruct {\n") @@ -44,33 +43,33 @@ class DemandResponseLoadControlClusterTemperatureControlStruct( startStructure(tlvTag) if (coolingTempOffset != null) { if (coolingTempOffset.isPresent) { - val optcoolingTempOffset = coolingTempOffset.get() - put(ContextSpecificTag(TAG_COOLING_TEMP_OFFSET), optcoolingTempOffset) - } + val optcoolingTempOffset = coolingTempOffset.get() + put(ContextSpecificTag(TAG_COOLING_TEMP_OFFSET), optcoolingTempOffset) + } } else { putNull(ContextSpecificTag(TAG_COOLING_TEMP_OFFSET)) } if (heatingtTempOffset != null) { if (heatingtTempOffset.isPresent) { - val optheatingtTempOffset = heatingtTempOffset.get() - put(ContextSpecificTag(TAG_HEATINGT_TEMP_OFFSET), optheatingtTempOffset) - } + val optheatingtTempOffset = heatingtTempOffset.get() + put(ContextSpecificTag(TAG_HEATINGT_TEMP_OFFSET), optheatingtTempOffset) + } } else { putNull(ContextSpecificTag(TAG_HEATINGT_TEMP_OFFSET)) } if (coolingTempSetpoint != null) { if (coolingTempSetpoint.isPresent) { - val optcoolingTempSetpoint = coolingTempSetpoint.get() - put(ContextSpecificTag(TAG_COOLING_TEMP_SETPOINT), optcoolingTempSetpoint) - } + val optcoolingTempSetpoint = coolingTempSetpoint.get() + put(ContextSpecificTag(TAG_COOLING_TEMP_SETPOINT), optcoolingTempSetpoint) + } } else { putNull(ContextSpecificTag(TAG_COOLING_TEMP_SETPOINT)) } if (heatingTempSetpoint != null) { if (heatingTempSetpoint.isPresent) { - val optheatingTempSetpoint = heatingTempSetpoint.get() - put(ContextSpecificTag(TAG_HEATING_TEMP_SETPOINT), optheatingTempSetpoint) - } + val optheatingTempSetpoint = heatingTempSetpoint.get() + put(ContextSpecificTag(TAG_HEATING_TEMP_SETPOINT), optheatingTempSetpoint) + } } else { putNull(ContextSpecificTag(TAG_HEATING_TEMP_SETPOINT)) } @@ -84,52 +83,64 @@ class DemandResponseLoadControlClusterTemperatureControlStruct( private const val TAG_COOLING_TEMP_SETPOINT = 2 private const val TAG_HEATING_TEMP_SETPOINT = 3 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): DemandResponseLoadControlClusterTemperatureControlStruct { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): DemandResponseLoadControlClusterTemperatureControlStruct { tlvReader.enterStructure(tlvTag) - val coolingTempOffset = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_COOLING_TEMP_OFFSET))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_COOLING_TEMP_OFFSET))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_COOLING_TEMP_OFFSET)) - null - } - val heatingtTempOffset = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_HEATINGT_TEMP_OFFSET))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_HEATINGT_TEMP_OFFSET))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_HEATINGT_TEMP_OFFSET)) - null - } - val coolingTempSetpoint = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_COOLING_TEMP_SETPOINT))) { - Optional.of(tlvReader.getShort(ContextSpecificTag(TAG_COOLING_TEMP_SETPOINT))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_COOLING_TEMP_SETPOINT)) - null - } - val heatingTempSetpoint = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_HEATING_TEMP_SETPOINT))) { - Optional.of(tlvReader.getShort(ContextSpecificTag(TAG_HEATING_TEMP_SETPOINT))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_HEATING_TEMP_SETPOINT)) - null - } - + val coolingTempOffset = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_COOLING_TEMP_OFFSET))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_COOLING_TEMP_OFFSET))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_COOLING_TEMP_OFFSET)) + null + } + val heatingtTempOffset = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_HEATINGT_TEMP_OFFSET))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_HEATINGT_TEMP_OFFSET))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_HEATINGT_TEMP_OFFSET)) + null + } + val coolingTempSetpoint = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_COOLING_TEMP_SETPOINT))) { + Optional.of(tlvReader.getShort(ContextSpecificTag(TAG_COOLING_TEMP_SETPOINT))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_COOLING_TEMP_SETPOINT)) + null + } + val heatingTempSetpoint = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_HEATING_TEMP_SETPOINT))) { + Optional.of(tlvReader.getShort(ContextSpecificTag(TAG_HEATING_TEMP_SETPOINT))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_HEATING_TEMP_SETPOINT)) + null + } + tlvReader.exitContainer() - return DemandResponseLoadControlClusterTemperatureControlStruct(coolingTempOffset, heatingtTempOffset, coolingTempSetpoint, heatingTempSetpoint) + return DemandResponseLoadControlClusterTemperatureControlStruct( + coolingTempOffset, + heatingtTempOffset, + coolingTempSetpoint, + heatingTempSetpoint, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/DescriptorClusterDeviceTypeStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/DescriptorClusterDeviceTypeStruct.kt index 3b1d50b42659e8..c8cc82e04d50eb 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/DescriptorClusterDeviceTypeStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/DescriptorClusterDeviceTypeStruct.kt @@ -16,18 +16,13 @@ */ package matter.controller.cluster.structs -import java.util.Optional 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 DescriptorClusterDeviceTypeStruct( - val deviceType: UInt, - val revision: UShort -) { +class DescriptorClusterDeviceTypeStruct(val deviceType: UInt, val revision: UShort) { override fun toString(): String = buildString { append("DescriptorClusterDeviceTypeStruct {\n") append("\tdeviceType : $deviceType\n") @@ -52,7 +47,7 @@ class DescriptorClusterDeviceTypeStruct( tlvReader.enterStructure(tlvTag) val deviceType = tlvReader.getUInt(ContextSpecificTag(TAG_DEVICE_TYPE)) val revision = tlvReader.getUShort(ContextSpecificTag(TAG_REVISION)) - + tlvReader.exitContainer() return DescriptorClusterDeviceTypeStruct(deviceType, revision) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/DescriptorClusterSemanticTagStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/DescriptorClusterSemanticTagStruct.kt index 784537e96506e8..f0206f14fa26cc 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/DescriptorClusterSemanticTagStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/DescriptorClusterSemanticTagStruct.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -28,7 +27,7 @@ class DescriptorClusterSemanticTagStruct( val mfgCode: UShort?, val namespaceID: UByte, val tag: UByte, - val label: Optional? + val label: Optional?, ) { override fun toString(): String = buildString { append("DescriptorClusterSemanticTagStruct {\n") @@ -51,9 +50,9 @@ class DescriptorClusterSemanticTagStruct( put(ContextSpecificTag(TAG_TAG), tag) if (label != null) { if (label.isPresent) { - val optlabel = label.get() - put(ContextSpecificTag(TAG_LABEL), optlabel) - } + val optlabel = label.get() + put(ContextSpecificTag(TAG_LABEL), optlabel) + } } else { putNull(ContextSpecificTag(TAG_LABEL)) } @@ -69,25 +68,27 @@ class DescriptorClusterSemanticTagStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): DescriptorClusterSemanticTagStruct { tlvReader.enterStructure(tlvTag) - val mfgCode = if (!tlvReader.isNull()) { - tlvReader.getUShort(ContextSpecificTag(TAG_MFG_CODE)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_MFG_CODE)) - null - } + val mfgCode = + if (!tlvReader.isNull()) { + tlvReader.getUShort(ContextSpecificTag(TAG_MFG_CODE)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_MFG_CODE)) + null + } val namespaceID = tlvReader.getUByte(ContextSpecificTag(TAG_NAMESPACE_ID)) val tag = tlvReader.getUByte(ContextSpecificTag(TAG_TAG)) - val label = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_LABEL))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_LABEL))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_LABEL)) - null - } - + val label = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_LABEL))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_LABEL))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_LABEL)) + null + } + tlvReader.exitContainer() return DescriptorClusterSemanticTagStruct(mfgCode, namespaceID, tag, label) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterConstraintsStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterConstraintsStruct.kt index 0972701ad34688..f0f18cebb2e1e0 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterConstraintsStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterConstraintsStruct.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -29,7 +28,7 @@ class DeviceEnergyManagementClusterConstraintsStruct( val duration: UInt, val nominalPower: Optional, val maximumEnergy: Optional, - val loadControl: Optional + val loadControl: Optional, ) { override fun toString(): String = buildString { append("DeviceEnergyManagementClusterConstraintsStruct {\n") @@ -73,25 +72,34 @@ class DeviceEnergyManagementClusterConstraintsStruct( tlvReader.enterStructure(tlvTag) val startTime = tlvReader.getUInt(ContextSpecificTag(TAG_START_TIME)) val duration = tlvReader.getUInt(ContextSpecificTag(TAG_DURATION)) - val nominalPower = if (tlvReader.isNextTag(ContextSpecificTag(TAG_NOMINAL_POWER))) { - Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_NOMINAL_POWER))) - } else { - Optional.empty() - } - val maximumEnergy = if (tlvReader.isNextTag(ContextSpecificTag(TAG_MAXIMUM_ENERGY))) { - Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_MAXIMUM_ENERGY))) - } else { - Optional.empty() - } - val loadControl = if (tlvReader.isNextTag(ContextSpecificTag(TAG_LOAD_CONTROL))) { - Optional.of(tlvReader.getByte(ContextSpecificTag(TAG_LOAD_CONTROL))) - } else { - Optional.empty() - } - + val nominalPower = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_NOMINAL_POWER))) { + Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_NOMINAL_POWER))) + } else { + Optional.empty() + } + val maximumEnergy = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_MAXIMUM_ENERGY))) { + Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_MAXIMUM_ENERGY))) + } else { + Optional.empty() + } + val loadControl = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_LOAD_CONTROL))) { + Optional.of(tlvReader.getByte(ContextSpecificTag(TAG_LOAD_CONTROL))) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return DeviceEnergyManagementClusterConstraintsStruct(startTime, duration, nominalPower, maximumEnergy, loadControl) + return DeviceEnergyManagementClusterConstraintsStruct( + startTime, + duration, + nominalPower, + maximumEnergy, + loadControl, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterCostStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterCostStruct.kt index f75628b28ac4f9..71a113c9fd2b43 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterCostStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterCostStruct.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -28,7 +27,7 @@ class DeviceEnergyManagementClusterCostStruct( val costType: UByte, val value: Int, val decimalPoints: UByte, - val currency: Optional + val currency: Optional, ) { override fun toString(): String = buildString { append("DeviceEnergyManagementClusterCostStruct {\n") @@ -64,12 +63,13 @@ class DeviceEnergyManagementClusterCostStruct( val costType = tlvReader.getUByte(ContextSpecificTag(TAG_COST_TYPE)) val value = tlvReader.getInt(ContextSpecificTag(TAG_VALUE)) val decimalPoints = tlvReader.getUByte(ContextSpecificTag(TAG_DECIMAL_POINTS)) - val currency = if (tlvReader.isNextTag(ContextSpecificTag(TAG_CURRENCY))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_CURRENCY))) - } else { - Optional.empty() - } - + val currency = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_CURRENCY))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_CURRENCY))) + } else { + Optional.empty() + } + tlvReader.exitContainer() return DeviceEnergyManagementClusterCostStruct(costType, value, decimalPoints, currency) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterForecastStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterForecastStruct.kt index 050a8c6ae1d424..d10b032374dade 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterForecastStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterForecastStruct.kt @@ -33,7 +33,7 @@ class DeviceEnergyManagementClusterForecastStruct( val latestEndTime: Optional, val isPausable: Boolean, val slots: List, - val forecastUpdateReason: UByte + val forecastUpdateReason: UByte, ) { override fun toString(): String = buildString { append("DeviceEnergyManagementClusterForecastStruct {\n") @@ -62,9 +62,9 @@ class DeviceEnergyManagementClusterForecastStruct( put(ContextSpecificTag(TAG_END_TIME), endTime) if (earliestStartTime != null) { if (earliestStartTime.isPresent) { - val optearliestStartTime = earliestStartTime.get() - put(ContextSpecificTag(TAG_EARLIEST_START_TIME), optearliestStartTime) - } + val optearliestStartTime = earliestStartTime.get() + put(ContextSpecificTag(TAG_EARLIEST_START_TIME), optearliestStartTime) + } } else { putNull(ContextSpecificTag(TAG_EARLIEST_START_TIME)) } @@ -97,42 +97,56 @@ class DeviceEnergyManagementClusterForecastStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): DeviceEnergyManagementClusterForecastStruct { tlvReader.enterStructure(tlvTag) val forecastID = tlvReader.getUInt(ContextSpecificTag(TAG_FORECAST_ID)) - val activeSlotNumber = if (!tlvReader.isNull()) { - tlvReader.getUShort(ContextSpecificTag(TAG_ACTIVE_SLOT_NUMBER)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_ACTIVE_SLOT_NUMBER)) - null - } + val activeSlotNumber = + if (!tlvReader.isNull()) { + tlvReader.getUShort(ContextSpecificTag(TAG_ACTIVE_SLOT_NUMBER)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_ACTIVE_SLOT_NUMBER)) + null + } val startTime = tlvReader.getUInt(ContextSpecificTag(TAG_START_TIME)) val endTime = tlvReader.getUInt(ContextSpecificTag(TAG_END_TIME)) - val earliestStartTime = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_EARLIEST_START_TIME))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_EARLIEST_START_TIME))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_EARLIEST_START_TIME)) - null - } - val latestEndTime = if (tlvReader.isNextTag(ContextSpecificTag(TAG_LATEST_END_TIME))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_LATEST_END_TIME))) - } else { - Optional.empty() - } + val earliestStartTime = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_EARLIEST_START_TIME))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_EARLIEST_START_TIME))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_EARLIEST_START_TIME)) + null + } + val latestEndTime = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_LATEST_END_TIME))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_LATEST_END_TIME))) + } else { + Optional.empty() + } val isPausable = tlvReader.getBoolean(ContextSpecificTag(TAG_IS_PAUSABLE)) - val slots = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_SLOTS)) - while(!tlvReader.isEndOfContainer()) { - add(DeviceEnergyManagementClusterSlotStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } + val slots = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_SLOTS)) + while (!tlvReader.isEndOfContainer()) { + add(DeviceEnergyManagementClusterSlotStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } val forecastUpdateReason = tlvReader.getUByte(ContextSpecificTag(TAG_FORECAST_UPDATE_REASON)) - + tlvReader.exitContainer() - return DeviceEnergyManagementClusterForecastStruct(forecastID, activeSlotNumber, startTime, endTime, earliestStartTime, latestEndTime, isPausable, slots, forecastUpdateReason) + return DeviceEnergyManagementClusterForecastStruct( + forecastID, + activeSlotNumber, + startTime, + endTime, + earliestStartTime, + latestEndTime, + isPausable, + slots, + forecastUpdateReason, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterPowerAdjustCapabilityStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterPowerAdjustCapabilityStruct.kt index 188f6bffef9f73..0c1409014d254b 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterPowerAdjustCapabilityStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterPowerAdjustCapabilityStruct.kt @@ -16,7 +16,6 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -26,7 +25,7 @@ import matter.tlv.TlvWriter class DeviceEnergyManagementClusterPowerAdjustCapabilityStruct( val powerAdjustCapability: List?, - val cause: UByte + val cause: UByte, ) { override fun toString(): String = buildString { append("DeviceEnergyManagementClusterPowerAdjustCapabilityStruct {\n") @@ -40,10 +39,10 @@ class DeviceEnergyManagementClusterPowerAdjustCapabilityStruct( startStructure(tlvTag) if (powerAdjustCapability != null) { startArray(ContextSpecificTag(TAG_POWER_ADJUST_CAPABILITY)) - for (item in powerAdjustCapability.iterator()) { - item.toTlv(AnonymousTag, this) - } - endArray() + for (item in powerAdjustCapability.iterator()) { + item.toTlv(AnonymousTag, this) + } + endArray() } else { putNull(ContextSpecificTag(TAG_POWER_ADJUST_CAPABILITY)) } @@ -56,22 +55,26 @@ class DeviceEnergyManagementClusterPowerAdjustCapabilityStruct( private const val TAG_POWER_ADJUST_CAPABILITY = 0 private const val TAG_CAUSE = 1 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): DeviceEnergyManagementClusterPowerAdjustCapabilityStruct { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): DeviceEnergyManagementClusterPowerAdjustCapabilityStruct { tlvReader.enterStructure(tlvTag) - val powerAdjustCapability = if (!tlvReader.isNull()) { - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_POWER_ADJUST_CAPABILITY)) - while(!tlvReader.isEndOfContainer()) { - add(DeviceEnergyManagementClusterPowerAdjustStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_POWER_ADJUST_CAPABILITY)) - null - } + val powerAdjustCapability = + if (!tlvReader.isNull()) { + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_POWER_ADJUST_CAPABILITY)) + while (!tlvReader.isEndOfContainer()) { + add(DeviceEnergyManagementClusterPowerAdjustStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_POWER_ADJUST_CAPABILITY)) + null + } val cause = tlvReader.getUByte(ContextSpecificTag(TAG_CAUSE)) - + tlvReader.exitContainer() return DeviceEnergyManagementClusterPowerAdjustCapabilityStruct(powerAdjustCapability, cause) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterPowerAdjustStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterPowerAdjustStruct.kt index f03165bcf17f94..c7a29be35ead97 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterPowerAdjustStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterPowerAdjustStruct.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -28,7 +26,7 @@ class DeviceEnergyManagementClusterPowerAdjustStruct( val minPower: Long, val maxPower: Long, val minDuration: UInt, - val maxDuration: UInt + val maxDuration: UInt, ) { override fun toString(): String = buildString { append("DeviceEnergyManagementClusterPowerAdjustStruct {\n") @@ -62,10 +60,15 @@ class DeviceEnergyManagementClusterPowerAdjustStruct( val maxPower = tlvReader.getLong(ContextSpecificTag(TAG_MAX_POWER)) val minDuration = tlvReader.getUInt(ContextSpecificTag(TAG_MIN_DURATION)) val maxDuration = tlvReader.getUInt(ContextSpecificTag(TAG_MAX_DURATION)) - + tlvReader.exitContainer() - return DeviceEnergyManagementClusterPowerAdjustStruct(minPower, maxPower, minDuration, maxDuration) + return DeviceEnergyManagementClusterPowerAdjustStruct( + minPower, + maxPower, + minDuration, + maxDuration, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterSlotAdjustmentStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterSlotAdjustmentStruct.kt index 5be69214a8dfd4..34dc8ddf4b2864 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterSlotAdjustmentStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterSlotAdjustmentStruct.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -27,7 +26,7 @@ import matter.tlv.TlvWriter class DeviceEnergyManagementClusterSlotAdjustmentStruct( val slotIndex: UByte, val nominalPower: Optional, - val duration: UInt + val duration: UInt, ) { override fun toString(): String = buildString { append("DeviceEnergyManagementClusterSlotAdjustmentStruct {\n") @@ -55,16 +54,20 @@ class DeviceEnergyManagementClusterSlotAdjustmentStruct( private const val TAG_NOMINAL_POWER = 1 private const val TAG_DURATION = 2 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): DeviceEnergyManagementClusterSlotAdjustmentStruct { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): DeviceEnergyManagementClusterSlotAdjustmentStruct { tlvReader.enterStructure(tlvTag) val slotIndex = tlvReader.getUByte(ContextSpecificTag(TAG_SLOT_INDEX)) - val nominalPower = if (tlvReader.isNextTag(ContextSpecificTag(TAG_NOMINAL_POWER))) { - Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_NOMINAL_POWER))) - } else { - Optional.empty() - } + val nominalPower = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_NOMINAL_POWER))) { + Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_NOMINAL_POWER))) + } else { + Optional.empty() + } val duration = tlvReader.getUInt(ContextSpecificTag(TAG_DURATION)) - + tlvReader.exitContainer() return DeviceEnergyManagementClusterSlotAdjustmentStruct(slotIndex, nominalPower, duration) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterSlotStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterSlotStruct.kt index 2d723d6c772bdc..d1babaf255c322 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterSlotStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementClusterSlotStruct.kt @@ -42,7 +42,7 @@ class DeviceEnergyManagementClusterSlotStruct( val minPowerAdjustment: Optional, val maxPowerAdjustment: Optional, val minDurationAdjustment: Optional, - val maxDurationAdjustment: Optional + val maxDurationAdjustment: Optional, ) { override fun toString(): String = buildString { append("DeviceEnergyManagementClusterSlotStruct {\n") @@ -110,10 +110,10 @@ class DeviceEnergyManagementClusterSlotStruct( if (costs.isPresent) { val optcosts = costs.get() startArray(ContextSpecificTag(TAG_COSTS)) - for (item in optcosts.iterator()) { - item.toTlv(AnonymousTag, this) - } - endArray() + for (item in optcosts.iterator()) { + item.toTlv(AnonymousTag, this) + } + endArray() } if (minPowerAdjustment.isPresent) { val optminPowerAdjustment = minPowerAdjustment.get() @@ -162,81 +162,115 @@ class DeviceEnergyManagementClusterSlotStruct( val defaultDuration = tlvReader.getUInt(ContextSpecificTag(TAG_DEFAULT_DURATION)) val elapsedSlotTime = tlvReader.getUInt(ContextSpecificTag(TAG_ELAPSED_SLOT_TIME)) val remainingSlotTime = tlvReader.getUInt(ContextSpecificTag(TAG_REMAINING_SLOT_TIME)) - val slotIsPausable = if (tlvReader.isNextTag(ContextSpecificTag(TAG_SLOT_IS_PAUSABLE))) { - Optional.of(tlvReader.getBoolean(ContextSpecificTag(TAG_SLOT_IS_PAUSABLE))) - } else { - Optional.empty() - } - val minPauseDuration = if (tlvReader.isNextTag(ContextSpecificTag(TAG_MIN_PAUSE_DURATION))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_MIN_PAUSE_DURATION))) - } else { - Optional.empty() - } - val maxPauseDuration = if (tlvReader.isNextTag(ContextSpecificTag(TAG_MAX_PAUSE_DURATION))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_MAX_PAUSE_DURATION))) - } else { - Optional.empty() - } - val manufacturerESAState = if (tlvReader.isNextTag(ContextSpecificTag(TAG_MANUFACTURER_ESA_STATE))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_MANUFACTURER_ESA_STATE))) - } else { - Optional.empty() - } - val nominalPower = if (tlvReader.isNextTag(ContextSpecificTag(TAG_NOMINAL_POWER))) { - Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_NOMINAL_POWER))) - } else { - Optional.empty() - } - val minPower = if (tlvReader.isNextTag(ContextSpecificTag(TAG_MIN_POWER))) { - Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_MIN_POWER))) - } else { - Optional.empty() - } - val maxPower = if (tlvReader.isNextTag(ContextSpecificTag(TAG_MAX_POWER))) { - Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_MAX_POWER))) - } else { - Optional.empty() - } - val nominalEnergy = if (tlvReader.isNextTag(ContextSpecificTag(TAG_NOMINAL_ENERGY))) { - Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_NOMINAL_ENERGY))) - } else { - Optional.empty() - } - val costs = if (tlvReader.isNextTag(ContextSpecificTag(TAG_COSTS))) { - Optional.of(buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_COSTS)) - while(!tlvReader.isEndOfContainer()) { - add(DeviceEnergyManagementClusterCostStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - }) - } else { - Optional.empty() - } - val minPowerAdjustment = if (tlvReader.isNextTag(ContextSpecificTag(TAG_MIN_POWER_ADJUSTMENT))) { - Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_MIN_POWER_ADJUSTMENT))) - } else { - Optional.empty() - } - val maxPowerAdjustment = if (tlvReader.isNextTag(ContextSpecificTag(TAG_MAX_POWER_ADJUSTMENT))) { - Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_MAX_POWER_ADJUSTMENT))) - } else { - Optional.empty() - } - val minDurationAdjustment = if (tlvReader.isNextTag(ContextSpecificTag(TAG_MIN_DURATION_ADJUSTMENT))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_MIN_DURATION_ADJUSTMENT))) - } else { - Optional.empty() - } - val maxDurationAdjustment = if (tlvReader.isNextTag(ContextSpecificTag(TAG_MAX_DURATION_ADJUSTMENT))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_MAX_DURATION_ADJUSTMENT))) - } else { - Optional.empty() - } - + val slotIsPausable = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_SLOT_IS_PAUSABLE))) { + Optional.of(tlvReader.getBoolean(ContextSpecificTag(TAG_SLOT_IS_PAUSABLE))) + } else { + Optional.empty() + } + val minPauseDuration = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_MIN_PAUSE_DURATION))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_MIN_PAUSE_DURATION))) + } else { + Optional.empty() + } + val maxPauseDuration = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_MAX_PAUSE_DURATION))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_MAX_PAUSE_DURATION))) + } else { + Optional.empty() + } + val manufacturerESAState = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_MANUFACTURER_ESA_STATE))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_MANUFACTURER_ESA_STATE))) + } else { + Optional.empty() + } + val nominalPower = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_NOMINAL_POWER))) { + Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_NOMINAL_POWER))) + } else { + Optional.empty() + } + val minPower = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_MIN_POWER))) { + Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_MIN_POWER))) + } else { + Optional.empty() + } + val maxPower = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_MAX_POWER))) { + Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_MAX_POWER))) + } else { + Optional.empty() + } + val nominalEnergy = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_NOMINAL_ENERGY))) { + Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_NOMINAL_ENERGY))) + } else { + Optional.empty() + } + val costs = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_COSTS))) { + Optional.of( + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_COSTS)) + while (!tlvReader.isEndOfContainer()) { + add(DeviceEnergyManagementClusterCostStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + ) + } else { + Optional.empty() + } + val minPowerAdjustment = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_MIN_POWER_ADJUSTMENT))) { + Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_MIN_POWER_ADJUSTMENT))) + } else { + Optional.empty() + } + val maxPowerAdjustment = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_MAX_POWER_ADJUSTMENT))) { + Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_MAX_POWER_ADJUSTMENT))) + } else { + Optional.empty() + } + val minDurationAdjustment = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_MIN_DURATION_ADJUSTMENT))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_MIN_DURATION_ADJUSTMENT))) + } else { + Optional.empty() + } + val maxDurationAdjustment = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_MAX_DURATION_ADJUSTMENT))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_MAX_DURATION_ADJUSTMENT))) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return DeviceEnergyManagementClusterSlotStruct(minDuration, maxDuration, defaultDuration, elapsedSlotTime, remainingSlotTime, slotIsPausable, minPauseDuration, maxPauseDuration, manufacturerESAState, nominalPower, minPower, maxPower, nominalEnergy, costs, minPowerAdjustment, maxPowerAdjustment, minDurationAdjustment, maxDurationAdjustment) + return DeviceEnergyManagementClusterSlotStruct( + minDuration, + maxDuration, + defaultDuration, + elapsedSlotTime, + remainingSlotTime, + slotIsPausable, + minPauseDuration, + maxPauseDuration, + manufacturerESAState, + nominalPower, + minPower, + maxPower, + nominalEnergy, + costs, + minPowerAdjustment, + maxPowerAdjustment, + minDurationAdjustment, + maxDurationAdjustment, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementModeClusterModeOptionStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementModeClusterModeOptionStruct.kt index e506d757bc4d25..1193974cf9a915 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementModeClusterModeOptionStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementModeClusterModeOptionStruct.kt @@ -16,7 +16,6 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -27,7 +26,7 @@ import matter.tlv.TlvWriter class DeviceEnergyManagementModeClusterModeOptionStruct( val label: String, val mode: UByte, - val modeTags: List + val modeTags: List, ) { override fun toString(): String = buildString { append("DeviceEnergyManagementModeClusterModeOptionStruct {\n") @@ -56,18 +55,22 @@ class DeviceEnergyManagementModeClusterModeOptionStruct( private const val TAG_MODE = 1 private const val TAG_MODE_TAGS = 2 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): DeviceEnergyManagementModeClusterModeOptionStruct { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): DeviceEnergyManagementModeClusterModeOptionStruct { tlvReader.enterStructure(tlvTag) val label = tlvReader.getString(ContextSpecificTag(TAG_LABEL)) val mode = tlvReader.getUByte(ContextSpecificTag(TAG_MODE)) - val modeTags = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_MODE_TAGS)) - while(!tlvReader.isEndOfContainer()) { - add(DeviceEnergyManagementModeClusterModeTagStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - + val modeTags = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_MODE_TAGS)) + while (!tlvReader.isEndOfContainer()) { + add(DeviceEnergyManagementModeClusterModeTagStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + tlvReader.exitContainer() return DeviceEnergyManagementModeClusterModeOptionStruct(label, mode, modeTags) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementModeClusterModeTagStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementModeClusterModeTagStruct.kt index 50409c33b33106..740b9abf0fd5b2 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementModeClusterModeTagStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/DeviceEnergyManagementModeClusterModeTagStruct.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +25,7 @@ import matter.tlv.TlvWriter class DeviceEnergyManagementModeClusterModeTagStruct( val mfgCode: Optional, - val value: UShort + val value: UShort, ) { override fun toString(): String = buildString { append("DeviceEnergyManagementModeClusterModeTagStruct {\n") @@ -53,13 +52,14 @@ class DeviceEnergyManagementModeClusterModeTagStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): DeviceEnergyManagementModeClusterModeTagStruct { tlvReader.enterStructure(tlvTag) - val mfgCode = if (tlvReader.isNextTag(ContextSpecificTag(TAG_MFG_CODE))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_MFG_CODE))) - } else { - Optional.empty() - } + val mfgCode = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_MFG_CODE))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_MFG_CODE))) + } else { + Optional.empty() + } val value = tlvReader.getUShort(ContextSpecificTag(TAG_VALUE)) - + tlvReader.exitContainer() return DeviceEnergyManagementModeClusterModeTagStruct(mfgCode, value) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/DishwasherModeClusterModeOptionStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/DishwasherModeClusterModeOptionStruct.kt index d250f1c10ccccc..f0b1a134612e7d 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/DishwasherModeClusterModeOptionStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/DishwasherModeClusterModeOptionStruct.kt @@ -16,7 +16,6 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -27,7 +26,7 @@ import matter.tlv.TlvWriter class DishwasherModeClusterModeOptionStruct( val label: String, val mode: UByte, - val modeTags: List + val modeTags: List, ) { override fun toString(): String = buildString { append("DishwasherModeClusterModeOptionStruct {\n") @@ -60,14 +59,15 @@ class DishwasherModeClusterModeOptionStruct( tlvReader.enterStructure(tlvTag) val label = tlvReader.getString(ContextSpecificTag(TAG_LABEL)) val mode = tlvReader.getUByte(ContextSpecificTag(TAG_MODE)) - val modeTags = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_MODE_TAGS)) - while(!tlvReader.isEndOfContainer()) { - add(DishwasherModeClusterModeTagStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - + val modeTags = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_MODE_TAGS)) + while (!tlvReader.isEndOfContainer()) { + add(DishwasherModeClusterModeTagStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + tlvReader.exitContainer() return DishwasherModeClusterModeOptionStruct(label, mode, modeTags) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/DishwasherModeClusterModeTagStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/DishwasherModeClusterModeTagStruct.kt index 033e60f5419f37..584dc79028182c 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/DishwasherModeClusterModeTagStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/DishwasherModeClusterModeTagStruct.kt @@ -18,16 +18,12 @@ package matter.controller.cluster.structs import java.util.Optional 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 DishwasherModeClusterModeTagStruct( - val mfgCode: Optional, - val value: UShort -) { +class DishwasherModeClusterModeTagStruct(val mfgCode: Optional, val value: UShort) { override fun toString(): String = buildString { append("DishwasherModeClusterModeTagStruct {\n") append("\tmfgCode : $mfgCode\n") @@ -53,13 +49,14 @@ class DishwasherModeClusterModeTagStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): DishwasherModeClusterModeTagStruct { tlvReader.enterStructure(tlvTag) - val mfgCode = if (tlvReader.isNextTag(ContextSpecificTag(TAG_MFG_CODE))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_MFG_CODE))) - } else { - Optional.empty() - } + val mfgCode = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_MFG_CODE))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_MFG_CODE))) + } else { + Optional.empty() + } val value = tlvReader.getUShort(ContextSpecificTag(TAG_VALUE)) - + tlvReader.exitContainer() return DishwasherModeClusterModeTagStruct(mfgCode, value) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/DoorLockClusterCredentialStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/DoorLockClusterCredentialStruct.kt index 5f2b5c37f2d96e..f66b57f47660ca 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/DoorLockClusterCredentialStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/DoorLockClusterCredentialStruct.kt @@ -16,18 +16,13 @@ */ package matter.controller.cluster.structs -import java.util.Optional 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 DoorLockClusterCredentialStruct( - val credentialType: UByte, - val credentialIndex: UShort -) { +class DoorLockClusterCredentialStruct(val credentialType: UByte, val credentialIndex: UShort) { override fun toString(): String = buildString { append("DoorLockClusterCredentialStruct {\n") append("\tcredentialType : $credentialType\n") @@ -52,7 +47,7 @@ class DoorLockClusterCredentialStruct( tlvReader.enterStructure(tlvTag) val credentialType = tlvReader.getUByte(ContextSpecificTag(TAG_CREDENTIAL_TYPE)) val credentialIndex = tlvReader.getUShort(ContextSpecificTag(TAG_CREDENTIAL_INDEX)) - + tlvReader.exitContainer() return DoorLockClusterCredentialStruct(credentialType, credentialIndex) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/EcosystemInformationClusterDeviceTypeStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/EcosystemInformationClusterDeviceTypeStruct.kt index 899c6a799f293e..1ebb7b6abd3f60 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/EcosystemInformationClusterDeviceTypeStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/EcosystemInformationClusterDeviceTypeStruct.kt @@ -16,18 +16,13 @@ */ package matter.controller.cluster.structs -import java.util.Optional 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 EcosystemInformationClusterDeviceTypeStruct( - val deviceType: UInt, - val revision: UShort -) { +class EcosystemInformationClusterDeviceTypeStruct(val deviceType: UInt, val revision: UShort) { override fun toString(): String = buildString { append("EcosystemInformationClusterDeviceTypeStruct {\n") append("\tdeviceType : $deviceType\n") @@ -52,7 +47,7 @@ class EcosystemInformationClusterDeviceTypeStruct( tlvReader.enterStructure(tlvTag) val deviceType = tlvReader.getUInt(ContextSpecificTag(TAG_DEVICE_TYPE)) val revision = tlvReader.getUShort(ContextSpecificTag(TAG_REVISION)) - + tlvReader.exitContainer() return EcosystemInformationClusterDeviceTypeStruct(deviceType, revision) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/EcosystemInformationClusterEcosystemDeviceStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/EcosystemInformationClusterEcosystemDeviceStruct.kt index 1a5d4c1d620374..0f04e02f973a58 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/EcosystemInformationClusterEcosystemDeviceStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/EcosystemInformationClusterEcosystemDeviceStruct.kt @@ -32,7 +32,7 @@ class EcosystemInformationClusterEcosystemDeviceStruct( val deviceTypes: List, val uniqueLocationIDs: List, val uniqueLocationIDsLastEdit: ULong, - val fabricIndex: UByte + val fabricIndex: UByte, ) { override fun toString(): String = buildString { append("EcosystemInformationClusterEcosystemDeviceStruct {\n") @@ -86,40 +86,57 @@ class EcosystemInformationClusterEcosystemDeviceStruct( private const val TAG_UNIQUE_LOCATION_I_DS_LAST_EDIT = 6 private const val TAG_FABRIC_INDEX = 254 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): EcosystemInformationClusterEcosystemDeviceStruct { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): EcosystemInformationClusterEcosystemDeviceStruct { tlvReader.enterStructure(tlvTag) - val deviceName = if (tlvReader.isNextTag(ContextSpecificTag(TAG_DEVICE_NAME))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_DEVICE_NAME))) - } else { - Optional.empty() - } - val deviceNameLastEdit = if (tlvReader.isNextTag(ContextSpecificTag(TAG_DEVICE_NAME_LAST_EDIT))) { - Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_DEVICE_NAME_LAST_EDIT))) - } else { - Optional.empty() - } + val deviceName = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_DEVICE_NAME))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_DEVICE_NAME))) + } else { + Optional.empty() + } + val deviceNameLastEdit = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_DEVICE_NAME_LAST_EDIT))) { + Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_DEVICE_NAME_LAST_EDIT))) + } else { + Optional.empty() + } val bridgedEndpoint = tlvReader.getUShort(ContextSpecificTag(TAG_BRIDGED_ENDPOINT)) val originalEndpoint = tlvReader.getUShort(ContextSpecificTag(TAG_ORIGINAL_ENDPOINT)) - val deviceTypes = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_DEVICE_TYPES)) - while(!tlvReader.isEndOfContainer()) { - add(EcosystemInformationClusterDeviceTypeStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - val uniqueLocationIDs = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_UNIQUE_LOCATION_I_DS)) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getString(AnonymousTag)) - } - tlvReader.exitContainer() - } - val uniqueLocationIDsLastEdit = tlvReader.getULong(ContextSpecificTag(TAG_UNIQUE_LOCATION_I_DS_LAST_EDIT)) + val deviceTypes = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_DEVICE_TYPES)) + while (!tlvReader.isEndOfContainer()) { + add(EcosystemInformationClusterDeviceTypeStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + val uniqueLocationIDs = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_UNIQUE_LOCATION_I_DS)) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getString(AnonymousTag)) + } + tlvReader.exitContainer() + } + val uniqueLocationIDsLastEdit = + tlvReader.getULong(ContextSpecificTag(TAG_UNIQUE_LOCATION_I_DS_LAST_EDIT)) val fabricIndex = tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) - + tlvReader.exitContainer() - return EcosystemInformationClusterEcosystemDeviceStruct(deviceName, deviceNameLastEdit, bridgedEndpoint, originalEndpoint, deviceTypes, uniqueLocationIDs, uniqueLocationIDsLastEdit, fabricIndex) + return EcosystemInformationClusterEcosystemDeviceStruct( + deviceName, + deviceNameLastEdit, + bridgedEndpoint, + originalEndpoint, + deviceTypes, + uniqueLocationIDs, + uniqueLocationIDsLastEdit, + fabricIndex, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/EcosystemInformationClusterEcosystemLocationStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/EcosystemInformationClusterEcosystemLocationStruct.kt index 7e161959c5c9e6..f59492e6195cfd 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/EcosystemInformationClusterEcosystemLocationStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/EcosystemInformationClusterEcosystemLocationStruct.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -28,7 +26,7 @@ class EcosystemInformationClusterEcosystemLocationStruct( val uniqueLocationID: String, val locationDescriptor: EcosystemInformationClusterLocationDescriptorStruct, val locationDescriptorLastEdit: ULong, - val fabricIndex: UByte + val fabricIndex: UByte, ) { override fun toString(): String = buildString { append("EcosystemInformationClusterEcosystemLocationStruct {\n") @@ -56,16 +54,29 @@ class EcosystemInformationClusterEcosystemLocationStruct( private const val TAG_LOCATION_DESCRIPTOR_LAST_EDIT = 2 private const val TAG_FABRIC_INDEX = 254 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): EcosystemInformationClusterEcosystemLocationStruct { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): EcosystemInformationClusterEcosystemLocationStruct { tlvReader.enterStructure(tlvTag) val uniqueLocationID = tlvReader.getString(ContextSpecificTag(TAG_UNIQUE_LOCATION_ID)) - val locationDescriptor = EcosystemInformationClusterLocationDescriptorStruct.fromTlv(ContextSpecificTag(TAG_LOCATION_DESCRIPTOR), tlvReader) - val locationDescriptorLastEdit = tlvReader.getULong(ContextSpecificTag(TAG_LOCATION_DESCRIPTOR_LAST_EDIT)) + val locationDescriptor = + EcosystemInformationClusterLocationDescriptorStruct.fromTlv( + ContextSpecificTag(TAG_LOCATION_DESCRIPTOR), + tlvReader, + ) + val locationDescriptorLastEdit = + tlvReader.getULong(ContextSpecificTag(TAG_LOCATION_DESCRIPTOR_LAST_EDIT)) val fabricIndex = tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) - + tlvReader.exitContainer() - return EcosystemInformationClusterEcosystemLocationStruct(uniqueLocationID, locationDescriptor, locationDescriptorLastEdit, fabricIndex) + return EcosystemInformationClusterEcosystemLocationStruct( + uniqueLocationID, + locationDescriptor, + locationDescriptorLastEdit, + fabricIndex, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/EcosystemInformationClusterLocationDescriptorStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/EcosystemInformationClusterLocationDescriptorStruct.kt index 596c2c5c7ad6c7..ddb0f9498efefc 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/EcosystemInformationClusterLocationDescriptorStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/EcosystemInformationClusterLocationDescriptorStruct.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -27,7 +25,7 @@ import matter.tlv.TlvWriter class EcosystemInformationClusterLocationDescriptorStruct( val locationName: String, val floorNumber: Short?, - val areaType: UByte? + val areaType: UByte?, ) { override fun toString(): String = buildString { append("EcosystemInformationClusterLocationDescriptorStruct {\n") @@ -60,25 +58,34 @@ class EcosystemInformationClusterLocationDescriptorStruct( private const val TAG_FLOOR_NUMBER = 1 private const val TAG_AREA_TYPE = 2 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): EcosystemInformationClusterLocationDescriptorStruct { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): EcosystemInformationClusterLocationDescriptorStruct { tlvReader.enterStructure(tlvTag) val locationName = tlvReader.getString(ContextSpecificTag(TAG_LOCATION_NAME)) - val floorNumber = if (!tlvReader.isNull()) { - tlvReader.getShort(ContextSpecificTag(TAG_FLOOR_NUMBER)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_FLOOR_NUMBER)) - null - } - val areaType = if (!tlvReader.isNull()) { - tlvReader.getUByte(ContextSpecificTag(TAG_AREA_TYPE)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_AREA_TYPE)) - null - } - + val floorNumber = + if (!tlvReader.isNull()) { + tlvReader.getShort(ContextSpecificTag(TAG_FLOOR_NUMBER)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_FLOOR_NUMBER)) + null + } + val areaType = + if (!tlvReader.isNull()) { + tlvReader.getUByte(ContextSpecificTag(TAG_AREA_TYPE)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_AREA_TYPE)) + null + } + tlvReader.exitContainer() - return EcosystemInformationClusterLocationDescriptorStruct(locationName, floorNumber, areaType) + return EcosystemInformationClusterLocationDescriptorStruct( + locationName, + floorNumber, + areaType, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct.kt index 0827d8124cf55e..8189ee00cb6b0a 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -28,7 +27,7 @@ class ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct( val importedResetTimestamp: Optional?, val exportedResetTimestamp: Optional?, val importedResetSystime: Optional?, - val exportedResetSystime: Optional? + val exportedResetSystime: Optional?, ) { override fun toString(): String = buildString { append("ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct {\n") @@ -44,33 +43,33 @@ class ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct( startStructure(tlvTag) if (importedResetTimestamp != null) { if (importedResetTimestamp.isPresent) { - val optimportedResetTimestamp = importedResetTimestamp.get() - put(ContextSpecificTag(TAG_IMPORTED_RESET_TIMESTAMP), optimportedResetTimestamp) - } + val optimportedResetTimestamp = importedResetTimestamp.get() + put(ContextSpecificTag(TAG_IMPORTED_RESET_TIMESTAMP), optimportedResetTimestamp) + } } else { putNull(ContextSpecificTag(TAG_IMPORTED_RESET_TIMESTAMP)) } if (exportedResetTimestamp != null) { if (exportedResetTimestamp.isPresent) { - val optexportedResetTimestamp = exportedResetTimestamp.get() - put(ContextSpecificTag(TAG_EXPORTED_RESET_TIMESTAMP), optexportedResetTimestamp) - } + val optexportedResetTimestamp = exportedResetTimestamp.get() + put(ContextSpecificTag(TAG_EXPORTED_RESET_TIMESTAMP), optexportedResetTimestamp) + } } else { putNull(ContextSpecificTag(TAG_EXPORTED_RESET_TIMESTAMP)) } if (importedResetSystime != null) { if (importedResetSystime.isPresent) { - val optimportedResetSystime = importedResetSystime.get() - put(ContextSpecificTag(TAG_IMPORTED_RESET_SYSTIME), optimportedResetSystime) - } + val optimportedResetSystime = importedResetSystime.get() + put(ContextSpecificTag(TAG_IMPORTED_RESET_SYSTIME), optimportedResetSystime) + } } else { putNull(ContextSpecificTag(TAG_IMPORTED_RESET_SYSTIME)) } if (exportedResetSystime != null) { if (exportedResetSystime.isPresent) { - val optexportedResetSystime = exportedResetSystime.get() - put(ContextSpecificTag(TAG_EXPORTED_RESET_SYSTIME), optexportedResetSystime) - } + val optexportedResetSystime = exportedResetSystime.get() + put(ContextSpecificTag(TAG_EXPORTED_RESET_SYSTIME), optexportedResetSystime) + } } else { putNull(ContextSpecificTag(TAG_EXPORTED_RESET_SYSTIME)) } @@ -84,52 +83,64 @@ class ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct( private const val TAG_IMPORTED_RESET_SYSTIME = 2 private const val TAG_EXPORTED_RESET_SYSTIME = 3 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct { tlvReader.enterStructure(tlvTag) - val importedResetTimestamp = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_IMPORTED_RESET_TIMESTAMP))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_IMPORTED_RESET_TIMESTAMP))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_IMPORTED_RESET_TIMESTAMP)) - null - } - val exportedResetTimestamp = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_EXPORTED_RESET_TIMESTAMP))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_EXPORTED_RESET_TIMESTAMP))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_EXPORTED_RESET_TIMESTAMP)) - null - } - val importedResetSystime = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_IMPORTED_RESET_SYSTIME))) { - Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_IMPORTED_RESET_SYSTIME))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_IMPORTED_RESET_SYSTIME)) - null - } - val exportedResetSystime = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_EXPORTED_RESET_SYSTIME))) { - Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_EXPORTED_RESET_SYSTIME))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_EXPORTED_RESET_SYSTIME)) - null - } - + val importedResetTimestamp = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_IMPORTED_RESET_TIMESTAMP))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_IMPORTED_RESET_TIMESTAMP))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_IMPORTED_RESET_TIMESTAMP)) + null + } + val exportedResetTimestamp = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_EXPORTED_RESET_TIMESTAMP))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_EXPORTED_RESET_TIMESTAMP))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_EXPORTED_RESET_TIMESTAMP)) + null + } + val importedResetSystime = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_IMPORTED_RESET_SYSTIME))) { + Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_IMPORTED_RESET_SYSTIME))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_IMPORTED_RESET_SYSTIME)) + null + } + val exportedResetSystime = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_EXPORTED_RESET_SYSTIME))) { + Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_EXPORTED_RESET_SYSTIME))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_EXPORTED_RESET_SYSTIME)) + null + } + tlvReader.exitContainer() - return ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct(importedResetTimestamp, exportedResetTimestamp, importedResetSystime, exportedResetSystime) + return ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct( + importedResetTimestamp, + exportedResetTimestamp, + importedResetSystime, + exportedResetSystime, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalEnergyMeasurementClusterEnergyMeasurementStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalEnergyMeasurementClusterEnergyMeasurementStruct.kt index 397f1eab428ecf..5842533174f022 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalEnergyMeasurementClusterEnergyMeasurementStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalEnergyMeasurementClusterEnergyMeasurementStruct.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -29,7 +28,7 @@ class ElectricalEnergyMeasurementClusterEnergyMeasurementStruct( val startTimestamp: Optional, val endTimestamp: Optional, val startSystime: Optional, - val endSystime: Optional + val endSystime: Optional, ) { override fun toString(): String = buildString { append("ElectricalEnergyMeasurementClusterEnergyMeasurementStruct {\n") @@ -72,33 +71,46 @@ class ElectricalEnergyMeasurementClusterEnergyMeasurementStruct( private const val TAG_START_SYSTIME = 3 private const val TAG_END_SYSTIME = 4 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ElectricalEnergyMeasurementClusterEnergyMeasurementStruct { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): ElectricalEnergyMeasurementClusterEnergyMeasurementStruct { tlvReader.enterStructure(tlvTag) val energy = tlvReader.getLong(ContextSpecificTag(TAG_ENERGY)) - val startTimestamp = if (tlvReader.isNextTag(ContextSpecificTag(TAG_START_TIMESTAMP))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_START_TIMESTAMP))) - } else { - Optional.empty() - } - val endTimestamp = if (tlvReader.isNextTag(ContextSpecificTag(TAG_END_TIMESTAMP))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_END_TIMESTAMP))) - } else { - Optional.empty() - } - val startSystime = if (tlvReader.isNextTag(ContextSpecificTag(TAG_START_SYSTIME))) { - Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_START_SYSTIME))) - } else { - Optional.empty() - } - val endSystime = if (tlvReader.isNextTag(ContextSpecificTag(TAG_END_SYSTIME))) { - Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_END_SYSTIME))) - } else { - Optional.empty() - } - + val startTimestamp = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_START_TIMESTAMP))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_START_TIMESTAMP))) + } else { + Optional.empty() + } + val endTimestamp = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_END_TIMESTAMP))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_END_TIMESTAMP))) + } else { + Optional.empty() + } + val startSystime = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_START_SYSTIME))) { + Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_START_SYSTIME))) + } else { + Optional.empty() + } + val endSystime = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_END_SYSTIME))) { + Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_END_SYSTIME))) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return ElectricalEnergyMeasurementClusterEnergyMeasurementStruct(energy, startTimestamp, endTimestamp, startSystime, endSystime) + return ElectricalEnergyMeasurementClusterEnergyMeasurementStruct( + energy, + startTimestamp, + endTimestamp, + startSystime, + endSystime, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalEnergyMeasurementClusterMeasurementAccuracyRangeStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalEnergyMeasurementClusterMeasurementAccuracyRangeStruct.kt index 4e0ca217ce09fe..8234247fa327ea 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalEnergyMeasurementClusterMeasurementAccuracyRangeStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalEnergyMeasurementClusterMeasurementAccuracyRangeStruct.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -32,7 +31,7 @@ class ElectricalEnergyMeasurementClusterMeasurementAccuracyRangeStruct( val percentTypical: Optional, val fixedMax: Optional, val fixedMin: Optional, - val fixedTypical: Optional + val fixedTypical: Optional, ) { override fun toString(): String = buildString { append("ElectricalEnergyMeasurementClusterMeasurementAccuracyRangeStruct {\n") @@ -90,44 +89,62 @@ class ElectricalEnergyMeasurementClusterMeasurementAccuracyRangeStruct( private const val TAG_FIXED_MIN = 6 private const val TAG_FIXED_TYPICAL = 7 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ElectricalEnergyMeasurementClusterMeasurementAccuracyRangeStruct { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): ElectricalEnergyMeasurementClusterMeasurementAccuracyRangeStruct { tlvReader.enterStructure(tlvTag) val rangeMin = tlvReader.getLong(ContextSpecificTag(TAG_RANGE_MIN)) val rangeMax = tlvReader.getLong(ContextSpecificTag(TAG_RANGE_MAX)) - val percentMax = if (tlvReader.isNextTag(ContextSpecificTag(TAG_PERCENT_MAX))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_PERCENT_MAX))) - } else { - Optional.empty() - } - val percentMin = if (tlvReader.isNextTag(ContextSpecificTag(TAG_PERCENT_MIN))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_PERCENT_MIN))) - } else { - Optional.empty() - } - val percentTypical = if (tlvReader.isNextTag(ContextSpecificTag(TAG_PERCENT_TYPICAL))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_PERCENT_TYPICAL))) - } else { - Optional.empty() - } - val fixedMax = if (tlvReader.isNextTag(ContextSpecificTag(TAG_FIXED_MAX))) { - Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_FIXED_MAX))) - } else { - Optional.empty() - } - val fixedMin = if (tlvReader.isNextTag(ContextSpecificTag(TAG_FIXED_MIN))) { - Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_FIXED_MIN))) - } else { - Optional.empty() - } - val fixedTypical = if (tlvReader.isNextTag(ContextSpecificTag(TAG_FIXED_TYPICAL))) { - Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_FIXED_TYPICAL))) - } else { - Optional.empty() - } - + val percentMax = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_PERCENT_MAX))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_PERCENT_MAX))) + } else { + Optional.empty() + } + val percentMin = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_PERCENT_MIN))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_PERCENT_MIN))) + } else { + Optional.empty() + } + val percentTypical = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_PERCENT_TYPICAL))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_PERCENT_TYPICAL))) + } else { + Optional.empty() + } + val fixedMax = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_FIXED_MAX))) { + Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_FIXED_MAX))) + } else { + Optional.empty() + } + val fixedMin = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_FIXED_MIN))) { + Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_FIXED_MIN))) + } else { + Optional.empty() + } + val fixedTypical = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_FIXED_TYPICAL))) { + Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_FIXED_TYPICAL))) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return ElectricalEnergyMeasurementClusterMeasurementAccuracyRangeStruct(rangeMin, rangeMax, percentMax, percentMin, percentTypical, fixedMax, fixedMin, fixedTypical) + return ElectricalEnergyMeasurementClusterMeasurementAccuracyRangeStruct( + rangeMin, + rangeMax, + percentMax, + percentMin, + percentTypical, + fixedMax, + fixedMin, + fixedTypical, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalEnergyMeasurementClusterMeasurementAccuracyStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalEnergyMeasurementClusterMeasurementAccuracyStruct.kt index b0ec26832b7c2d..b4068935ee9aef 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalEnergyMeasurementClusterMeasurementAccuracyStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalEnergyMeasurementClusterMeasurementAccuracyStruct.kt @@ -16,7 +16,6 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -29,7 +28,7 @@ class ElectricalEnergyMeasurementClusterMeasurementAccuracyStruct( val measured: Boolean, val minMeasuredValue: Long, val maxMeasuredValue: Long, - val accuracyRanges: List + val accuracyRanges: List, ) { override fun toString(): String = buildString { append("ElectricalEnergyMeasurementClusterMeasurementAccuracyStruct {\n") @@ -64,23 +63,38 @@ class ElectricalEnergyMeasurementClusterMeasurementAccuracyStruct( private const val TAG_MAX_MEASURED_VALUE = 3 private const val TAG_ACCURACY_RANGES = 4 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ElectricalEnergyMeasurementClusterMeasurementAccuracyStruct { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): ElectricalEnergyMeasurementClusterMeasurementAccuracyStruct { tlvReader.enterStructure(tlvTag) 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)) - val accuracyRanges = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_ACCURACY_RANGES)) - while(!tlvReader.isEndOfContainer()) { - add(ElectricalEnergyMeasurementClusterMeasurementAccuracyRangeStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - + val accuracyRanges = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_ACCURACY_RANGES)) + while (!tlvReader.isEndOfContainer()) { + add( + ElectricalEnergyMeasurementClusterMeasurementAccuracyRangeStruct.fromTlv( + AnonymousTag, + tlvReader, + ) + ) + } + tlvReader.exitContainer() + } + tlvReader.exitContainer() - return ElectricalEnergyMeasurementClusterMeasurementAccuracyStruct(measurementType, measured, minMeasuredValue, maxMeasuredValue, accuracyRanges) + return ElectricalEnergyMeasurementClusterMeasurementAccuracyStruct( + measurementType, + measured, + minMeasuredValue, + maxMeasuredValue, + accuracyRanges, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalPowerMeasurementClusterHarmonicMeasurementStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalPowerMeasurementClusterHarmonicMeasurementStruct.kt index 48533cc86b8586..2a83816368e304 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalPowerMeasurementClusterHarmonicMeasurementStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalPowerMeasurementClusterHarmonicMeasurementStruct.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +24,7 @@ import matter.tlv.TlvWriter class ElectricalPowerMeasurementClusterHarmonicMeasurementStruct( val order: UByte, - val measurement: Long? + val measurement: Long?, ) { override fun toString(): String = buildString { append("ElectricalPowerMeasurementClusterHarmonicMeasurementStruct {\n") @@ -52,16 +50,20 @@ class ElectricalPowerMeasurementClusterHarmonicMeasurementStruct( private const val TAG_ORDER = 0 private const val TAG_MEASUREMENT = 1 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ElectricalPowerMeasurementClusterHarmonicMeasurementStruct { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): ElectricalPowerMeasurementClusterHarmonicMeasurementStruct { tlvReader.enterStructure(tlvTag) val order = tlvReader.getUByte(ContextSpecificTag(TAG_ORDER)) - val measurement = if (!tlvReader.isNull()) { - tlvReader.getLong(ContextSpecificTag(TAG_MEASUREMENT)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_MEASUREMENT)) - null - } - + val measurement = + if (!tlvReader.isNull()) { + tlvReader.getLong(ContextSpecificTag(TAG_MEASUREMENT)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_MEASUREMENT)) + null + } + tlvReader.exitContainer() return ElectricalPowerMeasurementClusterHarmonicMeasurementStruct(order, measurement) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalPowerMeasurementClusterMeasurementAccuracyRangeStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalPowerMeasurementClusterMeasurementAccuracyRangeStruct.kt index 7cbe39cec83fae..b6c08c0fdbab38 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalPowerMeasurementClusterMeasurementAccuracyRangeStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalPowerMeasurementClusterMeasurementAccuracyRangeStruct.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -32,7 +31,7 @@ class ElectricalPowerMeasurementClusterMeasurementAccuracyRangeStruct( val percentTypical: Optional, val fixedMax: Optional, val fixedMin: Optional, - val fixedTypical: Optional + val fixedTypical: Optional, ) { override fun toString(): String = buildString { append("ElectricalPowerMeasurementClusterMeasurementAccuracyRangeStruct {\n") @@ -90,44 +89,62 @@ class ElectricalPowerMeasurementClusterMeasurementAccuracyRangeStruct( private const val TAG_FIXED_MIN = 6 private const val TAG_FIXED_TYPICAL = 7 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ElectricalPowerMeasurementClusterMeasurementAccuracyRangeStruct { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): ElectricalPowerMeasurementClusterMeasurementAccuracyRangeStruct { tlvReader.enterStructure(tlvTag) val rangeMin = tlvReader.getLong(ContextSpecificTag(TAG_RANGE_MIN)) val rangeMax = tlvReader.getLong(ContextSpecificTag(TAG_RANGE_MAX)) - val percentMax = if (tlvReader.isNextTag(ContextSpecificTag(TAG_PERCENT_MAX))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_PERCENT_MAX))) - } else { - Optional.empty() - } - val percentMin = if (tlvReader.isNextTag(ContextSpecificTag(TAG_PERCENT_MIN))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_PERCENT_MIN))) - } else { - Optional.empty() - } - val percentTypical = if (tlvReader.isNextTag(ContextSpecificTag(TAG_PERCENT_TYPICAL))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_PERCENT_TYPICAL))) - } else { - Optional.empty() - } - val fixedMax = if (tlvReader.isNextTag(ContextSpecificTag(TAG_FIXED_MAX))) { - Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_FIXED_MAX))) - } else { - Optional.empty() - } - val fixedMin = if (tlvReader.isNextTag(ContextSpecificTag(TAG_FIXED_MIN))) { - Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_FIXED_MIN))) - } else { - Optional.empty() - } - val fixedTypical = if (tlvReader.isNextTag(ContextSpecificTag(TAG_FIXED_TYPICAL))) { - Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_FIXED_TYPICAL))) - } else { - Optional.empty() - } - + val percentMax = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_PERCENT_MAX))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_PERCENT_MAX))) + } else { + Optional.empty() + } + val percentMin = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_PERCENT_MIN))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_PERCENT_MIN))) + } else { + Optional.empty() + } + val percentTypical = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_PERCENT_TYPICAL))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_PERCENT_TYPICAL))) + } else { + Optional.empty() + } + val fixedMax = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_FIXED_MAX))) { + Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_FIXED_MAX))) + } else { + Optional.empty() + } + val fixedMin = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_FIXED_MIN))) { + Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_FIXED_MIN))) + } else { + Optional.empty() + } + val fixedTypical = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_FIXED_TYPICAL))) { + Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_FIXED_TYPICAL))) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return ElectricalPowerMeasurementClusterMeasurementAccuracyRangeStruct(rangeMin, rangeMax, percentMax, percentMin, percentTypical, fixedMax, fixedMin, fixedTypical) + return ElectricalPowerMeasurementClusterMeasurementAccuracyRangeStruct( + rangeMin, + rangeMax, + percentMax, + percentMin, + percentTypical, + fixedMax, + fixedMin, + fixedTypical, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalPowerMeasurementClusterMeasurementAccuracyStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalPowerMeasurementClusterMeasurementAccuracyStruct.kt index 63fa1a24a39a54..a646766ca7d6a5 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalPowerMeasurementClusterMeasurementAccuracyStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalPowerMeasurementClusterMeasurementAccuracyStruct.kt @@ -16,7 +16,6 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -29,7 +28,7 @@ class ElectricalPowerMeasurementClusterMeasurementAccuracyStruct( val measured: Boolean, val minMeasuredValue: Long, val maxMeasuredValue: Long, - val accuracyRanges: List + val accuracyRanges: List, ) { override fun toString(): String = buildString { append("ElectricalPowerMeasurementClusterMeasurementAccuracyStruct {\n") @@ -64,23 +63,38 @@ class ElectricalPowerMeasurementClusterMeasurementAccuracyStruct( private const val TAG_MAX_MEASURED_VALUE = 3 private const val TAG_ACCURACY_RANGES = 4 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ElectricalPowerMeasurementClusterMeasurementAccuracyStruct { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): ElectricalPowerMeasurementClusterMeasurementAccuracyStruct { tlvReader.enterStructure(tlvTag) 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)) - val accuracyRanges = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_ACCURACY_RANGES)) - while(!tlvReader.isEndOfContainer()) { - add(ElectricalPowerMeasurementClusterMeasurementAccuracyRangeStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - + val accuracyRanges = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_ACCURACY_RANGES)) + while (!tlvReader.isEndOfContainer()) { + add( + ElectricalPowerMeasurementClusterMeasurementAccuracyRangeStruct.fromTlv( + AnonymousTag, + tlvReader, + ) + ) + } + tlvReader.exitContainer() + } + tlvReader.exitContainer() - return ElectricalPowerMeasurementClusterMeasurementAccuracyStruct(measurementType, measured, minMeasuredValue, maxMeasuredValue, accuracyRanges) + return ElectricalPowerMeasurementClusterMeasurementAccuracyStruct( + measurementType, + measured, + minMeasuredValue, + maxMeasuredValue, + accuracyRanges, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalPowerMeasurementClusterMeasurementRangeStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalPowerMeasurementClusterMeasurementRangeStruct.kt index e612421d19d891..eabd12a80a1358 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalPowerMeasurementClusterMeasurementRangeStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalPowerMeasurementClusterMeasurementRangeStruct.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -35,7 +34,7 @@ class ElectricalPowerMeasurementClusterMeasurementRangeStruct( val startSystime: Optional, val endSystime: Optional, val minSystime: Optional, - val maxSystime: Optional + val maxSystime: Optional, ) { override fun toString(): String = buildString { append("ElectricalPowerMeasurementClusterMeasurementRangeStruct {\n") @@ -108,55 +107,78 @@ class ElectricalPowerMeasurementClusterMeasurementRangeStruct( private const val TAG_MIN_SYSTIME = 9 private const val TAG_MAX_SYSTIME = 10 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ElectricalPowerMeasurementClusterMeasurementRangeStruct { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): ElectricalPowerMeasurementClusterMeasurementRangeStruct { tlvReader.enterStructure(tlvTag) val measurementType = tlvReader.getUShort(ContextSpecificTag(TAG_MEASUREMENT_TYPE)) val min = tlvReader.getLong(ContextSpecificTag(TAG_MIN)) val max = tlvReader.getLong(ContextSpecificTag(TAG_MAX)) - val startTimestamp = if (tlvReader.isNextTag(ContextSpecificTag(TAG_START_TIMESTAMP))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_START_TIMESTAMP))) - } else { - Optional.empty() - } - val endTimestamp = if (tlvReader.isNextTag(ContextSpecificTag(TAG_END_TIMESTAMP))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_END_TIMESTAMP))) - } else { - Optional.empty() - } - val minTimestamp = if (tlvReader.isNextTag(ContextSpecificTag(TAG_MIN_TIMESTAMP))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_MIN_TIMESTAMP))) - } else { - Optional.empty() - } - val maxTimestamp = if (tlvReader.isNextTag(ContextSpecificTag(TAG_MAX_TIMESTAMP))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_MAX_TIMESTAMP))) - } else { - Optional.empty() - } - val startSystime = if (tlvReader.isNextTag(ContextSpecificTag(TAG_START_SYSTIME))) { - Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_START_SYSTIME))) - } else { - Optional.empty() - } - val endSystime = if (tlvReader.isNextTag(ContextSpecificTag(TAG_END_SYSTIME))) { - Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_END_SYSTIME))) - } else { - Optional.empty() - } - val minSystime = if (tlvReader.isNextTag(ContextSpecificTag(TAG_MIN_SYSTIME))) { - Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_MIN_SYSTIME))) - } else { - Optional.empty() - } - val maxSystime = if (tlvReader.isNextTag(ContextSpecificTag(TAG_MAX_SYSTIME))) { - Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_MAX_SYSTIME))) - } else { - Optional.empty() - } - + val startTimestamp = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_START_TIMESTAMP))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_START_TIMESTAMP))) + } else { + Optional.empty() + } + val endTimestamp = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_END_TIMESTAMP))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_END_TIMESTAMP))) + } else { + Optional.empty() + } + val minTimestamp = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_MIN_TIMESTAMP))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_MIN_TIMESTAMP))) + } else { + Optional.empty() + } + val maxTimestamp = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_MAX_TIMESTAMP))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_MAX_TIMESTAMP))) + } else { + Optional.empty() + } + val startSystime = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_START_SYSTIME))) { + Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_START_SYSTIME))) + } else { + Optional.empty() + } + val endSystime = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_END_SYSTIME))) { + Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_END_SYSTIME))) + } else { + Optional.empty() + } + val minSystime = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_MIN_SYSTIME))) { + Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_MIN_SYSTIME))) + } else { + Optional.empty() + } + val maxSystime = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_MAX_SYSTIME))) { + Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_MAX_SYSTIME))) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return ElectricalPowerMeasurementClusterMeasurementRangeStruct(measurementType, min, max, startTimestamp, endTimestamp, minTimestamp, maxTimestamp, startSystime, endSystime, minSystime, maxSystime) + return ElectricalPowerMeasurementClusterMeasurementRangeStruct( + measurementType, + min, + max, + startTimestamp, + endTimestamp, + minTimestamp, + maxTimestamp, + startSystime, + endSystime, + minSystime, + maxSystime, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/EnergyEvseClusterChargingTargetScheduleStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/EnergyEvseClusterChargingTargetScheduleStruct.kt index 3ed256441cd2ff..a293094e84b288 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/EnergyEvseClusterChargingTargetScheduleStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/EnergyEvseClusterChargingTargetScheduleStruct.kt @@ -16,7 +16,6 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -26,7 +25,7 @@ import matter.tlv.TlvWriter class EnergyEvseClusterChargingTargetScheduleStruct( val dayOfWeekForSequence: UByte, - val chargingTargets: List + val chargingTargets: List, ) { override fun toString(): String = buildString { append("EnergyEvseClusterChargingTargetScheduleStruct {\n") @@ -54,15 +53,17 @@ class EnergyEvseClusterChargingTargetScheduleStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): EnergyEvseClusterChargingTargetScheduleStruct { tlvReader.enterStructure(tlvTag) - val dayOfWeekForSequence = tlvReader.getUByte(ContextSpecificTag(TAG_DAY_OF_WEEK_FOR_SEQUENCE)) - val chargingTargets = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_CHARGING_TARGETS)) - while(!tlvReader.isEndOfContainer()) { - add(EnergyEvseClusterChargingTargetStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - + val dayOfWeekForSequence = + tlvReader.getUByte(ContextSpecificTag(TAG_DAY_OF_WEEK_FOR_SEQUENCE)) + val chargingTargets = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_CHARGING_TARGETS)) + while (!tlvReader.isEndOfContainer()) { + add(EnergyEvseClusterChargingTargetStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + tlvReader.exitContainer() return EnergyEvseClusterChargingTargetScheduleStruct(dayOfWeekForSequence, chargingTargets) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/EnergyEvseClusterChargingTargetStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/EnergyEvseClusterChargingTargetStruct.kt index 72826868a15260..8a18bbab605267 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/EnergyEvseClusterChargingTargetStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/EnergyEvseClusterChargingTargetStruct.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -27,7 +26,7 @@ import matter.tlv.TlvWriter class EnergyEvseClusterChargingTargetStruct( val targetTimeMinutesPastMidnight: UShort, val targetSoC: Optional, - val addedEnergy: Optional + val addedEnergy: Optional, ) { override fun toString(): String = buildString { append("EnergyEvseClusterChargingTargetStruct {\n") @@ -60,21 +59,28 @@ class EnergyEvseClusterChargingTargetStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): EnergyEvseClusterChargingTargetStruct { tlvReader.enterStructure(tlvTag) - val targetTimeMinutesPastMidnight = tlvReader.getUShort(ContextSpecificTag(TAG_TARGET_TIME_MINUTES_PAST_MIDNIGHT)) - val targetSoC = if (tlvReader.isNextTag(ContextSpecificTag(TAG_TARGET_SO_C))) { - Optional.of(tlvReader.getUByte(ContextSpecificTag(TAG_TARGET_SO_C))) - } else { - Optional.empty() - } - val addedEnergy = if (tlvReader.isNextTag(ContextSpecificTag(TAG_ADDED_ENERGY))) { - Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_ADDED_ENERGY))) - } else { - Optional.empty() - } - + val targetTimeMinutesPastMidnight = + tlvReader.getUShort(ContextSpecificTag(TAG_TARGET_TIME_MINUTES_PAST_MIDNIGHT)) + val targetSoC = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_TARGET_SO_C))) { + Optional.of(tlvReader.getUByte(ContextSpecificTag(TAG_TARGET_SO_C))) + } else { + Optional.empty() + } + val addedEnergy = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_ADDED_ENERGY))) { + Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_ADDED_ENERGY))) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return EnergyEvseClusterChargingTargetStruct(targetTimeMinutesPastMidnight, targetSoC, addedEnergy) + return EnergyEvseClusterChargingTargetStruct( + targetTimeMinutesPastMidnight, + targetSoC, + addedEnergy, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/EnergyEvseModeClusterModeOptionStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/EnergyEvseModeClusterModeOptionStruct.kt index 19ee22542f25a9..ae35cef781c18b 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/EnergyEvseModeClusterModeOptionStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/EnergyEvseModeClusterModeOptionStruct.kt @@ -16,7 +16,6 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -27,7 +26,7 @@ import matter.tlv.TlvWriter class EnergyEvseModeClusterModeOptionStruct( val label: String, val mode: UByte, - val modeTags: List + val modeTags: List, ) { override fun toString(): String = buildString { append("EnergyEvseModeClusterModeOptionStruct {\n") @@ -60,14 +59,15 @@ class EnergyEvseModeClusterModeOptionStruct( tlvReader.enterStructure(tlvTag) val label = tlvReader.getString(ContextSpecificTag(TAG_LABEL)) val mode = tlvReader.getUByte(ContextSpecificTag(TAG_MODE)) - val modeTags = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_MODE_TAGS)) - while(!tlvReader.isEndOfContainer()) { - add(EnergyEvseModeClusterModeTagStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - + val modeTags = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_MODE_TAGS)) + while (!tlvReader.isEndOfContainer()) { + add(EnergyEvseModeClusterModeTagStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + tlvReader.exitContainer() return EnergyEvseModeClusterModeOptionStruct(label, mode, modeTags) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/EnergyEvseModeClusterModeTagStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/EnergyEvseModeClusterModeTagStruct.kt index c5c55fd1efc89e..e4a9a48c9244eb 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/EnergyEvseModeClusterModeTagStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/EnergyEvseModeClusterModeTagStruct.kt @@ -18,16 +18,12 @@ package matter.controller.cluster.structs import java.util.Optional 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 EnergyEvseModeClusterModeTagStruct( - val mfgCode: Optional, - val value: UShort -) { +class EnergyEvseModeClusterModeTagStruct(val mfgCode: Optional, val value: UShort) { override fun toString(): String = buildString { append("EnergyEvseModeClusterModeTagStruct {\n") append("\tmfgCode : $mfgCode\n") @@ -53,13 +49,14 @@ class EnergyEvseModeClusterModeTagStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): EnergyEvseModeClusterModeTagStruct { tlvReader.enterStructure(tlvTag) - val mfgCode = if (tlvReader.isNextTag(ContextSpecificTag(TAG_MFG_CODE))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_MFG_CODE))) - } else { - Optional.empty() - } + val mfgCode = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_MFG_CODE))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_MFG_CODE))) + } else { + Optional.empty() + } val value = tlvReader.getUShort(ContextSpecificTag(TAG_VALUE)) - + tlvReader.exitContainer() return EnergyEvseModeClusterModeTagStruct(mfgCode, value) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/EnergyPreferenceClusterBalanceStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/EnergyPreferenceClusterBalanceStruct.kt index 80e4c2b06d9cad..29980664d4cbec 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/EnergyPreferenceClusterBalanceStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/EnergyPreferenceClusterBalanceStruct.kt @@ -18,16 +18,12 @@ package matter.controller.cluster.structs import java.util.Optional 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 EnergyPreferenceClusterBalanceStruct( - val step: UByte, - val label: Optional -) { +class EnergyPreferenceClusterBalanceStruct(val step: UByte, val label: Optional) { override fun toString(): String = buildString { append("EnergyPreferenceClusterBalanceStruct {\n") append("\tstep : $step\n") @@ -54,12 +50,13 @@ class EnergyPreferenceClusterBalanceStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): EnergyPreferenceClusterBalanceStruct { tlvReader.enterStructure(tlvTag) val step = tlvReader.getUByte(ContextSpecificTag(TAG_STEP)) - val label = if (tlvReader.isNextTag(ContextSpecificTag(TAG_LABEL))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_LABEL))) - } else { - Optional.empty() - } - + val label = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_LABEL))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_LABEL))) + } else { + Optional.empty() + } + tlvReader.exitContainer() return EnergyPreferenceClusterBalanceStruct(step, label) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/FixedLabelClusterLabelStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/FixedLabelClusterLabelStruct.kt index 2465dd492ace99..b5181c44417b6d 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/FixedLabelClusterLabelStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/FixedLabelClusterLabelStruct.kt @@ -16,18 +16,13 @@ */ package matter.controller.cluster.structs -import java.util.Optional 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 FixedLabelClusterLabelStruct( - val label: String, - val value: String -) { +class FixedLabelClusterLabelStruct(val label: String, val value: String) { override fun toString(): String = buildString { append("FixedLabelClusterLabelStruct {\n") append("\tlabel : $label\n") @@ -52,7 +47,7 @@ class FixedLabelClusterLabelStruct( tlvReader.enterStructure(tlvTag) val label = tlvReader.getString(ContextSpecificTag(TAG_LABEL)) val value = tlvReader.getString(ContextSpecificTag(TAG_VALUE)) - + tlvReader.exitContainer() return FixedLabelClusterLabelStruct(label, value) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/GeneralCommissioningClusterBasicCommissioningInfo.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/GeneralCommissioningClusterBasicCommissioningInfo.kt index b2d6b7e97638e6..0ae15dd9ae01fe 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/GeneralCommissioningClusterBasicCommissioningInfo.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/GeneralCommissioningClusterBasicCommissioningInfo.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +24,7 @@ import matter.tlv.TlvWriter class GeneralCommissioningClusterBasicCommissioningInfo( val failSafeExpiryLengthSeconds: UShort, - val maxCumulativeFailsafeSeconds: UShort + val maxCumulativeFailsafeSeconds: UShort, ) { override fun toString(): String = buildString { append("GeneralCommissioningClusterBasicCommissioningInfo {\n") @@ -48,14 +46,22 @@ class GeneralCommissioningClusterBasicCommissioningInfo( private const val TAG_FAIL_SAFE_EXPIRY_LENGTH_SECONDS = 0 private const val TAG_MAX_CUMULATIVE_FAILSAFE_SECONDS = 1 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): GeneralCommissioningClusterBasicCommissioningInfo { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): GeneralCommissioningClusterBasicCommissioningInfo { tlvReader.enterStructure(tlvTag) - val failSafeExpiryLengthSeconds = tlvReader.getUShort(ContextSpecificTag(TAG_FAIL_SAFE_EXPIRY_LENGTH_SECONDS)) - val maxCumulativeFailsafeSeconds = tlvReader.getUShort(ContextSpecificTag(TAG_MAX_CUMULATIVE_FAILSAFE_SECONDS)) - + val failSafeExpiryLengthSeconds = + tlvReader.getUShort(ContextSpecificTag(TAG_FAIL_SAFE_EXPIRY_LENGTH_SECONDS)) + val maxCumulativeFailsafeSeconds = + tlvReader.getUShort(ContextSpecificTag(TAG_MAX_CUMULATIVE_FAILSAFE_SECONDS)) + tlvReader.exitContainer() - return GeneralCommissioningClusterBasicCommissioningInfo(failSafeExpiryLengthSeconds, maxCumulativeFailsafeSeconds) + return GeneralCommissioningClusterBasicCommissioningInfo( + failSafeExpiryLengthSeconds, + maxCumulativeFailsafeSeconds, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/GeneralDiagnosticsClusterNetworkInterface.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/GeneralDiagnosticsClusterNetworkInterface.kt index 61f8691c5f053a..b39378349cc934 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/GeneralDiagnosticsClusterNetworkInterface.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/GeneralDiagnosticsClusterNetworkInterface.kt @@ -16,7 +16,6 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -32,7 +31,7 @@ class GeneralDiagnosticsClusterNetworkInterface( val hardwareAddress: ByteArray, val IPv4Addresses: List, val IPv6Addresses: List, - val type: UByte + val type: UByte, ) { override fun toString(): String = buildString { append("GeneralDiagnosticsClusterNetworkInterface {\n") @@ -53,12 +52,18 @@ class GeneralDiagnosticsClusterNetworkInterface( put(ContextSpecificTag(TAG_NAME), name) put(ContextSpecificTag(TAG_IS_OPERATIONAL), isOperational) if (offPremiseServicesReachableIPv4 != null) { - put(ContextSpecificTag(TAG_OFF_PREMISE_SERVICES_REACHABLE_I_PV4), offPremiseServicesReachableIPv4) + put( + ContextSpecificTag(TAG_OFF_PREMISE_SERVICES_REACHABLE_I_PV4), + offPremiseServicesReachableIPv4, + ) } else { putNull(ContextSpecificTag(TAG_OFF_PREMISE_SERVICES_REACHABLE_I_PV4)) } if (offPremiseServicesReachableIPv6 != null) { - put(ContextSpecificTag(TAG_OFF_PREMISE_SERVICES_REACHABLE_I_PV6), offPremiseServicesReachableIPv6) + put( + ContextSpecificTag(TAG_OFF_PREMISE_SERVICES_REACHABLE_I_PV6), + offPremiseServicesReachableIPv6, + ) } else { putNull(ContextSpecificTag(TAG_OFF_PREMISE_SERVICES_REACHABLE_I_PV6)) } @@ -92,38 +97,51 @@ class GeneralDiagnosticsClusterNetworkInterface( tlvReader.enterStructure(tlvTag) val name = tlvReader.getString(ContextSpecificTag(TAG_NAME)) val isOperational = tlvReader.getBoolean(ContextSpecificTag(TAG_IS_OPERATIONAL)) - val offPremiseServicesReachableIPv4 = if (!tlvReader.isNull()) { - tlvReader.getBoolean(ContextSpecificTag(TAG_OFF_PREMISE_SERVICES_REACHABLE_I_PV4)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_OFF_PREMISE_SERVICES_REACHABLE_I_PV4)) - null - } - val offPremiseServicesReachableIPv6 = if (!tlvReader.isNull()) { - tlvReader.getBoolean(ContextSpecificTag(TAG_OFF_PREMISE_SERVICES_REACHABLE_I_PV6)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_OFF_PREMISE_SERVICES_REACHABLE_I_PV6)) - null - } + val offPremiseServicesReachableIPv4 = + if (!tlvReader.isNull()) { + tlvReader.getBoolean(ContextSpecificTag(TAG_OFF_PREMISE_SERVICES_REACHABLE_I_PV4)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_OFF_PREMISE_SERVICES_REACHABLE_I_PV4)) + null + } + val offPremiseServicesReachableIPv6 = + if (!tlvReader.isNull()) { + tlvReader.getBoolean(ContextSpecificTag(TAG_OFF_PREMISE_SERVICES_REACHABLE_I_PV6)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_OFF_PREMISE_SERVICES_REACHABLE_I_PV6)) + null + } val hardwareAddress = tlvReader.getByteArray(ContextSpecificTag(TAG_HARDWARE_ADDRESS)) - val IPv4Addresses = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_I_PV4_ADDRESSES)) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getByteArray(AnonymousTag)) - } - tlvReader.exitContainer() - } - val IPv6Addresses = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_I_PV6_ADDRESSES)) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getByteArray(AnonymousTag)) - } - tlvReader.exitContainer() - } + val IPv4Addresses = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_I_PV4_ADDRESSES)) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getByteArray(AnonymousTag)) + } + tlvReader.exitContainer() + } + val IPv6Addresses = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_I_PV6_ADDRESSES)) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getByteArray(AnonymousTag)) + } + tlvReader.exitContainer() + } val type = tlvReader.getUByte(ContextSpecificTag(TAG_TYPE)) - + tlvReader.exitContainer() - return GeneralDiagnosticsClusterNetworkInterface(name, isOperational, offPremiseServicesReachableIPv4, offPremiseServicesReachableIPv6, hardwareAddress, IPv4Addresses, IPv6Addresses, type) + return GeneralDiagnosticsClusterNetworkInterface( + name, + isOperational, + offPremiseServicesReachableIPv4, + offPremiseServicesReachableIPv6, + hardwareAddress, + IPv4Addresses, + IPv6Addresses, + type, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/GroupKeyManagementClusterGroupInfoMapStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/GroupKeyManagementClusterGroupInfoMapStruct.kt index ef8286072bfcfd..be8a3954bd0acb 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/GroupKeyManagementClusterGroupInfoMapStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/GroupKeyManagementClusterGroupInfoMapStruct.kt @@ -28,7 +28,7 @@ class GroupKeyManagementClusterGroupInfoMapStruct( val groupId: UShort, val endpoints: List, val groupName: Optional, - val fabricIndex: UByte + val fabricIndex: UByte, ) { override fun toString(): String = buildString { append("GroupKeyManagementClusterGroupInfoMapStruct {\n") @@ -66,20 +66,22 @@ class GroupKeyManagementClusterGroupInfoMapStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): GroupKeyManagementClusterGroupInfoMapStruct { tlvReader.enterStructure(tlvTag) val groupId = tlvReader.getUShort(ContextSpecificTag(TAG_GROUP_ID)) - val endpoints = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_ENDPOINTS)) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getUShort(AnonymousTag)) - } - tlvReader.exitContainer() - } - val groupName = if (tlvReader.isNextTag(ContextSpecificTag(TAG_GROUP_NAME))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_GROUP_NAME))) - } else { - Optional.empty() - } + val endpoints = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_ENDPOINTS)) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUShort(AnonymousTag)) + } + tlvReader.exitContainer() + } + val groupName = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_GROUP_NAME))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_GROUP_NAME))) + } else { + Optional.empty() + } val fabricIndex = tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) - + tlvReader.exitContainer() return GroupKeyManagementClusterGroupInfoMapStruct(groupId, endpoints, groupName, fabricIndex) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/GroupKeyManagementClusterGroupKeyMapStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/GroupKeyManagementClusterGroupKeyMapStruct.kt index 4c3fcea3b1e47b..ad1823e569c56e 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/GroupKeyManagementClusterGroupKeyMapStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/GroupKeyManagementClusterGroupKeyMapStruct.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -27,7 +25,7 @@ import matter.tlv.TlvWriter class GroupKeyManagementClusterGroupKeyMapStruct( val groupId: UShort, val groupKeySetID: UShort, - val fabricIndex: UByte + val fabricIndex: UByte, ) { override fun toString(): String = buildString { append("GroupKeyManagementClusterGroupKeyMapStruct {\n") @@ -57,7 +55,7 @@ class GroupKeyManagementClusterGroupKeyMapStruct( val groupId = tlvReader.getUShort(ContextSpecificTag(TAG_GROUP_ID)) val groupKeySetID = tlvReader.getUShort(ContextSpecificTag(TAG_GROUP_KEY_SET_ID)) val fabricIndex = tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) - + tlvReader.exitContainer() return GroupKeyManagementClusterGroupKeyMapStruct(groupId, groupKeySetID, fabricIndex) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/GroupKeyManagementClusterGroupKeySetStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/GroupKeyManagementClusterGroupKeySetStruct.kt index 357e8e78682da0..1419d29377c27a 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/GroupKeyManagementClusterGroupKeySetStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/GroupKeyManagementClusterGroupKeySetStruct.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -32,7 +30,7 @@ class GroupKeyManagementClusterGroupKeySetStruct( val epochKey1: ByteArray?, val epochStartTime1: ULong?, val epochKey2: ByteArray?, - val epochStartTime2: ULong? + val epochStartTime2: ULong?, ) { override fun toString(): String = buildString { append("GroupKeyManagementClusterGroupKeySetStruct {\n") @@ -99,47 +97,63 @@ class GroupKeyManagementClusterGroupKeySetStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): GroupKeyManagementClusterGroupKeySetStruct { tlvReader.enterStructure(tlvTag) val groupKeySetID = tlvReader.getUShort(ContextSpecificTag(TAG_GROUP_KEY_SET_ID)) - val groupKeySecurityPolicy = tlvReader.getUByte(ContextSpecificTag(TAG_GROUP_KEY_SECURITY_POLICY)) - val epochKey0 = if (!tlvReader.isNull()) { - tlvReader.getByteArray(ContextSpecificTag(TAG_EPOCH_KEY0)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_EPOCH_KEY0)) - null - } - val epochStartTime0 = if (!tlvReader.isNull()) { - tlvReader.getULong(ContextSpecificTag(TAG_EPOCH_START_TIME0)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_EPOCH_START_TIME0)) - null - } - val epochKey1 = if (!tlvReader.isNull()) { - tlvReader.getByteArray(ContextSpecificTag(TAG_EPOCH_KEY1)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_EPOCH_KEY1)) - null - } - val epochStartTime1 = if (!tlvReader.isNull()) { - tlvReader.getULong(ContextSpecificTag(TAG_EPOCH_START_TIME1)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_EPOCH_START_TIME1)) - null - } - val epochKey2 = if (!tlvReader.isNull()) { - tlvReader.getByteArray(ContextSpecificTag(TAG_EPOCH_KEY2)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_EPOCH_KEY2)) - null - } - val epochStartTime2 = if (!tlvReader.isNull()) { - tlvReader.getULong(ContextSpecificTag(TAG_EPOCH_START_TIME2)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_EPOCH_START_TIME2)) - null - } - + val groupKeySecurityPolicy = + tlvReader.getUByte(ContextSpecificTag(TAG_GROUP_KEY_SECURITY_POLICY)) + val epochKey0 = + if (!tlvReader.isNull()) { + tlvReader.getByteArray(ContextSpecificTag(TAG_EPOCH_KEY0)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_EPOCH_KEY0)) + null + } + val epochStartTime0 = + if (!tlvReader.isNull()) { + tlvReader.getULong(ContextSpecificTag(TAG_EPOCH_START_TIME0)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_EPOCH_START_TIME0)) + null + } + val epochKey1 = + if (!tlvReader.isNull()) { + tlvReader.getByteArray(ContextSpecificTag(TAG_EPOCH_KEY1)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_EPOCH_KEY1)) + null + } + val epochStartTime1 = + if (!tlvReader.isNull()) { + tlvReader.getULong(ContextSpecificTag(TAG_EPOCH_START_TIME1)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_EPOCH_START_TIME1)) + null + } + val epochKey2 = + if (!tlvReader.isNull()) { + tlvReader.getByteArray(ContextSpecificTag(TAG_EPOCH_KEY2)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_EPOCH_KEY2)) + null + } + val epochStartTime2 = + if (!tlvReader.isNull()) { + tlvReader.getULong(ContextSpecificTag(TAG_EPOCH_START_TIME2)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_EPOCH_START_TIME2)) + null + } + tlvReader.exitContainer() - return GroupKeyManagementClusterGroupKeySetStruct(groupKeySetID, groupKeySecurityPolicy, epochKey0, epochStartTime0, epochKey1, epochStartTime1, epochKey2, epochStartTime2) + return GroupKeyManagementClusterGroupKeySetStruct( + groupKeySetID, + groupKeySecurityPolicy, + epochKey0, + epochStartTime0, + epochKey1, + epochStartTime1, + epochKey2, + epochStartTime2, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/HepaFilterMonitoringClusterReplacementProductStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/HepaFilterMonitoringClusterReplacementProductStruct.kt index c838f5450b4c90..8d8d869afa3e55 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/HepaFilterMonitoringClusterReplacementProductStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/HepaFilterMonitoringClusterReplacementProductStruct.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +24,7 @@ import matter.tlv.TlvWriter class HepaFilterMonitoringClusterReplacementProductStruct( val productIdentifierType: UByte, - val productIdentifierValue: String + val productIdentifierValue: String, ) { override fun toString(): String = buildString { append("HepaFilterMonitoringClusterReplacementProductStruct {\n") @@ -48,14 +46,22 @@ class HepaFilterMonitoringClusterReplacementProductStruct( private const val TAG_PRODUCT_IDENTIFIER_TYPE = 0 private const val TAG_PRODUCT_IDENTIFIER_VALUE = 1 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): HepaFilterMonitoringClusterReplacementProductStruct { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): HepaFilterMonitoringClusterReplacementProductStruct { tlvReader.enterStructure(tlvTag) - val productIdentifierType = tlvReader.getUByte(ContextSpecificTag(TAG_PRODUCT_IDENTIFIER_TYPE)) - val productIdentifierValue = tlvReader.getString(ContextSpecificTag(TAG_PRODUCT_IDENTIFIER_VALUE)) - + val productIdentifierType = + tlvReader.getUByte(ContextSpecificTag(TAG_PRODUCT_IDENTIFIER_TYPE)) + val productIdentifierValue = + tlvReader.getString(ContextSpecificTag(TAG_PRODUCT_IDENTIFIER_VALUE)) + tlvReader.exitContainer() - return HepaFilterMonitoringClusterReplacementProductStruct(productIdentifierType, productIdentifierValue) + return HepaFilterMonitoringClusterReplacementProductStruct( + productIdentifierType, + productIdentifierValue, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/IcdManagementClusterMonitoringRegistrationStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/IcdManagementClusterMonitoringRegistrationStruct.kt index d88acef6d7dd5c..478ce9f25c4cd6 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/IcdManagementClusterMonitoringRegistrationStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/IcdManagementClusterMonitoringRegistrationStruct.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -28,7 +26,7 @@ class IcdManagementClusterMonitoringRegistrationStruct( val checkInNodeID: ULong, val monitoredSubject: ULong, val clientType: UByte, - val fabricIndex: UByte + val fabricIndex: UByte, ) { override fun toString(): String = buildString { append("IcdManagementClusterMonitoringRegistrationStruct {\n") @@ -56,16 +54,24 @@ class IcdManagementClusterMonitoringRegistrationStruct( private const val TAG_CLIENT_TYPE = 4 private const val TAG_FABRIC_INDEX = 254 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): IcdManagementClusterMonitoringRegistrationStruct { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): IcdManagementClusterMonitoringRegistrationStruct { tlvReader.enterStructure(tlvTag) val checkInNodeID = tlvReader.getULong(ContextSpecificTag(TAG_CHECK_IN_NODE_ID)) val monitoredSubject = tlvReader.getULong(ContextSpecificTag(TAG_MONITORED_SUBJECT)) val clientType = tlvReader.getUByte(ContextSpecificTag(TAG_CLIENT_TYPE)) val fabricIndex = tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) - + tlvReader.exitContainer() - return IcdManagementClusterMonitoringRegistrationStruct(checkInNodeID, monitoredSubject, clientType, fabricIndex) + return IcdManagementClusterMonitoringRegistrationStruct( + checkInNodeID, + monitoredSubject, + clientType, + fabricIndex, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/LaundryWasherModeClusterModeOptionStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/LaundryWasherModeClusterModeOptionStruct.kt index 869fc790e2c371..5d738a4020bda5 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/LaundryWasherModeClusterModeOptionStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/LaundryWasherModeClusterModeOptionStruct.kt @@ -16,7 +16,6 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -27,7 +26,7 @@ import matter.tlv.TlvWriter class LaundryWasherModeClusterModeOptionStruct( val label: String, val mode: UByte, - val modeTags: List + val modeTags: List, ) { override fun toString(): String = buildString { append("LaundryWasherModeClusterModeOptionStruct {\n") @@ -60,14 +59,15 @@ class LaundryWasherModeClusterModeOptionStruct( tlvReader.enterStructure(tlvTag) val label = tlvReader.getString(ContextSpecificTag(TAG_LABEL)) val mode = tlvReader.getUByte(ContextSpecificTag(TAG_MODE)) - val modeTags = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_MODE_TAGS)) - while(!tlvReader.isEndOfContainer()) { - add(LaundryWasherModeClusterModeTagStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - + val modeTags = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_MODE_TAGS)) + while (!tlvReader.isEndOfContainer()) { + add(LaundryWasherModeClusterModeTagStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + tlvReader.exitContainer() return LaundryWasherModeClusterModeOptionStruct(label, mode, modeTags) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/LaundryWasherModeClusterModeTagStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/LaundryWasherModeClusterModeTagStruct.kt index 1b9aaf99f45c57..a12e2840ead4ab 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/LaundryWasherModeClusterModeTagStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/LaundryWasherModeClusterModeTagStruct.kt @@ -18,16 +18,12 @@ package matter.controller.cluster.structs import java.util.Optional 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 LaundryWasherModeClusterModeTagStruct( - val mfgCode: Optional, - val value: UShort -) { +class LaundryWasherModeClusterModeTagStruct(val mfgCode: Optional, val value: UShort) { override fun toString(): String = buildString { append("LaundryWasherModeClusterModeTagStruct {\n") append("\tmfgCode : $mfgCode\n") @@ -53,13 +49,14 @@ class LaundryWasherModeClusterModeTagStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): LaundryWasherModeClusterModeTagStruct { tlvReader.enterStructure(tlvTag) - val mfgCode = if (tlvReader.isNextTag(ContextSpecificTag(TAG_MFG_CODE))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_MFG_CODE))) - } else { - Optional.empty() - } + val mfgCode = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_MFG_CODE))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_MFG_CODE))) + } else { + Optional.empty() + } val value = tlvReader.getUShort(ContextSpecificTag(TAG_VALUE)) - + tlvReader.exitContainer() return LaundryWasherModeClusterModeTagStruct(mfgCode, value) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/MediaInputClusterInputInfoStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/MediaInputClusterInputInfoStruct.kt index 13d46092d3725f..129dee7510d0b3 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/MediaInputClusterInputInfoStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/MediaInputClusterInputInfoStruct.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -28,7 +26,7 @@ class MediaInputClusterInputInfoStruct( val index: UByte, val inputType: UByte, val name: String, - val description: String + val description: String, ) { override fun toString(): String = buildString { append("MediaInputClusterInputInfoStruct {\n") @@ -62,7 +60,7 @@ class MediaInputClusterInputInfoStruct( val inputType = tlvReader.getUByte(ContextSpecificTag(TAG_INPUT_TYPE)) val name = tlvReader.getString(ContextSpecificTag(TAG_NAME)) val description = tlvReader.getString(ContextSpecificTag(TAG_DESCRIPTION)) - + tlvReader.exitContainer() return MediaInputClusterInputInfoStruct(index, inputType, name, description) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/MediaPlaybackClusterPlaybackPositionStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/MediaPlaybackClusterPlaybackPositionStruct.kt index 6df4407304fc0d..518da6b739efc8 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/MediaPlaybackClusterPlaybackPositionStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/MediaPlaybackClusterPlaybackPositionStruct.kt @@ -16,18 +16,13 @@ */ package matter.controller.cluster.structs -import java.util.Optional 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 MediaPlaybackClusterPlaybackPositionStruct( - val updatedAt: ULong, - val position: ULong? -) { +class MediaPlaybackClusterPlaybackPositionStruct(val updatedAt: ULong, val position: ULong?) { override fun toString(): String = buildString { append("MediaPlaybackClusterPlaybackPositionStruct {\n") append("\tupdatedAt : $updatedAt\n") @@ -55,13 +50,14 @@ class MediaPlaybackClusterPlaybackPositionStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): MediaPlaybackClusterPlaybackPositionStruct { tlvReader.enterStructure(tlvTag) val updatedAt = tlvReader.getULong(ContextSpecificTag(TAG_UPDATED_AT)) - val position = if (!tlvReader.isNull()) { - tlvReader.getULong(ContextSpecificTag(TAG_POSITION)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_POSITION)) - null - } - + val position = + if (!tlvReader.isNull()) { + tlvReader.getULong(ContextSpecificTag(TAG_POSITION)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_POSITION)) + null + } + tlvReader.exitContainer() return MediaPlaybackClusterPlaybackPositionStruct(updatedAt, position) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/MediaPlaybackClusterTrackAttributesStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/MediaPlaybackClusterTrackAttributesStruct.kt index b82ec49c17f735..15ee4ec93fbc54 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/MediaPlaybackClusterTrackAttributesStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/MediaPlaybackClusterTrackAttributesStruct.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +25,7 @@ import matter.tlv.TlvWriter class MediaPlaybackClusterTrackAttributesStruct( val languageCode: String, - val displayName: Optional? + val displayName: Optional?, ) { override fun toString(): String = buildString { append("MediaPlaybackClusterTrackAttributesStruct {\n") @@ -41,9 +40,9 @@ class MediaPlaybackClusterTrackAttributesStruct( put(ContextSpecificTag(TAG_LANGUAGE_CODE), languageCode) if (displayName != null) { if (displayName.isPresent) { - val optdisplayName = displayName.get() - put(ContextSpecificTag(TAG_DISPLAY_NAME), optdisplayName) - } + val optdisplayName = displayName.get() + put(ContextSpecificTag(TAG_DISPLAY_NAME), optdisplayName) + } } else { putNull(ContextSpecificTag(TAG_DISPLAY_NAME)) } @@ -58,17 +57,18 @@ class MediaPlaybackClusterTrackAttributesStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): MediaPlaybackClusterTrackAttributesStruct { tlvReader.enterStructure(tlvTag) val languageCode = tlvReader.getString(ContextSpecificTag(TAG_LANGUAGE_CODE)) - val displayName = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_DISPLAY_NAME))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_DISPLAY_NAME))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_DISPLAY_NAME)) - null - } - + val displayName = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_DISPLAY_NAME))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_DISPLAY_NAME))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_DISPLAY_NAME)) + null + } + tlvReader.exitContainer() return MediaPlaybackClusterTrackAttributesStruct(languageCode, displayName) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/MediaPlaybackClusterTrackStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/MediaPlaybackClusterTrackStruct.kt index f4c43f16e2337f..53ef5178a0c06a 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/MediaPlaybackClusterTrackStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/MediaPlaybackClusterTrackStruct.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +24,7 @@ import matter.tlv.TlvWriter class MediaPlaybackClusterTrackStruct( val id: String, - val trackAttributes: MediaPlaybackClusterTrackAttributesStruct? + val trackAttributes: MediaPlaybackClusterTrackAttributesStruct?, ) { override fun toString(): String = buildString { append("MediaPlaybackClusterTrackStruct {\n") @@ -55,13 +53,17 @@ class MediaPlaybackClusterTrackStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): MediaPlaybackClusterTrackStruct { tlvReader.enterStructure(tlvTag) val id = tlvReader.getString(ContextSpecificTag(TAG_ID)) - val trackAttributes = if (!tlvReader.isNull()) { - MediaPlaybackClusterTrackAttributesStruct.fromTlv(ContextSpecificTag(TAG_TRACK_ATTRIBUTES), tlvReader) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_TRACK_ATTRIBUTES)) - null - } - + val trackAttributes = + if (!tlvReader.isNull()) { + MediaPlaybackClusterTrackAttributesStruct.fromTlv( + ContextSpecificTag(TAG_TRACK_ATTRIBUTES), + tlvReader, + ) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_TRACK_ATTRIBUTES)) + null + } + tlvReader.exitContainer() return MediaPlaybackClusterTrackStruct(id, trackAttributes) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/MessagesClusterMessageResponseOptionStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/MessagesClusterMessageResponseOptionStruct.kt index 3589a12c78c37f..7240826c29fe10 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/MessagesClusterMessageResponseOptionStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/MessagesClusterMessageResponseOptionStruct.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +25,7 @@ import matter.tlv.TlvWriter class MessagesClusterMessageResponseOptionStruct( val messageResponseID: Optional, - val label: Optional + val label: Optional, ) { override fun toString(): String = buildString { append("MessagesClusterMessageResponseOptionStruct {\n") @@ -56,17 +55,19 @@ class MessagesClusterMessageResponseOptionStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): MessagesClusterMessageResponseOptionStruct { tlvReader.enterStructure(tlvTag) - val messageResponseID = if (tlvReader.isNextTag(ContextSpecificTag(TAG_MESSAGE_RESPONSE_ID))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_MESSAGE_RESPONSE_ID))) - } else { - Optional.empty() - } - val label = if (tlvReader.isNextTag(ContextSpecificTag(TAG_LABEL))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_LABEL))) - } else { - Optional.empty() - } - + val messageResponseID = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_MESSAGE_RESPONSE_ID))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_MESSAGE_RESPONSE_ID))) + } else { + Optional.empty() + } + val label = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_LABEL))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_LABEL))) + } else { + Optional.empty() + } + tlvReader.exitContainer() return MessagesClusterMessageResponseOptionStruct(messageResponseID, label) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/MessagesClusterMessageStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/MessagesClusterMessageStruct.kt index 352e0f3a8a4840..ff033fa133550b 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/MessagesClusterMessageStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/MessagesClusterMessageStruct.kt @@ -31,7 +31,7 @@ class MessagesClusterMessageStruct( val startTime: UInt?, val duration: ULong?, val messageText: String, - val responses: Optional> + val responses: Optional>, ) { override fun toString(): String = buildString { append("MessagesClusterMessageStruct {\n") @@ -65,10 +65,10 @@ class MessagesClusterMessageStruct( if (responses.isPresent) { val optresponses = responses.get() startArray(ContextSpecificTag(TAG_RESPONSES)) - for (item in optresponses.iterator()) { - item.toTlv(AnonymousTag, this) - } - endArray() + for (item in optresponses.iterator()) { + item.toTlv(AnonymousTag, this) + } + endArray() } endStructure() } @@ -88,34 +88,47 @@ class MessagesClusterMessageStruct( val messageID = tlvReader.getByteArray(ContextSpecificTag(TAG_MESSAGE_ID)) val priority = tlvReader.getUByte(ContextSpecificTag(TAG_PRIORITY)) val messageControl = tlvReader.getUByte(ContextSpecificTag(TAG_MESSAGE_CONTROL)) - val startTime = if (!tlvReader.isNull()) { - tlvReader.getUInt(ContextSpecificTag(TAG_START_TIME)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_START_TIME)) - null - } - val duration = if (!tlvReader.isNull()) { - tlvReader.getULong(ContextSpecificTag(TAG_DURATION)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_DURATION)) - null - } + val startTime = + if (!tlvReader.isNull()) { + tlvReader.getUInt(ContextSpecificTag(TAG_START_TIME)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_START_TIME)) + null + } + val duration = + if (!tlvReader.isNull()) { + tlvReader.getULong(ContextSpecificTag(TAG_DURATION)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_DURATION)) + null + } val messageText = tlvReader.getString(ContextSpecificTag(TAG_MESSAGE_TEXT)) - val responses = if (tlvReader.isNextTag(ContextSpecificTag(TAG_RESPONSES))) { - Optional.of(buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_RESPONSES)) - while(!tlvReader.isEndOfContainer()) { - add(MessagesClusterMessageResponseOptionStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - }) - } else { - Optional.empty() - } - + val responses = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_RESPONSES))) { + Optional.of( + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_RESPONSES)) + while (!tlvReader.isEndOfContainer()) { + add(MessagesClusterMessageResponseOptionStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + ) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return MessagesClusterMessageStruct(messageID, priority, messageControl, startTime, duration, messageText, responses) + return MessagesClusterMessageStruct( + messageID, + priority, + messageControl, + startTime, + duration, + messageText, + responses, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/MicrowaveOvenModeClusterModeOptionStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/MicrowaveOvenModeClusterModeOptionStruct.kt index 90d2e905cad2b1..fbffd7bc7714bc 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/MicrowaveOvenModeClusterModeOptionStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/MicrowaveOvenModeClusterModeOptionStruct.kt @@ -16,7 +16,6 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -27,7 +26,7 @@ import matter.tlv.TlvWriter class MicrowaveOvenModeClusterModeOptionStruct( val label: String, val mode: UByte, - val modeTags: List + val modeTags: List, ) { override fun toString(): String = buildString { append("MicrowaveOvenModeClusterModeOptionStruct {\n") @@ -60,14 +59,15 @@ class MicrowaveOvenModeClusterModeOptionStruct( tlvReader.enterStructure(tlvTag) val label = tlvReader.getString(ContextSpecificTag(TAG_LABEL)) val mode = tlvReader.getUByte(ContextSpecificTag(TAG_MODE)) - val modeTags = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_MODE_TAGS)) - while(!tlvReader.isEndOfContainer()) { - add(MicrowaveOvenModeClusterModeTagStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - + val modeTags = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_MODE_TAGS)) + while (!tlvReader.isEndOfContainer()) { + add(MicrowaveOvenModeClusterModeTagStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + tlvReader.exitContainer() return MicrowaveOvenModeClusterModeOptionStruct(label, mode, modeTags) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/MicrowaveOvenModeClusterModeTagStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/MicrowaveOvenModeClusterModeTagStruct.kt index 6ac44a062ca27a..ee00730c425f47 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/MicrowaveOvenModeClusterModeTagStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/MicrowaveOvenModeClusterModeTagStruct.kt @@ -18,16 +18,12 @@ package matter.controller.cluster.structs import java.util.Optional 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 MicrowaveOvenModeClusterModeTagStruct( - val mfgCode: Optional, - val value: UShort -) { +class MicrowaveOvenModeClusterModeTagStruct(val mfgCode: Optional, val value: UShort) { override fun toString(): String = buildString { append("MicrowaveOvenModeClusterModeTagStruct {\n") append("\tmfgCode : $mfgCode\n") @@ -53,13 +49,14 @@ class MicrowaveOvenModeClusterModeTagStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): MicrowaveOvenModeClusterModeTagStruct { tlvReader.enterStructure(tlvTag) - val mfgCode = if (tlvReader.isNextTag(ContextSpecificTag(TAG_MFG_CODE))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_MFG_CODE))) - } else { - Optional.empty() - } + val mfgCode = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_MFG_CODE))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_MFG_CODE))) + } else { + Optional.empty() + } val value = tlvReader.getUShort(ContextSpecificTag(TAG_VALUE)) - + tlvReader.exitContainer() return MicrowaveOvenModeClusterModeTagStruct(mfgCode, value) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ModeSelectClusterModeOptionStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ModeSelectClusterModeOptionStruct.kt index ee501cf2d85532..8a4730716992f9 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ModeSelectClusterModeOptionStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ModeSelectClusterModeOptionStruct.kt @@ -16,7 +16,6 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -27,7 +26,7 @@ import matter.tlv.TlvWriter class ModeSelectClusterModeOptionStruct( val label: String, val mode: UByte, - val semanticTags: List + val semanticTags: List, ) { override fun toString(): String = buildString { append("ModeSelectClusterModeOptionStruct {\n") @@ -60,14 +59,15 @@ class ModeSelectClusterModeOptionStruct( tlvReader.enterStructure(tlvTag) val label = tlvReader.getString(ContextSpecificTag(TAG_LABEL)) val mode = tlvReader.getUByte(ContextSpecificTag(TAG_MODE)) - val semanticTags = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_SEMANTIC_TAGS)) - while(!tlvReader.isEndOfContainer()) { - add(ModeSelectClusterSemanticTagStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - + val semanticTags = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_SEMANTIC_TAGS)) + while (!tlvReader.isEndOfContainer()) { + add(ModeSelectClusterSemanticTagStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + tlvReader.exitContainer() return ModeSelectClusterModeOptionStruct(label, mode, semanticTags) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ModeSelectClusterSemanticTagStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ModeSelectClusterSemanticTagStruct.kt index 323f73c99e7820..fe6cdd3b787f01 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ModeSelectClusterSemanticTagStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ModeSelectClusterSemanticTagStruct.kt @@ -16,18 +16,13 @@ */ package matter.controller.cluster.structs -import java.util.Optional 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 ModeSelectClusterSemanticTagStruct( - val mfgCode: UShort, - val value: UShort -) { +class ModeSelectClusterSemanticTagStruct(val mfgCode: UShort, val value: UShort) { override fun toString(): String = buildString { append("ModeSelectClusterSemanticTagStruct {\n") append("\tmfgCode : $mfgCode\n") @@ -52,7 +47,7 @@ class ModeSelectClusterSemanticTagStruct( tlvReader.enterStructure(tlvTag) val mfgCode = tlvReader.getUShort(ContextSpecificTag(TAG_MFG_CODE)) val value = tlvReader.getUShort(ContextSpecificTag(TAG_VALUE)) - + tlvReader.exitContainer() return ModeSelectClusterSemanticTagStruct(mfgCode, value) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/NetworkCommissioningClusterNetworkInfoStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/NetworkCommissioningClusterNetworkInfoStruct.kt index b7c7fe29c93d48..e7503f37514dc7 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/NetworkCommissioningClusterNetworkInfoStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/NetworkCommissioningClusterNetworkInfoStruct.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -28,7 +27,7 @@ class NetworkCommissioningClusterNetworkInfoStruct( val networkID: ByteArray, val connected: Boolean, val networkIdentifier: Optional?, - val clientIdentifier: Optional? + val clientIdentifier: Optional?, ) { override fun toString(): String = buildString { append("NetworkCommissioningClusterNetworkInfoStruct {\n") @@ -46,17 +45,17 @@ class NetworkCommissioningClusterNetworkInfoStruct( put(ContextSpecificTag(TAG_CONNECTED), connected) if (networkIdentifier != null) { if (networkIdentifier.isPresent) { - val optnetworkIdentifier = networkIdentifier.get() - put(ContextSpecificTag(TAG_NETWORK_IDENTIFIER), optnetworkIdentifier) - } + val optnetworkIdentifier = networkIdentifier.get() + put(ContextSpecificTag(TAG_NETWORK_IDENTIFIER), optnetworkIdentifier) + } } else { putNull(ContextSpecificTag(TAG_NETWORK_IDENTIFIER)) } if (clientIdentifier != null) { if (clientIdentifier.isPresent) { - val optclientIdentifier = clientIdentifier.get() - put(ContextSpecificTag(TAG_CLIENT_IDENTIFIER), optclientIdentifier) - } + val optclientIdentifier = clientIdentifier.get() + put(ContextSpecificTag(TAG_CLIENT_IDENTIFIER), optclientIdentifier) + } } else { putNull(ContextSpecificTag(TAG_CLIENT_IDENTIFIER)) } @@ -74,30 +73,37 @@ class NetworkCommissioningClusterNetworkInfoStruct( tlvReader.enterStructure(tlvTag) val networkID = tlvReader.getByteArray(ContextSpecificTag(TAG_NETWORK_ID)) val connected = tlvReader.getBoolean(ContextSpecificTag(TAG_CONNECTED)) - val networkIdentifier = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_NETWORK_IDENTIFIER))) { - Optional.of(tlvReader.getByteArray(ContextSpecificTag(TAG_NETWORK_IDENTIFIER))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_NETWORK_IDENTIFIER)) - null - } - val clientIdentifier = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_CLIENT_IDENTIFIER))) { - Optional.of(tlvReader.getByteArray(ContextSpecificTag(TAG_CLIENT_IDENTIFIER))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_CLIENT_IDENTIFIER)) - null - } - + val networkIdentifier = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_NETWORK_IDENTIFIER))) { + Optional.of(tlvReader.getByteArray(ContextSpecificTag(TAG_NETWORK_IDENTIFIER))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_NETWORK_IDENTIFIER)) + null + } + val clientIdentifier = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_CLIENT_IDENTIFIER))) { + Optional.of(tlvReader.getByteArray(ContextSpecificTag(TAG_CLIENT_IDENTIFIER))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_CLIENT_IDENTIFIER)) + null + } + tlvReader.exitContainer() - return NetworkCommissioningClusterNetworkInfoStruct(networkID, connected, networkIdentifier, clientIdentifier) + return NetworkCommissioningClusterNetworkInfoStruct( + networkID, + connected, + networkIdentifier, + clientIdentifier, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/NetworkCommissioningClusterThreadInterfaceScanResultStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/NetworkCommissioningClusterThreadInterfaceScanResultStruct.kt index c052531cdda164..89fd771c76a87b 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/NetworkCommissioningClusterThreadInterfaceScanResultStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/NetworkCommissioningClusterThreadInterfaceScanResultStruct.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -32,7 +30,7 @@ class NetworkCommissioningClusterThreadInterfaceScanResultStruct( val version: UByte, val extendedAddress: ByteArray, val rssi: Byte, - val lqi: UByte + val lqi: UByte, ) { override fun toString(): String = buildString { append("NetworkCommissioningClusterThreadInterfaceScanResultStruct {\n") @@ -72,7 +70,10 @@ class NetworkCommissioningClusterThreadInterfaceScanResultStruct( private const val TAG_RSSI = 6 private const val TAG_LQI = 7 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): NetworkCommissioningClusterThreadInterfaceScanResultStruct { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): NetworkCommissioningClusterThreadInterfaceScanResultStruct { tlvReader.enterStructure(tlvTag) val panId = tlvReader.getUShort(ContextSpecificTag(TAG_PAN_ID)) val extendedPanId = tlvReader.getULong(ContextSpecificTag(TAG_EXTENDED_PAN_ID)) @@ -82,10 +83,19 @@ class NetworkCommissioningClusterThreadInterfaceScanResultStruct( val extendedAddress = tlvReader.getByteArray(ContextSpecificTag(TAG_EXTENDED_ADDRESS)) val rssi = tlvReader.getByte(ContextSpecificTag(TAG_RSSI)) val lqi = tlvReader.getUByte(ContextSpecificTag(TAG_LQI)) - + tlvReader.exitContainer() - return NetworkCommissioningClusterThreadInterfaceScanResultStruct(panId, extendedPanId, networkName, channel, version, extendedAddress, rssi, lqi) + return NetworkCommissioningClusterThreadInterfaceScanResultStruct( + panId, + extendedPanId, + networkName, + channel, + version, + extendedAddress, + rssi, + lqi, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/NetworkCommissioningClusterWiFiInterfaceScanResultStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/NetworkCommissioningClusterWiFiInterfaceScanResultStruct.kt index 85c6cf71f7c47b..10de507ac304b1 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/NetworkCommissioningClusterWiFiInterfaceScanResultStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/NetworkCommissioningClusterWiFiInterfaceScanResultStruct.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -30,7 +28,7 @@ class NetworkCommissioningClusterWiFiInterfaceScanResultStruct( val bssid: ByteArray, val channel: UShort, val wiFiBand: UByte, - val rssi: Byte + val rssi: Byte, ) { override fun toString(): String = buildString { append("NetworkCommissioningClusterWiFiInterfaceScanResultStruct {\n") @@ -64,7 +62,10 @@ class NetworkCommissioningClusterWiFiInterfaceScanResultStruct( private const val TAG_WI_FI_BAND = 4 private const val TAG_RSSI = 5 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): NetworkCommissioningClusterWiFiInterfaceScanResultStruct { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): NetworkCommissioningClusterWiFiInterfaceScanResultStruct { tlvReader.enterStructure(tlvTag) val security = tlvReader.getUByte(ContextSpecificTag(TAG_SECURITY)) val ssid = tlvReader.getByteArray(ContextSpecificTag(TAG_SSID)) @@ -72,10 +73,17 @@ class NetworkCommissioningClusterWiFiInterfaceScanResultStruct( val channel = tlvReader.getUShort(ContextSpecificTag(TAG_CHANNEL)) val wiFiBand = tlvReader.getUByte(ContextSpecificTag(TAG_WI_FI_BAND)) val rssi = tlvReader.getByte(ContextSpecificTag(TAG_RSSI)) - + tlvReader.exitContainer() - return NetworkCommissioningClusterWiFiInterfaceScanResultStruct(security, ssid, bssid, channel, wiFiBand, rssi) + return NetworkCommissioningClusterWiFiInterfaceScanResultStruct( + security, + ssid, + bssid, + channel, + wiFiBand, + rssi, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/OccupancySensingClusterHoldTimeLimitsStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/OccupancySensingClusterHoldTimeLimitsStruct.kt index 56e69487fa2e90..be70d3b11ccbb3 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/OccupancySensingClusterHoldTimeLimitsStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/OccupancySensingClusterHoldTimeLimitsStruct.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -27,7 +25,7 @@ import matter.tlv.TlvWriter class OccupancySensingClusterHoldTimeLimitsStruct( val holdTimeMin: UShort, val holdTimeMax: UShort, - val holdTimeDefault: UShort + val holdTimeDefault: UShort, ) { override fun toString(): String = buildString { append("OccupancySensingClusterHoldTimeLimitsStruct {\n") @@ -57,7 +55,7 @@ class OccupancySensingClusterHoldTimeLimitsStruct( val holdTimeMin = tlvReader.getUShort(ContextSpecificTag(TAG_HOLD_TIME_MIN)) val holdTimeMax = tlvReader.getUShort(ContextSpecificTag(TAG_HOLD_TIME_MAX)) val holdTimeDefault = tlvReader.getUShort(ContextSpecificTag(TAG_HOLD_TIME_DEFAULT)) - + tlvReader.exitContainer() return OccupancySensingClusterHoldTimeLimitsStruct(holdTimeMin, holdTimeMax, holdTimeDefault) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/OperationalCredentialsClusterFabricDescriptorStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/OperationalCredentialsClusterFabricDescriptorStruct.kt index 1a186d2fcd77f3..6fad97097ca764 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/OperationalCredentialsClusterFabricDescriptorStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/OperationalCredentialsClusterFabricDescriptorStruct.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -30,7 +28,7 @@ class OperationalCredentialsClusterFabricDescriptorStruct( val fabricID: ULong, val nodeID: ULong, val label: String, - val fabricIndex: UByte + val fabricIndex: UByte, ) { override fun toString(): String = buildString { append("OperationalCredentialsClusterFabricDescriptorStruct {\n") @@ -64,7 +62,10 @@ class OperationalCredentialsClusterFabricDescriptorStruct( private const val TAG_LABEL = 5 private const val TAG_FABRIC_INDEX = 254 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): OperationalCredentialsClusterFabricDescriptorStruct { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): OperationalCredentialsClusterFabricDescriptorStruct { tlvReader.enterStructure(tlvTag) val rootPublicKey = tlvReader.getByteArray(ContextSpecificTag(TAG_ROOT_PUBLIC_KEY)) val vendorID = tlvReader.getUShort(ContextSpecificTag(TAG_VENDOR_ID)) @@ -72,10 +73,17 @@ class OperationalCredentialsClusterFabricDescriptorStruct( val nodeID = tlvReader.getULong(ContextSpecificTag(TAG_NODE_ID)) val label = tlvReader.getString(ContextSpecificTag(TAG_LABEL)) val fabricIndex = tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) - + tlvReader.exitContainer() - return OperationalCredentialsClusterFabricDescriptorStruct(rootPublicKey, vendorID, fabricID, nodeID, label, fabricIndex) + return OperationalCredentialsClusterFabricDescriptorStruct( + rootPublicKey, + vendorID, + fabricID, + nodeID, + label, + fabricIndex, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/OperationalCredentialsClusterNOCStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/OperationalCredentialsClusterNOCStruct.kt index 1a27ee6624fe40..3a743a2fcf0423 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/OperationalCredentialsClusterNOCStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/OperationalCredentialsClusterNOCStruct.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -27,7 +25,7 @@ import matter.tlv.TlvWriter class OperationalCredentialsClusterNOCStruct( val noc: ByteArray, val icac: ByteArray?, - val fabricIndex: UByte + val fabricIndex: UByte, ) { override fun toString(): String = buildString { append("OperationalCredentialsClusterNOCStruct {\n") @@ -59,14 +57,15 @@ class OperationalCredentialsClusterNOCStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): OperationalCredentialsClusterNOCStruct { tlvReader.enterStructure(tlvTag) val noc = tlvReader.getByteArray(ContextSpecificTag(TAG_NOC)) - val icac = if (!tlvReader.isNull()) { - tlvReader.getByteArray(ContextSpecificTag(TAG_ICAC)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_ICAC)) - null - } + val icac = + if (!tlvReader.isNull()) { + tlvReader.getByteArray(ContextSpecificTag(TAG_ICAC)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_ICAC)) + null + } val fabricIndex = tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) - + tlvReader.exitContainer() return OperationalCredentialsClusterNOCStruct(noc, icac, fabricIndex) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/OperationalStateClusterErrorStateStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/OperationalStateClusterErrorStateStruct.kt index f94b415fa99727..bea86d884fdc49 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/OperationalStateClusterErrorStateStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/OperationalStateClusterErrorStateStruct.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -27,7 +26,7 @@ import matter.tlv.TlvWriter class OperationalStateClusterErrorStateStruct( val errorStateID: UByte, val errorStateLabel: Optional, - val errorStateDetails: Optional + val errorStateDetails: Optional, ) { override fun toString(): String = buildString { append("OperationalStateClusterErrorStateStruct {\n") @@ -61,20 +60,26 @@ class OperationalStateClusterErrorStateStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): OperationalStateClusterErrorStateStruct { tlvReader.enterStructure(tlvTag) val errorStateID = tlvReader.getUByte(ContextSpecificTag(TAG_ERROR_STATE_ID)) - val errorStateLabel = if (tlvReader.isNextTag(ContextSpecificTag(TAG_ERROR_STATE_LABEL))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_ERROR_STATE_LABEL))) - } else { - Optional.empty() - } - val errorStateDetails = if (tlvReader.isNextTag(ContextSpecificTag(TAG_ERROR_STATE_DETAILS))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_ERROR_STATE_DETAILS))) - } else { - Optional.empty() - } - + val errorStateLabel = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_ERROR_STATE_LABEL))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_ERROR_STATE_LABEL))) + } else { + Optional.empty() + } + val errorStateDetails = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_ERROR_STATE_DETAILS))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_ERROR_STATE_DETAILS))) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return OperationalStateClusterErrorStateStruct(errorStateID, errorStateLabel, errorStateDetails) + return OperationalStateClusterErrorStateStruct( + errorStateID, + errorStateLabel, + errorStateDetails, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/OperationalStateClusterOperationalStateStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/OperationalStateClusterOperationalStateStruct.kt index 2c35206ce1f43a..7626d4a76910f8 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/OperationalStateClusterOperationalStateStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/OperationalStateClusterOperationalStateStruct.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +25,7 @@ import matter.tlv.TlvWriter class OperationalStateClusterOperationalStateStruct( val operationalStateID: UByte, - val operationalStateLabel: Optional + val operationalStateLabel: Optional, ) { override fun toString(): String = buildString { append("OperationalStateClusterOperationalStateStruct {\n") @@ -54,15 +53,19 @@ class OperationalStateClusterOperationalStateStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): OperationalStateClusterOperationalStateStruct { tlvReader.enterStructure(tlvTag) val operationalStateID = tlvReader.getUByte(ContextSpecificTag(TAG_OPERATIONAL_STATE_ID)) - val operationalStateLabel = if (tlvReader.isNextTag(ContextSpecificTag(TAG_OPERATIONAL_STATE_LABEL))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_OPERATIONAL_STATE_LABEL))) - } else { - Optional.empty() - } - + val operationalStateLabel = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_OPERATIONAL_STATE_LABEL))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_OPERATIONAL_STATE_LABEL))) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return OperationalStateClusterOperationalStateStruct(operationalStateID, operationalStateLabel) + return OperationalStateClusterOperationalStateStruct( + operationalStateID, + operationalStateLabel, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/OtaSoftwareUpdateRequestorClusterProviderLocation.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/OtaSoftwareUpdateRequestorClusterProviderLocation.kt index 774f039f2825ac..209c1580f35df2 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/OtaSoftwareUpdateRequestorClusterProviderLocation.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/OtaSoftwareUpdateRequestorClusterProviderLocation.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -27,7 +25,7 @@ import matter.tlv.TlvWriter class OtaSoftwareUpdateRequestorClusterProviderLocation( val providerNodeID: ULong, val endpoint: UShort, - val fabricIndex: UByte + val fabricIndex: UByte, ) { override fun toString(): String = buildString { append("OtaSoftwareUpdateRequestorClusterProviderLocation {\n") @@ -52,15 +50,22 @@ class OtaSoftwareUpdateRequestorClusterProviderLocation( private const val TAG_ENDPOINT = 2 private const val TAG_FABRIC_INDEX = 254 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): OtaSoftwareUpdateRequestorClusterProviderLocation { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): OtaSoftwareUpdateRequestorClusterProviderLocation { tlvReader.enterStructure(tlvTag) val providerNodeID = tlvReader.getULong(ContextSpecificTag(TAG_PROVIDER_NODE_ID)) val endpoint = tlvReader.getUShort(ContextSpecificTag(TAG_ENDPOINT)) val fabricIndex = tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) - + tlvReader.exitContainer() - return OtaSoftwareUpdateRequestorClusterProviderLocation(providerNodeID, endpoint, fabricIndex) + return OtaSoftwareUpdateRequestorClusterProviderLocation( + providerNodeID, + endpoint, + fabricIndex, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/OvenCavityOperationalStateClusterErrorStateStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/OvenCavityOperationalStateClusterErrorStateStruct.kt index 799c197712bf38..442c55ea088e3d 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/OvenCavityOperationalStateClusterErrorStateStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/OvenCavityOperationalStateClusterErrorStateStruct.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -27,7 +26,7 @@ import matter.tlv.TlvWriter class OvenCavityOperationalStateClusterErrorStateStruct( val errorStateID: UByte, val errorStateLabel: Optional, - val errorStateDetails: Optional + val errorStateDetails: Optional, ) { override fun toString(): String = buildString { append("OvenCavityOperationalStateClusterErrorStateStruct {\n") @@ -58,23 +57,32 @@ class OvenCavityOperationalStateClusterErrorStateStruct( private const val TAG_ERROR_STATE_LABEL = 1 private const val TAG_ERROR_STATE_DETAILS = 2 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): OvenCavityOperationalStateClusterErrorStateStruct { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): OvenCavityOperationalStateClusterErrorStateStruct { tlvReader.enterStructure(tlvTag) val errorStateID = tlvReader.getUByte(ContextSpecificTag(TAG_ERROR_STATE_ID)) - val errorStateLabel = if (tlvReader.isNextTag(ContextSpecificTag(TAG_ERROR_STATE_LABEL))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_ERROR_STATE_LABEL))) - } else { - Optional.empty() - } - val errorStateDetails = if (tlvReader.isNextTag(ContextSpecificTag(TAG_ERROR_STATE_DETAILS))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_ERROR_STATE_DETAILS))) - } else { - Optional.empty() - } - + val errorStateLabel = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_ERROR_STATE_LABEL))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_ERROR_STATE_LABEL))) + } else { + Optional.empty() + } + val errorStateDetails = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_ERROR_STATE_DETAILS))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_ERROR_STATE_DETAILS))) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return OvenCavityOperationalStateClusterErrorStateStruct(errorStateID, errorStateLabel, errorStateDetails) + return OvenCavityOperationalStateClusterErrorStateStruct( + errorStateID, + errorStateLabel, + errorStateDetails, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/OvenCavityOperationalStateClusterOperationalStateStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/OvenCavityOperationalStateClusterOperationalStateStruct.kt index 7f31dc31e05bb7..ef6a876dcef05f 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/OvenCavityOperationalStateClusterOperationalStateStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/OvenCavityOperationalStateClusterOperationalStateStruct.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +25,7 @@ import matter.tlv.TlvWriter class OvenCavityOperationalStateClusterOperationalStateStruct( val operationalStateID: UByte, - val operationalStateLabel: Optional + val operationalStateLabel: Optional, ) { override fun toString(): String = buildString { append("OvenCavityOperationalStateClusterOperationalStateStruct {\n") @@ -51,18 +50,25 @@ class OvenCavityOperationalStateClusterOperationalStateStruct( private const val TAG_OPERATIONAL_STATE_ID = 0 private const val TAG_OPERATIONAL_STATE_LABEL = 1 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): OvenCavityOperationalStateClusterOperationalStateStruct { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): OvenCavityOperationalStateClusterOperationalStateStruct { tlvReader.enterStructure(tlvTag) val operationalStateID = tlvReader.getUByte(ContextSpecificTag(TAG_OPERATIONAL_STATE_ID)) - val operationalStateLabel = if (tlvReader.isNextTag(ContextSpecificTag(TAG_OPERATIONAL_STATE_LABEL))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_OPERATIONAL_STATE_LABEL))) - } else { - Optional.empty() - } - + val operationalStateLabel = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_OPERATIONAL_STATE_LABEL))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_OPERATIONAL_STATE_LABEL))) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return OvenCavityOperationalStateClusterOperationalStateStruct(operationalStateID, operationalStateLabel) + return OvenCavityOperationalStateClusterOperationalStateStruct( + operationalStateID, + operationalStateLabel, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/OvenModeClusterModeOptionStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/OvenModeClusterModeOptionStruct.kt index 47fda3f789599e..6ae08faf4c850f 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/OvenModeClusterModeOptionStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/OvenModeClusterModeOptionStruct.kt @@ -16,7 +16,6 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -27,7 +26,7 @@ import matter.tlv.TlvWriter class OvenModeClusterModeOptionStruct( val label: String, val mode: UByte, - val modeTags: List + val modeTags: List, ) { override fun toString(): String = buildString { append("OvenModeClusterModeOptionStruct {\n") @@ -60,14 +59,15 @@ class OvenModeClusterModeOptionStruct( tlvReader.enterStructure(tlvTag) val label = tlvReader.getString(ContextSpecificTag(TAG_LABEL)) val mode = tlvReader.getUByte(ContextSpecificTag(TAG_MODE)) - val modeTags = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_MODE_TAGS)) - while(!tlvReader.isEndOfContainer()) { - add(OvenModeClusterModeTagStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - + val modeTags = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_MODE_TAGS)) + while (!tlvReader.isEndOfContainer()) { + add(OvenModeClusterModeTagStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + tlvReader.exitContainer() return OvenModeClusterModeOptionStruct(label, mode, modeTags) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/OvenModeClusterModeTagStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/OvenModeClusterModeTagStruct.kt index 3715c9253bd394..4ba9d368de022f 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/OvenModeClusterModeTagStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/OvenModeClusterModeTagStruct.kt @@ -18,16 +18,12 @@ package matter.controller.cluster.structs import java.util.Optional 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 OvenModeClusterModeTagStruct( - val mfgCode: Optional, - val value: UShort -) { +class OvenModeClusterModeTagStruct(val mfgCode: Optional, val value: UShort) { override fun toString(): String = buildString { append("OvenModeClusterModeTagStruct {\n") append("\tmfgCode : $mfgCode\n") @@ -53,13 +49,14 @@ class OvenModeClusterModeTagStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): OvenModeClusterModeTagStruct { tlvReader.enterStructure(tlvTag) - val mfgCode = if (tlvReader.isNextTag(ContextSpecificTag(TAG_MFG_CODE))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_MFG_CODE))) - } else { - Optional.empty() - } + val mfgCode = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_MFG_CODE))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_MFG_CODE))) + } else { + Optional.empty() + } val value = tlvReader.getUShort(ContextSpecificTag(TAG_VALUE)) - + tlvReader.exitContainer() return OvenModeClusterModeTagStruct(mfgCode, value) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/PowerSourceClusterBatChargeFaultChangeType.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/PowerSourceClusterBatChargeFaultChangeType.kt index 93b2e01e8dcd67..f4b9df55b032cf 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/PowerSourceClusterBatChargeFaultChangeType.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/PowerSourceClusterBatChargeFaultChangeType.kt @@ -16,7 +16,6 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -26,7 +25,7 @@ import matter.tlv.TlvWriter class PowerSourceClusterBatChargeFaultChangeType( val current: List, - val previous: List + val previous: List, ) { override fun toString(): String = buildString { append("PowerSourceClusterBatChargeFaultChangeType {\n") @@ -58,21 +57,23 @@ class PowerSourceClusterBatChargeFaultChangeType( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): PowerSourceClusterBatChargeFaultChangeType { tlvReader.enterStructure(tlvTag) - val current = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_CURRENT)) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } - val previous = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_PREVIOUS)) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } - + val current = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_CURRENT)) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + val previous = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_PREVIOUS)) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + tlvReader.exitContainer() return PowerSourceClusterBatChargeFaultChangeType(current, previous) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/PowerSourceClusterBatFaultChangeType.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/PowerSourceClusterBatFaultChangeType.kt index f5c4803e0482ac..6b849cc5874313 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/PowerSourceClusterBatFaultChangeType.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/PowerSourceClusterBatFaultChangeType.kt @@ -16,7 +16,6 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -24,10 +23,7 @@ import matter.tlv.Tag import matter.tlv.TlvReader import matter.tlv.TlvWriter -class PowerSourceClusterBatFaultChangeType( - val current: List, - val previous: List -) { +class PowerSourceClusterBatFaultChangeType(val current: List, val previous: List) { override fun toString(): String = buildString { append("PowerSourceClusterBatFaultChangeType {\n") append("\tcurrent : $current\n") @@ -58,21 +54,23 @@ class PowerSourceClusterBatFaultChangeType( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): PowerSourceClusterBatFaultChangeType { tlvReader.enterStructure(tlvTag) - val current = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_CURRENT)) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } - val previous = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_PREVIOUS)) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } - + val current = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_CURRENT)) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + val previous = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_PREVIOUS)) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + tlvReader.exitContainer() return PowerSourceClusterBatFaultChangeType(current, previous) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/PowerSourceClusterWiredFaultChangeType.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/PowerSourceClusterWiredFaultChangeType.kt index 0eb132ceb49b1e..9354883b16e760 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/PowerSourceClusterWiredFaultChangeType.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/PowerSourceClusterWiredFaultChangeType.kt @@ -16,7 +16,6 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -24,10 +23,7 @@ import matter.tlv.Tag import matter.tlv.TlvReader import matter.tlv.TlvWriter -class PowerSourceClusterWiredFaultChangeType( - val current: List, - val previous: List -) { +class PowerSourceClusterWiredFaultChangeType(val current: List, val previous: List) { override fun toString(): String = buildString { append("PowerSourceClusterWiredFaultChangeType {\n") append("\tcurrent : $current\n") @@ -58,21 +54,23 @@ class PowerSourceClusterWiredFaultChangeType( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): PowerSourceClusterWiredFaultChangeType { tlvReader.enterStructure(tlvTag) - val current = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_CURRENT)) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } - val previous = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_PREVIOUS)) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } - + val current = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_CURRENT)) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + val previous = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_PREVIOUS)) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + tlvReader.exitContainer() return PowerSourceClusterWiredFaultChangeType(current, previous) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/RefrigeratorAndTemperatureControlledCabinetModeClusterModeOptionStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/RefrigeratorAndTemperatureControlledCabinetModeClusterModeOptionStruct.kt index 59482e83c5039d..fd00724de7b7ac 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/RefrigeratorAndTemperatureControlledCabinetModeClusterModeOptionStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/RefrigeratorAndTemperatureControlledCabinetModeClusterModeOptionStruct.kt @@ -16,7 +16,6 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -27,7 +26,7 @@ import matter.tlv.TlvWriter class RefrigeratorAndTemperatureControlledCabinetModeClusterModeOptionStruct( val label: String, val mode: UByte, - val modeTags: List + val modeTags: List, ) { override fun toString(): String = buildString { append("RefrigeratorAndTemperatureControlledCabinetModeClusterModeOptionStruct {\n") @@ -56,21 +55,34 @@ class RefrigeratorAndTemperatureControlledCabinetModeClusterModeOptionStruct( private const val TAG_MODE = 1 private const val TAG_MODE_TAGS = 2 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): RefrigeratorAndTemperatureControlledCabinetModeClusterModeOptionStruct { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): RefrigeratorAndTemperatureControlledCabinetModeClusterModeOptionStruct { tlvReader.enterStructure(tlvTag) val label = tlvReader.getString(ContextSpecificTag(TAG_LABEL)) val mode = tlvReader.getUByte(ContextSpecificTag(TAG_MODE)) - val modeTags = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_MODE_TAGS)) - while(!tlvReader.isEndOfContainer()) { - add(RefrigeratorAndTemperatureControlledCabinetModeClusterModeTagStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - + val modeTags = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_MODE_TAGS)) + while (!tlvReader.isEndOfContainer()) { + add( + RefrigeratorAndTemperatureControlledCabinetModeClusterModeTagStruct.fromTlv( + AnonymousTag, + tlvReader, + ) + ) + } + tlvReader.exitContainer() + } + tlvReader.exitContainer() - return RefrigeratorAndTemperatureControlledCabinetModeClusterModeOptionStruct(label, mode, modeTags) + return RefrigeratorAndTemperatureControlledCabinetModeClusterModeOptionStruct( + label, + mode, + modeTags, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/RefrigeratorAndTemperatureControlledCabinetModeClusterModeTagStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/RefrigeratorAndTemperatureControlledCabinetModeClusterModeTagStruct.kt index 2ec589a6c0df35..46462a296a0d53 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/RefrigeratorAndTemperatureControlledCabinetModeClusterModeTagStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/RefrigeratorAndTemperatureControlledCabinetModeClusterModeTagStruct.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +25,7 @@ import matter.tlv.TlvWriter class RefrigeratorAndTemperatureControlledCabinetModeClusterModeTagStruct( val mfgCode: Optional, - val value: UShort + val value: UShort, ) { override fun toString(): String = buildString { append("RefrigeratorAndTemperatureControlledCabinetModeClusterModeTagStruct {\n") @@ -51,15 +50,19 @@ class RefrigeratorAndTemperatureControlledCabinetModeClusterModeTagStruct( private const val TAG_MFG_CODE = 0 private const val TAG_VALUE = 1 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): RefrigeratorAndTemperatureControlledCabinetModeClusterModeTagStruct { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): RefrigeratorAndTemperatureControlledCabinetModeClusterModeTagStruct { tlvReader.enterStructure(tlvTag) - val mfgCode = if (tlvReader.isNextTag(ContextSpecificTag(TAG_MFG_CODE))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_MFG_CODE))) - } else { - Optional.empty() - } + val mfgCode = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_MFG_CODE))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_MFG_CODE))) + } else { + Optional.empty() + } val value = tlvReader.getUShort(ContextSpecificTag(TAG_VALUE)) - + tlvReader.exitContainer() return RefrigeratorAndTemperatureControlledCabinetModeClusterModeTagStruct(mfgCode, value) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/RvcCleanModeClusterModeOptionStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/RvcCleanModeClusterModeOptionStruct.kt index a79f2a02599eba..e44fa3f8bc0e21 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/RvcCleanModeClusterModeOptionStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/RvcCleanModeClusterModeOptionStruct.kt @@ -16,7 +16,6 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -27,7 +26,7 @@ import matter.tlv.TlvWriter class RvcCleanModeClusterModeOptionStruct( val label: String, val mode: UByte, - val modeTags: List + val modeTags: List, ) { override fun toString(): String = buildString { append("RvcCleanModeClusterModeOptionStruct {\n") @@ -60,14 +59,15 @@ class RvcCleanModeClusterModeOptionStruct( tlvReader.enterStructure(tlvTag) val label = tlvReader.getString(ContextSpecificTag(TAG_LABEL)) val mode = tlvReader.getUByte(ContextSpecificTag(TAG_MODE)) - val modeTags = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_MODE_TAGS)) - while(!tlvReader.isEndOfContainer()) { - add(RvcCleanModeClusterModeTagStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - + val modeTags = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_MODE_TAGS)) + while (!tlvReader.isEndOfContainer()) { + add(RvcCleanModeClusterModeTagStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + tlvReader.exitContainer() return RvcCleanModeClusterModeOptionStruct(label, mode, modeTags) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/RvcCleanModeClusterModeTagStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/RvcCleanModeClusterModeTagStruct.kt index 88ea7b7b2f7002..ce35ad9a5a9960 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/RvcCleanModeClusterModeTagStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/RvcCleanModeClusterModeTagStruct.kt @@ -18,16 +18,12 @@ package matter.controller.cluster.structs import java.util.Optional 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 RvcCleanModeClusterModeTagStruct( - val mfgCode: Optional, - val value: UShort -) { +class RvcCleanModeClusterModeTagStruct(val mfgCode: Optional, val value: UShort) { override fun toString(): String = buildString { append("RvcCleanModeClusterModeTagStruct {\n") append("\tmfgCode : $mfgCode\n") @@ -53,13 +49,14 @@ class RvcCleanModeClusterModeTagStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): RvcCleanModeClusterModeTagStruct { tlvReader.enterStructure(tlvTag) - val mfgCode = if (tlvReader.isNextTag(ContextSpecificTag(TAG_MFG_CODE))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_MFG_CODE))) - } else { - Optional.empty() - } + val mfgCode = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_MFG_CODE))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_MFG_CODE))) + } else { + Optional.empty() + } val value = tlvReader.getUShort(ContextSpecificTag(TAG_VALUE)) - + tlvReader.exitContainer() return RvcCleanModeClusterModeTagStruct(mfgCode, value) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/RvcOperationalStateClusterErrorStateStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/RvcOperationalStateClusterErrorStateStruct.kt index aa4c5e47a918e7..e60738d973b0c5 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/RvcOperationalStateClusterErrorStateStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/RvcOperationalStateClusterErrorStateStruct.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -27,7 +26,7 @@ import matter.tlv.TlvWriter class RvcOperationalStateClusterErrorStateStruct( val errorStateID: UByte, val errorStateLabel: Optional, - val errorStateDetails: Optional + val errorStateDetails: Optional, ) { override fun toString(): String = buildString { append("RvcOperationalStateClusterErrorStateStruct {\n") @@ -61,20 +60,26 @@ class RvcOperationalStateClusterErrorStateStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): RvcOperationalStateClusterErrorStateStruct { tlvReader.enterStructure(tlvTag) val errorStateID = tlvReader.getUByte(ContextSpecificTag(TAG_ERROR_STATE_ID)) - val errorStateLabel = if (tlvReader.isNextTag(ContextSpecificTag(TAG_ERROR_STATE_LABEL))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_ERROR_STATE_LABEL))) - } else { - Optional.empty() - } - val errorStateDetails = if (tlvReader.isNextTag(ContextSpecificTag(TAG_ERROR_STATE_DETAILS))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_ERROR_STATE_DETAILS))) - } else { - Optional.empty() - } - + val errorStateLabel = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_ERROR_STATE_LABEL))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_ERROR_STATE_LABEL))) + } else { + Optional.empty() + } + val errorStateDetails = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_ERROR_STATE_DETAILS))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_ERROR_STATE_DETAILS))) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return RvcOperationalStateClusterErrorStateStruct(errorStateID, errorStateLabel, errorStateDetails) + return RvcOperationalStateClusterErrorStateStruct( + errorStateID, + errorStateLabel, + errorStateDetails, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/RvcOperationalStateClusterOperationalStateStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/RvcOperationalStateClusterOperationalStateStruct.kt index 78d0a91b1533c1..00680b85bb0c7b 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/RvcOperationalStateClusterOperationalStateStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/RvcOperationalStateClusterOperationalStateStruct.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +25,7 @@ import matter.tlv.TlvWriter class RvcOperationalStateClusterOperationalStateStruct( val operationalStateID: UByte, - val operationalStateLabel: Optional + val operationalStateLabel: Optional, ) { override fun toString(): String = buildString { append("RvcOperationalStateClusterOperationalStateStruct {\n") @@ -51,18 +50,25 @@ class RvcOperationalStateClusterOperationalStateStruct( private const val TAG_OPERATIONAL_STATE_ID = 0 private const val TAG_OPERATIONAL_STATE_LABEL = 1 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): RvcOperationalStateClusterOperationalStateStruct { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): RvcOperationalStateClusterOperationalStateStruct { tlvReader.enterStructure(tlvTag) val operationalStateID = tlvReader.getUByte(ContextSpecificTag(TAG_OPERATIONAL_STATE_ID)) - val operationalStateLabel = if (tlvReader.isNextTag(ContextSpecificTag(TAG_OPERATIONAL_STATE_LABEL))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_OPERATIONAL_STATE_LABEL))) - } else { - Optional.empty() - } - + val operationalStateLabel = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_OPERATIONAL_STATE_LABEL))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_OPERATIONAL_STATE_LABEL))) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return RvcOperationalStateClusterOperationalStateStruct(operationalStateID, operationalStateLabel) + return RvcOperationalStateClusterOperationalStateStruct( + operationalStateID, + operationalStateLabel, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/RvcRunModeClusterModeOptionStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/RvcRunModeClusterModeOptionStruct.kt index c98a49235c774f..3835b84979c2e2 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/RvcRunModeClusterModeOptionStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/RvcRunModeClusterModeOptionStruct.kt @@ -16,7 +16,6 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -27,7 +26,7 @@ import matter.tlv.TlvWriter class RvcRunModeClusterModeOptionStruct( val label: String, val mode: UByte, - val modeTags: List + val modeTags: List, ) { override fun toString(): String = buildString { append("RvcRunModeClusterModeOptionStruct {\n") @@ -60,14 +59,15 @@ class RvcRunModeClusterModeOptionStruct( tlvReader.enterStructure(tlvTag) val label = tlvReader.getString(ContextSpecificTag(TAG_LABEL)) val mode = tlvReader.getUByte(ContextSpecificTag(TAG_MODE)) - val modeTags = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_MODE_TAGS)) - while(!tlvReader.isEndOfContainer()) { - add(RvcRunModeClusterModeTagStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - + val modeTags = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_MODE_TAGS)) + while (!tlvReader.isEndOfContainer()) { + add(RvcRunModeClusterModeTagStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + tlvReader.exitContainer() return RvcRunModeClusterModeOptionStruct(label, mode, modeTags) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/RvcRunModeClusterModeTagStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/RvcRunModeClusterModeTagStruct.kt index d9c65679552d63..7ad69693847d17 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/RvcRunModeClusterModeTagStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/RvcRunModeClusterModeTagStruct.kt @@ -18,16 +18,12 @@ package matter.controller.cluster.structs import java.util.Optional 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 RvcRunModeClusterModeTagStruct( - val mfgCode: Optional, - val value: UShort -) { +class RvcRunModeClusterModeTagStruct(val mfgCode: Optional, val value: UShort) { override fun toString(): String = buildString { append("RvcRunModeClusterModeTagStruct {\n") append("\tmfgCode : $mfgCode\n") @@ -53,13 +49,14 @@ class RvcRunModeClusterModeTagStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): RvcRunModeClusterModeTagStruct { tlvReader.enterStructure(tlvTag) - val mfgCode = if (tlvReader.isNextTag(ContextSpecificTag(TAG_MFG_CODE))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_MFG_CODE))) - } else { - Optional.empty() - } + val mfgCode = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_MFG_CODE))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_MFG_CODE))) + } else { + Optional.empty() + } val value = tlvReader.getUShort(ContextSpecificTag(TAG_VALUE)) - + tlvReader.exitContainer() return RvcRunModeClusterModeTagStruct(mfgCode, value) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ScenesManagementClusterAttributeValuePairStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ScenesManagementClusterAttributeValuePairStruct.kt index a7016afac59d5d..232bfea8c1e5a7 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ScenesManagementClusterAttributeValuePairStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ScenesManagementClusterAttributeValuePairStruct.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -33,7 +32,7 @@ class ScenesManagementClusterAttributeValuePairStruct( val valueUnsigned32: Optional, val valueSigned32: Optional, val valueUnsigned64: Optional, - val valueSigned64: Optional + val valueSigned64: Optional, ) { override fun toString(): String = buildString { append("ScenesManagementClusterAttributeValuePairStruct {\n") @@ -100,53 +99,74 @@ class ScenesManagementClusterAttributeValuePairStruct( private const val TAG_VALUE_UNSIGNED64 = 7 private const val TAG_VALUE_SIGNED64 = 8 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ScenesManagementClusterAttributeValuePairStruct { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): ScenesManagementClusterAttributeValuePairStruct { tlvReader.enterStructure(tlvTag) val attributeID = tlvReader.getUInt(ContextSpecificTag(TAG_ATTRIBUTE_ID)) - val valueUnsigned8 = if (tlvReader.isNextTag(ContextSpecificTag(TAG_VALUE_UNSIGNED8))) { - Optional.of(tlvReader.getUByte(ContextSpecificTag(TAG_VALUE_UNSIGNED8))) - } else { - Optional.empty() - } - val valueSigned8 = if (tlvReader.isNextTag(ContextSpecificTag(TAG_VALUE_SIGNED8))) { - Optional.of(tlvReader.getByte(ContextSpecificTag(TAG_VALUE_SIGNED8))) - } else { - Optional.empty() - } - val valueUnsigned16 = if (tlvReader.isNextTag(ContextSpecificTag(TAG_VALUE_UNSIGNED16))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_VALUE_UNSIGNED16))) - } else { - Optional.empty() - } - val valueSigned16 = if (tlvReader.isNextTag(ContextSpecificTag(TAG_VALUE_SIGNED16))) { - Optional.of(tlvReader.getShort(ContextSpecificTag(TAG_VALUE_SIGNED16))) - } else { - Optional.empty() - } - val valueUnsigned32 = if (tlvReader.isNextTag(ContextSpecificTag(TAG_VALUE_UNSIGNED32))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_VALUE_UNSIGNED32))) - } else { - Optional.empty() - } - val valueSigned32 = if (tlvReader.isNextTag(ContextSpecificTag(TAG_VALUE_SIGNED32))) { - Optional.of(tlvReader.getInt(ContextSpecificTag(TAG_VALUE_SIGNED32))) - } else { - Optional.empty() - } - val valueUnsigned64 = if (tlvReader.isNextTag(ContextSpecificTag(TAG_VALUE_UNSIGNED64))) { - Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_VALUE_UNSIGNED64))) - } else { - Optional.empty() - } - val valueSigned64 = if (tlvReader.isNextTag(ContextSpecificTag(TAG_VALUE_SIGNED64))) { - Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_VALUE_SIGNED64))) - } else { - Optional.empty() - } - + val valueUnsigned8 = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_VALUE_UNSIGNED8))) { + Optional.of(tlvReader.getUByte(ContextSpecificTag(TAG_VALUE_UNSIGNED8))) + } else { + Optional.empty() + } + val valueSigned8 = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_VALUE_SIGNED8))) { + Optional.of(tlvReader.getByte(ContextSpecificTag(TAG_VALUE_SIGNED8))) + } else { + Optional.empty() + } + val valueUnsigned16 = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_VALUE_UNSIGNED16))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_VALUE_UNSIGNED16))) + } else { + Optional.empty() + } + val valueSigned16 = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_VALUE_SIGNED16))) { + Optional.of(tlvReader.getShort(ContextSpecificTag(TAG_VALUE_SIGNED16))) + } else { + Optional.empty() + } + val valueUnsigned32 = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_VALUE_UNSIGNED32))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_VALUE_UNSIGNED32))) + } else { + Optional.empty() + } + val valueSigned32 = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_VALUE_SIGNED32))) { + Optional.of(tlvReader.getInt(ContextSpecificTag(TAG_VALUE_SIGNED32))) + } else { + Optional.empty() + } + val valueUnsigned64 = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_VALUE_UNSIGNED64))) { + Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_VALUE_UNSIGNED64))) + } else { + Optional.empty() + } + val valueSigned64 = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_VALUE_SIGNED64))) { + Optional.of(tlvReader.getLong(ContextSpecificTag(TAG_VALUE_SIGNED64))) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return ScenesManagementClusterAttributeValuePairStruct(attributeID, valueUnsigned8, valueSigned8, valueUnsigned16, valueSigned16, valueUnsigned32, valueSigned32, valueUnsigned64, valueSigned64) + return ScenesManagementClusterAttributeValuePairStruct( + attributeID, + valueUnsigned8, + valueSigned8, + valueUnsigned16, + valueSigned16, + valueUnsigned32, + valueSigned32, + valueUnsigned64, + valueSigned64, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ScenesManagementClusterExtensionFieldSet.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ScenesManagementClusterExtensionFieldSet.kt index 0d27b983c567d4..4fcc98ecaf5921 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ScenesManagementClusterExtensionFieldSet.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ScenesManagementClusterExtensionFieldSet.kt @@ -16,7 +16,6 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -26,7 +25,7 @@ import matter.tlv.TlvWriter class ScenesManagementClusterExtensionFieldSet( val clusterID: UInt, - val attributeValueList: List + val attributeValueList: List, ) { override fun toString(): String = buildString { append("ScenesManagementClusterExtensionFieldSet {\n") @@ -55,14 +54,15 @@ class ScenesManagementClusterExtensionFieldSet( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ScenesManagementClusterExtensionFieldSet { tlvReader.enterStructure(tlvTag) val clusterID = tlvReader.getUInt(ContextSpecificTag(TAG_CLUSTER_ID)) - val attributeValueList = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_ATTRIBUTE_VALUE_LIST)) - while(!tlvReader.isEndOfContainer()) { - add(ScenesManagementClusterAttributeValuePairStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - + val attributeValueList = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_ATTRIBUTE_VALUE_LIST)) + while (!tlvReader.isEndOfContainer()) { + add(ScenesManagementClusterAttributeValuePairStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + tlvReader.exitContainer() return ScenesManagementClusterExtensionFieldSet(clusterID, attributeValueList) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ScenesManagementClusterSceneInfoStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ScenesManagementClusterSceneInfoStruct.kt index ea23bcb97924f6..915f63f84894ed 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ScenesManagementClusterSceneInfoStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ScenesManagementClusterSceneInfoStruct.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -30,7 +28,7 @@ class ScenesManagementClusterSceneInfoStruct( val currentGroup: UShort, val sceneValid: Boolean, val remainingCapacity: UByte, - val fabricIndex: UByte + val fabricIndex: UByte, ) { override fun toString(): String = buildString { append("ScenesManagementClusterSceneInfoStruct {\n") @@ -72,10 +70,17 @@ class ScenesManagementClusterSceneInfoStruct( 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 ScenesManagementClusterSceneInfoStruct(sceneCount, currentScene, currentGroup, sceneValid, remainingCapacity, fabricIndex) + return ScenesManagementClusterSceneInfoStruct( + sceneCount, + currentScene, + currentGroup, + sceneValid, + remainingCapacity, + fabricIndex, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ServiceAreaClusterAreaInfoStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ServiceAreaClusterAreaInfoStruct.kt index 97c042d1ffef49..1c71c6bcd1ff68 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ServiceAreaClusterAreaInfoStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ServiceAreaClusterAreaInfoStruct.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +24,7 @@ import matter.tlv.TlvWriter class ServiceAreaClusterAreaInfoStruct( val locationInfo: ServiceAreaClusterLocationDescriptorStruct?, - val landmarkInfo: ServiceAreaClusterLandmarkInfoStruct? + val landmarkInfo: ServiceAreaClusterLandmarkInfoStruct?, ) { override fun toString(): String = buildString { append("ServiceAreaClusterAreaInfoStruct {\n") @@ -58,19 +56,27 @@ class ServiceAreaClusterAreaInfoStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ServiceAreaClusterAreaInfoStruct { tlvReader.enterStructure(tlvTag) - val locationInfo = if (!tlvReader.isNull()) { - ServiceAreaClusterLocationDescriptorStruct.fromTlv(ContextSpecificTag(TAG_LOCATION_INFO), tlvReader) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_LOCATION_INFO)) - null - } - val landmarkInfo = if (!tlvReader.isNull()) { - ServiceAreaClusterLandmarkInfoStruct.fromTlv(ContextSpecificTag(TAG_LANDMARK_INFO), tlvReader) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_LANDMARK_INFO)) - null - } - + val locationInfo = + if (!tlvReader.isNull()) { + ServiceAreaClusterLocationDescriptorStruct.fromTlv( + ContextSpecificTag(TAG_LOCATION_INFO), + tlvReader, + ) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_LOCATION_INFO)) + null + } + val landmarkInfo = + if (!tlvReader.isNull()) { + ServiceAreaClusterLandmarkInfoStruct.fromTlv( + ContextSpecificTag(TAG_LANDMARK_INFO), + tlvReader, + ) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_LANDMARK_INFO)) + null + } + tlvReader.exitContainer() return ServiceAreaClusterAreaInfoStruct(locationInfo, landmarkInfo) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ServiceAreaClusterAreaStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ServiceAreaClusterAreaStruct.kt index d990f47c40ec3e..d310fe5c315bf8 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ServiceAreaClusterAreaStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ServiceAreaClusterAreaStruct.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -27,7 +25,7 @@ import matter.tlv.TlvWriter class ServiceAreaClusterAreaStruct( val areaID: UInt, val mapID: UInt?, - val areaDesc: ServiceAreaClusterAreaInfoStruct + val areaDesc: ServiceAreaClusterAreaInfoStruct, ) { override fun toString(): String = buildString { append("ServiceAreaClusterAreaStruct {\n") @@ -59,14 +57,16 @@ class ServiceAreaClusterAreaStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ServiceAreaClusterAreaStruct { tlvReader.enterStructure(tlvTag) val areaID = tlvReader.getUInt(ContextSpecificTag(TAG_AREA_ID)) - val mapID = if (!tlvReader.isNull()) { - tlvReader.getUInt(ContextSpecificTag(TAG_MAP_ID)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_MAP_ID)) - null - } - val areaDesc = ServiceAreaClusterAreaInfoStruct.fromTlv(ContextSpecificTag(TAG_AREA_DESC), tlvReader) - + val mapID = + if (!tlvReader.isNull()) { + tlvReader.getUInt(ContextSpecificTag(TAG_MAP_ID)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_MAP_ID)) + null + } + val areaDesc = + ServiceAreaClusterAreaInfoStruct.fromTlv(ContextSpecificTag(TAG_AREA_DESC), tlvReader) + tlvReader.exitContainer() return ServiceAreaClusterAreaStruct(areaID, mapID, areaDesc) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ServiceAreaClusterLandmarkInfoStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ServiceAreaClusterLandmarkInfoStruct.kt index 0bff30d349bf28..119667c339d88c 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ServiceAreaClusterLandmarkInfoStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ServiceAreaClusterLandmarkInfoStruct.kt @@ -16,18 +16,13 @@ */ package matter.controller.cluster.structs -import java.util.Optional 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 ServiceAreaClusterLandmarkInfoStruct( - val landmarkTag: UByte, - val positionTag: UByte? -) { +class ServiceAreaClusterLandmarkInfoStruct(val landmarkTag: UByte, val positionTag: UByte?) { override fun toString(): String = buildString { append("ServiceAreaClusterLandmarkInfoStruct {\n") append("\tlandmarkTag : $landmarkTag\n") @@ -55,13 +50,14 @@ class ServiceAreaClusterLandmarkInfoStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ServiceAreaClusterLandmarkInfoStruct { tlvReader.enterStructure(tlvTag) val landmarkTag = tlvReader.getUByte(ContextSpecificTag(TAG_LANDMARK_TAG)) - val positionTag = if (!tlvReader.isNull()) { - tlvReader.getUByte(ContextSpecificTag(TAG_POSITION_TAG)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_POSITION_TAG)) - null - } - + val positionTag = + if (!tlvReader.isNull()) { + tlvReader.getUByte(ContextSpecificTag(TAG_POSITION_TAG)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_POSITION_TAG)) + null + } + tlvReader.exitContainer() return ServiceAreaClusterLandmarkInfoStruct(landmarkTag, positionTag) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ServiceAreaClusterLocationDescriptorStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ServiceAreaClusterLocationDescriptorStruct.kt index 3ba125abe0dd9b..fd24fa9218c22d 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ServiceAreaClusterLocationDescriptorStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ServiceAreaClusterLocationDescriptorStruct.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -27,7 +25,7 @@ import matter.tlv.TlvWriter class ServiceAreaClusterLocationDescriptorStruct( val locationName: String, val floorNumber: Short?, - val areaType: UByte? + val areaType: UByte?, ) { override fun toString(): String = buildString { append("ServiceAreaClusterLocationDescriptorStruct {\n") @@ -63,19 +61,21 @@ class ServiceAreaClusterLocationDescriptorStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ServiceAreaClusterLocationDescriptorStruct { tlvReader.enterStructure(tlvTag) val locationName = tlvReader.getString(ContextSpecificTag(TAG_LOCATION_NAME)) - val floorNumber = if (!tlvReader.isNull()) { - tlvReader.getShort(ContextSpecificTag(TAG_FLOOR_NUMBER)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_FLOOR_NUMBER)) - null - } - val areaType = if (!tlvReader.isNull()) { - tlvReader.getUByte(ContextSpecificTag(TAG_AREA_TYPE)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_AREA_TYPE)) - null - } - + val floorNumber = + if (!tlvReader.isNull()) { + tlvReader.getShort(ContextSpecificTag(TAG_FLOOR_NUMBER)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_FLOOR_NUMBER)) + null + } + val areaType = + if (!tlvReader.isNull()) { + tlvReader.getUByte(ContextSpecificTag(TAG_AREA_TYPE)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_AREA_TYPE)) + null + } + tlvReader.exitContainer() return ServiceAreaClusterLocationDescriptorStruct(locationName, floorNumber, areaType) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ServiceAreaClusterMapStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ServiceAreaClusterMapStruct.kt index 83b961f4a3aa9b..19df0938c57b93 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ServiceAreaClusterMapStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ServiceAreaClusterMapStruct.kt @@ -16,18 +16,13 @@ */ package matter.controller.cluster.structs -import java.util.Optional 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 ServiceAreaClusterMapStruct( - val mapID: UInt, - val name: String -) { +class ServiceAreaClusterMapStruct(val mapID: UInt, val name: String) { override fun toString(): String = buildString { append("ServiceAreaClusterMapStruct {\n") append("\tmapID : $mapID\n") @@ -52,7 +47,7 @@ class ServiceAreaClusterMapStruct( tlvReader.enterStructure(tlvTag) val mapID = tlvReader.getUInt(ContextSpecificTag(TAG_MAP_ID)) val name = tlvReader.getString(ContextSpecificTag(TAG_NAME)) - + tlvReader.exitContainer() return ServiceAreaClusterMapStruct(mapID, name) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ServiceAreaClusterProgressStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ServiceAreaClusterProgressStruct.kt index 8e322fdfcd223f..02b16f17cd101d 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ServiceAreaClusterProgressStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ServiceAreaClusterProgressStruct.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -28,7 +27,7 @@ class ServiceAreaClusterProgressStruct( val areaID: UInt, val status: UByte, val totalOperationalTime: Optional?, - val estimatedTime: Optional? + val estimatedTime: Optional?, ) { override fun toString(): String = buildString { append("ServiceAreaClusterProgressStruct {\n") @@ -46,17 +45,17 @@ class ServiceAreaClusterProgressStruct( put(ContextSpecificTag(TAG_STATUS), status) if (totalOperationalTime != null) { if (totalOperationalTime.isPresent) { - val opttotalOperationalTime = totalOperationalTime.get() - put(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME), opttotalOperationalTime) - } + val opttotalOperationalTime = totalOperationalTime.get() + put(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME), opttotalOperationalTime) + } } else { putNull(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME)) } if (estimatedTime != null) { if (estimatedTime.isPresent) { - val optestimatedTime = estimatedTime.get() - put(ContextSpecificTag(TAG_ESTIMATED_TIME), optestimatedTime) - } + val optestimatedTime = estimatedTime.get() + put(ContextSpecificTag(TAG_ESTIMATED_TIME), optestimatedTime) + } } else { putNull(ContextSpecificTag(TAG_ESTIMATED_TIME)) } @@ -74,27 +73,29 @@ class ServiceAreaClusterProgressStruct( tlvReader.enterStructure(tlvTag) val areaID = tlvReader.getUInt(ContextSpecificTag(TAG_AREA_ID)) val status = tlvReader.getUByte(ContextSpecificTag(TAG_STATUS)) - val totalOperationalTime = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME)) - null - } - val estimatedTime = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_ESTIMATED_TIME))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_ESTIMATED_TIME))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_ESTIMATED_TIME)) - null - } - + val totalOperationalTime = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_TOTAL_OPERATIONAL_TIME)) + null + } + val estimatedTime = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_ESTIMATED_TIME))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_ESTIMATED_TIME))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_ESTIMATED_TIME)) + null + } + tlvReader.exitContainer() return ServiceAreaClusterProgressStruct(areaID, status, totalOperationalTime, estimatedTime) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/SoftwareDiagnosticsClusterThreadMetricsStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/SoftwareDiagnosticsClusterThreadMetricsStruct.kt index 75b362e21df943..3ddcff494d0580 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/SoftwareDiagnosticsClusterThreadMetricsStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/SoftwareDiagnosticsClusterThreadMetricsStruct.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -29,7 +28,7 @@ class SoftwareDiagnosticsClusterThreadMetricsStruct( val name: Optional, val stackFreeCurrent: Optional, val stackFreeMinimum: Optional, - val stackSize: Optional + val stackSize: Optional, ) { override fun toString(): String = buildString { append("SoftwareDiagnosticsClusterThreadMetricsStruct {\n") @@ -75,30 +74,40 @@ class SoftwareDiagnosticsClusterThreadMetricsStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): SoftwareDiagnosticsClusterThreadMetricsStruct { tlvReader.enterStructure(tlvTag) val id = tlvReader.getULong(ContextSpecificTag(TAG_ID)) - val name = if (tlvReader.isNextTag(ContextSpecificTag(TAG_NAME))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_NAME))) - } else { - Optional.empty() - } - val stackFreeCurrent = if (tlvReader.isNextTag(ContextSpecificTag(TAG_STACK_FREE_CURRENT))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_STACK_FREE_CURRENT))) - } else { - Optional.empty() - } - val stackFreeMinimum = if (tlvReader.isNextTag(ContextSpecificTag(TAG_STACK_FREE_MINIMUM))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_STACK_FREE_MINIMUM))) - } else { - Optional.empty() - } - val stackSize = if (tlvReader.isNextTag(ContextSpecificTag(TAG_STACK_SIZE))) { - Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_STACK_SIZE))) - } else { - Optional.empty() - } - + val name = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_NAME))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_NAME))) + } else { + Optional.empty() + } + val stackFreeCurrent = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_STACK_FREE_CURRENT))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_STACK_FREE_CURRENT))) + } else { + Optional.empty() + } + val stackFreeMinimum = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_STACK_FREE_MINIMUM))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_STACK_FREE_MINIMUM))) + } else { + Optional.empty() + } + val stackSize = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_STACK_SIZE))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_STACK_SIZE))) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return SoftwareDiagnosticsClusterThreadMetricsStruct(id, name, stackFreeCurrent, stackFreeMinimum, stackSize) + return SoftwareDiagnosticsClusterThreadMetricsStruct( + id, + name, + stackFreeCurrent, + stackFreeMinimum, + stackSize, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/TargetNavigatorClusterTargetInfoStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/TargetNavigatorClusterTargetInfoStruct.kt index 804fa744fe4660..d1c115ff44e58e 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/TargetNavigatorClusterTargetInfoStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/TargetNavigatorClusterTargetInfoStruct.kt @@ -16,18 +16,13 @@ */ package matter.controller.cluster.structs -import java.util.Optional 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 TargetNavigatorClusterTargetInfoStruct( - val identifier: UByte, - val name: String -) { +class TargetNavigatorClusterTargetInfoStruct(val identifier: UByte, val name: String) { override fun toString(): String = buildString { append("TargetNavigatorClusterTargetInfoStruct {\n") append("\tidentifier : $identifier\n") @@ -52,7 +47,7 @@ class TargetNavigatorClusterTargetInfoStruct( tlvReader.enterStructure(tlvTag) val identifier = tlvReader.getUByte(ContextSpecificTag(TAG_IDENTIFIER)) val name = tlvReader.getString(ContextSpecificTag(TAG_NAME)) - + tlvReader.exitContainer() return TargetNavigatorClusterTargetInfoStruct(identifier, name) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterAtomicAttributeStatusStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterAtomicAttributeStatusStruct.kt index 56527a73c80544..42fc80b898b3b8 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterAtomicAttributeStatusStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterAtomicAttributeStatusStruct.kt @@ -16,18 +16,13 @@ */ package matter.controller.cluster.structs -import java.util.Optional 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 ThermostatClusterAtomicAttributeStatusStruct( - val attributeID: UInt, - val statusCode: UByte -) { +class ThermostatClusterAtomicAttributeStatusStruct(val attributeID: UInt, val statusCode: UByte) { override fun toString(): String = buildString { append("ThermostatClusterAtomicAttributeStatusStruct {\n") append("\tattributeID : $attributeID\n") @@ -52,7 +47,7 @@ class ThermostatClusterAtomicAttributeStatusStruct( tlvReader.enterStructure(tlvTag) val attributeID = tlvReader.getUInt(ContextSpecificTag(TAG_ATTRIBUTE_ID)) val statusCode = tlvReader.getUByte(ContextSpecificTag(TAG_STATUS_CODE)) - + tlvReader.exitContainer() return ThermostatClusterAtomicAttributeStatusStruct(attributeID, statusCode) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterPresetStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterPresetStruct.kt index be590ab0cbc7f8..ede9623aa74fbb 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterPresetStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterPresetStruct.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -30,7 +29,7 @@ class ThermostatClusterPresetStruct( val name: Optional?, val coolingSetpoint: Optional, val heatingSetpoint: Optional, - val builtIn: Boolean? + val builtIn: Boolean?, ) { override fun toString(): String = buildString { append("ThermostatClusterPresetStruct {\n") @@ -54,9 +53,9 @@ class ThermostatClusterPresetStruct( put(ContextSpecificTag(TAG_PRESET_SCENARIO), presetScenario) if (name != null) { if (name.isPresent) { - val optname = name.get() - put(ContextSpecificTag(TAG_NAME), optname) - } + val optname = name.get() + put(ContextSpecificTag(TAG_NAME), optname) + } } else { putNull(ContextSpecificTag(TAG_NAME)) } @@ -87,43 +86,55 @@ class ThermostatClusterPresetStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ThermostatClusterPresetStruct { tlvReader.enterStructure(tlvTag) - val presetHandle = if (!tlvReader.isNull()) { - tlvReader.getByteArray(ContextSpecificTag(TAG_PRESET_HANDLE)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_PRESET_HANDLE)) - null - } + val presetHandle = + if (!tlvReader.isNull()) { + tlvReader.getByteArray(ContextSpecificTag(TAG_PRESET_HANDLE)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_PRESET_HANDLE)) + null + } val presetScenario = tlvReader.getUByte(ContextSpecificTag(TAG_PRESET_SCENARIO)) - val name = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_NAME))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_NAME))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_NAME)) - null - } - val coolingSetpoint = if (tlvReader.isNextTag(ContextSpecificTag(TAG_COOLING_SETPOINT))) { - Optional.of(tlvReader.getShort(ContextSpecificTag(TAG_COOLING_SETPOINT))) - } else { - Optional.empty() - } - val heatingSetpoint = if (tlvReader.isNextTag(ContextSpecificTag(TAG_HEATING_SETPOINT))) { - Optional.of(tlvReader.getShort(ContextSpecificTag(TAG_HEATING_SETPOINT))) - } else { - Optional.empty() - } - val builtIn = if (!tlvReader.isNull()) { - tlvReader.getBoolean(ContextSpecificTag(TAG_BUILT_IN)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_BUILT_IN)) - null - } - + val name = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_NAME))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_NAME))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_NAME)) + null + } + val coolingSetpoint = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_COOLING_SETPOINT))) { + Optional.of(tlvReader.getShort(ContextSpecificTag(TAG_COOLING_SETPOINT))) + } else { + Optional.empty() + } + val heatingSetpoint = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_HEATING_SETPOINT))) { + Optional.of(tlvReader.getShort(ContextSpecificTag(TAG_HEATING_SETPOINT))) + } else { + Optional.empty() + } + val builtIn = + if (!tlvReader.isNull()) { + tlvReader.getBoolean(ContextSpecificTag(TAG_BUILT_IN)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_BUILT_IN)) + null + } + tlvReader.exitContainer() - return ThermostatClusterPresetStruct(presetHandle, presetScenario, name, coolingSetpoint, heatingSetpoint, builtIn) + return ThermostatClusterPresetStruct( + presetHandle, + presetScenario, + name, + coolingSetpoint, + heatingSetpoint, + builtIn, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterPresetTypeStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterPresetTypeStruct.kt index e9d029d6a542f3..d0a100321f278d 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterPresetTypeStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterPresetTypeStruct.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -27,7 +25,7 @@ import matter.tlv.TlvWriter class ThermostatClusterPresetTypeStruct( val presetScenario: UByte, val numberOfPresets: UByte, - val presetTypeFeatures: UShort + val presetTypeFeatures: UShort, ) { override fun toString(): String = buildString { append("ThermostatClusterPresetTypeStruct {\n") @@ -57,7 +55,7 @@ class ThermostatClusterPresetTypeStruct( val presetScenario = tlvReader.getUByte(ContextSpecificTag(TAG_PRESET_SCENARIO)) val numberOfPresets = tlvReader.getUByte(ContextSpecificTag(TAG_NUMBER_OF_PRESETS)) val presetTypeFeatures = tlvReader.getUShort(ContextSpecificTag(TAG_PRESET_TYPE_FEATURES)) - + tlvReader.exitContainer() return ThermostatClusterPresetTypeStruct(presetScenario, numberOfPresets, presetTypeFeatures) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterScheduleStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterScheduleStruct.kt index 57f20a9bd42299..90ca5ab50b6514 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterScheduleStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterScheduleStruct.kt @@ -30,7 +30,7 @@ class ThermostatClusterScheduleStruct( val name: Optional, val presetHandle: Optional, val transitions: List, - val builtIn: Boolean? + val builtIn: Boolean?, ) { override fun toString(): String = buildString { append("ThermostatClusterScheduleStruct {\n") @@ -84,40 +84,52 @@ class ThermostatClusterScheduleStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ThermostatClusterScheduleStruct { tlvReader.enterStructure(tlvTag) - val scheduleHandle = if (!tlvReader.isNull()) { - tlvReader.getByteArray(ContextSpecificTag(TAG_SCHEDULE_HANDLE)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_SCHEDULE_HANDLE)) - null - } + val scheduleHandle = + if (!tlvReader.isNull()) { + tlvReader.getByteArray(ContextSpecificTag(TAG_SCHEDULE_HANDLE)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_SCHEDULE_HANDLE)) + null + } val systemMode = tlvReader.getUByte(ContextSpecificTag(TAG_SYSTEM_MODE)) - val name = if (tlvReader.isNextTag(ContextSpecificTag(TAG_NAME))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_NAME))) - } else { - Optional.empty() - } - val presetHandle = if (tlvReader.isNextTag(ContextSpecificTag(TAG_PRESET_HANDLE))) { - Optional.of(tlvReader.getByteArray(ContextSpecificTag(TAG_PRESET_HANDLE))) - } else { - Optional.empty() - } - val transitions = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_TRANSITIONS)) - while(!tlvReader.isEndOfContainer()) { - add(ThermostatClusterScheduleTransitionStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - val builtIn = if (!tlvReader.isNull()) { - tlvReader.getBoolean(ContextSpecificTag(TAG_BUILT_IN)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_BUILT_IN)) - null - } - + val name = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_NAME))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_NAME))) + } else { + Optional.empty() + } + val presetHandle = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_PRESET_HANDLE))) { + Optional.of(tlvReader.getByteArray(ContextSpecificTag(TAG_PRESET_HANDLE))) + } else { + Optional.empty() + } + val transitions = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_TRANSITIONS)) + while (!tlvReader.isEndOfContainer()) { + add(ThermostatClusterScheduleTransitionStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + val builtIn = + if (!tlvReader.isNull()) { + tlvReader.getBoolean(ContextSpecificTag(TAG_BUILT_IN)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_BUILT_IN)) + null + } + tlvReader.exitContainer() - return ThermostatClusterScheduleStruct(scheduleHandle, systemMode, name, presetHandle, transitions, builtIn) + return ThermostatClusterScheduleStruct( + scheduleHandle, + systemMode, + name, + presetHandle, + transitions, + builtIn, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterScheduleTransitionStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterScheduleTransitionStruct.kt index 1bd8bfe8cbf3be..5bcc01a15d4f90 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterScheduleTransitionStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterScheduleTransitionStruct.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -30,7 +29,7 @@ class ThermostatClusterScheduleTransitionStruct( val presetHandle: Optional, val systemMode: Optional, val coolingSetpoint: Optional, - val heatingSetpoint: Optional + val heatingSetpoint: Optional, ) { override fun toString(): String = buildString { append("ThermostatClusterScheduleTransitionStruct {\n") @@ -80,30 +79,41 @@ class ThermostatClusterScheduleTransitionStruct( tlvReader.enterStructure(tlvTag) val dayOfWeek = tlvReader.getUByte(ContextSpecificTag(TAG_DAY_OF_WEEK)) val transitionTime = tlvReader.getUShort(ContextSpecificTag(TAG_TRANSITION_TIME)) - val presetHandle = if (tlvReader.isNextTag(ContextSpecificTag(TAG_PRESET_HANDLE))) { - Optional.of(tlvReader.getByteArray(ContextSpecificTag(TAG_PRESET_HANDLE))) - } else { - Optional.empty() - } - val systemMode = if (tlvReader.isNextTag(ContextSpecificTag(TAG_SYSTEM_MODE))) { - Optional.of(tlvReader.getUByte(ContextSpecificTag(TAG_SYSTEM_MODE))) - } else { - Optional.empty() - } - val coolingSetpoint = if (tlvReader.isNextTag(ContextSpecificTag(TAG_COOLING_SETPOINT))) { - Optional.of(tlvReader.getShort(ContextSpecificTag(TAG_COOLING_SETPOINT))) - } else { - Optional.empty() - } - val heatingSetpoint = if (tlvReader.isNextTag(ContextSpecificTag(TAG_HEATING_SETPOINT))) { - Optional.of(tlvReader.getShort(ContextSpecificTag(TAG_HEATING_SETPOINT))) - } else { - Optional.empty() - } - + val presetHandle = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_PRESET_HANDLE))) { + Optional.of(tlvReader.getByteArray(ContextSpecificTag(TAG_PRESET_HANDLE))) + } else { + Optional.empty() + } + val systemMode = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_SYSTEM_MODE))) { + Optional.of(tlvReader.getUByte(ContextSpecificTag(TAG_SYSTEM_MODE))) + } else { + Optional.empty() + } + val coolingSetpoint = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_COOLING_SETPOINT))) { + Optional.of(tlvReader.getShort(ContextSpecificTag(TAG_COOLING_SETPOINT))) + } else { + Optional.empty() + } + val heatingSetpoint = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_HEATING_SETPOINT))) { + Optional.of(tlvReader.getShort(ContextSpecificTag(TAG_HEATING_SETPOINT))) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return ThermostatClusterScheduleTransitionStruct(dayOfWeek, transitionTime, presetHandle, systemMode, coolingSetpoint, heatingSetpoint) + return ThermostatClusterScheduleTransitionStruct( + dayOfWeek, + transitionTime, + presetHandle, + systemMode, + coolingSetpoint, + heatingSetpoint, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterScheduleTypeStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterScheduleTypeStruct.kt index 781f9fdd1aee97..4c9a9b879477b9 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterScheduleTypeStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterScheduleTypeStruct.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -27,7 +25,7 @@ import matter.tlv.TlvWriter class ThermostatClusterScheduleTypeStruct( val systemMode: UByte, val numberOfSchedules: UByte, - val scheduleTypeFeatures: UShort + val scheduleTypeFeatures: UShort, ) { override fun toString(): String = buildString { append("ThermostatClusterScheduleTypeStruct {\n") @@ -57,10 +55,14 @@ class ThermostatClusterScheduleTypeStruct( val systemMode = tlvReader.getUByte(ContextSpecificTag(TAG_SYSTEM_MODE)) val numberOfSchedules = tlvReader.getUByte(ContextSpecificTag(TAG_NUMBER_OF_SCHEDULES)) val scheduleTypeFeatures = tlvReader.getUShort(ContextSpecificTag(TAG_SCHEDULE_TYPE_FEATURES)) - + tlvReader.exitContainer() - return ThermostatClusterScheduleTypeStruct(systemMode, numberOfSchedules, scheduleTypeFeatures) + return ThermostatClusterScheduleTypeStruct( + systemMode, + numberOfSchedules, + scheduleTypeFeatures, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterWeeklyScheduleTransitionStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterWeeklyScheduleTransitionStruct.kt index 98721edcba9faa..f3c6dd6260c386 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterWeeklyScheduleTransitionStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ThermostatClusterWeeklyScheduleTransitionStruct.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -27,7 +25,7 @@ import matter.tlv.TlvWriter class ThermostatClusterWeeklyScheduleTransitionStruct( val transitionTime: UShort, val heatSetpoint: Short?, - val coolSetpoint: Short? + val coolSetpoint: Short?, ) { override fun toString(): String = buildString { append("ThermostatClusterWeeklyScheduleTransitionStruct {\n") @@ -60,25 +58,34 @@ class ThermostatClusterWeeklyScheduleTransitionStruct( private const val TAG_HEAT_SETPOINT = 1 private const val TAG_COOL_SETPOINT = 2 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ThermostatClusterWeeklyScheduleTransitionStruct { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): ThermostatClusterWeeklyScheduleTransitionStruct { tlvReader.enterStructure(tlvTag) val transitionTime = tlvReader.getUShort(ContextSpecificTag(TAG_TRANSITION_TIME)) - val heatSetpoint = if (!tlvReader.isNull()) { - tlvReader.getShort(ContextSpecificTag(TAG_HEAT_SETPOINT)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_HEAT_SETPOINT)) - null - } - val coolSetpoint = if (!tlvReader.isNull()) { - tlvReader.getShort(ContextSpecificTag(TAG_COOL_SETPOINT)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_COOL_SETPOINT)) - null - } - + val heatSetpoint = + if (!tlvReader.isNull()) { + tlvReader.getShort(ContextSpecificTag(TAG_HEAT_SETPOINT)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_HEAT_SETPOINT)) + null + } + val coolSetpoint = + if (!tlvReader.isNull()) { + tlvReader.getShort(ContextSpecificTag(TAG_COOL_SETPOINT)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_COOL_SETPOINT)) + null + } + tlvReader.exitContainer() - return ThermostatClusterWeeklyScheduleTransitionStruct(transitionTime, heatSetpoint, coolSetpoint) + return ThermostatClusterWeeklyScheduleTransitionStruct( + transitionTime, + heatSetpoint, + coolSetpoint, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ThreadNetworkDiagnosticsClusterNeighborTableStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ThreadNetworkDiagnosticsClusterNeighborTableStruct.kt index 21ee03ed5e51b3..1804582d9d3402 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ThreadNetworkDiagnosticsClusterNeighborTableStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ThreadNetworkDiagnosticsClusterNeighborTableStruct.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -38,7 +36,7 @@ class ThreadNetworkDiagnosticsClusterNeighborTableStruct( val rxOnWhenIdle: Boolean, val fullThreadDevice: Boolean, val fullNetworkData: Boolean, - val isChild: Boolean + val isChild: Boolean, ) { override fun toString(): String = buildString { append("ThreadNetworkDiagnosticsClusterNeighborTableStruct {\n") @@ -104,7 +102,10 @@ class ThreadNetworkDiagnosticsClusterNeighborTableStruct( private const val TAG_FULL_NETWORK_DATA = 12 private const val TAG_IS_CHILD = 13 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ThreadNetworkDiagnosticsClusterNeighborTableStruct { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): ThreadNetworkDiagnosticsClusterNeighborTableStruct { tlvReader.enterStructure(tlvTag) val extAddress = tlvReader.getULong(ContextSpecificTag(TAG_EXT_ADDRESS)) val age = tlvReader.getUInt(ContextSpecificTag(TAG_AGE)) @@ -112,28 +113,45 @@ class ThreadNetworkDiagnosticsClusterNeighborTableStruct( val linkFrameCounter = tlvReader.getUInt(ContextSpecificTag(TAG_LINK_FRAME_COUNTER)) val mleFrameCounter = tlvReader.getUInt(ContextSpecificTag(TAG_MLE_FRAME_COUNTER)) val lqi = tlvReader.getUByte(ContextSpecificTag(TAG_LQI)) - val averageRssi = if (!tlvReader.isNull()) { - tlvReader.getByte(ContextSpecificTag(TAG_AVERAGE_RSSI)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_AVERAGE_RSSI)) - null - } - val lastRssi = if (!tlvReader.isNull()) { - tlvReader.getByte(ContextSpecificTag(TAG_LAST_RSSI)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_LAST_RSSI)) - null - } + val averageRssi = + if (!tlvReader.isNull()) { + tlvReader.getByte(ContextSpecificTag(TAG_AVERAGE_RSSI)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_AVERAGE_RSSI)) + null + } + val lastRssi = + if (!tlvReader.isNull()) { + tlvReader.getByte(ContextSpecificTag(TAG_LAST_RSSI)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_LAST_RSSI)) + null + } val frameErrorRate = tlvReader.getUByte(ContextSpecificTag(TAG_FRAME_ERROR_RATE)) val messageErrorRate = tlvReader.getUByte(ContextSpecificTag(TAG_MESSAGE_ERROR_RATE)) val rxOnWhenIdle = tlvReader.getBoolean(ContextSpecificTag(TAG_RX_ON_WHEN_IDLE)) val fullThreadDevice = tlvReader.getBoolean(ContextSpecificTag(TAG_FULL_THREAD_DEVICE)) val fullNetworkData = tlvReader.getBoolean(ContextSpecificTag(TAG_FULL_NETWORK_DATA)) val isChild = tlvReader.getBoolean(ContextSpecificTag(TAG_IS_CHILD)) - + tlvReader.exitContainer() - return ThreadNetworkDiagnosticsClusterNeighborTableStruct(extAddress, age, rloc16, linkFrameCounter, mleFrameCounter, lqi, averageRssi, lastRssi, frameErrorRate, messageErrorRate, rxOnWhenIdle, fullThreadDevice, fullNetworkData, isChild) + return ThreadNetworkDiagnosticsClusterNeighborTableStruct( + extAddress, + age, + rloc16, + linkFrameCounter, + mleFrameCounter, + lqi, + averageRssi, + lastRssi, + frameErrorRate, + messageErrorRate, + rxOnWhenIdle, + fullThreadDevice, + fullNetworkData, + isChild, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ThreadNetworkDiagnosticsClusterOperationalDatasetComponents.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ThreadNetworkDiagnosticsClusterOperationalDatasetComponents.kt index 91975101984aaa..167f1411d1c386 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ThreadNetworkDiagnosticsClusterOperationalDatasetComponents.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ThreadNetworkDiagnosticsClusterOperationalDatasetComponents.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -36,7 +34,7 @@ class ThreadNetworkDiagnosticsClusterOperationalDatasetComponents( val channelPresent: Boolean, val pskcPresent: Boolean, val securityPolicyPresent: Boolean, - val channelMaskPresent: Boolean + val channelMaskPresent: Boolean, ) { override fun toString(): String = buildString { append("ThreadNetworkDiagnosticsClusterOperationalDatasetComponents {\n") @@ -88,24 +86,45 @@ class ThreadNetworkDiagnosticsClusterOperationalDatasetComponents( private const val TAG_SECURITY_POLICY_PRESENT = 10 private const val TAG_CHANNEL_MASK_PRESENT = 11 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ThreadNetworkDiagnosticsClusterOperationalDatasetComponents { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): ThreadNetworkDiagnosticsClusterOperationalDatasetComponents { tlvReader.enterStructure(tlvTag) - val activeTimestampPresent = tlvReader.getBoolean(ContextSpecificTag(TAG_ACTIVE_TIMESTAMP_PRESENT)) - val pendingTimestampPresent = tlvReader.getBoolean(ContextSpecificTag(TAG_PENDING_TIMESTAMP_PRESENT)) + val activeTimestampPresent = + tlvReader.getBoolean(ContextSpecificTag(TAG_ACTIVE_TIMESTAMP_PRESENT)) + val pendingTimestampPresent = + tlvReader.getBoolean(ContextSpecificTag(TAG_PENDING_TIMESTAMP_PRESENT)) val masterKeyPresent = tlvReader.getBoolean(ContextSpecificTag(TAG_MASTER_KEY_PRESENT)) val networkNamePresent = tlvReader.getBoolean(ContextSpecificTag(TAG_NETWORK_NAME_PRESENT)) - val extendedPanIdPresent = tlvReader.getBoolean(ContextSpecificTag(TAG_EXTENDED_PAN_ID_PRESENT)) - val meshLocalPrefixPresent = tlvReader.getBoolean(ContextSpecificTag(TAG_MESH_LOCAL_PREFIX_PRESENT)) + val extendedPanIdPresent = + tlvReader.getBoolean(ContextSpecificTag(TAG_EXTENDED_PAN_ID_PRESENT)) + val meshLocalPrefixPresent = + tlvReader.getBoolean(ContextSpecificTag(TAG_MESH_LOCAL_PREFIX_PRESENT)) val delayPresent = tlvReader.getBoolean(ContextSpecificTag(TAG_DELAY_PRESENT)) val panIdPresent = tlvReader.getBoolean(ContextSpecificTag(TAG_PAN_ID_PRESENT)) val channelPresent = tlvReader.getBoolean(ContextSpecificTag(TAG_CHANNEL_PRESENT)) val pskcPresent = tlvReader.getBoolean(ContextSpecificTag(TAG_PSKC_PRESENT)) - val securityPolicyPresent = tlvReader.getBoolean(ContextSpecificTag(TAG_SECURITY_POLICY_PRESENT)) + val securityPolicyPresent = + tlvReader.getBoolean(ContextSpecificTag(TAG_SECURITY_POLICY_PRESENT)) val channelMaskPresent = tlvReader.getBoolean(ContextSpecificTag(TAG_CHANNEL_MASK_PRESENT)) - + tlvReader.exitContainer() - return ThreadNetworkDiagnosticsClusterOperationalDatasetComponents(activeTimestampPresent, pendingTimestampPresent, masterKeyPresent, networkNamePresent, extendedPanIdPresent, meshLocalPrefixPresent, delayPresent, panIdPresent, channelPresent, pskcPresent, securityPolicyPresent, channelMaskPresent) + return ThreadNetworkDiagnosticsClusterOperationalDatasetComponents( + activeTimestampPresent, + pendingTimestampPresent, + masterKeyPresent, + networkNamePresent, + extendedPanIdPresent, + meshLocalPrefixPresent, + delayPresent, + panIdPresent, + channelPresent, + pskcPresent, + securityPolicyPresent, + channelMaskPresent, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ThreadNetworkDiagnosticsClusterRouteTableStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ThreadNetworkDiagnosticsClusterRouteTableStruct.kt index 1d9802bca85da4..86860ea6803c82 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ThreadNetworkDiagnosticsClusterRouteTableStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ThreadNetworkDiagnosticsClusterRouteTableStruct.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -34,7 +32,7 @@ class ThreadNetworkDiagnosticsClusterRouteTableStruct( val LQIOut: UByte, val age: UByte, val allocated: Boolean, - val linkEstablished: Boolean + val linkEstablished: Boolean, ) { override fun toString(): String = buildString { append("ThreadNetworkDiagnosticsClusterRouteTableStruct {\n") @@ -80,7 +78,10 @@ class ThreadNetworkDiagnosticsClusterRouteTableStruct( private const val TAG_ALLOCATED = 8 private const val TAG_LINK_ESTABLISHED = 9 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ThreadNetworkDiagnosticsClusterRouteTableStruct { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): ThreadNetworkDiagnosticsClusterRouteTableStruct { tlvReader.enterStructure(tlvTag) val extAddress = tlvReader.getULong(ContextSpecificTag(TAG_EXT_ADDRESS)) val rloc16 = tlvReader.getUShort(ContextSpecificTag(TAG_RLOC16)) @@ -92,10 +93,21 @@ class ThreadNetworkDiagnosticsClusterRouteTableStruct( val age = tlvReader.getUByte(ContextSpecificTag(TAG_AGE)) val allocated = tlvReader.getBoolean(ContextSpecificTag(TAG_ALLOCATED)) val linkEstablished = tlvReader.getBoolean(ContextSpecificTag(TAG_LINK_ESTABLISHED)) - + tlvReader.exitContainer() - return ThreadNetworkDiagnosticsClusterRouteTableStruct(extAddress, rloc16, routerId, nextHop, pathCost, LQIIn, LQIOut, age, allocated, linkEstablished) + return ThreadNetworkDiagnosticsClusterRouteTableStruct( + extAddress, + rloc16, + routerId, + nextHop, + pathCost, + LQIIn, + LQIOut, + age, + allocated, + linkEstablished, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ThreadNetworkDiagnosticsClusterSecurityPolicy.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ThreadNetworkDiagnosticsClusterSecurityPolicy.kt index 3228a78b13b000..720cdd6c854a72 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ThreadNetworkDiagnosticsClusterSecurityPolicy.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ThreadNetworkDiagnosticsClusterSecurityPolicy.kt @@ -16,18 +16,13 @@ */ package matter.controller.cluster.structs -import java.util.Optional 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 ThreadNetworkDiagnosticsClusterSecurityPolicy( - val rotationTime: UShort, - val flags: UShort -) { +class ThreadNetworkDiagnosticsClusterSecurityPolicy(val rotationTime: UShort, val flags: UShort) { override fun toString(): String = buildString { append("ThreadNetworkDiagnosticsClusterSecurityPolicy {\n") append("\trotationTime : $rotationTime\n") @@ -52,7 +47,7 @@ class ThreadNetworkDiagnosticsClusterSecurityPolicy( tlvReader.enterStructure(tlvTag) val rotationTime = tlvReader.getUShort(ContextSpecificTag(TAG_ROTATION_TIME)) val flags = tlvReader.getUShort(ContextSpecificTag(TAG_FLAGS)) - + tlvReader.exitContainer() return ThreadNetworkDiagnosticsClusterSecurityPolicy(rotationTime, flags) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ThreadNetworkDirectoryClusterThreadNetworkStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ThreadNetworkDirectoryClusterThreadNetworkStruct.kt index cf60e4f50d8a7a..04f8c6abcd3ba8 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ThreadNetworkDirectoryClusterThreadNetworkStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/ThreadNetworkDirectoryClusterThreadNetworkStruct.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -28,7 +26,7 @@ class ThreadNetworkDirectoryClusterThreadNetworkStruct( val extendedPanID: ByteArray, val networkName: String, val channel: UShort, - val activeTimestamp: ULong + val activeTimestamp: ULong, ) { override fun toString(): String = buildString { append("ThreadNetworkDirectoryClusterThreadNetworkStruct {\n") @@ -56,16 +54,24 @@ class ThreadNetworkDirectoryClusterThreadNetworkStruct( private const val TAG_CHANNEL = 2 private const val TAG_ACTIVE_TIMESTAMP = 3 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ThreadNetworkDirectoryClusterThreadNetworkStruct { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): ThreadNetworkDirectoryClusterThreadNetworkStruct { tlvReader.enterStructure(tlvTag) val extendedPanID = tlvReader.getByteArray(ContextSpecificTag(TAG_EXTENDED_PAN_ID)) val networkName = tlvReader.getString(ContextSpecificTag(TAG_NETWORK_NAME)) val channel = tlvReader.getUShort(ContextSpecificTag(TAG_CHANNEL)) val activeTimestamp = tlvReader.getULong(ContextSpecificTag(TAG_ACTIVE_TIMESTAMP)) - + tlvReader.exitContainer() - return ThreadNetworkDirectoryClusterThreadNetworkStruct(extendedPanID, networkName, channel, activeTimestamp) + return ThreadNetworkDirectoryClusterThreadNetworkStruct( + extendedPanID, + networkName, + channel, + activeTimestamp, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/TimeSynchronizationClusterDSTOffsetStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/TimeSynchronizationClusterDSTOffsetStruct.kt index 366d9e19dc429b..a40f9fb0c74943 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/TimeSynchronizationClusterDSTOffsetStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/TimeSynchronizationClusterDSTOffsetStruct.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -27,7 +25,7 @@ import matter.tlv.TlvWriter class TimeSynchronizationClusterDSTOffsetStruct( val offset: Int, val validStarting: ULong, - val validUntil: ULong? + val validUntil: ULong?, ) { override fun toString(): String = buildString { append("TimeSynchronizationClusterDSTOffsetStruct {\n") @@ -60,13 +58,14 @@ class TimeSynchronizationClusterDSTOffsetStruct( tlvReader.enterStructure(tlvTag) val offset = tlvReader.getInt(ContextSpecificTag(TAG_OFFSET)) val validStarting = tlvReader.getULong(ContextSpecificTag(TAG_VALID_STARTING)) - val validUntil = if (!tlvReader.isNull()) { - tlvReader.getULong(ContextSpecificTag(TAG_VALID_UNTIL)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_VALID_UNTIL)) - null - } - + val validUntil = + if (!tlvReader.isNull()) { + tlvReader.getULong(ContextSpecificTag(TAG_VALID_UNTIL)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_VALID_UNTIL)) + null + } + tlvReader.exitContainer() return TimeSynchronizationClusterDSTOffsetStruct(offset, validStarting, validUntil) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/TimeSynchronizationClusterFabricScopedTrustedTimeSourceStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/TimeSynchronizationClusterFabricScopedTrustedTimeSourceStruct.kt index d1393bff247d8a..f294cfbe427ee1 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/TimeSynchronizationClusterFabricScopedTrustedTimeSourceStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/TimeSynchronizationClusterFabricScopedTrustedTimeSourceStruct.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -26,7 +24,7 @@ import matter.tlv.TlvWriter class TimeSynchronizationClusterFabricScopedTrustedTimeSourceStruct( val nodeID: ULong, - val endpoint: UShort + val endpoint: UShort, ) { override fun toString(): String = buildString { append("TimeSynchronizationClusterFabricScopedTrustedTimeSourceStruct {\n") @@ -48,11 +46,14 @@ class TimeSynchronizationClusterFabricScopedTrustedTimeSourceStruct( private const val TAG_NODE_ID = 0 private const val TAG_ENDPOINT = 1 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): TimeSynchronizationClusterFabricScopedTrustedTimeSourceStruct { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): TimeSynchronizationClusterFabricScopedTrustedTimeSourceStruct { tlvReader.enterStructure(tlvTag) val nodeID = tlvReader.getULong(ContextSpecificTag(TAG_NODE_ID)) val endpoint = tlvReader.getUShort(ContextSpecificTag(TAG_ENDPOINT)) - + tlvReader.exitContainer() return TimeSynchronizationClusterFabricScopedTrustedTimeSourceStruct(nodeID, endpoint) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/TimeSynchronizationClusterTimeZoneStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/TimeSynchronizationClusterTimeZoneStruct.kt index d8b7a7a33d130e..91ad83d2624a76 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/TimeSynchronizationClusterTimeZoneStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/TimeSynchronizationClusterTimeZoneStruct.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -27,7 +26,7 @@ import matter.tlv.TlvWriter class TimeSynchronizationClusterTimeZoneStruct( val offset: Int, val validAt: ULong, - val name: Optional + val name: Optional, ) { override fun toString(): String = buildString { append("TimeSynchronizationClusterTimeZoneStruct {\n") @@ -59,12 +58,13 @@ class TimeSynchronizationClusterTimeZoneStruct( tlvReader.enterStructure(tlvTag) val offset = tlvReader.getInt(ContextSpecificTag(TAG_OFFSET)) val validAt = tlvReader.getULong(ContextSpecificTag(TAG_VALID_AT)) - val name = if (tlvReader.isNextTag(ContextSpecificTag(TAG_NAME))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_NAME))) - } else { - Optional.empty() - } - + val name = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_NAME))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_NAME))) + } else { + Optional.empty() + } + tlvReader.exitContainer() return TimeSynchronizationClusterTimeZoneStruct(offset, validAt, name) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/TimeSynchronizationClusterTrustedTimeSourceStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/TimeSynchronizationClusterTrustedTimeSourceStruct.kt index 290f507604c31f..215bb8c35d2e57 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/TimeSynchronizationClusterTrustedTimeSourceStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/TimeSynchronizationClusterTrustedTimeSourceStruct.kt @@ -16,9 +16,7 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -27,7 +25,7 @@ import matter.tlv.TlvWriter class TimeSynchronizationClusterTrustedTimeSourceStruct( val fabricIndex: UByte, val nodeID: ULong, - val endpoint: UShort + val endpoint: UShort, ) { override fun toString(): String = buildString { append("TimeSynchronizationClusterTrustedTimeSourceStruct {\n") @@ -52,12 +50,15 @@ class TimeSynchronizationClusterTrustedTimeSourceStruct( private const val TAG_NODE_ID = 1 private const val TAG_ENDPOINT = 2 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): TimeSynchronizationClusterTrustedTimeSourceStruct { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): TimeSynchronizationClusterTrustedTimeSourceStruct { tlvReader.enterStructure(tlvTag) val fabricIndex = tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) val nodeID = tlvReader.getULong(ContextSpecificTag(TAG_NODE_ID)) val endpoint = tlvReader.getUShort(ContextSpecificTag(TAG_ENDPOINT)) - + tlvReader.exitContainer() return TimeSynchronizationClusterTrustedTimeSourceStruct(fabricIndex, nodeID, endpoint) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterDoubleNestedStructList.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterDoubleNestedStructList.kt index a78f035f9d5e70..b308907db2a90c 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterDoubleNestedStructList.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterDoubleNestedStructList.kt @@ -16,7 +16,6 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -24,9 +23,7 @@ import matter.tlv.Tag import matter.tlv.TlvReader import matter.tlv.TlvWriter -class UnitTestingClusterDoubleNestedStructList( - val a: List -) { +class UnitTestingClusterDoubleNestedStructList(val a: List) { override fun toString(): String = buildString { append("UnitTestingClusterDoubleNestedStructList {\n") append("\ta : $a\n") @@ -50,14 +47,15 @@ class UnitTestingClusterDoubleNestedStructList( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): UnitTestingClusterDoubleNestedStructList { tlvReader.enterStructure(tlvTag) - val a = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_A)) - while(!tlvReader.isEndOfContainer()) { - add(UnitTestingClusterNestedStructList.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - + val a = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_A)) + while (!tlvReader.isEndOfContainer()) { + add(UnitTestingClusterNestedStructList.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + tlvReader.exitContainer() return UnitTestingClusterDoubleNestedStructList(a) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterNestedStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterNestedStruct.kt index f208e28093e2b6..d57a0432a7c7ed 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterNestedStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterNestedStruct.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -28,7 +27,7 @@ class UnitTestingClusterNestedStruct( val a: UByte, val b: Boolean, val c: UnitTestingClusterSimpleStruct, - val d: Optional + val d: Optional, ) { override fun toString(): String = buildString { append("UnitTestingClusterNestedStruct {\n") @@ -64,12 +63,15 @@ class UnitTestingClusterNestedStruct( val a = tlvReader.getUByte(ContextSpecificTag(TAG_A)) val b = tlvReader.getBoolean(ContextSpecificTag(TAG_B)) val c = UnitTestingClusterSimpleStruct.fromTlv(ContextSpecificTag(TAG_C), tlvReader) - val d = if (tlvReader.isNextTag(ContextSpecificTag(TAG_D))) { - Optional.of(UnitTestingClusterTestGlobalStruct.fromTlv(ContextSpecificTag(TAG_D), tlvReader)) - } else { - Optional.empty() - } - + val d = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_D))) { + Optional.of( + UnitTestingClusterTestGlobalStruct.fromTlv(ContextSpecificTag(TAG_D), tlvReader) + ) + } else { + Optional.empty() + } + tlvReader.exitContainer() return UnitTestingClusterNestedStruct(a, b, c, d) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterNestedStructList.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterNestedStructList.kt index 653e0e8f3a39d8..fe1df8f2f231e6 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterNestedStructList.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterNestedStructList.kt @@ -16,7 +16,6 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -31,7 +30,7 @@ class UnitTestingClusterNestedStructList( val d: List, val e: List, val f: List, - val g: List + val g: List, ) { override fun toString(): String = buildString { append("UnitTestingClusterNestedStructList {\n") @@ -89,35 +88,39 @@ class UnitTestingClusterNestedStructList( val a = tlvReader.getUByte(ContextSpecificTag(TAG_A)) val b = tlvReader.getBoolean(ContextSpecificTag(TAG_B)) val c = UnitTestingClusterSimpleStruct.fromTlv(ContextSpecificTag(TAG_C), tlvReader) - val d = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_D)) - while(!tlvReader.isEndOfContainer()) { - add(UnitTestingClusterSimpleStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - val e = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_E)) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getUInt(AnonymousTag)) - } - tlvReader.exitContainer() - } - val f = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_F)) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getByteArray(AnonymousTag)) - } - tlvReader.exitContainer() - } - val g = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_G)) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } - + val d = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_D)) + while (!tlvReader.isEndOfContainer()) { + add(UnitTestingClusterSimpleStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + val e = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_E)) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } + val f = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_F)) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getByteArray(AnonymousTag)) + } + tlvReader.exitContainer() + } + val g = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_G)) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + tlvReader.exitContainer() return UnitTestingClusterNestedStructList(a, b, c, d, e, f, g) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterNullablesAndOptionalsStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterNullablesAndOptionalsStruct.kt index 279d19e7f4ed48..a0bbb707e46a51 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterNullablesAndOptionalsStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterNullablesAndOptionalsStruct.kt @@ -36,7 +36,7 @@ class UnitTestingClusterNullablesAndOptionalsStruct( val nullableOptionalStruct: Optional?, val nullableList: List?, val optionalList: Optional>, - val nullableOptionalList: Optional>? + val nullableOptionalList: Optional>?, ) { override fun toString(): String = buildString { append("UnitTestingClusterNullablesAndOptionalsStruct {\n") @@ -69,9 +69,9 @@ class UnitTestingClusterNullablesAndOptionalsStruct( } if (nullableOptionalInt != null) { if (nullableOptionalInt.isPresent) { - val optnullableOptionalInt = nullableOptionalInt.get() - put(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_INT), optnullableOptionalInt) - } + val optnullableOptionalInt = nullableOptionalInt.get() + put(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_INT), optnullableOptionalInt) + } } else { putNull(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_INT)) } @@ -86,9 +86,9 @@ class UnitTestingClusterNullablesAndOptionalsStruct( } if (nullableOptionalString != null) { if (nullableOptionalString.isPresent) { - val optnullableOptionalString = nullableOptionalString.get() - put(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRING), optnullableOptionalString) - } + val optnullableOptionalString = nullableOptionalString.get() + put(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRING), optnullableOptionalString) + } } else { putNull(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRING)) } @@ -103,38 +103,38 @@ class UnitTestingClusterNullablesAndOptionalsStruct( } if (nullableOptionalStruct != null) { if (nullableOptionalStruct.isPresent) { - val optnullableOptionalStruct = nullableOptionalStruct.get() - optnullableOptionalStruct.toTlv(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRUCT), this) - } + val optnullableOptionalStruct = nullableOptionalStruct.get() + optnullableOptionalStruct.toTlv(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRUCT), this) + } } else { putNull(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRUCT)) } if (nullableList != null) { startArray(ContextSpecificTag(TAG_NULLABLE_LIST)) - for (item in nullableList.iterator()) { - put(AnonymousTag, item) - } - endArray() + for (item in nullableList.iterator()) { + put(AnonymousTag, item) + } + endArray() } else { putNull(ContextSpecificTag(TAG_NULLABLE_LIST)) } if (optionalList.isPresent) { val optoptionalList = optionalList.get() startArray(ContextSpecificTag(TAG_OPTIONAL_LIST)) - for (item in optoptionalList.iterator()) { - put(AnonymousTag, item) - } - endArray() + for (item in optoptionalList.iterator()) { + put(AnonymousTag, item) + } + endArray() } if (nullableOptionalList != null) { if (nullableOptionalList.isPresent) { - val optnullableOptionalList = nullableOptionalList.get() - startArray(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_LIST)) - for (item in optnullableOptionalList.iterator()) { - put(AnonymousTag, item) - } - endArray() - } + val optnullableOptionalList = nullableOptionalList.get() + startArray(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_LIST)) + for (item in optnullableOptionalList.iterator()) { + put(AnonymousTag, item) + } + endArray() + } } else { putNull(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_LIST)) } @@ -158,112 +158,151 @@ class UnitTestingClusterNullablesAndOptionalsStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): UnitTestingClusterNullablesAndOptionalsStruct { tlvReader.enterStructure(tlvTag) - val nullableInt = if (!tlvReader.isNull()) { - tlvReader.getUShort(ContextSpecificTag(TAG_NULLABLE_INT)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_NULLABLE_INT)) - null - } - val optionalInt = if (tlvReader.isNextTag(ContextSpecificTag(TAG_OPTIONAL_INT))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_OPTIONAL_INT))) - } else { - Optional.empty() - } - val nullableOptionalInt = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_INT))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_INT))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_INT)) - null - } - val nullableString = if (!tlvReader.isNull()) { - tlvReader.getString(ContextSpecificTag(TAG_NULLABLE_STRING)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_NULLABLE_STRING)) - null - } - val optionalString = if (tlvReader.isNextTag(ContextSpecificTag(TAG_OPTIONAL_STRING))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_OPTIONAL_STRING))) - } else { - Optional.empty() - } - val nullableOptionalString = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRING))) { - Optional.of(tlvReader.getString(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRING))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRING)) - null - } - val nullableStruct = if (!tlvReader.isNull()) { - UnitTestingClusterSimpleStruct.fromTlv(ContextSpecificTag(TAG_NULLABLE_STRUCT), tlvReader) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_NULLABLE_STRUCT)) - null - } - val optionalStruct = if (tlvReader.isNextTag(ContextSpecificTag(TAG_OPTIONAL_STRUCT))) { - Optional.of(UnitTestingClusterSimpleStruct.fromTlv(ContextSpecificTag(TAG_OPTIONAL_STRUCT), tlvReader)) - } else { - Optional.empty() - } - val nullableOptionalStruct = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRUCT))) { - Optional.of(UnitTestingClusterSimpleStruct.fromTlv(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRUCT), tlvReader)) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRUCT)) - null - } - val nullableList = if (!tlvReader.isNull()) { - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_NULLABLE_LIST)) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_NULLABLE_LIST)) - null - } - val optionalList = if (tlvReader.isNextTag(ContextSpecificTag(TAG_OPTIONAL_LIST))) { - Optional.of(buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_OPTIONAL_LIST)) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - }) - } else { - Optional.empty() - } - val nullableOptionalList = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_LIST))) { - Optional.of(buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_LIST)) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - }) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_LIST)) - null - } - + val nullableInt = + if (!tlvReader.isNull()) { + tlvReader.getUShort(ContextSpecificTag(TAG_NULLABLE_INT)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_NULLABLE_INT)) + null + } + val optionalInt = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_OPTIONAL_INT))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_OPTIONAL_INT))) + } else { + Optional.empty() + } + val nullableOptionalInt = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_INT))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_INT))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_INT)) + null + } + val nullableString = + if (!tlvReader.isNull()) { + tlvReader.getString(ContextSpecificTag(TAG_NULLABLE_STRING)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_NULLABLE_STRING)) + null + } + val optionalString = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_OPTIONAL_STRING))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_OPTIONAL_STRING))) + } else { + Optional.empty() + } + val nullableOptionalString = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRING))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRING))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRING)) + null + } + val nullableStruct = + if (!tlvReader.isNull()) { + UnitTestingClusterSimpleStruct.fromTlv(ContextSpecificTag(TAG_NULLABLE_STRUCT), tlvReader) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_NULLABLE_STRUCT)) + null + } + val optionalStruct = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_OPTIONAL_STRUCT))) { + Optional.of( + UnitTestingClusterSimpleStruct.fromTlv( + ContextSpecificTag(TAG_OPTIONAL_STRUCT), + tlvReader, + ) + ) + } else { + Optional.empty() + } + val nullableOptionalStruct = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRUCT))) { + Optional.of( + UnitTestingClusterSimpleStruct.fromTlv( + ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRUCT), + tlvReader, + ) + ) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_STRUCT)) + null + } + val nullableList = + if (!tlvReader.isNull()) { + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_NULLABLE_LIST)) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_NULLABLE_LIST)) + null + } + val optionalList = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_OPTIONAL_LIST))) { + Optional.of( + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_OPTIONAL_LIST)) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + ) + } else { + Optional.empty() + } + val nullableOptionalList = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_LIST))) { + Optional.of( + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_LIST)) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } + ) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_LIST)) + null + } + tlvReader.exitContainer() - return UnitTestingClusterNullablesAndOptionalsStruct(nullableInt, optionalInt, nullableOptionalInt, nullableString, optionalString, nullableOptionalString, nullableStruct, optionalStruct, nullableOptionalStruct, nullableList, optionalList, nullableOptionalList) + return UnitTestingClusterNullablesAndOptionalsStruct( + nullableInt, + optionalInt, + nullableOptionalInt, + nullableString, + optionalString, + nullableOptionalString, + nullableStruct, + optionalStruct, + nullableOptionalStruct, + nullableList, + optionalList, + nullableOptionalList, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterSimpleStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterSimpleStruct.kt index d591b816461da2..722445efea8504 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterSimpleStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterSimpleStruct.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -33,7 +32,7 @@ class UnitTestingClusterSimpleStruct( val f: UByte, val g: Float, val h: Double, - val i: Optional + val i: Optional, ) { override fun toString(): String = buildString { append("UnitTestingClusterSimpleStruct {\n") @@ -89,12 +88,13 @@ class UnitTestingClusterSimpleStruct( val f = tlvReader.getUByte(ContextSpecificTag(TAG_F)) val g = tlvReader.getFloat(ContextSpecificTag(TAG_G)) val h = tlvReader.getDouble(ContextSpecificTag(TAG_H)) - val i = if (tlvReader.isNextTag(ContextSpecificTag(TAG_I))) { - Optional.of(tlvReader.getUByte(ContextSpecificTag(TAG_I))) - } else { - Optional.empty() - } - + val i = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_I))) { + Optional.of(tlvReader.getUByte(ContextSpecificTag(TAG_I))) + } else { + Optional.empty() + } + tlvReader.exitContainer() return UnitTestingClusterSimpleStruct(a, b, c, d, e, f, g, h, i) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterTestFabricScoped.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterTestFabricScoped.kt index 1f38827ddec220..b6196f58d7546a 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterTestFabricScoped.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterTestFabricScoped.kt @@ -32,7 +32,7 @@ class UnitTestingClusterTestFabricScoped( val fabricSensitiveCharString: String, val fabricSensitiveStruct: UnitTestingClusterSimpleStruct, val fabricSensitiveInt8uList: List, - val fabricIndex: UByte + val fabricIndex: UByte, ) { override fun toString(): String = buildString { append("UnitTestingClusterTestFabricScoped {\n") @@ -53,7 +53,10 @@ class UnitTestingClusterTestFabricScoped( put(ContextSpecificTag(TAG_FABRIC_SENSITIVE_INT8U), fabricSensitiveInt8u) if (optionalFabricSensitiveInt8u.isPresent) { val optoptionalFabricSensitiveInt8u = optionalFabricSensitiveInt8u.get() - put(ContextSpecificTag(TAG_OPTIONAL_FABRIC_SENSITIVE_INT8U), optoptionalFabricSensitiveInt8u) + put( + ContextSpecificTag(TAG_OPTIONAL_FABRIC_SENSITIVE_INT8U), + optoptionalFabricSensitiveInt8u, + ) } if (nullableFabricSensitiveInt8u != null) { put(ContextSpecificTag(TAG_NULLABLE_FABRIC_SENSITIVE_INT8U), nullableFabricSensitiveInt8u) @@ -62,9 +65,12 @@ class UnitTestingClusterTestFabricScoped( } if (nullableOptionalFabricSensitiveInt8u != null) { if (nullableOptionalFabricSensitiveInt8u.isPresent) { - val optnullableOptionalFabricSensitiveInt8u = nullableOptionalFabricSensitiveInt8u.get() - put(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_FABRIC_SENSITIVE_INT8U), optnullableOptionalFabricSensitiveInt8u) - } + val optnullableOptionalFabricSensitiveInt8u = nullableOptionalFabricSensitiveInt8u.get() + put( + ContextSpecificTag(TAG_NULLABLE_OPTIONAL_FABRIC_SENSITIVE_INT8U), + optnullableOptionalFabricSensitiveInt8u, + ) + } } else { putNull(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_FABRIC_SENSITIVE_INT8U)) } @@ -93,41 +99,63 @@ class UnitTestingClusterTestFabricScoped( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): UnitTestingClusterTestFabricScoped { tlvReader.enterStructure(tlvTag) val fabricSensitiveInt8u = tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_SENSITIVE_INT8U)) - val optionalFabricSensitiveInt8u = if (tlvReader.isNextTag(ContextSpecificTag(TAG_OPTIONAL_FABRIC_SENSITIVE_INT8U))) { - Optional.of(tlvReader.getUByte(ContextSpecificTag(TAG_OPTIONAL_FABRIC_SENSITIVE_INT8U))) - } else { - Optional.empty() - } - val nullableFabricSensitiveInt8u = if (!tlvReader.isNull()) { - tlvReader.getUByte(ContextSpecificTag(TAG_NULLABLE_FABRIC_SENSITIVE_INT8U)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_NULLABLE_FABRIC_SENSITIVE_INT8U)) - null - } - val nullableOptionalFabricSensitiveInt8u = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_FABRIC_SENSITIVE_INT8U))) { - Optional.of(tlvReader.getUByte(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_FABRIC_SENSITIVE_INT8U))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_FABRIC_SENSITIVE_INT8U)) - null - } - val fabricSensitiveCharString = tlvReader.getString(ContextSpecificTag(TAG_FABRIC_SENSITIVE_CHAR_STRING)) - val fabricSensitiveStruct = UnitTestingClusterSimpleStruct.fromTlv(ContextSpecificTag(TAG_FABRIC_SENSITIVE_STRUCT), tlvReader) - val fabricSensitiveInt8uList = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_FABRIC_SENSITIVE_INT8U_LIST)) - while(!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } + val optionalFabricSensitiveInt8u = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_OPTIONAL_FABRIC_SENSITIVE_INT8U))) { + Optional.of(tlvReader.getUByte(ContextSpecificTag(TAG_OPTIONAL_FABRIC_SENSITIVE_INT8U))) + } else { + Optional.empty() + } + val nullableFabricSensitiveInt8u = + if (!tlvReader.isNull()) { + tlvReader.getUByte(ContextSpecificTag(TAG_NULLABLE_FABRIC_SENSITIVE_INT8U)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_NULLABLE_FABRIC_SENSITIVE_INT8U)) + null + } + val nullableOptionalFabricSensitiveInt8u = + if (!tlvReader.isNull()) { + if ( + tlvReader.isNextTag(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_FABRIC_SENSITIVE_INT8U)) + ) { + Optional.of( + tlvReader.getUByte(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_FABRIC_SENSITIVE_INT8U)) + ) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_NULLABLE_OPTIONAL_FABRIC_SENSITIVE_INT8U)) + null + } + val fabricSensitiveCharString = + tlvReader.getString(ContextSpecificTag(TAG_FABRIC_SENSITIVE_CHAR_STRING)) + val fabricSensitiveStruct = + UnitTestingClusterSimpleStruct.fromTlv( + ContextSpecificTag(TAG_FABRIC_SENSITIVE_STRUCT), + tlvReader, + ) + val fabricSensitiveInt8uList = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_FABRIC_SENSITIVE_INT8U_LIST)) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUByte(AnonymousTag)) + } + tlvReader.exitContainer() + } val fabricIndex = tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) - + tlvReader.exitContainer() - return UnitTestingClusterTestFabricScoped(fabricSensitiveInt8u, optionalFabricSensitiveInt8u, nullableFabricSensitiveInt8u, nullableOptionalFabricSensitiveInt8u, fabricSensitiveCharString, fabricSensitiveStruct, fabricSensitiveInt8uList, fabricIndex) + return UnitTestingClusterTestFabricScoped( + fabricSensitiveInt8u, + optionalFabricSensitiveInt8u, + nullableFabricSensitiveInt8u, + nullableOptionalFabricSensitiveInt8u, + fabricSensitiveCharString, + fabricSensitiveStruct, + fabricSensitiveInt8uList, + fabricIndex, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterTestGlobalStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterTestGlobalStruct.kt index 2f80d7a22c226d..66caded2c08ab3 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterTestGlobalStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterTestGlobalStruct.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -27,7 +26,7 @@ import matter.tlv.TlvWriter class UnitTestingClusterTestGlobalStruct( val name: String, val myBitmap: UInt?, - val myEnum: Optional? + val myEnum: Optional?, ) { override fun toString(): String = buildString { append("UnitTestingClusterTestGlobalStruct {\n") @@ -48,9 +47,9 @@ class UnitTestingClusterTestGlobalStruct( } if (myEnum != null) { if (myEnum.isPresent) { - val optmyEnum = myEnum.get() - put(ContextSpecificTag(TAG_MY_ENUM), optmyEnum) - } + val optmyEnum = myEnum.get() + put(ContextSpecificTag(TAG_MY_ENUM), optmyEnum) + } } else { putNull(ContextSpecificTag(TAG_MY_ENUM)) } @@ -66,23 +65,25 @@ class UnitTestingClusterTestGlobalStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): UnitTestingClusterTestGlobalStruct { tlvReader.enterStructure(tlvTag) val name = tlvReader.getString(ContextSpecificTag(TAG_NAME)) - val myBitmap = if (!tlvReader.isNull()) { - tlvReader.getUInt(ContextSpecificTag(TAG_MY_BITMAP)) - } else { - tlvReader.getNull(ContextSpecificTag(TAG_MY_BITMAP)) - null - } - val myEnum = if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(ContextSpecificTag(TAG_MY_ENUM))) { - Optional.of(tlvReader.getUByte(ContextSpecificTag(TAG_MY_ENUM))) - } else { - Optional.empty() - } - } else { - tlvReader.getNull(ContextSpecificTag(TAG_MY_ENUM)) - null - } - + val myBitmap = + if (!tlvReader.isNull()) { + tlvReader.getUInt(ContextSpecificTag(TAG_MY_BITMAP)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_MY_BITMAP)) + null + } + val myEnum = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_MY_ENUM))) { + Optional.of(tlvReader.getUByte(ContextSpecificTag(TAG_MY_ENUM))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_MY_ENUM)) + null + } + tlvReader.exitContainer() return UnitTestingClusterTestGlobalStruct(name, myBitmap, myEnum) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterTestListStructOctet.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterTestListStructOctet.kt index 5478f2bd44b175..9a7f7d3ba58b08 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterTestListStructOctet.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/UnitTestingClusterTestListStructOctet.kt @@ -16,18 +16,13 @@ */ package matter.controller.cluster.structs -import java.util.Optional 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 UnitTestingClusterTestListStructOctet( - val member1: ULong, - val member2: ByteArray -) { +class UnitTestingClusterTestListStructOctet(val member1: ULong, val member2: ByteArray) { override fun toString(): String = buildString { append("UnitTestingClusterTestListStructOctet {\n") append("\tmember1 : $member1\n") @@ -52,7 +47,7 @@ class UnitTestingClusterTestListStructOctet( tlvReader.enterStructure(tlvTag) val member1 = tlvReader.getULong(ContextSpecificTag(TAG_MEMBER1)) val member2 = tlvReader.getByteArray(ContextSpecificTag(TAG_MEMBER2)) - + tlvReader.exitContainer() return UnitTestingClusterTestListStructOctet(member1, member2) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/UserLabelClusterLabelStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/UserLabelClusterLabelStruct.kt index fd4efa9375bbe4..8840aec05a78bd 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/UserLabelClusterLabelStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/UserLabelClusterLabelStruct.kt @@ -16,18 +16,13 @@ */ package matter.controller.cluster.structs -import java.util.Optional 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 UserLabelClusterLabelStruct( - val label: String, - val value: String -) { +class UserLabelClusterLabelStruct(val label: String, val value: String) { override fun toString(): String = buildString { append("UserLabelClusterLabelStruct {\n") append("\tlabel : $label\n") @@ -52,7 +47,7 @@ class UserLabelClusterLabelStruct( tlvReader.enterStructure(tlvTag) val label = tlvReader.getString(ContextSpecificTag(TAG_LABEL)) val value = tlvReader.getString(ContextSpecificTag(TAG_VALUE)) - + tlvReader.exitContainer() return UserLabelClusterLabelStruct(label, value) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/WaterHeaterManagementClusterWaterHeaterBoostInfoStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/WaterHeaterManagementClusterWaterHeaterBoostInfoStruct.kt index ef90bea8b30b6c..0b2fede4f1537a 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/WaterHeaterManagementClusterWaterHeaterBoostInfoStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/WaterHeaterManagementClusterWaterHeaterBoostInfoStruct.kt @@ -18,7 +18,6 @@ package matter.controller.cluster.structs import java.util.Optional import matter.controller.cluster.* -import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag import matter.tlv.Tag import matter.tlv.TlvReader @@ -30,7 +29,7 @@ class WaterHeaterManagementClusterWaterHeaterBoostInfoStruct( val emergencyBoost: Optional, val temporarySetpoint: Optional, val targetPercentage: Optional, - val targetReheat: Optional + val targetReheat: Optional, ) { override fun toString(): String = buildString { append("WaterHeaterManagementClusterWaterHeaterBoostInfoStruct {\n") @@ -79,38 +78,53 @@ class WaterHeaterManagementClusterWaterHeaterBoostInfoStruct( private const val TAG_TARGET_PERCENTAGE = 4 private const val TAG_TARGET_REHEAT = 5 - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): WaterHeaterManagementClusterWaterHeaterBoostInfoStruct { + fun fromTlv( + tlvTag: Tag, + tlvReader: TlvReader, + ): WaterHeaterManagementClusterWaterHeaterBoostInfoStruct { tlvReader.enterStructure(tlvTag) val duration = tlvReader.getUInt(ContextSpecificTag(TAG_DURATION)) - val oneShot = if (tlvReader.isNextTag(ContextSpecificTag(TAG_ONE_SHOT))) { - Optional.of(tlvReader.getBoolean(ContextSpecificTag(TAG_ONE_SHOT))) - } else { - Optional.empty() - } - val emergencyBoost = if (tlvReader.isNextTag(ContextSpecificTag(TAG_EMERGENCY_BOOST))) { - Optional.of(tlvReader.getBoolean(ContextSpecificTag(TAG_EMERGENCY_BOOST))) - } else { - Optional.empty() - } - val temporarySetpoint = if (tlvReader.isNextTag(ContextSpecificTag(TAG_TEMPORARY_SETPOINT))) { - Optional.of(tlvReader.getShort(ContextSpecificTag(TAG_TEMPORARY_SETPOINT))) - } else { - Optional.empty() - } - val targetPercentage = if (tlvReader.isNextTag(ContextSpecificTag(TAG_TARGET_PERCENTAGE))) { - Optional.of(tlvReader.getUByte(ContextSpecificTag(TAG_TARGET_PERCENTAGE))) - } else { - Optional.empty() - } - val targetReheat = if (tlvReader.isNextTag(ContextSpecificTag(TAG_TARGET_REHEAT))) { - Optional.of(tlvReader.getUByte(ContextSpecificTag(TAG_TARGET_REHEAT))) - } else { - Optional.empty() - } - + val oneShot = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_ONE_SHOT))) { + Optional.of(tlvReader.getBoolean(ContextSpecificTag(TAG_ONE_SHOT))) + } else { + Optional.empty() + } + val emergencyBoost = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_EMERGENCY_BOOST))) { + Optional.of(tlvReader.getBoolean(ContextSpecificTag(TAG_EMERGENCY_BOOST))) + } else { + Optional.empty() + } + val temporarySetpoint = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_TEMPORARY_SETPOINT))) { + Optional.of(tlvReader.getShort(ContextSpecificTag(TAG_TEMPORARY_SETPOINT))) + } else { + Optional.empty() + } + val targetPercentage = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_TARGET_PERCENTAGE))) { + Optional.of(tlvReader.getUByte(ContextSpecificTag(TAG_TARGET_PERCENTAGE))) + } else { + Optional.empty() + } + val targetReheat = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_TARGET_REHEAT))) { + Optional.of(tlvReader.getUByte(ContextSpecificTag(TAG_TARGET_REHEAT))) + } else { + Optional.empty() + } + tlvReader.exitContainer() - return WaterHeaterManagementClusterWaterHeaterBoostInfoStruct(duration, oneShot, emergencyBoost, temporarySetpoint, targetPercentage, targetReheat) + return WaterHeaterManagementClusterWaterHeaterBoostInfoStruct( + duration, + oneShot, + emergencyBoost, + temporarySetpoint, + targetPercentage, + targetReheat, + ) } } } diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/WaterHeaterModeClusterModeOptionStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/WaterHeaterModeClusterModeOptionStruct.kt index 05c0c4a36421cc..52252bf6e4cc56 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/WaterHeaterModeClusterModeOptionStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/WaterHeaterModeClusterModeOptionStruct.kt @@ -16,7 +16,6 @@ */ package matter.controller.cluster.structs -import java.util.Optional import matter.controller.cluster.* import matter.tlv.AnonymousTag import matter.tlv.ContextSpecificTag @@ -27,7 +26,7 @@ import matter.tlv.TlvWriter class WaterHeaterModeClusterModeOptionStruct( val label: String, val mode: UByte, - val modeTags: List + val modeTags: List, ) { override fun toString(): String = buildString { append("WaterHeaterModeClusterModeOptionStruct {\n") @@ -60,14 +59,15 @@ class WaterHeaterModeClusterModeOptionStruct( tlvReader.enterStructure(tlvTag) val label = tlvReader.getString(ContextSpecificTag(TAG_LABEL)) val mode = tlvReader.getUByte(ContextSpecificTag(TAG_MODE)) - val modeTags = buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_MODE_TAGS)) - while(!tlvReader.isEndOfContainer()) { - add(WaterHeaterModeClusterModeTagStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - + val modeTags = + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_MODE_TAGS)) + while (!tlvReader.isEndOfContainer()) { + add(WaterHeaterModeClusterModeTagStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + tlvReader.exitContainer() return WaterHeaterModeClusterModeOptionStruct(label, mode, modeTags) diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/WaterHeaterModeClusterModeTagStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/WaterHeaterModeClusterModeTagStruct.kt index 42c4cea0a93cd2..fc91c1389574ab 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/WaterHeaterModeClusterModeTagStruct.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/WaterHeaterModeClusterModeTagStruct.kt @@ -18,16 +18,12 @@ package matter.controller.cluster.structs import java.util.Optional 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 WaterHeaterModeClusterModeTagStruct( - val mfgCode: Optional, - val value: UShort -) { +class WaterHeaterModeClusterModeTagStruct(val mfgCode: Optional, val value: UShort) { override fun toString(): String = buildString { append("WaterHeaterModeClusterModeTagStruct {\n") append("\tmfgCode : $mfgCode\n") @@ -53,13 +49,14 @@ class WaterHeaterModeClusterModeTagStruct( fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): WaterHeaterModeClusterModeTagStruct { tlvReader.enterStructure(tlvTag) - val mfgCode = if (tlvReader.isNextTag(ContextSpecificTag(TAG_MFG_CODE))) { - Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_MFG_CODE))) - } else { - Optional.empty() - } + val mfgCode = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_MFG_CODE))) { + Optional.of(tlvReader.getUShort(ContextSpecificTag(TAG_MFG_CODE))) + } else { + Optional.empty() + } val value = tlvReader.getUShort(ContextSpecificTag(TAG_VALUE)) - + tlvReader.exitContainer() return WaterHeaterModeClusterModeTagStruct(mfgCode, value) From 18081b4873aaaabbd459f066e487bcf1549f479b Mon Sep 17 00:00:00 2001 From: pcoleman Date: Thu, 22 Aug 2024 11:00:47 +0100 Subject: [PATCH 19/45] Fix typo in comment --- src/python_testing/TC_DEM_1_1.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python_testing/TC_DEM_1_1.py b/src/python_testing/TC_DEM_1_1.py index d9eaadda07657a..89a6d49ffbf10d 100644 --- a/src/python_testing/TC_DEM_1_1.py +++ b/src/python_testing/TC_DEM_1_1.py @@ -109,7 +109,7 @@ async def test_TC_DEM_1_1(self): asserts.assert_true(mandatory_attribute in attribute_list, f"Expected to find mandatory attribute {mandatory_attribute} in attribute_list {attribute_list}") - # Remove the enrty from the list + # Remove the entry from the list attribute_list.remove(mandatory_attribute) # Now check feature dependant attributes From d58723fa0a7a922bb74b23499ba010c6a6a35878 Mon Sep 17 00:00:00 2001 From: pcoleman Date: Thu, 22 Aug 2024 11:01:06 +0100 Subject: [PATCH 20/45] Cancel subscriptions at the end of the test --- src/python_testing/TC_DEM_2_10.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/python_testing/TC_DEM_2_10.py b/src/python_testing/TC_DEM_2_10.py index 0be913e2194632..c7596379d66c34 100644 --- a/src/python_testing/TC_DEM_2_10.py +++ b/src/python_testing/TC_DEM_2_10.py @@ -86,7 +86,9 @@ def steps_TC_DEM_2_10(self) -> list[TestStep]: "Verify DUT responds w/ status SUCCESS(0x00)"), TestStep("8", "TH counts all report transactions with an attribute report for the Forecast attribute over the next Forecast.Slots[0].MinDurationAdjustment}", "TH verifies that numberOfReportsReceived <= 2 + Forecast.Slots[0].MinDurationAdjustment}"), - TestStep("9", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TESTEVENT_TRIGGERKEY and EventTrigger field set to PIXIT.DEM.TESTEVENTTRIGGER for Forecast Adjustment Test Event Clear", + TestStep("9", "Cancel the subscription to the Forecast attribute", + "The subscription is cancelled successfully"), + TestStep("10", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TESTEVENT_TRIGGERKEY and EventTrigger field set to PIXIT.DEM.TESTEVENTTRIGGER for Forecast Adjustment Test Event Clear", "Verify DUT responds w/ status SUCCESS(0x00)"), ] @@ -123,7 +125,7 @@ async def test_TC_DEM_2_10(self): self.step("5") sub_handler = ClusterAttributeChangeAccumulator(Clusters.DeviceEnergyManagement) - await sub_handler.start(self.default_controller, self.dut_node_id, self.matter_test_config.endpoint) + await sub_handler.start(self.default_controller, self.dut_node_id, self.matter_test_config.endpoint, keepSubscriptions=False) sub_handler.reset() self.step("6") @@ -143,11 +145,14 @@ async def test_TC_DEM_2_10(self): time.sleep(forecast.slots[0].minDurationAdjustment) count = sub_handler.attribute_report_counts[Clusters.DeviceEnergyManagement.Attributes.Forecast] + logging.info(f"Number of Forecast updates {count}") asserts.assert_less_equal(count, 10, "More than 10 reports received") self.step("9") - await self.send_test_event_trigger_forecast_adjustment_clear() + sub_handler.cancel() + self.step("10") + await self.send_test_event_trigger_forecast_adjustment_clear() if __name__ == "__main__": default_matter_test_main() From cdd8bd7091b4effe6541dcdcb18a9c98ace74a8b Mon Sep 17 00:00:00 2001 From: pcoleman Date: Thu, 22 Aug 2024 11:01:36 +0100 Subject: [PATCH 21/45] Add a cancel subscription method --- src/python_testing/matter_testing_support.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/python_testing/matter_testing_support.py b/src/python_testing/matter_testing_support.py index eb8a6ba20d63b9..3a7edc093b0edb 100644 --- a/src/python_testing/matter_testing_support.py +++ b/src/python_testing/matter_testing_support.py @@ -410,18 +410,23 @@ def reset(self): self._attribute_reports[a] = [] self._q = queue.Queue() - async def start(self, dev_ctrl, node_id: int, endpoint: int, fabric_filtered: bool = False, min_interval_sec: int = 0, max_interval_sec: int = 5) -> Any: + async def start(self, dev_ctrl, node_id: int, endpoint: int, fabric_filtered: bool = False, min_interval_sec: int = 0, max_interval_sec: int = 5, keepSubscriptions: bool=True) -> Any: """This starts a subscription for attributes on the specified node_id and endpoint. The cluster is specified when the class instance is created.""" self._subscription = await dev_ctrl.ReadAttribute( nodeid=node_id, attributes=[(endpoint, self._expected_cluster)], reportInterval=(int(min_interval_sec), int(max_interval_sec)), fabricFiltered=fabric_filtered, - keepSubscriptions=True + keepSubscriptions=keepSubscriptions ) self._subscription.SetAttributeUpdateCallback(self.__call__) return self._subscription + def cancel(self): + """This cancels a subscription.""" + self._subscription.Shutdown() + self._subscription = None + def __call__(self, path: TypedAttributePath, transaction: SubscriptionTransaction): """This is the subscription callback when an attribute report is received. It checks the report is from the expected_cluster and then posts it into the queue for later processing.""" From 4703c7e8a16d0c367b769ec14536a7c0833047ab Mon Sep 17 00:00:00 2001 From: pcoleman Date: Thu, 22 Aug 2024 11:02:09 +0100 Subject: [PATCH 22/45] Ensure MatterReportingAttributeChangeCallback is called after forecast is changed --- .../DeviceEnergyManagementDelegateImpl.cpp | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/examples/energy-management-app/energy-management-common/device-energy-management/src/DeviceEnergyManagementDelegateImpl.cpp b/examples/energy-management-app/energy-management-common/device-energy-management/src/DeviceEnergyManagementDelegateImpl.cpp index 273bc9e0614333..161ea2f77c0750 100644 --- a/examples/energy-management-app/energy-management-common/device-energy-management/src/DeviceEnergyManagementDelegateImpl.cpp +++ b/examples/energy-management-app/energy-management-common/device-energy-management/src/DeviceEnergyManagementDelegateImpl.cpp @@ -377,10 +377,14 @@ Status DeviceEnergyManagementDelegate::StartTimeAdjustRequest(const uint32_t req mForecast.Value().startTime = savedStartTime; mForecast.Value().endTime = savedEndTime; + MatterReportingAttributeChangeCallback(mEndpointId, DeviceEnergyManagement::Id, Forecast::Id); + return Status::Failure; } } + MatterReportingAttributeChangeCallback(mEndpointId, DeviceEnergyManagement::Id, Forecast::Id); + return Status::Success; } @@ -457,10 +461,14 @@ Status DeviceEnergyManagementDelegate::PauseRequest(const uint32_t durationS, Ad if (cause == AdjustmentCauseEnum::kLocalOptimization) { mForecast.Value().forecastUpdateReason = ForecastUpdateReasonEnum::kLocalOptimization; + + MatterReportingAttributeChangeCallback(mEndpointId, DeviceEnergyManagement::Id, Forecast::Id); } else if (cause == AdjustmentCauseEnum::kGridOptimization) { mForecast.Value().forecastUpdateReason = ForecastUpdateReasonEnum::kGridOptimization; + + MatterReportingAttributeChangeCallback(mEndpointId, DeviceEnergyManagement::Id, Forecast::Id); } return Status::Success; @@ -606,6 +614,8 @@ Status DeviceEnergyManagementDelegate::ResumeRequest() // The PauseRequest has effectively been cancelled so as a result the device should // go back to InternalOptimisation mForecast.Value().forecastUpdateReason = ForecastUpdateReasonEnum::kInternalOptimization; + + MatterReportingAttributeChangeCallback(mEndpointId, DeviceEnergyManagement::Id, Forecast::Id); } CHIP_ERROR err = CancelPauseRequestAndGenerateEvent(CauseEnum::kCancelled); @@ -672,6 +682,8 @@ Status DeviceEnergyManagementDelegate::ModifyForecastRequest( } mForecast.Value().forecastID++; + + MatterReportingAttributeChangeCallback(mEndpointId, DeviceEnergyManagement::Id, Forecast::Id); } return status; @@ -725,6 +737,8 @@ Status DeviceEnergyManagementDelegate::RequestConstraintBasedForecast( mForecast.Value().forecastID++; + MatterReportingAttributeChangeCallback(mEndpointId, DeviceEnergyManagement::Id, Forecast::Id); + status = Status::Success; } @@ -748,6 +762,8 @@ Status DeviceEnergyManagementDelegate::CancelRequest() mForecast.Value().forecastUpdateReason = ForecastUpdateReasonEnum::kInternalOptimization; + MatterReportingAttributeChangeCallback(mEndpointId, DeviceEnergyManagement::Id, Forecast::Id); + /* It is expected the mpDEMManufacturerDelegate will cancel the effects of any previous adjustment * request commands, and re-evaluate its forecast for intended operation ignoring those previous * requests. @@ -980,6 +996,8 @@ CHIP_ERROR DeviceEnergyManagementDelegate::SetOptOutState(OptOutStateEnum newVal if ((mOptOutState == OptOutStateEnum::kOptOut) || (mOptOutState == OptOutStateEnum::kLocalOptOut)) { mForecast.Value().forecastUpdateReason = ForecastUpdateReasonEnum::kInternalOptimization; + + MatterReportingAttributeChangeCallback(mEndpointId, DeviceEnergyManagement::Id, Forecast::Id); // Generate a new forecast with Internal Optimization // TODO } @@ -988,6 +1006,8 @@ CHIP_ERROR DeviceEnergyManagementDelegate::SetOptOutState(OptOutStateEnum newVal if ((mOptOutState == OptOutStateEnum::kOptOut) || (mOptOutState == OptOutStateEnum::kGridOptOut)) { mForecast.Value().forecastUpdateReason = ForecastUpdateReasonEnum::kInternalOptimization; + + MatterReportingAttributeChangeCallback(mEndpointId, DeviceEnergyManagement::Id, Forecast::Id); // Generate a new forecast with Internal Optimization // TODO } From 7dbbb2f574466918d10a6c05a01990f185f236ba Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 22 Aug 2024 09:00:22 +0000 Subject: [PATCH 23/45] Restyled by autopep8 --- src/python_testing/TC_DEM_2_10.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/python_testing/TC_DEM_2_10.py b/src/python_testing/TC_DEM_2_10.py index c7596379d66c34..3b4b0285b9fbf3 100644 --- a/src/python_testing/TC_DEM_2_10.py +++ b/src/python_testing/TC_DEM_2_10.py @@ -138,7 +138,8 @@ async def test_TC_DEM_2_10(self): await self.check_dem_attribute("OptOutState", Clusters.DeviceEnergyManagement.Enums.OptOutStateEnum.kLocalOptOut) self.step("7") - slotAdjustments = [Clusters.DeviceEnergyManagement.Structs.SlotAdjustmentStruct(slotIndex=0, duration=forecast.slots[0].minDurationAdjustment)] + slotAdjustments = [Clusters.DeviceEnergyManagement.Structs.SlotAdjustmentStruct( + slotIndex=0, duration=forecast.slots[0].minDurationAdjustment)] await self.send_modify_forecast_request_command(forecast.forecastID, slotAdjustments, Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kGridOptimization, expected_status=Status.Success) self.step("8") From bdb637a4b53f689940f512b7060f6817c6ceda27 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 22 Aug 2024 09:00:23 +0000 Subject: [PATCH 24/45] Restyled by isort --- src/python_testing/TC_DEM_2_10.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/python_testing/TC_DEM_2_10.py b/src/python_testing/TC_DEM_2_10.py index 3b4b0285b9fbf3..676c03ca570879 100644 --- a/src/python_testing/TC_DEM_2_10.py +++ b/src/python_testing/TC_DEM_2_10.py @@ -30,13 +30,14 @@ """Define Matter test case TC_DEM_2_10.""" -import logging import datetime +import logging import time import chip.clusters as Clusters from chip.interaction_model import Status -from matter_testing_support import ClusterAttributeChangeAccumulator, MatterBaseTest, TestStep, async_test_body, default_matter_test_main +from matter_testing_support import (ClusterAttributeChangeAccumulator, MatterBaseTest, TestStep, async_test_body, + default_matter_test_main) from mobly import asserts from TC_DEMTestBase import DEMTestBase From 7b8ba115cb01e18fc8c549be55bb284d0d5b821e Mon Sep 17 00:00:00 2001 From: James Harrow Date: Thu, 22 Aug 2024 13:24:33 +0100 Subject: [PATCH 25/45] Fix ruff detected errors --- src/python_testing/TC_DEM_1_1.py | 3 +-- src/python_testing/TC_DEM_2_10.py | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/python_testing/TC_DEM_1_1.py b/src/python_testing/TC_DEM_1_1.py index 89a6d49ffbf10d..26eb94e7b2f40f 100644 --- a/src/python_testing/TC_DEM_1_1.py +++ b/src/python_testing/TC_DEM_1_1.py @@ -33,7 +33,6 @@ import logging import chip.clusters as Clusters -from chip.interaction_model import Status from matter_testing_support import MatterBaseTest, TestStep, async_test_body, default_matter_test_main from mobly import asserts from TC_DEMTestBase import DEMTestBase @@ -151,7 +150,7 @@ async def test_TC_DEM_1_1(self): asserts.assert_equal(len(attribute_list), 0) self.step("5") - logging.info(f"Not supported/skipped") + logging.info("Not supported/skipped") self.step("6") accepted_command_list = await self.read_dem_attribute_expect_success(attribute="AcceptedCommandList") diff --git a/src/python_testing/TC_DEM_2_10.py b/src/python_testing/TC_DEM_2_10.py index 676c03ca570879..8fe05769b4243e 100644 --- a/src/python_testing/TC_DEM_2_10.py +++ b/src/python_testing/TC_DEM_2_10.py @@ -30,7 +30,6 @@ """Define Matter test case TC_DEM_2_10.""" -import datetime import logging import time From e95b739cbd1ce0906288401fa2014d8524d99771 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 22 Aug 2024 12:24:57 +0000 Subject: [PATCH 26/45] Restyled by autopep8 --- src/python_testing/TC_DEM_2_10.py | 1 + src/python_testing/matter_testing_support.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/python_testing/TC_DEM_2_10.py b/src/python_testing/TC_DEM_2_10.py index 8fe05769b4243e..81e1ca83cb18a8 100644 --- a/src/python_testing/TC_DEM_2_10.py +++ b/src/python_testing/TC_DEM_2_10.py @@ -155,5 +155,6 @@ async def test_TC_DEM_2_10(self): self.step("10") await self.send_test_event_trigger_forecast_adjustment_clear() + if __name__ == "__main__": default_matter_test_main() diff --git a/src/python_testing/matter_testing_support.py b/src/python_testing/matter_testing_support.py index 3a7edc093b0edb..e4bbdac56ddf92 100644 --- a/src/python_testing/matter_testing_support.py +++ b/src/python_testing/matter_testing_support.py @@ -410,7 +410,7 @@ def reset(self): self._attribute_reports[a] = [] self._q = queue.Queue() - async def start(self, dev_ctrl, node_id: int, endpoint: int, fabric_filtered: bool = False, min_interval_sec: int = 0, max_interval_sec: int = 5, keepSubscriptions: bool=True) -> Any: + async def start(self, dev_ctrl, node_id: int, endpoint: int, fabric_filtered: bool = False, min_interval_sec: int = 0, max_interval_sec: int = 5, keepSubscriptions: bool = True) -> Any: """This starts a subscription for attributes on the specified node_id and endpoint. The cluster is specified when the class instance is created.""" self._subscription = await dev_ctrl.ReadAttribute( nodeid=node_id, From 69f2ea1b2c7c3520ef328b4944084467c955c574 Mon Sep 17 00:00:00 2001 From: pcoleman Date: Thu, 22 Aug 2024 17:24:26 +0100 Subject: [PATCH 27/45] Fix the cancelling of subscriptions --- src/python_testing/TC_DEM_2_10.py | 2 +- src/python_testing/matter_testing_support.py | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/python_testing/TC_DEM_2_10.py b/src/python_testing/TC_DEM_2_10.py index 81e1ca83cb18a8..17d5e192709ec6 100644 --- a/src/python_testing/TC_DEM_2_10.py +++ b/src/python_testing/TC_DEM_2_10.py @@ -150,7 +150,7 @@ async def test_TC_DEM_2_10(self): asserts.assert_less_equal(count, 10, "More than 10 reports received") self.step("9") - sub_handler.cancel() + await sub_handler.cancel() self.step("10") await self.send_test_event_trigger_forecast_adjustment_clear() diff --git a/src/python_testing/matter_testing_support.py b/src/python_testing/matter_testing_support.py index e4bbdac56ddf92..d39c499eb296a8 100644 --- a/src/python_testing/matter_testing_support.py +++ b/src/python_testing/matter_testing_support.py @@ -422,10 +422,15 @@ async def start(self, dev_ctrl, node_id: int, endpoint: int, fabric_filtered: bo self._subscription.SetAttributeUpdateCallback(self.__call__) return self._subscription - def cancel(self): + async def cancel(self): """This cancels a subscription.""" - self._subscription.Shutdown() - self._subscription = None + # Wait for the asyncio.CancelledError to be called before returning + try: + self._subscription.Shutdown() + await asyncio.sleep(5) + except asyncio.CancelledError: + pass + def __call__(self, path: TypedAttributePath, transaction: SubscriptionTransaction): """This is the subscription callback when an attribute report is received. From e601967028bedde09342c147ec30a13604078593 Mon Sep 17 00:00:00 2001 From: James Harrow Date: Wed, 28 Aug 2024 10:29:52 +0100 Subject: [PATCH 28/45] Used .name instead of needing a feature string mapping. --- src/python_testing/TC_DEMTestBase.py | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/python_testing/TC_DEMTestBase.py b/src/python_testing/TC_DEMTestBase.py index befec0be815a97..da51ba252820cc 100644 --- a/src/python_testing/TC_DEMTestBase.py +++ b/src/python_testing/TC_DEMTestBase.py @@ -24,14 +24,6 @@ logger = logging.getLogger(__name__) -s_feature_strs = {Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerAdjustment: "kPowerAdjustment", - Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerForecastReporting: "kPowerForecastReporting", - Clusters.DeviceEnergyManagement.Bitmaps.Feature.kStateForecastReporting: "kStateForecastReporting", - Clusters.DeviceEnergyManagement.Bitmaps.Feature.kStartTimeAdjustment: "kStartTimeAdjustment", - Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPausable: "kPausable", - Clusters.DeviceEnergyManagement.Bitmaps.Feature.kForecastAdjustment: "kForecastAdjustment", - Clusters.DeviceEnergyManagement.Bitmaps.Feature.kConstraintBasedAdjustment: "kConstraintBasedAdjustment"} - class DEMTestBase: @@ -50,11 +42,11 @@ async def validate_feature_map(self, must_have_features, must_not_have_features) feature_map = await self.read_dem_attribute_expect_success(attribute="FeatureMap") for must_have_feature in must_have_features: asserts.assert_true(feature_map & must_have_feature, - f"{s_feature_strs[must_have_feature]} must be set but is not. feature_map 0x{feature_map:x}") + f"{must_have_feature.name} must be set but is not. feature_map 0x{feature_map:x}") for must_not_have_feature in must_not_have_features: asserts.assert_false(feature_map & must_not_have_feature, - f"{s_feature_strs[must_not_have_feature]} is not allowed to be set. feature_map 0x{feature_map:x}") + f"{must_not_have_feature.name} is not allowed to be set. feature_map 0x{feature_map:x}") async def validate_pfr_or_sfr_in_feature_map(self): feature_map = await self.read_dem_attribute_expect_success(attribute="FeatureMap") From e9a5f2bbcc2c55ed9588314af3625b99ea33f60b Mon Sep 17 00:00:00 2001 From: James Harrow Date: Wed, 28 Aug 2024 10:36:20 +0100 Subject: [PATCH 29/45] Removed TC_DEM_1_1 now that the test plan has removed this test case. --- src/python_testing/TC_DEM_1_1.py | 214 ------------------------------- 1 file changed, 214 deletions(-) delete mode 100644 src/python_testing/TC_DEM_1_1.py diff --git a/src/python_testing/TC_DEM_1_1.py b/src/python_testing/TC_DEM_1_1.py deleted file mode 100644 index 26eb94e7b2f40f..00000000000000 --- a/src/python_testing/TC_DEM_1_1.py +++ /dev/null @@ -1,214 +0,0 @@ -# -# Copyright (c) 2024 Project CHIP Authors -# All rights reserved. -# -# 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. -# pylint: disable=invalid-name - -# See https://github.com/project-chip/connectedhomeip/blob/master/docs/testing/python.md#defining-the-ci-test-arguments -# for details about the block below. -# -# === BEGIN CI TEST ARGUMENTS === -# test-runner-runs: run1 -# test-runner-run/run1/app: ${ENERGY_MANAGEMENT_APP} -# test-runner-run/run1/factoryreset: True -# test-runner-run/run1/quiet: True -# test-runner-run/run1/app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json --enable-key 000102030405060708090a0b0c0d0e0f --featureSet 0x7b -# test-runner-run/run1/script-args: --storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --hex-arg enableKey:000102030405060708090a0b0c0d0e0f --endpoint 1 --trace-to json:${TRACE_TEST_JSON}.json --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto -# === END CI TEST ARGUMENTS === - -"""Define Matter test case TC_DEM_1_1.""" - - -import logging - -import chip.clusters as Clusters -from matter_testing_support import MatterBaseTest, TestStep, async_test_body, default_matter_test_main -from mobly import asserts -from TC_DEMTestBase import DEMTestBase - -logger = logging.getLogger(__name__) - - -class TC_DEM_1_1(MatterBaseTest, DEMTestBase): - """Implementation of test case TC_DEM_1_1.""" - - def desc_TC_DEM_1_1(self) -> str: - """Return a description of this test.""" - return "4.1.3. [TC-DEM-2.5] Forecast Adjustment with Power Forecast Reporting feature functionality with DUT as Server" - - def pics_TC_DEM_1_1(self): - """Return the PICS definitions associated with this test.""" - pics = [ - # Depends on Feature 05 (ForecastAdjustment) & Feature 01 (PowerForecastReporting) - "DEM.S.F05", "DEM.S.F01" - ] - return pics - - def steps_TC_DEM_1_1(self) -> list[TestStep]: - """Execute the test steps.""" - steps = [ - TestStep("1", "Commission DUT to TH (can be skipped if done in a preceding test)."), - TestStep("2", "TH reads from the DUT the ClusterRevision attribute.", - "Verify that the DUT response contains the ClusterRevision attribute and has the value 3."), - TestStep("3", "TH reads from the DUT the FeatureMap attribute.", - "Verify that the DUT response contains the FeatureMap attribute and have the following bit set:\n- bit 0: SHALL be 1 if and only if DEM.S.F00(PowerAdjustment).\n- bit 1: SHALL be 1 if and only if DEM.S.F01(PowerForecastReporting).\n- bit 2: SHALL be 1 if and only if DEM.S.F02(StateForecastReporting).\n- bit 3: SHALL be 1 if and only if DEM.S.F03(StartTimeAdjustment).\n- bit 4: SHALL be 1 if and only if DEM.S.F04(Pausable).\nAll remaining bits SHALL be 0. Provisional features DEM.S.F05(ForecastAdjustment) and DEM.S.F06(ConstraintBasedAdjustment) must not be supported."), - TestStep("4", "TH reads from the DUT the AttributeList attribute.", - "Verify that the DUT response contains the AttributeList attribute and have the list of supported attributes:\nThe list SHALL include all the mandatory entries: +\n0x0000, 0x0001, 0x0002, 0x0003, 0x0004\n0xfff8, 0xfff9, 0xfffb, 0xfffc and 0xfffd.\nThe list includes entries based on feature support: +\n- 0x0005: SHALL be included if and only if DEM.S.F00(PowerAdjustment).\n- 0x0006: SHALL be included if and only if DEM.S.F01(PowerForecastReporting) | DEM.S.F02(StateForecastReporting).\n- 0x0007: SHALL be included if and only if DEM.S.F00(PowerAdjustment) | DEM.S.F03(StartTimeAdjustment) | DEM.S.F04(Pausable) | DEM.S.F05(ForecastAdjustment) | DEM.S.F06(ConstraintBasedAdjustment)."), - TestStep("5", "TH reads from the DUT the EventList attribute.", - "Verify that the DUT response contains the EventList attribute and have the list of supported events:\nThe list includes entries based on feature support: +\n- 0x00, 0x01: SHALL be included if and only if DEM.S.F00(PowerAdjustment).\n- 0x02, 0x03: SHALL be included if and only if DEM.S.F04(Pausable)."), - TestStep("6", "TH reads from the DUT the AcceptedCommandList attribute.", - "Verify that the DUT response contains the AcceptedCommandList attribute and have the list of Accepted Command:\nThe list includes entries based on feature support: +\n- 0x00, 0x01: SHALL be included if and only if DEM.S.F00(PowerAdjustment).\n- 0x02: SHALL be included if and only if DEM.S.F03(StartTimeAdjustment).\n- 0x03, 0x04: SHALL be included if and only if DEM.S.F04(Pausable).\n- 0x05: SHALL be included if and only if DEM.S.F05(ForecastAdjustment).\n- 0x06: SHALL be included if and only if DEM.S.F06(ConstraintBasedAdjustment).\n- 0x07: SHALL be included if and only if DEM.S.F03(StartTimeAdjustment)|DEM.S.F05(ForecastAdjustment)|DEM.S.F06(ConstraintBasedAdjustment)"), - TestStep("7", "TH reads from the DUT the GeneratedCommandList attribute.", - "Verify that the DUT response contains the GeneratedCommandList attribute and have the list of Generated Command:\nThis cluster has no entries in the standard or scoped range. +"), - ] - - return steps - - @async_test_body - async def test_TC_DEM_1_1(self): - # pylint: disable=too-many-locals, too-many-statements - """Run the test steps.""" - self.step("1") - # Commission DUT - already done - - self.step("2") - await self.check_dem_attribute("ClusterRevision", 4) - - self.step("3") - await self.validate_feature_map([Clusters.DeviceEnergyManagement.Bitmaps.Feature.kForecastAdjustment, - Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerForecastReporting, - Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerAdjustment, - Clusters.DeviceEnergyManagement.Bitmaps.Feature.kStartTimeAdjustment, - Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPausable, - Clusters.DeviceEnergyManagement.Bitmaps.Feature.kConstraintBasedAdjustment], - [Clusters.DeviceEnergyManagement.Bitmaps.Feature.kStateForecastReporting]) - - self.step("4") - attribute_list = await self.read_dem_attribute_expect_success(attribute="AttributeList") - logging.info(attribute_list) - - mandatory_attributes = [Clusters.DeviceEnergyManagement.Attributes.ESAType.attribute_id, - Clusters.DeviceEnergyManagement.Attributes.ESACanGenerate.attribute_id, - Clusters.DeviceEnergyManagement.Attributes.ESAState.attribute_id, - Clusters.DeviceEnergyManagement.Attributes.AbsMinPower.attribute_id, - Clusters.DeviceEnergyManagement.Attributes.AbsMaxPower.attribute_id] - - for mandatory_attribute in mandatory_attributes: - asserts.assert_true(mandatory_attribute in attribute_list, - f"Expected to find mandatory attribute {mandatory_attribute} in attribute_list {attribute_list}") - - # Remove the entry from the list - attribute_list.remove(mandatory_attribute) - - # Now check feature dependant attributes - feature_map = await self.read_dem_attribute_expect_success(attribute="FeatureMap") - - attribute_id = Clusters.DeviceEnergyManagement.Attributes.PowerAdjustmentCapability.attribute_id - required_features = Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerAdjustment - self.check_attribute_valid_and_remove_from_list(attribute_id, feature_map, attribute_list, required_features) - - attribute_id = Clusters.DeviceEnergyManagement.Attributes.Forecast.attribute_id - required_features = (Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerForecastReporting | - Clusters.DeviceEnergyManagement.Bitmaps.Feature.kStateForecastReporting) - self.check_attribute_valid_and_remove_from_list(attribute_id, feature_map, attribute_list, required_features) - - attribute_id = Clusters.DeviceEnergyManagement.Attributes.OptOutState.attribute_id - required_features = (Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerAdjustment | - Clusters.DeviceEnergyManagement.Bitmaps.Feature.kStartTimeAdjustment | - Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPausable | - Clusters.DeviceEnergyManagement.Bitmaps.Feature.kForecastAdjustment | - Clusters.DeviceEnergyManagement.Bitmaps.Feature.kConstraintBasedAdjustment) - - self.check_attribute_valid_and_remove_from_list(attribute_id, feature_map, attribute_list, required_features) - - global_attributes = [Clusters.DeviceEnergyManagement.Attributes.GeneratedCommandList.attribute_id, - Clusters.DeviceEnergyManagement.Attributes.AcceptedCommandList.attribute_id, - Clusters.DeviceEnergyManagement.Attributes.AttributeList.attribute_id, - Clusters.DeviceEnergyManagement.Attributes.FeatureMap.attribute_id, - Clusters.DeviceEnergyManagement.Attributes.ClusterRevision.attribute_id] - - for global_attribute in global_attributes: - logging.info(f"global_attribute {global_attribute} global_attributes {global_attributes}") - asserts.assert_true(global_attribute in attribute_list, - f"Expected to find global attribute {global_attribute} in attribute_list {attribute_list}") - - # Remove the enrty from the list - attribute_list.remove(global_attribute) - - # Check there are no unknown attributes left in the list - asserts.assert_equal(len(attribute_list), 0) - - self.step("5") - logging.info("Not supported/skipped") - - self.step("6") - accepted_command_list = await self.read_dem_attribute_expect_success(attribute="AcceptedCommandList") - logging.info(f"accepted_command_list {accepted_command_list}") - - required_features = Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerAdjustment - expected_commands = [Clusters.DeviceEnergyManagement.Commands.PowerAdjustRequest.command_id, - Clusters.DeviceEnergyManagement.Commands.CancelPowerAdjustRequest.command_id] - self.check_expected_commands_in_list(expected_commands, feature_map, accepted_command_list, required_features) - - required_features = Clusters.DeviceEnergyManagement.Bitmaps.Feature.kStartTimeAdjustment - expected_commands = [Clusters.DeviceEnergyManagement.Commands.StartTimeAdjustRequest.command_id] - self.check_expected_commands_in_list(expected_commands, feature_map, accepted_command_list, required_features) - - required_features = Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPausable - expected_commands = [Clusters.DeviceEnergyManagement.Commands.PauseRequest.command_id, - Clusters.DeviceEnergyManagement.Commands.ResumeRequest.command_id] - self.check_expected_commands_in_list(expected_commands, feature_map, accepted_command_list, required_features) - - required_features = Clusters.DeviceEnergyManagement.Bitmaps.Feature.kForecastAdjustment - expected_commands = [Clusters.DeviceEnergyManagement.Commands.ModifyForecastRequest.command_id] - self.check_expected_commands_in_list(expected_commands, feature_map, accepted_command_list, required_features) - - required_features = Clusters.DeviceEnergyManagement.Bitmaps.Feature.kConstraintBasedAdjustment - expected_commands = [Clusters.DeviceEnergyManagement.Commands.RequestConstraintBasedForecast.command_id] - self.check_expected_commands_in_list(expected_commands, feature_map, accepted_command_list, required_features) - - required_features = (Clusters.DeviceEnergyManagement.Bitmaps.Feature.kStartTimeAdjustment | - Clusters.DeviceEnergyManagement.Bitmaps.Feature.kForecastAdjustment | - Clusters.DeviceEnergyManagement.Bitmaps.Feature.kConstraintBasedAdjustment) - expected_commands = [Clusters.DeviceEnergyManagement.Commands.CancelRequest.command_id] - self.check_expected_commands_in_list(expected_commands, feature_map, accepted_command_list, required_features) - - self.step("7") - generated_command_list = await self.read_dem_attribute_expect_success(attribute="GeneratedCommandList") - asserts.assert_equal(len(generated_command_list), 0) - - def check_attribute_valid_and_remove_from_list(self, attribute_id, feature_map, attribute_list, required_features): - if feature_map & required_features: - asserts.assert_true(attribute_id in attribute_list, - f"Expected to find attribute {attribute_id} in attribute_list {attribute_list} given feature_map 0x{feature_map:x}") - attribute_list.remove(attribute_id) - - else: - asserts.assert_false(attribute_id in attribute_list, - f"Did not expect to find attribute {attribute_id} in attribute_list {attribute_list} given feature_map 0x{feature_map:x}") - - def check_expected_commands_in_list(self, expected_commands, feature_map, accepted_command_list, required_features): - if (feature_map & required_features) != 0: - for command in expected_commands: - asserts.assert_true(command in accepted_command_list, - f"Expected command {command} to be in accepted_command_list {accepted_command_list} given required_features {required_features} in feature_map 0x{feature_map:x}") - - else: - for command in expected_commands: - asserts.assert_false(command in accepted_command_list, - f"Did not expect command {command} to be in accepted_command_list {accepted_command_list} given required_features {required_features} in feature_map 0x{feature_map:x}") - - -if __name__ == "__main__": - default_matter_test_main() From 47d35cb820925b9d625139abeff0d3bdb9a18ce3 Mon Sep 17 00:00:00 2001 From: James Harrow Date: Wed, 28 Aug 2024 11:39:37 +0100 Subject: [PATCH 30/45] Corrected Featuremap -> FeatureMap in test steps --- src/python_testing/TC_DEM_2_2.py | 4 ++-- src/python_testing/TC_DEM_2_3.py | 4 ++-- src/python_testing/TC_DEM_2_4.py | 4 ++-- src/python_testing/TC_DEM_2_5.py | 4 ++-- src/python_testing/TC_DEM_2_6.py | 4 ++-- src/python_testing/TC_DEM_2_7.py | 4 ++-- src/python_testing/TC_DEM_2_8.py | 4 ++-- src/python_testing/TC_DEM_2_9.py | 4 ++-- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/python_testing/TC_DEM_2_2.py b/src/python_testing/TC_DEM_2_2.py index ec288bb709a70a..3175508d056cb5 100644 --- a/src/python_testing/TC_DEM_2_2.py +++ b/src/python_testing/TC_DEM_2_2.py @@ -62,8 +62,8 @@ def steps_TC_DEM_2_2(self) -> list[TestStep]: """Execute the test steps.""" steps = [ TestStep("1", "Commission DUT to TH (can be skipped if done in a preceding test)"), - TestStep("2", "TH reads from the DUT the _Featuremap_ attribute", - "Verify that the DUT response contains the _Featuremap_ attribute. Verify PowerAdjustment is supported."), + TestStep("2", "TH reads from the DUT the _FeatureMap_ attribute", + "Verify that the DUT response contains the _FeatureMap_ attribute. Verify PowerAdjustment is supported."), TestStep("3", "Set up a subscription to all DeviceEnergyManagement cluster events"), TestStep("4", "TH reads TestEventTriggersEnabled attribute from General Diagnostics Cluster", "Value has to be 1 (True)"), diff --git a/src/python_testing/TC_DEM_2_3.py b/src/python_testing/TC_DEM_2_3.py index b1b1b59baa77aa..03b07b4fb64643 100644 --- a/src/python_testing/TC_DEM_2_3.py +++ b/src/python_testing/TC_DEM_2_3.py @@ -55,8 +55,8 @@ def pics_TC_DEM_2_3(self): def steps_TC_DEM_2_3(self) -> list[TestStep]: steps = [ TestStep("1", "Commission DUT to TH (can be skipped if done in a preceding test)"), - TestStep("2", "TH reads from the DUT the _Featuremap_ attribute", - "Verify that the DUT response contains the _Featuremap_ attribute. Verify StartTimeAdjustment is supported."), + TestStep("2", "TH reads from the DUT the _FeatureMap_ attribute", + "Verify that the DUT response contains the _FeatureMap_ attribute. Verify StartTimeAdjustment is supported."), TestStep("3", "TH reads TestEventTriggersEnabled attribute from General Diagnostics Cluster", "Value has to be 1 (True)"), TestStep("4", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Start Time Adjustment Test Event", diff --git a/src/python_testing/TC_DEM_2_4.py b/src/python_testing/TC_DEM_2_4.py index 3ae49282ac502e..2c98b6641e1f5f 100644 --- a/src/python_testing/TC_DEM_2_4.py +++ b/src/python_testing/TC_DEM_2_4.py @@ -56,8 +56,8 @@ def pics_TC_DEM_2_4(self): def steps_TC_DEM_2_4(self) -> list[TestStep]: steps = [ TestStep("1", "Commission DUT to TH (can be skipped if done in a preceding test)"), - TestStep("2", "TH reads from the DUT the _Featuremap_ attribute", - "Verify that the DUT response contains the _Featuremap_ attribute. Verify Pausable is supported."), + TestStep("2", "TH reads from the DUT the _FeatureMap_ attribute", + "Verify that the DUT response contains the _FeatureMap_ attribute. Verify Pausable is supported."), TestStep("3", "Set up a subscription to all DeviceEnergyManagement cluster events"), TestStep("4", "TH reads TestEventTriggersEnabled attribute from General Diagnostics Cluster", "Value has to be 1 (True)"), diff --git a/src/python_testing/TC_DEM_2_5.py b/src/python_testing/TC_DEM_2_5.py index 96aa23f34e948b..150070a4984232 100644 --- a/src/python_testing/TC_DEM_2_5.py +++ b/src/python_testing/TC_DEM_2_5.py @@ -60,8 +60,8 @@ def steps_TC_DEM_2_5(self) -> list[TestStep]: """Execute the test steps.""" steps = [ TestStep("1", "Commission DUT to TH (can be skipped if done in a preceding test)"), - TestStep("2", "TH reads from the DUT the _Featuremap_ attribute", - "Verify that the DUT response contains the _Featuremap_ attribute. Verify ForecastAdjustment and PowerForecastReporting is supported. . Verify StateForecastReporting is not supported."), + TestStep("2", "TH reads from the DUT the _FeatureMap_ attribute", + "Verify that the DUT response contains the _FeatureMap_ attribute. Verify ForecastAdjustment and PowerForecastReporting is supported. . Verify StateForecastReporting is not supported."), TestStep("3", "TH reads TestEventTriggersEnabled attribute from General Diagnostics Cluster", "Value has to be 1 (True)"), TestStep("4", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Forecast Adjustment Test Event", diff --git a/src/python_testing/TC_DEM_2_6.py b/src/python_testing/TC_DEM_2_6.py index 3cdaf99ee5006a..1e90becfec1d9f 100644 --- a/src/python_testing/TC_DEM_2_6.py +++ b/src/python_testing/TC_DEM_2_6.py @@ -60,8 +60,8 @@ def steps_TC_DEM_2_6(self) -> list[TestStep]: """Execute the test steps.""" steps = [ TestStep("1", "Commission DUT to TH (can be skipped if done in a preceding test)"), - TestStep("2", "TH reads from the DUT the _Featuremap_ attribute", - "Verify that the DUT response contains the _Featuremap_ attribute. Verify ForecastAdjustment and StateForecastReporting is supported. Verify PowerForecastReporting is not supported."), + TestStep("2", "TH reads from the DUT the _FeatureMap_ attribute", + "Verify that the DUT response contains the _FeatureMap_ attribute. Verify ForecastAdjustment and StateForecastReporting is supported. Verify PowerForecastReporting is not supported."), TestStep("3", "TH reads TestEventTriggersEnabled attribute from General Diagnostics Cluster", "Value has to be 1 (True)"), TestStep("4", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Forecast Adjustment Test Event", diff --git a/src/python_testing/TC_DEM_2_7.py b/src/python_testing/TC_DEM_2_7.py index 0ab64793ab6f44..c1ab79359125c7 100644 --- a/src/python_testing/TC_DEM_2_7.py +++ b/src/python_testing/TC_DEM_2_7.py @@ -60,8 +60,8 @@ def steps_TC_DEM_2_7(self) -> list[TestStep]: """Execute the test steps.""" steps = [ TestStep("1", "Commission DUT to TH (can be skipped if done in a preceding test)"), - TestStep("2", "TH reads from the DUT the _Featuremap_ attribute", - "Verify that the DUT response contains the _Featuremap_ attribute. Verify ConstraintBasedAdjustment and PowerForecastReporting is supported. Verify StateForecastReporting is not supported."), + TestStep("2", "TH reads from the DUT the _FeatureMap_ attribute", + "Verify that the DUT response contains the _FeatureMap_ attribute. Verify ConstraintBasedAdjustment and PowerForecastReporting is supported. Verify StateForecastReporting is not supported."), TestStep("3", "TH reads TestEventTriggersEnabled attribute from General Diagnostics Cluster", "Value has to be 1 (True)"), TestStep("4", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Constraints-based Adjustment Test Event", diff --git a/src/python_testing/TC_DEM_2_8.py b/src/python_testing/TC_DEM_2_8.py index 3ad8e7d74ccab6..0130df65f72c91 100644 --- a/src/python_testing/TC_DEM_2_8.py +++ b/src/python_testing/TC_DEM_2_8.py @@ -60,8 +60,8 @@ def steps_TC_DEM_2_8(self) -> list[TestStep]: """Execute the test steps.""" steps = [ TestStep("1", "Commission DUT to TH (can be skipped if done in a preceding test)"), - TestStep("2", "TH reads from the DUT the _Featuremap_ attribute", - "Verify that the DUT response contains the _Featuremap_ attribute. Verify ConstraintBasedAdjustment and StateForecastReporting is supported. Verify PowerForecastReporting is not supported."), + TestStep("2", "TH reads from the DUT the _FeatureMap_ attribute", + "Verify that the DUT response contains the _FeatureMap_ attribute. Verify ConstraintBasedAdjustment and StateForecastReporting is supported. Verify PowerForecastReporting is not supported."), TestStep("3", "TH reads TestEventTriggersEnabled attribute from General Diagnostics Cluster", "Value has to be 1 (True)"), TestStep("4", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Constraints-based Adjustment Test Event", diff --git a/src/python_testing/TC_DEM_2_9.py b/src/python_testing/TC_DEM_2_9.py index 400960905f165e..4fbdc510d2cc02 100644 --- a/src/python_testing/TC_DEM_2_9.py +++ b/src/python_testing/TC_DEM_2_9.py @@ -59,8 +59,8 @@ def steps_TC_DEM_2_9(self) -> list[TestStep]: """Execute the test steps.""" steps = [ TestStep("1", "Commission DUT to TH (can be skipped if done in a preceding test)"), - TestStep("2", "TH reads from the DUT the _Featuremap_ attribute", - "Verify that the DUT response contains the _Featuremap_ attribute. Verify one of PowerForecastReporting or StateForecastReporting is supported but not both."), + TestStep("2", "TH reads from the DUT the _FeatureMap_ attribute", + "Verify that the DUT response contains the _FeatureMap_ attribute. Verify one of PowerForecastReporting or StateForecastReporting is supported but not both."), TestStep("3", "TH reads TestEventTriggersEnabled attribute from General Diagnostics Cluster", "Value has to be 1 (True)"), TestStep("4", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Forecast Test Event", From 1f8470f5d962841ff4f043754f36c47c52091399 Mon Sep 17 00:00:00 2001 From: James Harrow Date: Wed, 28 Aug 2024 11:56:13 +0100 Subject: [PATCH 31/45] Aligned verification step 2 on TC_DEM_2.3 to actual code and syncd test plan. --- src/python_testing/TC_DEM_2_3.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python_testing/TC_DEM_2_3.py b/src/python_testing/TC_DEM_2_3.py index 03b07b4fb64643..d462c390596449 100644 --- a/src/python_testing/TC_DEM_2_3.py +++ b/src/python_testing/TC_DEM_2_3.py @@ -56,7 +56,7 @@ def steps_TC_DEM_2_3(self) -> list[TestStep]: steps = [ TestStep("1", "Commission DUT to TH (can be skipped if done in a preceding test)"), TestStep("2", "TH reads from the DUT the _FeatureMap_ attribute", - "Verify that the DUT response contains the _FeatureMap_ attribute. Verify StartTimeAdjustment is supported."), + "Verify that the DUT response contains the _FeatureMap_ attribute. Verify StartTimeAdjustment feature is supported on the cluster. Verify PowerForecastReporting or StateForecastReporting feature is supported on the cluster."), TestStep("3", "TH reads TestEventTriggersEnabled attribute from General Diagnostics Cluster", "Value has to be 1 (True)"), TestStep("4", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Start Time Adjustment Test Event", From ac9efe2ad198c97cf73a7b837f4878c062cfa95e Mon Sep 17 00:00:00 2001 From: James Harrow Date: Wed, 28 Aug 2024 12:45:07 +0100 Subject: [PATCH 32/45] Aligned verification step 2 on TC_DEM_2.4 to actual code and syncd test plan. --- src/python_testing/TC_DEM_2_4.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python_testing/TC_DEM_2_4.py b/src/python_testing/TC_DEM_2_4.py index 2c98b6641e1f5f..ea5e7107417de2 100644 --- a/src/python_testing/TC_DEM_2_4.py +++ b/src/python_testing/TC_DEM_2_4.py @@ -57,7 +57,7 @@ def steps_TC_DEM_2_4(self) -> list[TestStep]: steps = [ TestStep("1", "Commission DUT to TH (can be skipped if done in a preceding test)"), TestStep("2", "TH reads from the DUT the _FeatureMap_ attribute", - "Verify that the DUT response contains the _FeatureMap_ attribute. Verify Pausable is supported."), + "Verify that the DUT response contains the _FeatureMap_ attribute. Verify Pausable feature is supported on the cluster. Verify PowerForecastReporting or StateForecastReporting feature is supported on the cluster."), TestStep("3", "Set up a subscription to all DeviceEnergyManagement cluster events"), TestStep("4", "TH reads TestEventTriggersEnabled attribute from General Diagnostics Cluster", "Value has to be 1 (True)"), From 4a25dc61d47c23d7a0f9cb0fbdf0fa6f8a728814 Mon Sep 17 00:00:00 2001 From: James Harrow Date: Wed, 28 Aug 2024 12:57:19 +0100 Subject: [PATCH 33/45] Added in missing text in step 18 in TC_DEM_2.4 --- src/python_testing/TC_DEM_2_4.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python_testing/TC_DEM_2_4.py b/src/python_testing/TC_DEM_2_4.py index ea5e7107417de2..734712099e8798 100644 --- a/src/python_testing/TC_DEM_2_4.py +++ b/src/python_testing/TC_DEM_2_4.py @@ -131,7 +131,7 @@ def steps_TC_DEM_2_4(self) -> list[TestStep]: "Verify DUT responds w/ status SUCCESS(0x00) and Event DEM.S.E02(Paused) sent"), TestStep("17a", "TH reads from the DUT the ESAState", "Value has to be 0x05 (Paused)"), - TestStep("18", "", + TestStep("18", "Wait for minPauseDuration.", "Event DEM.S.E03(Resumed) sent with Cause=0 (NormalCompletion)"), TestStep("18a", "TH reads from the DUT the ESAState", "Value has to be 0x01 (Online)"), From 6d8af0c732f5efb0392b046bdd8daac69aa28a16 Mon Sep 17 00:00:00 2001 From: James Harrow Date: Wed, 28 Aug 2024 13:19:51 +0100 Subject: [PATCH 34/45] TC_DEM_2.5 minor update to step 2 and aligning to updated test plan. --- src/python_testing/TC_DEM_2_5.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python_testing/TC_DEM_2_5.py b/src/python_testing/TC_DEM_2_5.py index 150070a4984232..9e2df14846a505 100644 --- a/src/python_testing/TC_DEM_2_5.py +++ b/src/python_testing/TC_DEM_2_5.py @@ -61,7 +61,7 @@ def steps_TC_DEM_2_5(self) -> list[TestStep]: steps = [ TestStep("1", "Commission DUT to TH (can be skipped if done in a preceding test)"), TestStep("2", "TH reads from the DUT the _FeatureMap_ attribute", - "Verify that the DUT response contains the _FeatureMap_ attribute. Verify ForecastAdjustment and PowerForecastReporting is supported. . Verify StateForecastReporting is not supported."), + "Verify that the DUT response contains the _FeatureMap_ attribute. Verify ForecastAdjustment feature is supported on the cluster. Verify PowerForecastReporting feature is supported on the cluster. Verify StateForecastReporting feature is not supported on the cluster."), TestStep("3", "TH reads TestEventTriggersEnabled attribute from General Diagnostics Cluster", "Value has to be 1 (True)"), TestStep("4", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Forecast Adjustment Test Event", From fd96e7d71794f56a2ce858ece0b2c646ce3b23df Mon Sep 17 00:00:00 2001 From: James Harrow Date: Wed, 28 Aug 2024 13:37:37 +0100 Subject: [PATCH 35/45] TC_DEM_2.5 - slight change to call to name args in validate_feature_map() call --- src/python_testing/TC_DEM_2_5.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/python_testing/TC_DEM_2_5.py b/src/python_testing/TC_DEM_2_5.py index 9e2df14846a505..38bac00f32cfdf 100644 --- a/src/python_testing/TC_DEM_2_5.py +++ b/src/python_testing/TC_DEM_2_5.py @@ -148,9 +148,9 @@ async def test_TC_DEM_2_5(self): # Commission DUT - already done self.step("2") - await self.validate_feature_map([Clusters.DeviceEnergyManagement.Bitmaps.Feature.kForecastAdjustment, - Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerForecastReporting], - [Clusters.DeviceEnergyManagement.Bitmaps.Feature.kStateForecastReporting]) + await self.validate_feature_map(must_have_features=[Clusters.DeviceEnergyManagement.Bitmaps.Feature.kForecastAdjustment, + Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerForecastReporting], + must_not_have_features=[Clusters.DeviceEnergyManagement.Bitmaps.Feature.kStateForecastReporting]) self.step("3") await self.check_test_event_triggers_enabled() From 5349094ff23ab528f5c8fb26e309320179ac3e00 Mon Sep 17 00:00:00 2001 From: James Harrow Date: Wed, 28 Aug 2024 13:54:12 +0100 Subject: [PATCH 36/45] TC_DEM_2.6,2.7,2.8 step 2 alignment with tweaked test plan --- src/python_testing/TC_DEM_2_6.py | 2 +- src/python_testing/TC_DEM_2_7.py | 2 +- src/python_testing/TC_DEM_2_8.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/python_testing/TC_DEM_2_6.py b/src/python_testing/TC_DEM_2_6.py index 1e90becfec1d9f..9e0324b8318f29 100644 --- a/src/python_testing/TC_DEM_2_6.py +++ b/src/python_testing/TC_DEM_2_6.py @@ -61,7 +61,7 @@ def steps_TC_DEM_2_6(self) -> list[TestStep]: steps = [ TestStep("1", "Commission DUT to TH (can be skipped if done in a preceding test)"), TestStep("2", "TH reads from the DUT the _FeatureMap_ attribute", - "Verify that the DUT response contains the _FeatureMap_ attribute. Verify ForecastAdjustment and StateForecastReporting is supported. Verify PowerForecastReporting is not supported."), + "Verify that the DUT response contains the _FeatureMap_ attribute. Verify ForecastAdjustment feature is supported on the cluster. Verify StateForecastReporting feature is supported on the cluster. Verify PowerForecastReporting feature is not supported on the cluster."), TestStep("3", "TH reads TestEventTriggersEnabled attribute from General Diagnostics Cluster", "Value has to be 1 (True)"), TestStep("4", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Forecast Adjustment Test Event", diff --git a/src/python_testing/TC_DEM_2_7.py b/src/python_testing/TC_DEM_2_7.py index c1ab79359125c7..3a1ce8959a2280 100644 --- a/src/python_testing/TC_DEM_2_7.py +++ b/src/python_testing/TC_DEM_2_7.py @@ -61,7 +61,7 @@ def steps_TC_DEM_2_7(self) -> list[TestStep]: steps = [ TestStep("1", "Commission DUT to TH (can be skipped if done in a preceding test)"), TestStep("2", "TH reads from the DUT the _FeatureMap_ attribute", - "Verify that the DUT response contains the _FeatureMap_ attribute. Verify ConstraintBasedAdjustment and PowerForecastReporting is supported. Verify StateForecastReporting is not supported."), + "Verify that the DUT response contains the _FeatureMap_ attribute. Verify ConstraintBasedAdjustment feature is supported on the cluster. Verify PowerForecastReporting feature is supported on the cluster. Verify StateForecastReporting feature is not supported on the cluster."), TestStep("3", "TH reads TestEventTriggersEnabled attribute from General Diagnostics Cluster", "Value has to be 1 (True)"), TestStep("4", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Constraints-based Adjustment Test Event", diff --git a/src/python_testing/TC_DEM_2_8.py b/src/python_testing/TC_DEM_2_8.py index 0130df65f72c91..cc79bb068f8e62 100644 --- a/src/python_testing/TC_DEM_2_8.py +++ b/src/python_testing/TC_DEM_2_8.py @@ -61,7 +61,7 @@ def steps_TC_DEM_2_8(self) -> list[TestStep]: steps = [ TestStep("1", "Commission DUT to TH (can be skipped if done in a preceding test)"), TestStep("2", "TH reads from the DUT the _FeatureMap_ attribute", - "Verify that the DUT response contains the _FeatureMap_ attribute. Verify ConstraintBasedAdjustment and StateForecastReporting is supported. Verify PowerForecastReporting is not supported."), + "Verify that the DUT response contains the _FeatureMap_ attribute. Verify ConstraintBasedAdjustment feature is supported on the cluster. Verify StateForecastReporting feature is supported on the cluster. Verify PowerForecastReporting feature is not supported on the cluster."), TestStep("3", "TH reads TestEventTriggersEnabled attribute from General Diagnostics Cluster", "Value has to be 1 (True)"), TestStep("4", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Constraints-based Adjustment Test Event", From 65af1b34fa9003f694d938d1aa28b8186dba7f99 Mon Sep 17 00:00:00 2001 From: James Harrow Date: Wed, 28 Aug 2024 14:06:41 +0100 Subject: [PATCH 37/45] TC_DEM_2.6/2.7/2.8 - slight change to call to name args in validate_feature_map() call --- src/python_testing/TC_DEM_2_6.py | 6 +++--- src/python_testing/TC_DEM_2_7.py | 6 +++--- src/python_testing/TC_DEM_2_8.py | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/python_testing/TC_DEM_2_6.py b/src/python_testing/TC_DEM_2_6.py index 9e0324b8318f29..c05a80c6c3909a 100644 --- a/src/python_testing/TC_DEM_2_6.py +++ b/src/python_testing/TC_DEM_2_6.py @@ -142,9 +142,9 @@ async def test_TC_DEM_2_6(self): # Commission DUT - already done self.step("2") - await self.validate_feature_map([Clusters.DeviceEnergyManagement.Bitmaps.Feature.kForecastAdjustment, - Clusters.DeviceEnergyManagement.Bitmaps.Feature.kStateForecastReporting], - [Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerForecastReporting]) + await self.validate_feature_map(must_have_features=[Clusters.DeviceEnergyManagement.Bitmaps.Feature.kForecastAdjustment, + Clusters.DeviceEnergyManagement.Bitmaps.Feature.kStateForecastReporting], + must_not_have_features=[Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerForecastReporting]) self.step("3") await self.check_test_event_triggers_enabled() diff --git a/src/python_testing/TC_DEM_2_7.py b/src/python_testing/TC_DEM_2_7.py index 3a1ce8959a2280..b45643868a6e71 100644 --- a/src/python_testing/TC_DEM_2_7.py +++ b/src/python_testing/TC_DEM_2_7.py @@ -150,9 +150,9 @@ async def test_TC_DEM_2_7(self): # Commission DUT - already done self.step("2") - await self.validate_feature_map([Clusters.DeviceEnergyManagement.Bitmaps.Feature.kConstraintBasedAdjustment, - Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerForecastReporting], - [Clusters.DeviceEnergyManagement.Bitmaps.Feature.kStateForecastReporting]) + await self.validate_feature_map(must_have_features=[Clusters.DeviceEnergyManagement.Bitmaps.Feature.kConstraintBasedAdjustment, + Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerForecastReporting], + must_not_have_features=[Clusters.DeviceEnergyManagement.Bitmaps.Feature.kStateForecastReporting]) self.step("3") await self.check_test_event_triggers_enabled() diff --git a/src/python_testing/TC_DEM_2_8.py b/src/python_testing/TC_DEM_2_8.py index cc79bb068f8e62..1b1a2a31537098 100644 --- a/src/python_testing/TC_DEM_2_8.py +++ b/src/python_testing/TC_DEM_2_8.py @@ -142,9 +142,9 @@ async def test_TC_DEM_2_8(self): # Commission DUT - already done self.step("2") - await self.validate_feature_map([Clusters.DeviceEnergyManagement.Bitmaps.Feature.kConstraintBasedAdjustment, - Clusters.DeviceEnergyManagement.Bitmaps.Feature.kStateForecastReporting], - [Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerForecastReporting]) + await self.validate_feature_map(must_have_features=[Clusters.DeviceEnergyManagement.Bitmaps.Feature.kConstraintBasedAdjustment, + Clusters.DeviceEnergyManagement.Bitmaps.Feature.kStateForecastReporting], + must_not_have_features=[Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerForecastReporting]) self.step("3") await self.check_test_event_triggers_enabled() From 17edc0cea15584d80582da6c2adf8d19a9fb3912 Mon Sep 17 00:00:00 2001 From: James Harrow Date: Wed, 28 Aug 2024 15:09:08 +0100 Subject: [PATCH 38/45] Corrected log message in TC_DEM_2.9 step 4b --- src/python_testing/TC_DEM_2_9.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python_testing/TC_DEM_2_9.py b/src/python_testing/TC_DEM_2_9.py index 4fbdc510d2cc02..3acc4b7a517ece 100644 --- a/src/python_testing/TC_DEM_2_9.py +++ b/src/python_testing/TC_DEM_2_9.py @@ -108,7 +108,7 @@ async def test_TC_DEM_2_9(self): asserts.assert_is_not_none(forecast.slots[0].maxPower) asserts.assert_is_not_none(forecast.slots[0].nominalEnergy) else: - logging.info('Device does not support StateForecastReporting. Skipping step 4b') + logging.info('Device does not support PowerForecastReporting. Skipping step 4b') self.step("5") await self.send_test_event_trigger_forecast_clear() From 58e6bf3ed90e7722e562d4da02cba2d516b83ebc Mon Sep 17 00:00:00 2001 From: James Harrow Date: Thu, 29 Aug 2024 00:38:29 +0100 Subject: [PATCH 39/45] Updated TC_DEM_2.10 (Q Quality) Basic structure is there - steps need tidying up and fails due to powerAdjustmentCapability not being updated as expected. --- src/python_testing/TC_DEM_2_10.py | 257 +++++++++++++++++++++++------- 1 file changed, 199 insertions(+), 58 deletions(-) diff --git a/src/python_testing/TC_DEM_2_10.py b/src/python_testing/TC_DEM_2_10.py index 17d5e192709ec6..f7293030918791 100644 --- a/src/python_testing/TC_DEM_2_10.py +++ b/src/python_testing/TC_DEM_2_10.py @@ -32,6 +32,7 @@ import logging import time +import sys import chip.clusters as Clusters from chip.interaction_model import Status @@ -53,48 +54,72 @@ def desc_TC_DEM_2_10(self) -> str: def pics_TC_DEM_2_10(self): """Return the PICS definitions associated with this test.""" pics = [ - # Depends on Feature 05 (ForecastAdjustment) & Feature 02 (StateForecastReporting) - "DEM.S.F05", "DEM.S.F02" + "DEM.S" ] return pics def steps_TC_DEM_2_10(self) -> list[TestStep]: """Execute the test steps.""" steps = [ - TestStep("1", "Commission DUT to TH"), - TestStep("2", "TH reads from the DUT the Featuremap attribute", - "Verify that the DUT response contains the Featuremap attribute. Verify ForecastAdjustment and StateForecastReporting is supported. Verify PowerForecastReporting is not supported."), + TestStep("1", "Commission DUT to TH (can be skipped if done in a preceding test)"), + TestStep("2", "TH reads from the DUT the FeatureMap attribute", + "Verify that the DUT response contains the FeatureMap attribute. Store the value as FeatureMap."), TestStep("3", "TH reads TestEventTriggersEnabled attribute from General Diagnostics Cluster", "Value has to be 1 (True)"), - TestStep("4", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TESTEVENT_TRIGGERKEY and EventTrigger field set to PIXIT.DEM.TESTEVENTTRIGGER for Forecast Adjustment Test Event", + TestStep("4", "Set up a subscription to the DeviceEnergyManagement cluster, with MinIntervalFloor set to 0, MaxIntervalCeiling set to 10 and KeepSubscriptions set to false", + "Subscription successfully established"), + TestStep("5", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TESTEVENT_TRIGGERKEY and EventTrigger field set to PIXIT.DEM.TESTEVENTTRIGGER for User Opt-out Test Event Clear", "Verify DUT responds w/ status SUCCESS(0x00)"), - TestStep("4a", "TH reads from the DUT the ESAState", - "Value has to be 0x01 (Online)"), - TestStep("4b", "TH reads from the DUT the Forecast", - "Value has to include slots[0].MinDurationAdjustment, slots[0].MaxDurationAdjustment"), - TestStep("4c", "TH reads from the DUT the OptOutState", + TestStep("5a", "TH reads from the DUT the OptOutState", "Value has to be 0x00 (NoOptOut)"), - TestStep("5", "Set up a subscription to the Forecast attribute, with MinIntervalFloor set to 0, MaxIntervalCeiling set to 10 and KeepSubscriptions set to false", - "Subscription successfully established"), - TestStep("6", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TESTEVENT_TRIGGERKEY and EventTrigger field set to PIXIT.DEM.TESTEVENTTRIGGER for User Opt-out Local Optimization Test Event", + TestStep("6", "If {PICS_S_FA} {featIsNotSupported} skip to step 14", + "Value has to be 0x00 (NoOptOut)"), + + TestStep("7", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TESTEVENT_TRIGGERKEY and EventTrigger field set to PIXIT.DEM.TESTEVENTTRIGGER for Forecast Adjustment Test Event", "Verify DUT responds w/ status SUCCESS(0x00)"), - TestStep("6a", "TH reads from the DUT the ESAState", + TestStep("7a", "TH reads from the DUT the ESAState", "Value has to be 0x01 (Online)"), - TestStep("6b", "TH reads from the DUT the OptOutState", - "Value has to be 0x02 (LocalOptOut)"), - TestStep("7", "TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, Duration=Forecast.Slots[0].MinDurationAdjustment}, Cause=GridOptimization", + TestStep("8", "Reset all accumulated report counts, then wait 12 seconds"), + TestStep("9", "TH counts all report transactions with an attribute report for the Forecast attribute", + "TH verifies that numberOfReportsReceived \<= 2"), + TestStep("10", "TH reads from the DUT the Forecast", + "Value has to include slots[0].MinDurationAdjustment, slots[0].MaxDurationAdjustment"), + TestStep("11", "TH sends command ModifyForecastRequest... TODO", "Verify DUT responds w/ status SUCCESS(0x00)"), - TestStep("8", "TH counts all report transactions with an attribute report for the Forecast attribute over the next Forecast.Slots[0].MinDurationAdjustment}", - "TH verifies that numberOfReportsReceived <= 2 + Forecast.Slots[0].MinDurationAdjustment}"), - TestStep("9", "Cancel the subscription to the Forecast attribute", - "The subscription is cancelled successfully"), - TestStep("10", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TESTEVENT_TRIGGERKEY and EventTrigger field set to PIXIT.DEM.TESTEVENTTRIGGER for Forecast Adjustment Test Event Clear", + + TestStep("12", "TH resets all accumulated report counts, then TH sends command CancelRequest//// TODO"), + + TestStep("13", "Wait 5 seconds"), + + TestStep("13a", "TH counts all report transactions with an attribute report for the Forecast attribute_", + "TH verifies that numberOfReportsReceived >= 1 and Value has to include ForecastUpdateReason=InternalOptimization in the last attribute report received."), + + TestStep("14", "Clear forecast trigger --- TODO"), + TestStep("15", "If {PICS_S_PA} {featIsNotSupported} skip to step 22 - TODO", ""), + TestStep("16", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TESTEVENT_TRIGGERKEY and EventTrigger field set to PIXIT.DEM.TESTEVENTTRIGGER for Power Adjustment Test Event", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("16b", "TH reads from the DUT the PowerAdjustmentCapability", + "Value has to include Cause=NoAdjustment."), + TestStep("17", "TH resets all accumulated report counts, then TH sends command PowerAdjustRequest with Power=PowerAdjustmentCapability[0].MaxPower, Duration=20, Cause=LocalOptimization", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("18", "Wait 12 seconds"), + TestStep("18a", "TH counts all report transactions with an attribute report for the PowerAdjustmentCapability attribute", + "TH verifies that numberOfReportsReceived \<= 2"), + TestStep("19", "TH resets all accumulated report counts, then TH sends command CancelPowerAdjustment", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("20", "Wait 5 seconds"), + TestStep("20a", "TH counts all report transactions with an attribute report for the PowerAdjustmentCapability attribute", + "TH verifies that numberOfReportsReceived >=1"), + + TestStep("21", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TESTEVENT_TRIGGERKEY and EventTrigger field set to PIXIT.DEM.TESTEVENTTRIGGER for Power Adjustment Test Event Clear", "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("22", "Cancel the subscription to the Device Energy Management cluster", + "The subscription is cancelled successfully"), ] return steps - @async_test_body + @ async_test_body async def test_TC_DEM_2_10(self): # pylint: disable=too-many-locals, too-many-statements """Run the test steps.""" @@ -102,58 +127,174 @@ async def test_TC_DEM_2_10(self): # Commission DUT - already done self.step("2") - await self.validate_feature_map([Clusters.DeviceEnergyManagement.Bitmaps.Feature.kForecastAdjustment, - Clusters.DeviceEnergyManagement.Bitmaps.Feature.kStateForecastReporting], - [Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerForecastReporting]) + feature_map = await self.read_dem_attribute_expect_success(attribute="FeatureMap") + logger.info(f"FeatureMap: {feature_map}") + + has_pfr = feature_map & Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerForecastReporting + has_sfr = feature_map & Clusters.DeviceEnergyManagement.Bitmaps.Feature.kStateForecastReporting + has_pa = feature_map & Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerAdjustment + has_sta = feature_map & Clusters.DeviceEnergyManagement.Bitmaps.Feature.kStartTimeAdjustment + has_pau = feature_map & Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPausable + has_fa = feature_map & Clusters.DeviceEnergyManagement.Bitmaps.Feature.kForecastAdjustment + has_con = feature_map & Clusters.DeviceEnergyManagement.Bitmaps.Feature.kConstraintBasedAdjustment + has_any_forecast_adjustment = has_sta | has_pau | has_fa | has_con + if has_any_forecast_adjustment: + # check it has pfr or sfr (one not both) + asserts.assert_false(has_pfr and has_sfr, "Not allowed to have both PFR and SFR features enabled!") + asserts.assert_true(has_pfr or has_sfr, "Must have either PFR or SFR with a forecast adjustment feature") + + if has_pa: + asserts.assert_true(has_pfr, "Since PowerAdjustment is supported, PFR should be used, not SFR") self.step("3") await self.check_test_event_triggers_enabled() self.step("4") - await self.send_test_event_trigger_forecast_adjustment() + sub_handler = ClusterAttributeChangeAccumulator(Clusters.DeviceEnergyManagement) + await sub_handler.start(self.default_controller, self.dut_node_id, + self.matter_test_config.endpoint, + min_interval_sec=0, + max_interval_sec=10, keepSubscriptions=False) - self.step("4a") - await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kOnline) + def accumulate_reports(wait_time): + logging.info(f"Test will now wait {wait_time} seconds to accumulate reports") + time.sleep(wait_time) - self.step("4b") - forecast = await self.read_dem_attribute_expect_success(attribute="Forecast") - asserts.assert_is_not_none(forecast.slots[0].minDurationAdjustment) - asserts.assert_is_not_none(forecast.slots[0].maxDurationAdjustment) + self.step("5") + await self.send_test_event_trigger_user_opt_out_clear_all() - self.step("4c") + self.step("5a") await self.check_dem_attribute("OptOutState", Clusters.DeviceEnergyManagement.Enums.OptOutStateEnum.kNoOptOut) - self.step("5") - sub_handler = ClusterAttributeChangeAccumulator(Clusters.DeviceEnergyManagement) - await sub_handler.start(self.default_controller, self.dut_node_id, self.matter_test_config.endpoint, keepSubscriptions=False) - sub_handler.reset() - self.step("6") - await self.send_test_event_trigger_user_opt_out_local() + if not has_fa: + self.skip_step("7") + self.skip_step("7a") + self.skip_step("8") + self.skip_step("9") + self.skip_step("10") + self.skip_step("11") + self.skip_step("12") + self.skip_step("13") + self.skip_step("13a") + self.skip_step("14") + else: + self.step("7") + await self.send_test_event_trigger_forecast_adjustment() - self.step("6a") - await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kOnline) + self.step("7a") + await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kOnline) - self.step("6b") - await self.check_dem_attribute("OptOutState", Clusters.DeviceEnergyManagement.Enums.OptOutStateEnum.kLocalOptOut) + self.step("8") + wait = 12 # Wait 12 seconds - the spec says we should only get reports every 10s at most, unless a command changes it + sub_handler.reset() + accumulate_reports(wait) - self.step("7") - slotAdjustments = [Clusters.DeviceEnergyManagement.Structs.SlotAdjustmentStruct( - slotIndex=0, duration=forecast.slots[0].minDurationAdjustment)] - await self.send_modify_forecast_request_command(forecast.forecastID, slotAdjustments, Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kGridOptimization, expected_status=Status.Success) + self.step("9") + count = sub_handler.attribute_report_counts[Clusters.DeviceEnergyManagement.Attributes.Forecast] + logging.info(f"Received {count} Forecast updates in {wait} seconds") + asserts.assert_less_equal(count, 2, f"Expected <= 2 Forecast updates in {wait} seconds") - self.step("8") - time.sleep(forecast.slots[0].minDurationAdjustment) + self.step("10") + forecast = await self.read_dem_attribute_expect_success(attribute="Forecast") + asserts.assert_is_not_none(forecast.slots[0].minDurationAdjustment) + asserts.assert_is_not_none(forecast.slots[0].maxDurationAdjustment) - count = sub_handler.attribute_report_counts[Clusters.DeviceEnergyManagement.Attributes.Forecast] - logging.info(f"Number of Forecast updates {count}") - asserts.assert_less_equal(count, 10, "More than 10 reports received") + self.step("11") + if has_pfr: + # we include nominalPower + slotAdjustments = [Clusters.DeviceEnergyManagement.Structs.SlotAdjustmentStruct( + slotIndex=0, duration=forecast.slots[0].maxDurationAdjustment, + nominalPower=forecast.slots[0].minPowerAdjustment)] + else: + # SFR we don't provide nominalPower + slotAdjustments = [Clusters.DeviceEnergyManagement.Structs.SlotAdjustmentStruct( + slotIndex=0, duration=forecast.slots[0].maxDurationAdjustment)] + await self.send_modify_forecast_request_command(forecast.forecastID, slotAdjustments, Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kGridOptimization, expected_status=Status.Success) - self.step("9") - await sub_handler.cancel() + self.step("12") + sub_handler.reset() + await self.send_cancel_request_command() + + self.step("13") + wait = 5 # We expect a change to the forecast attribute after the cancel, Wait 5 seconds - allow time for the report to come in + accumulate_reports(wait) + + self.step("13a") + count = sub_handler.attribute_report_counts[Clusters.DeviceEnergyManagement.Attributes.Forecast] + logging.info(f"Received {count} Forecast updates in {wait} seconds") + asserts.assert_greater_equal(count, 1, "Expected >= 1 Forecast updates after a cancelled operation") + + self.step("14") + await self.send_test_event_trigger_forecast_adjustment_clear() + + self.step("15") + if not has_pa: + self.skip_step("16") + self.skip_step("16b") + self.skip_step("17") + self.skip_step("18") + self.skip_step("18a") + self.skip_step("19") + self.skip_step("20") + self.skip_step("20a") + self.skip_step("21") + else: + + self.step("16") + await self.send_test_event_trigger_power_adjustment() + + self.step("16b") + powerAdjustCapabilityStruct = await self.read_dem_attribute_expect_success(attribute="PowerAdjustmentCapability") + asserts.assert_greater_equal(len(powerAdjustCapabilityStruct.powerAdjustCapability), 1) + logging.info(powerAdjustCapabilityStruct) + asserts.assert_equal(powerAdjustCapabilityStruct.cause, + Clusters.DeviceEnergyManagement.Enums.PowerAdjustReasonEnum.kNoAdjustment) + + # we should expect powerAdjustCapabilityStruct to have multiple entries with different max powers, min powers, max and min durations + min_power = sys.maxsize + max_power = 0 - self.step("10") - await self.send_test_event_trigger_forecast_adjustment_clear() + for entry in powerAdjustCapabilityStruct.powerAdjustCapability: + min_power = min(min_power, entry.minPower) + max_power = max(max_power, entry.maxPower) + + result = f"min_power {min_power} max_power {max_power}" + logging.info(result) + + self.step("17") + sub_handler.reset() + await self.send_power_adjustment_command(power=powerAdjustCapabilityStruct.powerAdjustCapability[0].maxPower, + duration=20, + cause=Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization) + + self.step("18") + wait = 12 # Wait 12 seconds - the spec says we should only get reports every 10s at most, unless a command changes it + accumulate_reports(wait) + + self.step("18a") + count = sub_handler.attribute_report_counts[Clusters.DeviceEnergyManagement.Attributes.PowerAdjustmentCapability] + logging.info(f"Received {count} PowerAdjustmentCapability updates in {wait} seconds") + asserts.assert_less_equal(count, 2, f"Expected <= 2 PowerAdjustmentCapability updates in {wait} seconds") + + self.step("19") + sub_handler.reset() + await self.send_cancel_power_adjustment_command() + + self.step("20") + wait = 5 # We expect a change to the forecast attribute after the cancel, Wait 5 seconds - allow time for the report to come in + accumulate_reports(wait) + + self.step("20a") + count = sub_handler.attribute_report_counts[Clusters.DeviceEnergyManagement.Attributes.PowerAdjustmentCapability] + logging.info(f"Received {count} PowerAdjustmentCapability updates in {wait} seconds") + asserts.assert_greater_equal(count, 1, "Expected >= 1 PowerAdjustmentCapability updates after a cancelled operation") + + self.step("21") + await self.send_test_event_trigger_power_adjustment_clear() + + self.step("22") + await sub_handler.cancel() if __name__ == "__main__": From 81175d300d3b8dc8446cf59430ccaa61789c9b74 Mon Sep 17 00:00:00 2001 From: James Harrow Date: Thu, 29 Aug 2024 01:01:11 +0100 Subject: [PATCH 40/45] Fixed bug where PowerAdjustReason wasn't calling MatterReportingAttributeChangeCallback when reason was changing. --- .../DeviceEnergyManagementDelegateImpl.h | 1 + .../DeviceEnergyManagementDelegateImpl.cpp | 27 +++++++++++++------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/examples/energy-management-app/energy-management-common/device-energy-management/include/DeviceEnergyManagementDelegateImpl.h b/examples/energy-management-app/energy-management-common/device-energy-management/include/DeviceEnergyManagementDelegateImpl.h index e540d56e030058..eb2cedb2676b45 100644 --- a/examples/energy-management-app/energy-management-common/device-energy-management/include/DeviceEnergyManagementDelegateImpl.h +++ b/examples/energy-management-app/energy-management-common/device-energy-management/include/DeviceEnergyManagementDelegateImpl.h @@ -189,6 +189,7 @@ class DeviceEnergyManagementDelegate : public DeviceEnergyManagement::Delegate CHIP_ERROR SetAbsMinPower(int64_t); CHIP_ERROR SetAbsMaxPower(int64_t); CHIP_ERROR SetPowerAdjustmentCapability(const DataModel::Nullable &); + CHIP_ERROR SetPowerAdjustmentCapabilityPowerAdjustReason( const PowerAdjustReasonEnum ); // The DeviceEnergyManagementDelegate owns the master copy of the ForecastStruct object which is accessed via GetForecast and // SetForecast. The slots field of forecast is owned and managed by the object that implements the DEMManufacturerDelegate diff --git a/examples/energy-management-app/energy-management-common/device-energy-management/src/DeviceEnergyManagementDelegateImpl.cpp b/examples/energy-management-app/energy-management-common/device-energy-management/src/DeviceEnergyManagementDelegateImpl.cpp index 161ea2f77c0750..157b85d4773f5f 100644 --- a/examples/energy-management-app/energy-management-common/device-energy-management/src/DeviceEnergyManagementDelegateImpl.cpp +++ b/examples/energy-management-app/energy-management-common/device-energy-management/src/DeviceEnergyManagementDelegateImpl.cpp @@ -120,11 +120,11 @@ Status DeviceEnergyManagementDelegate::PowerAdjustRequest(const int64_t powerMw, switch (cause) { case AdjustmentCauseEnum::kLocalOptimization: - mPowerAdjustCapabilityStruct.Value().cause = PowerAdjustReasonEnum::kLocalOptimizationAdjustment; + SetPowerAdjustmentCapabilityPowerAdjustReason(PowerAdjustReasonEnum::kLocalOptimizationAdjustment); break; case AdjustmentCauseEnum::kGridOptimization: - mPowerAdjustCapabilityStruct.Value().cause = PowerAdjustReasonEnum::kGridOptimizationAdjustment; + SetPowerAdjustmentCapabilityPowerAdjustReason(PowerAdjustReasonEnum::kGridOptimizationAdjustment); break; default: @@ -175,7 +175,7 @@ void DeviceEnergyManagementDelegate::HandlePowerAdjustRequestFailure() mPowerAdjustmentInProgress = false; - mPowerAdjustCapabilityStruct.Value().cause = PowerAdjustReasonEnum::kNoAdjustment; + SetPowerAdjustmentCapabilityPowerAdjustReason(PowerAdjustReasonEnum::kNoAdjustment); // TODO // Should we inform the mpDEMManufacturerDelegate that PowerAdjustRequest has failed? @@ -210,7 +210,7 @@ void DeviceEnergyManagementDelegate::HandlePowerAdjustTimerExpiry() SetESAState(ESAStateEnum::kOnline); - mPowerAdjustCapabilityStruct.Value().cause = PowerAdjustReasonEnum::kNoAdjustment; + SetPowerAdjustmentCapabilityPowerAdjustReason(PowerAdjustReasonEnum::kNoAdjustment); // Generate a PowerAdjustEnd event GeneratePowerAdjustEndEvent(CauseEnum::kNormalCompletion); @@ -264,8 +264,7 @@ CHIP_ERROR DeviceEnergyManagementDelegate::CancelPowerAdjustRequestAndGenerateEv SetESAState(ESAStateEnum::kOnline); mPowerAdjustmentInProgress = false; - - mPowerAdjustCapabilityStruct.Value().cause = PowerAdjustReasonEnum::kNoAdjustment; + SetPowerAdjustmentCapabilityPowerAdjustReason(PowerAdjustReasonEnum::kNoAdjustment); CHIP_ERROR err = GeneratePowerAdjustEndEvent(cause); @@ -922,6 +921,18 @@ DeviceEnergyManagementDelegate::SetPowerAdjustmentCapability( return CHIP_NO_ERROR; } +CHIP_ERROR +DeviceEnergyManagementDelegate::SetPowerAdjustmentCapabilityPowerAdjustReason(PowerAdjustReasonEnum powerAdjustReason) +{ + assertChipStackLockedByCurrentThread(); + + mPowerAdjustCapabilityStruct.Value().cause = powerAdjustReason; + + MatterReportingAttributeChangeCallback(mEndpointId, DeviceEnergyManagement::Id, PowerAdjustmentCapability::Id); + + return CHIP_NO_ERROR; +} + CHIP_ERROR DeviceEnergyManagementDelegate::SetForecast(const DataModel::Nullable & forecast) { assertChipStackLockedByCurrentThread(); @@ -962,9 +973,9 @@ CHIP_ERROR DeviceEnergyManagementDelegate::SetOptOutState(OptOutStateEnum newVal if (mPowerAdjustmentInProgress) { if ((newValue == OptOutStateEnum::kLocalOptOut && - mPowerAdjustCapabilityStruct.Value().cause == PowerAdjustReasonEnum::kLocalOptimizationAdjustment) || + GetPowerAdjustmentCapability().Value().cause == PowerAdjustReasonEnum::kLocalOptimizationAdjustment) || (newValue == OptOutStateEnum::kGridOptOut && - mPowerAdjustCapabilityStruct.Value().cause == PowerAdjustReasonEnum::kGridOptimizationAdjustment) || + GetPowerAdjustmentCapability().Value().cause == PowerAdjustReasonEnum::kGridOptimizationAdjustment) || newValue == OptOutStateEnum::kOptOut) { err = CancelPowerAdjustRequestAndGenerateEvent(DeviceEnergyManagement::CauseEnum::kUserOptOut); From 91e017a988ca02ff4f8935d4ad0133bf0b2915ef Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 29 Aug 2024 00:02:03 +0000 Subject: [PATCH 41/45] Restyled by clang-format --- .../include/DeviceEnergyManagementDelegateImpl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/energy-management-app/energy-management-common/device-energy-management/include/DeviceEnergyManagementDelegateImpl.h b/examples/energy-management-app/energy-management-common/device-energy-management/include/DeviceEnergyManagementDelegateImpl.h index eb2cedb2676b45..da563910f749c7 100644 --- a/examples/energy-management-app/energy-management-common/device-energy-management/include/DeviceEnergyManagementDelegateImpl.h +++ b/examples/energy-management-app/energy-management-common/device-energy-management/include/DeviceEnergyManagementDelegateImpl.h @@ -189,7 +189,7 @@ class DeviceEnergyManagementDelegate : public DeviceEnergyManagement::Delegate CHIP_ERROR SetAbsMinPower(int64_t); CHIP_ERROR SetAbsMaxPower(int64_t); CHIP_ERROR SetPowerAdjustmentCapability(const DataModel::Nullable &); - CHIP_ERROR SetPowerAdjustmentCapabilityPowerAdjustReason( const PowerAdjustReasonEnum ); + CHIP_ERROR SetPowerAdjustmentCapabilityPowerAdjustReason(const PowerAdjustReasonEnum); // The DeviceEnergyManagementDelegate owns the master copy of the ForecastStruct object which is accessed via GetForecast and // SetForecast. The slots field of forecast is owned and managed by the object that implements the DEMManufacturerDelegate From 5236180efb0fb9ab1c2752cd2fc9520e148e4066 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 29 Aug 2024 00:02:08 +0000 Subject: [PATCH 42/45] Restyled by autopep8 --- src/python_testing/matter_testing_support.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/python_testing/matter_testing_support.py b/src/python_testing/matter_testing_support.py index f963a63536f9b1..39c0d7dc5a4f15 100644 --- a/src/python_testing/matter_testing_support.py +++ b/src/python_testing/matter_testing_support.py @@ -443,7 +443,6 @@ async def cancel(self): except asyncio.CancelledError: pass - def __call__(self, path: TypedAttributePath, transaction: SubscriptionTransaction): """This is the subscription callback when an attribute report is received. It checks the report is from the expected_cluster and then posts it into the queue for later processing.""" From 4307db7dbb34fe5a68d794fdb8ca4c919213e52b Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 29 Aug 2024 00:02:08 +0000 Subject: [PATCH 43/45] Restyled by isort --- src/python_testing/TC_DEM_2_10.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python_testing/TC_DEM_2_10.py b/src/python_testing/TC_DEM_2_10.py index f7293030918791..afbb2f5845ab60 100644 --- a/src/python_testing/TC_DEM_2_10.py +++ b/src/python_testing/TC_DEM_2_10.py @@ -31,8 +31,8 @@ import logging -import time import sys +import time import chip.clusters as Clusters from chip.interaction_model import Status From 50085bed18de06438ef9917e19fc50f7b4901a5f Mon Sep 17 00:00:00 2001 From: James Harrow Date: Thu, 29 Aug 2024 09:58:32 +0100 Subject: [PATCH 44/45] Autogen'd the TestSteps from latest test plan --- src/python_testing/TC_DEM_2_10.py | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/src/python_testing/TC_DEM_2_10.py b/src/python_testing/TC_DEM_2_10.py index afbb2f5845ab60..eda4d977737586 100644 --- a/src/python_testing/TC_DEM_2_10.py +++ b/src/python_testing/TC_DEM_2_10.py @@ -62,7 +62,7 @@ def steps_TC_DEM_2_10(self) -> list[TestStep]: """Execute the test steps.""" steps = [ TestStep("1", "Commission DUT to TH (can be skipped if done in a preceding test)"), - TestStep("2", "TH reads from the DUT the FeatureMap attribute", + TestStep("2", "TH reads from the DUT the FeatureMap", "Verify that the DUT response contains the FeatureMap attribute. Store the value as FeatureMap."), TestStep("3", "TH reads TestEventTriggersEnabled attribute from General Diagnostics Cluster", "Value has to be 1 (True)"), @@ -72,30 +72,26 @@ def steps_TC_DEM_2_10(self) -> list[TestStep]: "Verify DUT responds w/ status SUCCESS(0x00)"), TestStep("5a", "TH reads from the DUT the OptOutState", "Value has to be 0x00 (NoOptOut)"), - TestStep("6", "If {PICS_S_FA} {featIsNotSupported} skip to step 14", - "Value has to be 0x00 (NoOptOut)"), - + TestStep("6", "If ForecastAdjustment feature is not supported on the cluster skip steps 7 to 14"), TestStep("7", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TESTEVENT_TRIGGERKEY and EventTrigger field set to PIXIT.DEM.TESTEVENTTRIGGER for Forecast Adjustment Test Event", "Verify DUT responds w/ status SUCCESS(0x00)"), TestStep("7a", "TH reads from the DUT the ESAState", "Value has to be 0x01 (Online)"), TestStep("8", "Reset all accumulated report counts, then wait 12 seconds"), TestStep("9", "TH counts all report transactions with an attribute report for the Forecast attribute", - "TH verifies that numberOfReportsReceived \<= 2"), + "TH verifies that numberOfReportsReceived <= 2"), TestStep("10", "TH reads from the DUT the Forecast", "Value has to include slots[0].MinDurationAdjustment, slots[0].MaxDurationAdjustment"), - TestStep("11", "TH sends command ModifyForecastRequest... TODO", + TestStep("11", "If PowerForecastReporting feature is supported on the cluster TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, Duration=Forecast.Slots[0].MaxDurationAdjustment, NominalPower=forecast.slots[0].minPowerAdjustment}, Cause=GridOptimization, else StateForecastReporting shall be used, omit the NominalPower: TH sends command ModifyForecastRequest with ForecastID=Forecast.ForecastID, SlotAdjustments[0].{SlotIndex=0, Duration=Forecast.Slots[0].MaxDurationAdjustment}, Cause=GridOptimization", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("12", "TH resets all accumulated report counts, then TH sends command CancelRequest", "Verify DUT responds w/ status SUCCESS(0x00)"), - - TestStep("12", "TH resets all accumulated report counts, then TH sends command CancelRequest//// TODO"), - TestStep("13", "Wait 5 seconds"), - - TestStep("13a", "TH counts all report transactions with an attribute report for the Forecast attribute_", - "TH verifies that numberOfReportsReceived >= 1 and Value has to include ForecastUpdateReason=InternalOptimization in the last attribute report received."), - - TestStep("14", "Clear forecast trigger --- TODO"), - TestStep("15", "If {PICS_S_PA} {featIsNotSupported} skip to step 22 - TODO", ""), + TestStep("13a", "TH counts all report transactions with an attribute report for the Forecast attribute", + "TH verifies that numberOfReportsReceived >= 1"), + TestStep("14", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TESTEVENT_TRIGGERKEY and EventTrigger field set to PIXIT.DEM.TESTEVENTTRIGGER for Forecast Adjustment Test Event Clear", + "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep("15", "If PowerAdjustment feature is not supported on the cluster skip steps 16 to 21"), TestStep("16", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TESTEVENT_TRIGGERKEY and EventTrigger field set to PIXIT.DEM.TESTEVENTTRIGGER for Power Adjustment Test Event", "Verify DUT responds w/ status SUCCESS(0x00)"), TestStep("16b", "TH reads from the DUT the PowerAdjustmentCapability", @@ -104,13 +100,12 @@ def steps_TC_DEM_2_10(self) -> list[TestStep]: "Verify DUT responds w/ status SUCCESS(0x00)"), TestStep("18", "Wait 12 seconds"), TestStep("18a", "TH counts all report transactions with an attribute report for the PowerAdjustmentCapability attribute", - "TH verifies that numberOfReportsReceived \<= 2"), + "TH verifies that numberOfReportsReceived <= 2"), TestStep("19", "TH resets all accumulated report counts, then TH sends command CancelPowerAdjustment", "Verify DUT responds w/ status SUCCESS(0x00)"), TestStep("20", "Wait 5 seconds"), TestStep("20a", "TH counts all report transactions with an attribute report for the PowerAdjustmentCapability attribute", "TH verifies that numberOfReportsReceived >=1"), - TestStep("21", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TESTEVENT_TRIGGERKEY and EventTrigger field set to PIXIT.DEM.TESTEVENTTRIGGER for Power Adjustment Test Event Clear", "Verify DUT responds w/ status SUCCESS(0x00)"), TestStep("22", "Cancel the subscription to the Device Energy Management cluster", From ce885c774df7625d5d6cc42774d8857a854531bf Mon Sep 17 00:00:00 2001 From: James Harrow Date: Thu, 29 Aug 2024 10:58:15 +0100 Subject: [PATCH 45/45] Changed featureSet to 0x7b to enable PA, PFR, FA (plus other) features --- src/python_testing/TC_DEM_2_10.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python_testing/TC_DEM_2_10.py b/src/python_testing/TC_DEM_2_10.py index eda4d977737586..eb983a16e07401 100644 --- a/src/python_testing/TC_DEM_2_10.py +++ b/src/python_testing/TC_DEM_2_10.py @@ -23,7 +23,7 @@ # test-runner-run/run1/app: ${ENERGY_MANAGEMENT_APP} # test-runner-run/run1/factoryreset: True # test-runner-run/run1/quiet: True -# test-runner-run/run1/app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json --enable-key 000102030405060708090a0b0c0d0e0f --featureSet 0x7c +# test-runner-run/run1/app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json --enable-key 000102030405060708090a0b0c0d0e0f --featureSet 0x7b # test-runner-run/run1/script-args: --storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --hex-arg enableKey:000102030405060708090a0b0c0d0e0f --endpoint 1 --trace-to json:${TRACE_TEST_JSON}.json --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto # === END CI TEST ARGUMENTS ===